Files
YachtDice/Assets/Scripts/Economy/CurrencyBank.cs
T
horooko ba626acb9b [Add] Universal modifier system, shop, inventory & persistence
Replace hardcoded BonusForOnes/MultiplierForSixes with data-driven
modifier system supporting 2 scopes (SelectedCategory, AnyCategoryClosed),
4 effect types, durability modes (Permanent, LimitedUses), and
configurable targets via ScriptableObject (ModifierData).

- Modifier domain: ModifierEnums, ModifierTarget, ModifierData,
  ModifierRuntime, ModifierEffect (dict-based strategy), ModifierPipeline
  (4-pass: cat-additive → cat-multiplicative → final-additive → final-multiplicative)
- ScoringSystem: replaced old modifier list with ModifierPipeline integration,
  added OnCategoryConfirmed event
- Shop MVC: ShopCatalog (SO), ShopModel, ShopView, ShopItemView, ShopController
- Inventory MVC: InventoryModel (activate/deactivate/sell/durability),
  InventoryView, InventorySlotView, InventoryController
- CurrencyBank: editor-adjustable balance with events
- Persistence: SaveData + SaveSystem (Newtonsoft JSON + PlayerPrefs)
- Editor: ModifierAssetCreator menu item to generate 6 example modifiers + catalog
- Tests: 6 test classes covering effects, pipeline, scoring, shop, inventory, save
- GameController: wired shop/inventory/save lifecycle
- GameInfoView: added currency display, shop/inventory toggle buttons

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-28 06:40:33 +07:00

45 lines
891 B
C#

using System;
using UnityEngine;
public sealed class CurrencyBank : MonoBehaviour
{
[SerializeField] private int startingBalance = 500;
private int balance;
public int Balance => balance;
public event Action<int> OnBalanceChanged;
private void Awake()
{
balance = startingBalance;
}
public void Add(int amount)
{
if (amount <= 0) return;
balance += amount;
OnBalanceChanged?.Invoke(balance);
}
public bool Spend(int amount)
{
if (amount <= 0) return false;
if (balance < amount) return false;
balance -= amount;
OnBalanceChanged?.Invoke(balance);
return true;
}
public bool CanAfford(int amount) => balance >= amount;
public void SetBalance(int value)
{
balance = Mathf.Max(0, value);
OnBalanceChanged?.Invoke(balance);
}
}