In D&D 5e, creatures have a speed (e.g., 30ft) and can move up to that distance during their turn. We need to track how much movement a creature has used or has remaining to enforce this limit.
We decided to encapsulate movement logic in an IMovement interface composed into ICreature.
IMovement: TracksSpeed(base) andMovementRemaining(current turn).StandardMovement: Concrete implementation.Move(int distance): ReducesMovementRemaining. Throws if distance > remaining.ResetTurn(): ResetsMovementRemainingto the currentSpeed.
- Integration:
ICreatureexposes aMovementproperty.StandardCreature.StartTurn()callsMovement.ResetTurn().
- Pros:
- Enforcement: Prevents illegal movement distances.
- Automation: Resets automatically at start of turn.
- Flexibility:
Speedproperty onIMovementdelegates toICombatStats, so changes to stats (buffs) are immediately reflected in the next reset.
- Cons:
- Grid Independence: Currently just tracks abstract "feet". Grid-based logic (diagonals, difficult terrain) would need to be handled by a higher-level system (e.g., a Map Manager) that calculates the "cost" of a move and then calls
Move(cost).
- Grid Independence: Currently just tracks abstract "feet". Grid-based logic (diagonals, difficult terrain) would need to be handled by a higher-level system (e.g., a Map Manager) that calculates the "cost" of a move and then calls
Accepted and Implemented.