[Refactor] Replace enum-driven modifier system with data-driven SO composition
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>
This commit is contained in:
@@ -0,0 +1,9 @@
|
||||
using YachtDice.Modifiers.Runtime;
|
||||
|
||||
namespace YachtDice.Modifiers.Core
|
||||
{
|
||||
public interface ICondition
|
||||
{
|
||||
bool Evaluate(ModifierContext context, ModifierInstance instance);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
using Cysharp.Threading.Tasks;
|
||||
using YachtDice.Modifiers.Runtime;
|
||||
|
||||
namespace YachtDice.Modifiers.Core
|
||||
{
|
||||
public interface IEffect
|
||||
{
|
||||
ModifierPhase Phase { get; }
|
||||
int Priority { get; }
|
||||
UniTask Apply(ModifierContext context, ModifierInstance instance);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using YachtDice.Modifiers.Runtime;
|
||||
using YachtDice.Scoring;
|
||||
|
||||
namespace YachtDice.Modifiers.Core
|
||||
{
|
||||
public class ModifierContext
|
||||
{
|
||||
// Scoring data
|
||||
public int BaseScore;
|
||||
public int FlatBonus;
|
||||
public float Multiplier = 1f;
|
||||
public float PostMultiplier = 1f;
|
||||
public int[] DiceValues;
|
||||
public YachtCategory Category;
|
||||
|
||||
// Game state (read-only snapshot)
|
||||
public int CurrentRoll;
|
||||
public int CurrentTurn;
|
||||
public int PlayerCurrency;
|
||||
public IReadOnlyList<ModifierInstance> AllActiveModifiers;
|
||||
|
||||
// Trigger info
|
||||
public TriggerType Trigger;
|
||||
|
||||
// Side-effect accumulators
|
||||
public int CurrencyDelta;
|
||||
|
||||
// Debug trace (populated when tracing is enabled)
|
||||
public List<string> DebugLog;
|
||||
|
||||
public int FinalScore => Mathf.FloorToInt((BaseScore + FlatBonus) * Multiplier * PostMultiplier);
|
||||
|
||||
public ScoreResult ToScoreResult()
|
||||
{
|
||||
return new ScoreResult
|
||||
{
|
||||
BaseScore = BaseScore,
|
||||
FlatBonus = FlatBonus,
|
||||
Multiplier = Multiplier * PostMultiplier,
|
||||
DiceValues = DiceValues,
|
||||
Category = Category,
|
||||
};
|
||||
}
|
||||
|
||||
public static ModifierContext CreateForScoring(
|
||||
int baseScore,
|
||||
int[] diceValues,
|
||||
YachtCategory category,
|
||||
int currentRoll,
|
||||
int currentTurn,
|
||||
int playerCurrency,
|
||||
IReadOnlyList<ModifierInstance> activeModifiers)
|
||||
{
|
||||
return new ModifierContext
|
||||
{
|
||||
BaseScore = baseScore,
|
||||
DiceValues = diceValues,
|
||||
Category = category,
|
||||
CurrentRoll = currentRoll,
|
||||
CurrentTurn = currentTurn,
|
||||
PlayerCurrency = playerCurrency,
|
||||
AllActiveModifiers = activeModifiers,
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
namespace YachtDice.Modifiers.Core
|
||||
{
|
||||
public enum ModifierPhase
|
||||
{
|
||||
Pre = 0,
|
||||
Additive = 100,
|
||||
Multiplicative = 200,
|
||||
PostMultiplicative = 300,
|
||||
Final = 400,
|
||||
SideEffect = 500,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
namespace YachtDice.Modifiers.Core
|
||||
{
|
||||
public enum ModifierRarity
|
||||
{
|
||||
Common,
|
||||
Uncommon,
|
||||
Rare,
|
||||
Epic,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
namespace YachtDice.Modifiers.Core
|
||||
{
|
||||
public enum TriggerType
|
||||
{
|
||||
OnCategoryScored,
|
||||
OnTurnStart,
|
||||
OnTurnEnd,
|
||||
OnRollComplete,
|
||||
OnDiceLocked,
|
||||
OnShopOpened,
|
||||
OnItemPurchased,
|
||||
OnGameStart,
|
||||
OnGameEnd,
|
||||
OnModifierActivated,
|
||||
OnModifierDeactivated,
|
||||
OnCurrencyChanged,
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user