Files
YachtDice/Assets/Scripts/Modifiers/Definition/ModifierDefinition.cs
T
horooko fcceb0ce45 Rework shop to support multiple item types and add unified PlayerModel
Generalize the shop from selling only ModifierDefinition to any IShopItem
(modifiers + dice). Add purchase condition checks, hover tooltips, and
fixed prices. Introduce PlayerModel as a facade over CurrencyBank,
InventoryModel, and DiceCollection for centralized state and save/load.

New files:
- IShopItem interface for purchasable items
- ShopCatalog SO (unified catalog for all item types)
- ShopTooltipView (description on hover)
- PlayerModel (aggregates player state)
- DiceCollection (owned dice tracking)
- DiceCatalog SO (dice definition registry)
- DiceCollectionTests

Modified:
- ModifierDefinition/DieDefinitionSO implement IShopItem
- ShopModel/ShopView/ShopItemView/ShopController use IShopItem
- SaveData v3 with OwnedDiceIds
- GameController uses PlayerModel for save/load
- GameLifetimeScope registers new services

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-01 21:04:34 +07:00

68 lines
2.3 KiB
C#

using System.Collections.Generic;
using UnityEngine;
using YachtDice.Modifiers.Core;
using YachtDice.Shop;
namespace YachtDice.Modifiers.Definition
{
[CreateAssetMenu(fileName = "NewModifier", menuName = "YachtDice/Modifiers/Definition")]
public class ModifierDefinition : ScriptableObject, IShopItem
{
[Header("Identity")]
[SerializeField] private string id;
[SerializeField] private string displayName;
[SerializeField, TextArea] private string description;
[SerializeField] private Sprite icon;
[SerializeField] private ModifierRarity rarity;
[Header("Economy")]
[SerializeField] private int shopPrice;
[SerializeField] private int sellPrice;
[Header("Durability")]
[SerializeField] private bool hasLimitedUses;
[SerializeField] private int maxUses;
[SerializeField] private int maxStacks = 1;
[Header("Behaviors")]
[SerializeField] private List<ModifierBehavior> behaviors = new();
public string Id => id;
public string DisplayName => displayName;
public string Description => description;
public Sprite Icon => icon;
public ModifierRarity Rarity => rarity;
public int ShopPrice => shopPrice;
public int SellPrice => sellPrice;
public bool HasLimitedUses => hasLimitedUses;
public int MaxUses => maxUses;
public int MaxStacks => maxStacks;
public bool IsRepurchasable => hasLimitedUses;
public IReadOnlyList<ModifierBehavior> Behaviors => behaviors;
#if UNITY_EDITOR
public static ModifierDefinition CreateForTest(
string id,
List<ModifierBehavior> behaviors,
bool hasLimitedUses = false,
int maxUses = 0,
int shopPrice = 100,
int sellPrice = 50,
ModifierRarity rarity = ModifierRarity.Common)
{
var so = CreateInstance<ModifierDefinition>();
so.id = id;
so.displayName = id;
so.description = id;
so.rarity = rarity;
so.shopPrice = shopPrice;
so.sellPrice = sellPrice;
so.hasLimitedUses = hasLimitedUses;
so.maxUses = maxUses;
so.behaviors = behaviors ?? new List<ModifierBehavior>();
return so;
}
#endif
}
}