Date: 2025-12-11
Accepted
The initial implementation of the Combat Loop (StandardCombatManager and StandardTurnManager) had two main limitations:
- Hardcoded Win Condition: The "Last Team Standing" logic was embedded directly in the manager, making it impossible to support other match types (e.g., "Kill the Boss", "Survive X Rounds").
- Ghost Turns: Dead creatures were still receiving turns, requiring them to manually pass or do nothing, which cluttered the flow.
We decided to:
- Extract Win Logic: Create an
IWinConditionstrategy interface with aCheck(ICombatManager)method. - Default Implementation: Move the existing logic into
LastTeamStandingWinConditionand make it the default forStandardCombatManager. - Refactor Turn Loop: Update
StandardTurnManager.NextTurn()to iterate through the initiative order until it finds a living creature or completes a full loop (preventing infinite loops if everyone is dead).
- Flexibility: Developers can now inject custom win conditions for specific encounters.
- Robustness: The combat flow is smoother as dead participants are automatically skipped.
- Testability: Win conditions can be tested in isolation.
- API Change:
StandardCombatManagerconstructor now takes an optionalIWinCondition.
- Verified with
CombatLoopTestscovering initiative, turn skipping, and custom win conditions.