<commit_before>﻿using System;
using System.Collections;
using System.Linq;
using Assets.Core.Configuration;
using Assets.Core.InteractableObjects;
using Assets.Core.NavMesh;
using UnityEngine;

namespace Assets.Characters.AiScripts.States
{
    public class InteractWithNearestState : IState
    {
        private readonly NavMeshAgent _agent;
        private readonly IInteractable _intaractableGoal;
        private float _waitUntill;
        private State _state;
        private Vector2 _interactGoalPosition;
        private CharacterAnimMovement cam;

        private GameObject _interactGameObject;
        
        public InteractWithNearestState(NavMeshAgent agnet, string tag, GameObject pickup)
        {
            _agent = agnet;

            cam = _agent.gameObject.GetComponent<CharacterAnimMovement>();

            _interactGameObject = pickup;

            var interactables = GameObject.FindGameObjectsWithTag(tag);
            if(interactables.Length < 1)
                return;
            
            foreach (var i in interactables)
            {
                var dest = i.GetComponent<IInteractable>();
                if(!dest.CanThisBeInteractedWith(pickup)) continue;
                var path = new NavMeshPath();
                agnet.CalculatePath(dest.InteractPosition(_agent.transform.position), path);

                if (path.status != NavMeshPathStatus.PathComplete) continue;

                _intaractableGoal = dest;
                break;
            }

            if(_intaractableGoal == null)
                _state = State.Done;
        }

        public InteractWithNearestState(NavMeshAgent agent, GameObject goal)
        {
            
            _agent = agent;
            cam = _agent.gameObject.GetComponent<CharacterAnimMovement>();
            _intaractableGoal = goal.GetComponent<IInteractable>();
            _interactGameObject = goal;
        }

        public float WaitingTime { get; set; }

        public void ExecuteState()
        {
            switch (_state)
            {
                case State.Neutral:
                    var pos = _intaractableGoal.InteractPosition(_agent.transform.position);
                    _interactGoalPosition = new Vector2(pos.x, pos.z);
                    _agent.SetDestination(pos);
                    _state = State.GoToIntactable;
                    return;
                case State.GoToIntactable:
                    if (_agent.HasReachedTarget())
                    {
                        _agent.ResetPath();

                        if (_agent.enabled)
                        {
                            cam.StartAdjustPosition(_interactGameObject);
                        }

                        if (_agent.updateRotation)
                        {
                            var t = Vector2.Distance(_interactGoalPosition,
                                new Vector2(_agent.transform.position.x, _agent.transform.position.z));
                            _state = t < .6 ? State.Interact : State.Done;
                        }
                    }
                    return;
                case State.Interact:
                    var puh = _agent.gameObject.GetComponent<PickupHandler>();
                    var returnItem = _intaractableGoal.Interact(puh.CurrentPickup);
                    puh.PickUpItem(returnItem);

                    if (_interactGameObject.tag == Constants.Tags.Lever)
                    {
                        _agent.gameObject.GetComponent<Animator>().SetTrigger("PullLever");
                    }
                    else if (_interactGameObject.tag == Constants.Tags.Brazier)
                    {
                        _agent.gameObject.GetComponent<Animator>().SetTrigger("LightFire");
                    }
                    else
                    {
                        _agent.gameObject.GetComponent<Animator>().SetTrigger("PickUp");
                    }
                    _waitUntill = Time.time + WaitingTime;
                    _state = State.WaitSomeTime;
                    return;
                case State.WaitSomeTime:
                    if (_waitUntill < Time.time)
                        _state = State.Done;
                    return;
                default:
                    return;
            }
        }

