[Add] Universal modifier system, shop, inventory & persistence
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>
This commit is contained in:
@@ -0,0 +1,62 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
public static class ModifierPipeline
|
||||
{
|
||||
// Application order (explicit):
|
||||
// 1. Category-level additive (AddPerDieValue)
|
||||
// 2. Category-level multiplicative (MultiplyPerDieValue)
|
||||
// 3. Final-score additive (AddFlatToFinalScore)
|
||||
// 4. Final-score multiplicative (MultiplyFinalScore)
|
||||
|
||||
public static void Apply(
|
||||
IReadOnlyList<ModifierData> activeModifiers,
|
||||
ref ScoreResult result,
|
||||
ModifierScope currentScope)
|
||||
{
|
||||
if (activeModifiers == null) return;
|
||||
|
||||
// Pass 1: Category-level additive
|
||||
for (int i = 0; i < activeModifiers.Count; i++)
|
||||
{
|
||||
var mod = activeModifiers[i];
|
||||
if (!ShouldApply(mod, ref result, currentScope)) continue;
|
||||
if (mod.IsCategoryLevel && mod.IsAdditive)
|
||||
ModifierEffect.Apply(mod, ref result);
|
||||
}
|
||||
|
||||
// Pass 2: Category-level multiplicative
|
||||
for (int i = 0; i < activeModifiers.Count; i++)
|
||||
{
|
||||
var mod = activeModifiers[i];
|
||||
if (!ShouldApply(mod, ref result, currentScope)) continue;
|
||||
if (mod.IsCategoryLevel && mod.IsMultiplicative)
|
||||
ModifierEffect.Apply(mod, ref result);
|
||||
}
|
||||
|
||||
// Pass 3: Final-score additive
|
||||
for (int i = 0; i < activeModifiers.Count; i++)
|
||||
{
|
||||
var mod = activeModifiers[i];
|
||||
if (!ShouldApply(mod, ref result, currentScope)) continue;
|
||||
if (mod.IsFinalScoreLevel && mod.IsAdditive)
|
||||
ModifierEffect.Apply(mod, ref result);
|
||||
}
|
||||
|
||||
// Pass 4: Final-score multiplicative
|
||||
for (int i = 0; i < activeModifiers.Count; i++)
|
||||
{
|
||||
var mod = activeModifiers[i];
|
||||
if (!ShouldApply(mod, ref result, currentScope)) continue;
|
||||
if (mod.IsFinalScoreLevel && mod.IsMultiplicative)
|
||||
ModifierEffect.Apply(mod, ref result);
|
||||
}
|
||||
}
|
||||
|
||||
private static bool ShouldApply(ModifierData mod, ref ScoreResult result, ModifierScope currentScope)
|
||||
{
|
||||
if (mod == null) return false;
|
||||
if (mod.Scope != currentScope) return false;
|
||||
if (mod.Target.HasCategoryFilter && mod.Target.TargetCategory != result.Category) return false;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user