diff --git a/Assets/Scenes/SampleScene.unity b/Assets/Scenes/SampleScene.unity index cc2a0b75..b501f291 100644 --- a/Assets/Scenes/SampleScene.unity +++ b/Assets/Scenes/SampleScene.unity @@ -38,7 +38,7 @@ RenderSettings: m_ReflectionIntensity: 1 m_CustomReflection: {fileID: 0} m_Sun: {fileID: 705507994} - m_IndirectSpecularColor: {r: 0.44657826, g: 0.49641263, b: 0.57481676, a: 1} + m_IndirectSpecularColor: {r: 0.44657898, g: 0.4964133, b: 0.5748178, a: 1} m_UseRadianceAmbientProbe: 0 --- !u!157 &3 LightmapSettings: @@ -3129,7 +3129,7 @@ RectTransform: m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 0.5, y: 0.5} m_AnchorMax: {x: 0.5, y: 0.5} - m_AnchoredPosition: {x: -472, y: 295} + m_AnchoredPosition: {x: -450, y: 223} m_SizeDelta: {x: 200, y: 50} m_Pivot: {x: 0.5, y: 0.5} --- !u!114 &443940496 @@ -4179,6 +4179,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: c802a0d9d32b0c04b841113e87b83e4b, type: 3} m_Name: m_EditorClassIdentifier: + _moneyText: {fileID: 443940496} Clock: 0 --- !u!1 &875821251 GameObject: @@ -6927,7 +6928,7 @@ RectTransform: m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 0.5, y: 0.5} m_AnchorMax: {x: 0.5, y: 0.5} - m_AnchoredPosition: {x: 192.27, y: -259} + m_AnchoredPosition: {x: 199.2, y: -230} m_SizeDelta: {x: 93.6024, y: 40.945} m_Pivot: {x: 0.5, y: 0.5} --- !u!114 &1765440972 @@ -7055,8 +7056,8 @@ RectTransform: m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 0.5, y: 0.5} m_AnchorMax: {x: 0.5, y: 0.5} - m_AnchoredPosition: {x: -256, y: -265} - m_SizeDelta: {x: 512, y: 530} + m_AnchoredPosition: {x: -256, y: -226.06555} + m_SizeDelta: {x: 512, y: 474.0656} m_Pivot: {x: 0, y: 0} --- !u!114 &1928618663 MonoBehaviour: @@ -7443,7 +7444,7 @@ RectTransform: m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 0.5, y: 0.5} m_AnchorMax: {x: 0.5, y: 0.5} - m_AnchoredPosition: {x: 478, y: 295} + m_AnchoredPosition: {x: 448, y: 223} m_SizeDelta: {x: 200, y: 50} m_Pivot: {x: 0.5, y: 0.5} --- !u!114 &2089282903 diff --git a/Assets/Scripts/Actions/Eat.cs b/Assets/Scripts/Actions/Eat.cs index 863e54e2..c79f69ca 100644 --- a/Assets/Scripts/Actions/Eat.cs +++ b/Assets/Scripts/Actions/Eat.cs @@ -1,10 +1,14 @@ -namespace Assets.Scripts.Actions +using Assets.Scripts.Actions.Interfaces; + +namespace Assets.Scripts.Actions { - public class Eat : BaseAction + public class Eat : BaseAction, ISellableItem { + public double Cost { get; private set; } private int energyPerTick; public Eat(int duration, int energyPerTick, double cost) : base(duration) { + Cost = cost; this.energyPerTick = energyPerTick; } public override void ApplyAction(PlayerController playerController) diff --git a/Assets/Scripts/Actions/Interfaces.meta b/Assets/Scripts/Actions/Interfaces.meta new file mode 100644 index 00000000..8cedf4d1 --- /dev/null +++ b/Assets/Scripts/Actions/Interfaces.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 75ecd68a88c4c904393604b692b01a43 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Actions/Interfaces/ISellableItem.cs b/Assets/Scripts/Actions/Interfaces/ISellableItem.cs new file mode 100644 index 00000000..d5842234 --- /dev/null +++ b/Assets/Scripts/Actions/Interfaces/ISellableItem.cs @@ -0,0 +1,8 @@ + +namespace Assets.Scripts.Actions.Interfaces +{ + internal interface ISellableItem + { + public double Cost { get; } + } +} diff --git a/Assets/Scripts/Actions/Interfaces/ISellableItem.cs.meta b/Assets/Scripts/Actions/Interfaces/ISellableItem.cs.meta new file mode 100644 index 00000000..61d5e68a --- /dev/null +++ b/Assets/Scripts/Actions/Interfaces/ISellableItem.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 11ca03325bf76704b91eb2f9b2fafec9 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/DialogueSystem/ChoiceController.cs b/Assets/Scripts/DialogueSystem/ChoiceController.cs index 034fe53c..28438705 100644 --- a/Assets/Scripts/DialogueSystem/ChoiceController.cs +++ b/Assets/Scripts/DialogueSystem/ChoiceController.cs @@ -42,7 +42,20 @@ public class ChoiceController : MonoBehaviour public void MakeChoice() { - playerController.TryBuyAction(_option.Value); - conversationChangeEvent.Invoke(_option.Value); + if (playerController.TryBuyAction(_option.Value)) + { + conversationChangeEvent.Invoke(_option.Value); + } + else + { + YesNoDialogUI.Instance.ShowQuestion("not enouth money", + () => + { + }, + () => + { + //do nothing + }); + } } } diff --git a/Assets/Scripts/PlayerController.cs b/Assets/Scripts/PlayerController.cs index 3d1e45d3..18560325 100644 --- a/Assets/Scripts/PlayerController.cs +++ b/Assets/Scripts/PlayerController.cs @@ -1,9 +1,14 @@ using Assets.Scripts.Actions; +using Assets.Scripts.Actions.Interfaces; +using TMPro; using UnityEngine; public class PlayerController : MonoBehaviour { - public Stat money = new Stat("Money", 1000.00); + [SerializeField] + private TextMeshProUGUI _moneyText; + + public Stat money = new Stat("Money", 100.00); public Stat rentAccount = new Stat("Rent Account", 0); public Stat foodEnergy = new Stat("Food Energy", 0); public Stat restEnergy = new Stat("Rest Energy", 0); @@ -47,7 +52,7 @@ public class PlayerController : MonoBehaviour // Start is called before the first frame update void Start() { - + _moneyText.text = $"Money: {money.Value}$"; } // Update is called once per frame @@ -62,9 +67,16 @@ public class PlayerController : MonoBehaviour Clock = 24; } - public void TryBuyAction(BaseAction action) + public bool TryBuyAction(BaseAction action) { + if(action is ISellableItem) + { + if (!money.deduct(((ISellableItem)action).Cost)) + return false; + _moneyText.text = $"Money: {money.Value}$"; + } action.ApplyAction(this); + return true; } }