The system required a way to represent various entities (PCs, NPCs, Monsters) in the combat engine. The original proposal was an IEntity interface. We needed a flexible, extensible architecture that avoids deep inheritance hierarchies (e.g., Dragon : Monster : Entity).
We decided to use a Composition-based architecture with ICreature as the primary container interface.
ICreature: The root interface for any being. It composes other capabilities.IAbilityScores: Encapsulates the six standard ability scores (Str, Dex, Con, Int, Wis, Cha) and modifier logic.IHitPoints: Encapsulates health state (Current, Max, Temp).
We implemented "Standard" versions of these interfaces to support SRD 5.1 rules:
StandardAbilityScores: Immutable record that calculates modifiers usingfloor((Score - 10) / 2).StandardHitPoints: Manages health state, enforcing non-negative values and death state.StandardCreature: A concrete implementation ofICreaturethat holds these components.
- Pros:
- Flexible: Can easily add new components (e.g.,
ISpeed,ISenses) without breaking existing code. - Testable: Components can be tested in isolation.
- Extensible: Different implementations of
IHitPoints(e.g., one with damage reduction) can be swapped in.
- Flexible: Can easily add new components (e.g.,
- Cons:
- slightly more verbose instantiation than a simple class hierarchy.
Accepted and Implemented.