Interface ICommand
Base interface for all game commands Commands provide validation, execution, and undo support All game state changes must go through commands for:
- Validation before execution
- Event emission for system coordination
- Multiplayer synchronization
- Replay/undo support
public interface ICommand
Properties
CommandId
Get unique command ID for networking and logging
string CommandId { get; }
Property Value
- string
Priority
Get command priority for execution ordering Higher priority commands execute first
int Priority { get; }
Property Value
- int
Methods
Deserialize(BinaryReader)
Deserialize command data from binary reader Used for save/load and command replay Must reconstruct identical command state
void Deserialize(BinaryReader reader)
Parameters
readerBinaryReaderBinary reader to deserialize from
Execute(GameState)
Execute the command and modify game state Should emit appropriate events for other systems to react Must be deterministic for multiplayer compatibility
void Execute(GameState gameState)
Parameters
gameStateGameStateGame state to modify
Serialize(BinaryWriter)
Serialize command data to binary writer Used for save/load and command logging Must be deterministic - same command = same bytes
void Serialize(BinaryWriter writer)
Parameters
writerBinaryWriterBinary writer to serialize to
Undo(GameState)
Undo the command - restore previous state Required for replay systems and error recovery
void Undo(GameState gameState)
Parameters
gameStateGameStateGame state to restore
Validate(GameState)
Validate that this command can be executed in the current game state. Should be fast and have no side effects.
bool Validate(GameState gameState)
Parameters
gameStateGameStateCurrent game state for validation
Returns
- bool
True if command can be executed