68c4abace3
Replace the entire static, enum-based modifier pipeline with a composition-based, data-driven architecture using ScriptableObject polymorphism. New modifiers can now be created by assembling SO building blocks (Conditions + Effects + Behaviors) — no core code edits needed. New architecture: - Core/: TriggerType, ModifierPhase, ModifierContext, ICondition, IEffect - Definition/: ModifierDefinitionSO, ModifierBehaviorSO, ConditionSO, EffectSO, ModifierCatalogSO - Conditions/: DieValueCondition, CategoryCondition, MinScoreCondition, DiceCountCondition - Effects/: AddFlat, AddPerDie, Multiply, MultiplyPerDie, PostMultiply, AddCurrency, ConsumeCharge - Runtime/: ModifierInstance, ModifierRegistry (non-static service) - Pipeline/: async ModifierPipeline with phase ordering, tracing, anti-recursion - Editor/: ModifierDefinitionValidator with menu items - Events/: GameEventBus (non-static typed dispatcher) - DI/: GameLifetimeScope (VContainer composition root) Deleted old system: ModifierData, ModifierEffect, ModifierEnums, ModifierPipeline (static), ModifierRuntime, ModifierTarget, ShopCatalog, ModifierAssetCreator. Updated: ScoringSystem (VContainer + async), InventoryModel (delegates to ModifierRegistry), ShopModel (uses ModifierDefinitionSO), GameController (VContainer injection), SaveData (uses Runtime.ModifierSaveEntry), all views/controllers, and all test files. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
83 lines
2.5 KiB
C#
83 lines
2.5 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using YachtDice.Economy;
|
|
using YachtDice.Inventory;
|
|
using YachtDice.Modifiers.Definition;
|
|
|
|
namespace YachtDice.Shop
|
|
{
|
|
public class ShopModel
|
|
{
|
|
private readonly CurrencyBank currencyBank;
|
|
private readonly InventoryModel inventoryModel;
|
|
private readonly HashSet<string> purchasedPermanentIds = new();
|
|
|
|
public event Action<ModifierDefinitionSO> OnItemPurchased;
|
|
|
|
public ShopModel(CurrencyBank currencyBank, InventoryModel inventoryModel)
|
|
{
|
|
this.currencyBank = currencyBank;
|
|
this.inventoryModel = inventoryModel;
|
|
}
|
|
|
|
public bool CanPurchase(ModifierDefinitionSO modifier)
|
|
{
|
|
if (modifier == null) return false;
|
|
if (!currencyBank.CanAfford(modifier.ShopPrice)) return false;
|
|
|
|
if (!modifier.HasLimitedUses && purchasedPermanentIds.Contains(modifier.Id))
|
|
return false;
|
|
|
|
return true;
|
|
}
|
|
|
|
public bool TryPurchase(ModifierDefinitionSO modifier)
|
|
{
|
|
if (!CanPurchase(modifier)) return false;
|
|
|
|
if (!currencyBank.Spend(modifier.ShopPrice)) return false;
|
|
|
|
if (!modifier.HasLimitedUses)
|
|
purchasedPermanentIds.Add(modifier.Id);
|
|
|
|
inventoryModel.AddModifier(modifier);
|
|
OnItemPurchased?.Invoke(modifier);
|
|
return true;
|
|
}
|
|
|
|
public bool IsPermanentOwned(string modifierId) => purchasedPermanentIds.Contains(modifierId);
|
|
|
|
public ShopItemState GetItemState(ModifierDefinitionSO modifier)
|
|
{
|
|
if (modifier == null) return ShopItemState.TooExpensive;
|
|
|
|
if (!modifier.HasLimitedUses && purchasedPermanentIds.Contains(modifier.Id))
|
|
return ShopItemState.Owned;
|
|
|
|
if (!currencyBank.CanAfford(modifier.ShopPrice))
|
|
return ShopItemState.TooExpensive;
|
|
|
|
return modifier.HasLimitedUses
|
|
? 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,
|
|
}
|
|
}
|