13b18b0a8b
Standardize all class, interface, file, method, event, field, and variable names from the inconsistent "Die" form to "Dice", matching the existing DiceManager/DiceCatalog/DiceCollection convention. Renamed files (7 + meta): IDie→IDice, DieInstance→DiceInstance, DieDefinitionSO→DiceDefinitionSO, StandardDieSO→StandardDiceSO, DieValueCondition→DiceValueCondition, AddPerDieEffect→AddPerDiceEffect, MultiplyPerDieEffect→MultiplyPerDiceEffect. Updated all 31 consumer and test files with matching reference changes. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
96 lines
2.8 KiB
C#
96 lines
2.8 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using YachtDice.Dice;
|
|
using YachtDice.Economy;
|
|
using YachtDice.Inventory;
|
|
using YachtDice.Modifiers.Definition;
|
|
using YachtDice.Player;
|
|
|
|
namespace YachtDice.Shop
|
|
{
|
|
public class ShopModel
|
|
{
|
|
private readonly CurrencyBank currencyBank;
|
|
private readonly InventoryModel inventoryModel;
|
|
private readonly DiceCollection diceCollection;
|
|
private readonly HashSet<string> purchasedPermanentIds = new();
|
|
|
|
public event Action<IShopItem> OnItemPurchased;
|
|
|
|
public ShopModel(CurrencyBank currencyBank, InventoryModel inventoryModel, DiceCollection diceCollection)
|
|
{
|
|
this.currencyBank = currencyBank;
|
|
this.inventoryModel = inventoryModel;
|
|
this.diceCollection = diceCollection;
|
|
}
|
|
|
|
public bool CanPurchase(IShopItem item)
|
|
{
|
|
if (item == null) return false;
|
|
if (!currencyBank.CanAfford(item.ShopPrice)) return false;
|
|
|
|
if (!item.IsRepurchasable && purchasedPermanentIds.Contains(item.Id))
|
|
return false;
|
|
|
|
return true;
|
|
}
|
|
|
|
public bool TryPurchase(IShopItem item)
|
|
{
|
|
if (!CanPurchase(item)) return false;
|
|
|
|
if (!currencyBank.Spend(item.ShopPrice)) return false;
|
|
|
|
if (!item.IsRepurchasable)
|
|
purchasedPermanentIds.Add(item.Id);
|
|
|
|
switch (item)
|
|
{
|
|
case ModifierDefinition modifier:
|
|
inventoryModel.AddModifier(modifier);
|
|
break;
|
|
case DiceDefinitionSO dice:
|
|
diceCollection.Add(dice);
|
|
break;
|
|
}
|
|
|
|
OnItemPurchased?.Invoke(item);
|
|
return true;
|
|
}
|
|
|
|
public bool IsPermanentOwned(string itemId) => purchasedPermanentIds.Contains(itemId);
|
|
|
|
public ShopItemState GetItemState(IShopItem item)
|
|
{
|
|
if (item == null) return ShopItemState.TooExpensive;
|
|
|
|
if (!item.IsRepurchasable && purchasedPermanentIds.Contains(item.Id))
|
|
return ShopItemState.Owned;
|
|
|
|
if (!currencyBank.CanAfford(item.ShopPrice))
|
|
return ShopItemState.TooExpensive;
|
|
|
|
return item.IsRepurchasable
|
|
? ShopItemState.RepurchaseAvailable
|
|
: ShopItemState.Available;
|
|
}
|
|
|
|
public void LoadPurchasedPermanentIds(IEnumerable<string> ids)
|
|
{
|
|
purchasedPermanentIds.Clear();
|
|
if (ids != null)
|
|
foreach (var id in ids) purchasedPermanentIds.Add(id);
|
|
}
|
|
|
|
public HashSet<string> GetPurchasedPermanentIds() => new(purchasedPermanentIds);
|
|
}
|
|
|
|
public enum ShopItemState
|
|
{
|
|
Available,
|
|
TooExpensive,
|
|
Owned,
|
|
RepurchaseAvailable,
|
|
}
|
|
}
|