public void AddBankInterest() { if (hasBank) { int interestGain = CalculateInterestGain(); if (interestGain > maxAmount) { interestGain = maxAmount; } if (interestGain > 0) { int gain = interestGain; if (bank + interestGain > maxAmount) { if (interestGain > bank) { gain = interestGain - bank; } else { gain = bank - interestGain; } } bank += gain; _lastInterestDate = World.CurrentDate; _lastInterestTime = World.CurrentTimeOfDay; EconomyEventArgs e = new EconomyEventArgs(); e.amount = gain; OnBankInterestReceived(e); } } }
public void SpendCash(int amount) { if (amount <= cash) { if (amount > 0) { cash -= amount; EconomyEventArgs e = new EconomyEventArgs(); e.amount = amount; OnSpentCash(e); } } }
public void GainCash(int amount) { if (amount < 0) { amount = 0; } if (amount > 0) { cash += amount; EconomyEventArgs e = new EconomyEventArgs(); e.amount = amount; OnGainedCash(e); } }
public void DepositBank(int amount) { if (hasBank) { if (amount <= cash) { if (amount > 0) { cash -= amount; bank += amount; EconomyEventArgs e = new EconomyEventArgs(); e.amount = amount; OnDepositedBank(e); } } } }
public void WithdrawBank(int amount) { if (hasBank) { if (amount <= bank) { if (amount > 0) { cash += amount; bank -= amount; EconomyEventArgs e = new EconomyEventArgs(); e.amount = amount; OnWithdrewBank(e); } } } }
private void EconomyScript_BankInterestReceived(object sender, EconomyEventArgs e) { }
private void EconomyScript_WithdrewBank(object sender, EconomyEventArgs e) { }
private void EconomyScript_DepositedBank(object sender, EconomyEventArgs e) { }
private void EconomyScript_SpentCash(object sender, EconomyEventArgs e) { }
private void EconomyScript_GainedCash(object sender, EconomyEventArgs e) { }
protected virtual void OnBankInterestReceived(EconomyEventArgs e) { BankInterestReceived?.Invoke(this, e); }
protected virtual void OnDepositedBank(EconomyEventArgs e) { DepositedBank?.Invoke(this, e); }
protected virtual void OnWithdrewBank(EconomyEventArgs e) { WithdrewBank?.Invoke(this, e); }
protected virtual void OnSpentCash(EconomyEventArgs e) { SpentCash?.Invoke(this, e); }
protected virtual void OnGainedCash(EconomyEventArgs e) { GainedCash?.Invoke(this, e); }