diff --git a/Assets/Scripts/Actions/BaseAction.cs b/Assets/Scripts/Actions/BaseAction.cs index 7356b1f2..66044235 100644 --- a/Assets/Scripts/Actions/BaseAction.cs +++ b/Assets/Scripts/Actions/BaseAction.cs @@ -10,6 +10,7 @@ namespace Assets.Scripts.Actions DurationInTicks = durationTicks; } - public abstract void ConsumeTick(); + public abstract void ApplyAction(PlayerController playerController); + } } \ No newline at end of file diff --git a/Assets/Scripts/Actions/Eat.cs b/Assets/Scripts/Actions/Eat.cs index 2a1ac84f..863e54e2 100644 --- a/Assets/Scripts/Actions/Eat.cs +++ b/Assets/Scripts/Actions/Eat.cs @@ -2,14 +2,12 @@ { public class Eat : BaseAction { - private PlayerController playerController; private int energyPerTick; - public Eat(PlayerController player, int duration, int energyPerTick, double cost) : base(duration) + public Eat(int duration, int energyPerTick, double cost) : base(duration) { - this.playerController = player; this.energyPerTick = energyPerTick; } - public override void ConsumeTick() + public override void ApplyAction(PlayerController playerController) { playerController.foodEnergy.increase(energyPerTick); } diff --git a/Assets/Scripts/Actions/Relax.cs b/Assets/Scripts/Actions/Relax.cs index 89af0005..5656e1f0 100644 --- a/Assets/Scripts/Actions/Relax.cs +++ b/Assets/Scripts/Actions/Relax.cs @@ -2,16 +2,14 @@ { public class Relax : BaseAction { - private PlayerController _playerController; private int _energyPerTick; - public Relax(PlayerController player, int duration, int energyPerTick) : base(duration) + public Relax(int duration, int energyPerTick) : base(duration) { - _playerController = player; _energyPerTick = energyPerTick; } - public override void ConsumeTick() + public override void ApplyAction(PlayerController playerController) { - _playerController.restEnergy.increase(_energyPerTick); + playerController.restEnergy.increase(_energyPerTick); } } } diff --git a/Assets/Scripts/Actions/Work.cs b/Assets/Scripts/Actions/Work.cs index 3bb8ea73..9b3b7c26 100644 --- a/Assets/Scripts/Actions/Work.cs +++ b/Assets/Scripts/Actions/Work.cs @@ -9,7 +9,7 @@ this.playerController = player; this.energyPerTick = energyPerTick; } - public override void ConsumeTick() + public override void ApplyAction(PlayerController playerController) { throw new System.NotImplementedException(); } diff --git a/Assets/Scripts/Buildings/Building.cs b/Assets/Scripts/Buildings/Building.cs index 2f768be0..e1be7071 100644 --- a/Assets/Scripts/Buildings/Building.cs +++ b/Assets/Scripts/Buildings/Building.cs @@ -8,7 +8,8 @@ namespace Assets.Scripts.Buildings { protected string _name; protected Dictionary _optionsList; - + [SerializeField] + private ConversationController _conversationController; // Start is called before the first frame update void Start() { @@ -28,7 +29,8 @@ namespace Assets.Scripts.Buildings void OnTriggerEnter(Collider other) { - ConversationController.Instance.Change(_name, _optionsList); + _conversationController.Change(_name, _optionsList); + } } } \ No newline at end of file diff --git a/Assets/Scripts/Buildings/Burger.cs b/Assets/Scripts/Buildings/Burger.cs index 54302cb9..9073b6d5 100644 --- a/Assets/Scripts/Buildings/Burger.cs +++ b/Assets/Scripts/Buildings/Burger.cs @@ -1,5 +1,4 @@ using Assets.Scripts.Actions; -using UnityEngine; namespace Assets.Scripts.Buildings { @@ -12,17 +11,13 @@ namespace Assets.Scripts.Buildings protected override void BuildOptionsList() { - _optionsList.Add("Hamburgers - 83$", new Eat(null, 6, 1, 83)); - _optionsList.Add("Cheesburger - 94$", new Eat(null, 6, 1, 94)); - _optionsList.Add("Astro chicken - 131$", new Eat(null, 6, 1, 131)); - _optionsList.Add("Fries - 68$", new Eat(null, 6, 1, 68)); - _optionsList.Add("Shakes - 108$", new Eat(null, 6, 1, 108)); - _optionsList.Add("Colas - 73$", new Eat(null, 6, 1, 73)); + _optionsList.Add("Hamburgers - 83$", new Eat(6, 1, 83)); + _optionsList.Add("Cheesburger - 94$", new Eat(6, 1, 94)); + _optionsList.Add("Astro chicken - 131$", new Eat(6, 1, 131)); + _optionsList.Add("Fries - 68$", new Eat(6, 1, 68)); + _optionsList.Add("Shakes - 108$", new Eat(6, 1, 108)); + _optionsList.Add("Colas - 73$", new Eat(6, 1, 73)); } - void OnTriggerEnter(Collider other) - { - ConversationController.Instance.Change(_name, _optionsList); - } } } diff --git a/Assets/Scripts/Buildings/House.cs b/Assets/Scripts/Buildings/House.cs index bf3aab69..035ba2eb 100644 --- a/Assets/Scripts/Buildings/House.cs +++ b/Assets/Scripts/Buildings/House.cs @@ -6,7 +6,7 @@ namespace Assets.Scripts.Buildings { protected override void BuildOptionsList() { - _optionsList.Add("Rest", new Relax(null, 6, 1)); + _optionsList.Add("Rest", new Relax(6, 1)); } protected override void Initialize() diff --git a/Assets/Scripts/DialogueSystem/ChoiceController.cs b/Assets/Scripts/DialogueSystem/ChoiceController.cs index 1ac008db..034fe53c 100644 --- a/Assets/Scripts/DialogueSystem/ChoiceController.cs +++ b/Assets/Scripts/DialogueSystem/ChoiceController.cs @@ -10,6 +10,7 @@ public class ConversationChangeEvent : UnityEvent { } public class ChoiceController : MonoBehaviour { + public PlayerController playerController; public KeyValuePair _option; public ConversationChangeEvent conversationChangeEvent; // Update is called once per frame @@ -41,6 +42,7 @@ public class ChoiceController : MonoBehaviour public void MakeChoice() { + playerController.TryBuyAction(_option.Value); conversationChangeEvent.Invoke(_option.Value); } } diff --git a/Assets/Scripts/DialogueSystem/ConversationController.cs b/Assets/Scripts/DialogueSystem/ConversationController.cs index 2afce40e..1267f448 100644 --- a/Assets/Scripts/DialogueSystem/ConversationController.cs +++ b/Assets/Scripts/DialogueSystem/ConversationController.cs @@ -11,16 +11,14 @@ public class ConversationController : MonoBehaviour public TextMeshProUGUI _title; [SerializeField] public Button _choiceButton; - [SerializeField] private Button _closeBtn; + public ConversationChangeEvent conversationChangeEvent; private List choiceControllers = new(); - public static ConversationController Instance { get; private set; } private void Awake() { - Instance = this; Hide(); } @@ -35,17 +33,14 @@ public class ConversationController : MonoBehaviour ChoiceController c = ChoiceController.AddChoiceButton(_choiceButton, options.ElementAt(count), count); choiceControllers.Add(c); } - _closeBtn.onClick.AddListener(() => - { - Hide(); - }); + + StopAllCoroutines(); + Time.timeScale = 0; _choiceButton.gameObject.SetActive(false); } - - private void RemoveChoices() { foreach (ChoiceController c in choiceControllers) diff --git a/Assets/Scripts/DialogueSystem/TestingQuestionDialog.cs b/Assets/Scripts/DialogueSystem/TestingQuestionDialog.cs index da41738e..380ffd16 100644 --- a/Assets/Scripts/DialogueSystem/TestingQuestionDialog.cs +++ b/Assets/Scripts/DialogueSystem/TestingQuestionDialog.cs @@ -1,5 +1,3 @@ -using Assets.Scripts.Actions; -using System.Collections.Generic; using UnityEditor; using UnityEngine; @@ -22,19 +20,7 @@ public class TestingQuestionDialog : MonoBehaviour }); } - if (Input.GetKeyDown(KeyCode.Space)) - { - Dictionary optionsList = new Dictionary - { - { "Hamburgers - 83$", new Eat(null, 6, 1, 83) }, - { "Cheesburger - 94$", new Eat(null, 6, 1, 94) }, - { "Astro chicken - 131$", new Eat(null, 6, 1, 131) }, - { "Fries - 68$", new Eat(null, 6, 1, 68) }, - { "Shakes - 108$", new Eat(null, 6, 1, 108) }, - { "Colas - 73$", new Eat(null, 6, 1, 73) } - }; - ConversationController.Instance.Change("Monolith burger", optionsList); - } + } diff --git a/Assets/Scripts/PlayerController.cs b/Assets/Scripts/PlayerController.cs index 25b100c9..3d1e45d3 100644 --- a/Assets/Scripts/PlayerController.cs +++ b/Assets/Scripts/PlayerController.cs @@ -1,3 +1,4 @@ +using Assets.Scripts.Actions; using UnityEngine; public class PlayerController : MonoBehaviour @@ -61,5 +62,9 @@ public class PlayerController : MonoBehaviour Clock = 24; } + public void TryBuyAction(BaseAction action) + { + action.ApplyAction(this); + } }