display player money, dialog when player have not enough money
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 75ecd68a88c4c904393604b692b01a43
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
|
||||
namespace Assets.Scripts.Actions.Interfaces
|
||||
{
|
||||
internal interface ISellableItem
|
||||
{
|
||||
public double Cost { get; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 11ca03325bf76704b91eb2f9b2fafec9
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -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
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user