using Assets.Scripts.Actions; using Assets.Scripts.Actions.Interfaces; using UnityEngine; using UnityEngine.AI; public class PlayerManager : MonoBehaviour { private enum States { Idle, Walking, Sleeping }; public Stat money = new Stat("Money", 100.0f); public Stat rentAccount = new Stat("Rent Account", 0); public Stat food = new Stat("Food Energy", 100); public Stat energy = new Stat("Energy", 100); // bank public Stat bankAccount = new Stat("Bank Account", 0); // jobs public Stat job = new Stat("Unemployed", 0); // Knowledge for University Jobs public Stat literatureKnowledge = new Stat("LiteratureKnowledge", 0); public Stat mathematicsKnowledge = new Stat("MathematicsKnowledge", 0); public Stat computerScienceKnowledge = new Stat("ComputerScienceKnowledge", 0); // Knowledge for Factory Jobs public Stat electronicsKnowledge = new Stat("ElectronicsKnowledge", 0); public Stat roboticsKnowledge = new Stat("RoboticsKnowledge", 0); public Stat industrialDesignKnowledge = new Stat("IndustrialDesignKnowledge", 0); public Stat careerPoints = new Stat("careerPoints", 0); // Achievements - to WIN the game public Stat whealthAchievement = new Stat("whealthAchievement", 999999); public Stat educationAchievement = new Stat("educationAchievement", 999999); public Stat careerAchievement = new Stat("careerAchievement", 999999); public Stat happinessAchievement = new Stat("happinessAchievement", 999999); // Inventory items public Stat freezerItem = new Stat("Freezer Item", 400, 1); public Stat clothesItem = new Stat("Clothes Item", 200, 3); public Stat booksItem = new Stat("Books Item", 150, 2); public Stat tvItem = new Stat("Tv Item", 1500, 1); public Stat laptopItem = new Stat("Laptop Item", 3000, 1); [SerializeField] public NavMeshAgent _navAgent; [SerializeField] public Animator _animator; [SerializeField] private Camera _camera; [SerializeField] public ParticleSystem _targetDest; public bool allowMovement = true; private States _state; private Vector3 _groundDeltaPosition; private void OnEnable() { TimeManager.OnMinuteChanged += DecreaseEnergy; } private void OnDisable() { TimeManager.OnMinuteChanged -= DecreaseEnergy; } // Start is called before the first frame update void Start() { allowMovement = true; _navAgent.updatePosition = false; } // Update is called once per frame void Update() { if (allowMovement) { if (Input.GetMouseButton(0)) { _targetDest.Stop(); if (Physics.Raycast(_camera.ScreenPointToRay(Input.mousePosition), out RaycastHit hit, 100)) { var pos = hit.point; pos.y += 0.2f; _targetDest.transform.position = pos; _navAgent.SetDestination(pos); _targetDest.Play(); } } } var worldDeltaPosition=_navAgent.nextPosition- transform.position; _groundDeltaPosition.x=Vector3.Dot(transform.right, worldDeltaPosition); _groundDeltaPosition.y = Vector3.Dot(transform.forward, worldDeltaPosition); Vector2 velocity = (Time.deltaTime > 1e-5f) ? _groundDeltaPosition / Time.deltaTime : Vector2.zero; var shouldMove = velocity.magnitude > 0.025f && _navAgent.remainingDistance > _navAgent.radius; _state = shouldMove ? States.Walking : States.Idle; _animator.SetBool("Move", shouldMove); _animator.SetFloat("velY", velocity.y); } private void OnAnimatorMove() { transform.position = _navAgent.nextPosition; } public void DecreaseEnergy() { food.deduct(0.034f); // 48 hours it's 100, 100/2880=~0.034 per minute switch (_state) { case States.Idle: case States.Walking: energy.deduct(0.1f); // 24 hours it's 100, 100/1440=~0.096 per minute break; case States.Sleeping: energy.increase(1f); break; } if (energy.Value <= 10 && _state != States.Sleeping) { _state = States.Sleeping; allowMovement = false; _animator.SetBool("IsSleeping", true); } if (energy.Value >= 100 && _state == States.Sleeping) { _state = States.Idle; allowMovement = false; _animator.SetBool("IsSleeping", false); } } public bool TryBuyAction(BaseAction action) { if (action is ISellableItem) { if (!money.deduct(((ISellableItem)action).Price)) return false; } action.ApplyAction(this); return true; } }