        public bool IsDoneExecuting()
        {
            return _state == State.Done;
        }<commit_msg>Commented out my bad code<commit_after>﻿using System;
using System.Collections;
using System.Linq;
using Assets.Core.Configuration;
using Assets.Core.InteractableObjects;
using Assets.Core.NavMesh;
using UnityEngine;

namespace Assets.Characters.AiScripts.States
{
    public class InteractWithNearestState : IState
    {
        private readonly NavMeshAgent _agent;
        private readonly IInteractable _intaractableGoal;
        private float _waitUntill;
        private State _state;
        private Vector2 _interactGoalPosition;
        private CharacterAnimMovement cam;

        private GameObject _interactGameObject;
        
        public InteractWithNearestState(NavMeshAgent agnet, string tag, GameObject pickup)
        {
            _agent = agnet;

            cam = _agent.gameObject.GetComponent<CharacterAnimMovement>();

            _interactGameObject = pickup;

            var interactables = GameObject.FindGameObjectsWithTag(tag);
            if(interactables.Length < 1)
                return;
            
            foreach (var i in interactables)
            {
                var dest = i.GetComponent<IInteractable>();
                if(!dest.CanThisBeInteractedWith(pickup)) continue;
                var path = new NavMeshPath();
                agnet.CalculatePath(dest.InteractPosition(_agent.transform.position), path);

                if (path.status != NavMeshPathStatus.PathComplete) continue;

                _intaractableGoal = dest;
                break;
            }

            if(_intaractableGoal == null)
                _state = State.Done;
        }

        public InteractWithNearestState(NavMeshAgent agent, GameObject goal)
        {
            
            _agent = agent;
            cam = _agent.gameObject.GetComponent<CharacterAnimMovement>();
            _intaractableGoal = goal.GetComponent<IInteractable>();
            _interactGameObject = goal;
        }

        public float WaitingTime { get; set; }

        public void ExecuteState()
        {
            switch (_state)
            {
                case State.Neutral:
                    var pos = _intaractableGoal.InteractPosition(_agent.transform.position);
                    _interactGoalPosition = new Vector2(pos.x, pos.z);
                    _agent.SetDestination(pos);
                    _state = State.GoToIntactable;
                    return;
                case State.GoToIntactable:
                    if (_agent.HasReachedTarget())
                    {
                        _agent.ResetPath();

                        if (_agent.enabled)
                        {
                           // cam.StartAdjustPosition(_interactGameObject);
                        }

                        if (_agent.updateRotation)
                        {
                            var t = Vector2.Distance(_interactGoalPosition,
                                new Vector2(_agent.transform.position.x, _agent.transform.position.z));
                            _state = t < .6 ? State.Interact : State.Done;
                        }
                    }
                    return;
                case State.Interact:
                    var puh = _agent.gameObject.GetComponent<PickupHandler>();
                    var returnItem = _intaractableGoal.Interact(puh.CurrentPickup);
                    puh.PickUpItem(returnItem);

                 //   if (_interactGameObject.tag == Constants.Tags.Lever)
                 //   {
                        _agent.gameObject.GetComponent<Animator>().SetTrigger("PullLever");
                 //   }
                    //else if (_interactGameObject.tag == Constants.Tags.Brazier)
                    //{
                    //    _agent.gameObject.GetComponent<Animator>().SetTrigger("LightFire");
                    //}
                    //else
                    //{
                    //    _agent.gameObject.GetComponent<Animator>().SetTrigger("PickUp");
                    //}
                    _waitUntill = Time.time + WaitingTime;
                    _state = State.WaitSomeTime;
                    return;
                case State.WaitSomeTime:
                    if (_waitUntill < Time.time)
                        _state = State.Done;
                    return;
                default:
                    return;
            }
        }

        public bool IsDoneExecuting()
        {
            return _state == State.Done;
        }
{'fraction_non_alphanumeric': 0.07550561797752808, 'fraction_numerical': 0.001348314606741573, 'mean_word_length': 1.3319360754519256, 'pattern_counts': {'":': 0, '<': 25, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '136787', 'n_tokens_mistral': 2250, 'n_tokens_neox': 2099, 'n_words': 382}