start to change action system
This commit is contained in:
@@ -10,6 +10,7 @@ namespace Assets.Scripts.Actions
|
||||
DurationInTicks = durationTicks;
|
||||
}
|
||||
|
||||
public abstract void ConsumeTick();
|
||||
public abstract void ApplyAction(PlayerController playerController);
|
||||
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
this.playerController = player;
|
||||
this.energyPerTick = energyPerTick;
|
||||
}
|
||||
public override void ConsumeTick()
|
||||
public override void ApplyAction(PlayerController playerController)
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
|
||||
@@ -8,7 +8,8 @@ namespace Assets.Scripts.Buildings
|
||||
{
|
||||
protected string _name;
|
||||
protected Dictionary<string, BaseAction> _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);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -10,6 +10,7 @@ public class ConversationChangeEvent : UnityEvent<BaseAction> { }
|
||||
|
||||
public class ChoiceController : MonoBehaviour
|
||||
{
|
||||
public PlayerController playerController;
|
||||
public KeyValuePair<string, BaseAction> _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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -11,16 +11,14 @@ public class ConversationController : MonoBehaviour
|
||||
public TextMeshProUGUI _title;
|
||||
[SerializeField]
|
||||
public Button _choiceButton;
|
||||
|
||||
[SerializeField]
|
||||
private Button _closeBtn;
|
||||
|
||||
public ConversationChangeEvent conversationChangeEvent;
|
||||
private List<ChoiceController> 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)
|
||||
|
||||
@@ -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<string, BaseAction> optionsList = new Dictionary<string, BaseAction>
|
||||
{
|
||||
{ "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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user