ba626acb9b
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>
92 lines
2.5 KiB
C#
92 lines
2.5 KiB
C#
using UnityEngine;
|
|
|
|
public sealed class InventoryController : MonoBehaviour
|
|
{
|
|
[SerializeField] private InventoryView inventoryView;
|
|
[SerializeField] private ScoringSystem scoringSystem;
|
|
[SerializeField] private CurrencyBank currencyBank;
|
|
|
|
private InventoryModel model;
|
|
|
|
public InventoryModel Model => model;
|
|
|
|
public void Initialize(InventoryModel inventoryModel)
|
|
{
|
|
model = inventoryModel;
|
|
|
|
inventoryView.OnActivateClicked += HandleActivate;
|
|
inventoryView.OnDeactivateClicked += HandleDeactivate;
|
|
inventoryView.OnSellClicked += HandleSell;
|
|
|
|
model.OnActiveModifiersChanged += HandleActiveModifiersChanged;
|
|
model.OnInventoryChanged += HandleInventoryChanged;
|
|
|
|
if (scoringSystem != null)
|
|
scoringSystem.OnCategoryConfirmed += HandleCategoryConfirmed;
|
|
|
|
RefreshView();
|
|
}
|
|
|
|
private void OnDestroy()
|
|
{
|
|
if (inventoryView != null)
|
|
{
|
|
inventoryView.OnActivateClicked -= HandleActivate;
|
|
inventoryView.OnDeactivateClicked -= HandleDeactivate;
|
|
inventoryView.OnSellClicked -= HandleSell;
|
|
}
|
|
|
|
if (model != null)
|
|
{
|
|
model.OnActiveModifiersChanged -= HandleActiveModifiersChanged;
|
|
model.OnInventoryChanged -= HandleInventoryChanged;
|
|
}
|
|
|
|
if (scoringSystem != null)
|
|
scoringSystem.OnCategoryConfirmed -= HandleCategoryConfirmed;
|
|
}
|
|
|
|
private void HandleActivate(ModifierRuntime runtime)
|
|
{
|
|
model.TryActivate(runtime);
|
|
}
|
|
|
|
private void HandleDeactivate(ModifierRuntime runtime)
|
|
{
|
|
model.Deactivate(runtime);
|
|
}
|
|
|
|
private void HandleSell(ModifierRuntime runtime)
|
|
{
|
|
if (runtime.Data == null) return;
|
|
|
|
int sellPrice = runtime.Data.SellPrice;
|
|
model.RemoveModifier(runtime);
|
|
|
|
if (currencyBank != null)
|
|
currencyBank.Add(sellPrice);
|
|
}
|
|
|
|
private void HandleActiveModifiersChanged(System.Collections.Generic.List<ModifierData> activeModifiers)
|
|
{
|
|
if (scoringSystem != null)
|
|
scoringSystem.SetActiveModifiers(activeModifiers);
|
|
}
|
|
|
|
private void HandleInventoryChanged()
|
|
{
|
|
RefreshView();
|
|
}
|
|
|
|
private void HandleCategoryConfirmed(YachtCategory category, ScoreResult result)
|
|
{
|
|
model.ConsumeUseOnActive();
|
|
}
|
|
|
|
private void RefreshView()
|
|
{
|
|
if (inventoryView != null && model != null)
|
|
inventoryView.Refresh(model.OwnedModifiers, model.MaxActiveSlots);
|
|
}
|
|
}
|