Files
SimUL/Assets/Scripts/PlayerManager.cs
T
Vladimir Koshevarov c8047bd170 Fix shop System
add food indicator
2022-11-17 17:24:00 +02:00

115 lines
3.6 KiB
C#

using Assets.Scripts.Actions;
using Assets.Scripts.Actions.Interfaces;
using UnityEngine;
using UnityEngine.AI;
public class PlayerManager : MonoBehaviour
{
public Stat money = new Stat("Money", 1000.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);
public NavMeshAgent player;
public Animator playerAnimator;
public Camera playerCamera;
public ParticleSystem targetDest;
public bool allowMovement = true;
private void OnEnable()
{
TimeManager.OnMinuteChanged += DecreaseEnergy;
}
private void OnDisable()
{
TimeManager.OnMinuteChanged -= DecreaseEnergy;
}
// Start is called before the first frame update
void Start()
{
allowMovement = true;
}
// Update is called once per frame
void Update()
{
if (allowMovement)
{
if (Input.GetMouseButton(0))
{
Ray myRay = playerCamera.ScreenPointToRay(Input.mousePosition);
if (Physics.Raycast(myRay, out RaycastHit hit))
{
targetDest.transform.position = hit.point;
targetDest.Play();
player.SetDestination(hit.point);
}
}
}
else
{
player.SetDestination(player.transform.position);
player.velocity = Vector3.zero;
}
if (player.velocity != Vector3.zero)
{
playerAnimator.SetBool("IsWalking", true);
}
else if (player.velocity == Vector3.zero)
{
playerAnimator.SetBool("IsWalking", false);
}
}
public void DecreaseEnergy()
{
food.deduct(1f);
energy.deduct(0.096f); // 24 hours it's 100, 100/1440=~0.096 per minute
}
public bool TryBuyAction(BaseAction action)
{
if (action is ISellableItem)
{
if (!money.deduct(((ISellableItem)action).Price))
return false;
}
action.ApplyAction(this);
return true;
}
}