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>
139 lines
4.0 KiB
C#
139 lines
4.0 KiB
C#
using NUnit.Framework;
|
|
using UnityEngine;
|
|
using YachtDice.Economy;
|
|
using YachtDice.Inventory;
|
|
using YachtDice.Shop;
|
|
using YachtDice.Modifiers.Definition;
|
|
using YachtDice.Modifiers.Runtime;
|
|
|
|
namespace YachtDice.Tests
|
|
{
|
|
public sealed class ShopModelTests
|
|
{
|
|
private CurrencyBank bank;
|
|
private ModifierRegistry registry;
|
|
private InventoryModel inventory;
|
|
private ShopModel shop;
|
|
|
|
[SetUp]
|
|
public void SetUp()
|
|
{
|
|
var go = new GameObject("Bank");
|
|
bank = go.AddComponent<CurrencyBank>();
|
|
bank.SetBalance(500);
|
|
|
|
registry = new ModifierRegistry(5);
|
|
inventory = new InventoryModel(registry);
|
|
shop = new ShopModel(bank, inventory);
|
|
}
|
|
|
|
[TearDown]
|
|
public void TearDown()
|
|
{
|
|
foreach (var go in Object.FindObjectsByType<CurrencyBank>(FindObjectsSortMode.None))
|
|
Object.DestroyImmediate(go.gameObject);
|
|
}
|
|
|
|
private ModifierDefinitionSO CreateDef(string id = "test",
|
|
bool hasLimitedUses = false, int maxUses = 0,
|
|
int shopPrice = 100, int sellPrice = 50)
|
|
{
|
|
return ModifierDefinitionSO.CreateForTest(id, null,
|
|
hasLimitedUses: hasLimitedUses, maxUses: maxUses,
|
|
shopPrice: shopPrice, sellPrice: sellPrice);
|
|
}
|
|
|
|
[Test]
|
|
public void TryPurchase_SucceedsWithSufficientCurrency()
|
|
{
|
|
var mod = CreateDef("test", shopPrice: 100);
|
|
|
|
bool result = shop.TryPurchase(mod);
|
|
|
|
Assert.IsTrue(result);
|
|
Assert.AreEqual(400, bank.Balance);
|
|
Assert.AreEqual(1, inventory.OwnedModifiers.Count);
|
|
}
|
|
|
|
[Test]
|
|
public void TryPurchase_FailsWhenBroke()
|
|
{
|
|
bank.SetBalance(10);
|
|
var mod = CreateDef("test", shopPrice: 100);
|
|
|
|
bool result = shop.TryPurchase(mod);
|
|
|
|
Assert.IsFalse(result);
|
|
Assert.AreEqual(10, bank.Balance);
|
|
Assert.AreEqual(0, inventory.OwnedModifiers.Count);
|
|
}
|
|
|
|
[Test]
|
|
public void TryPurchase_PermanentCannotBeBoughtTwice()
|
|
{
|
|
var mod = CreateDef("perm", shopPrice: 100);
|
|
|
|
shop.TryPurchase(mod);
|
|
bool secondResult = shop.TryPurchase(mod);
|
|
|
|
Assert.IsFalse(secondResult);
|
|
Assert.AreEqual(400, bank.Balance);
|
|
Assert.AreEqual(1, inventory.OwnedModifiers.Count);
|
|
}
|
|
|
|
[Test]
|
|
public void TryPurchase_LimitedCanBeReBought()
|
|
{
|
|
var mod = CreateDef("limited", hasLimitedUses: true, maxUses: 3, shopPrice: 100);
|
|
|
|
shop.TryPurchase(mod);
|
|
bool secondResult = shop.TryPurchase(mod);
|
|
|
|
Assert.IsTrue(secondResult);
|
|
Assert.AreEqual(300, bank.Balance);
|
|
Assert.AreEqual(2, inventory.OwnedModifiers.Count);
|
|
}
|
|
|
|
[Test]
|
|
public void TryPurchase_FiresPurchaseEvent()
|
|
{
|
|
ModifierDefinitionSO purchased = null;
|
|
shop.OnItemPurchased += def => purchased = def;
|
|
|
|
var mod = CreateDef("test", shopPrice: 100);
|
|
|
|
shop.TryPurchase(mod);
|
|
|
|
Assert.IsNotNull(purchased);
|
|
Assert.AreEqual("test", purchased.Id);
|
|
}
|
|
|
|
[Test]
|
|
public void GetItemState_Available_WhenCanAfford()
|
|
{
|
|
var mod = CreateDef("test", shopPrice: 100);
|
|
|
|
Assert.AreEqual(ShopItemState.Available, shop.GetItemState(mod));
|
|
}
|
|
|
|
[Test]
|
|
public void GetItemState_TooExpensive_WhenCannotAfford()
|
|
{
|
|
bank.SetBalance(10);
|
|
var mod = CreateDef("test", shopPrice: 100);
|
|
|
|
Assert.AreEqual(ShopItemState.TooExpensive, shop.GetItemState(mod));
|
|
}
|
|
|
|
[Test]
|
|
public void GetItemState_Owned_WhenPermanentPurchased()
|
|
{
|
|
var mod = CreateDef("perm", shopPrice: 100);
|
|
|
|
shop.TryPurchase(mod);
|
|
|
|
Assert.AreEqual(ShopItemState.Owned, shop.GetItemState(mod));
|
|
}
|
|
}
|
|
}
|