[Add] Dice & Refactor private names

This commit is contained in:
2026-03-02 11:22:01 +07:00
parent 4890fa946e
commit f65976796d
36 changed files with 883 additions and 489 deletions
+11 -11
View File
@@ -7,41 +7,41 @@ namespace YachtDice.Economy
{
[SerializeField] private int startingBalance = 500;
private int balance;
private int _balance;
public int Balance => balance;
public int Balance => _balance;
public event Action<int> OnBalanceChanged;
private void Awake()
{
balance = startingBalance;
_balance = startingBalance;
}
public void Add(int amount)
{
if (amount <= 0) return;
balance += amount;
OnBalanceChanged?.Invoke(balance);
_balance += amount;
OnBalanceChanged?.Invoke(_balance);
}
public bool Spend(int amount)
{
if (amount <= 0) return false;
if (balance < amount) return false;
if (_balance < amount) return false;
balance -= amount;
OnBalanceChanged?.Invoke(balance);
_balance -= amount;
OnBalanceChanged?.Invoke(_balance);
return true;
}
public bool CanAfford(int amount) => balance >= amount;
public bool CanAfford(int amount) => _balance >= amount;
public void SetBalance(int value)
{
balance = Mathf.Max(0, value);
OnBalanceChanged?.Invoke(balance);
_balance = Mathf.Max(0, value);
OnBalanceChanged?.Invoke(_balance);
}
}
}