Class CreateUnitCommand
Command to create a new unit.
VALIDATION:
- Province must be owned by the country
- Country must have sufficient resources (checked by game layer command factory)
- Unit type must be valid
EXECUTION:
- Deduct resources (handled by game layer wrapper)
- Create unit in UnitSystem
- Emit UnitCreatedEvent
public class CreateUnitCommand : BaseCommand, ICommand
- Inheritance
-
objectCreateUnitCommand
- Implements
- Inherited Members
Constructors
CreateUnitCommand(UnitSystem, ushort, ushort, ushort)
public CreateUnitCommand(UnitSystem unitSystem, ushort provinceID, ushort countryID, ushort unitTypeID)
Parameters
unitSystemUnitSystemprovinceIDushortcountryIDushortunitTypeIDushort
Methods
Deserialize(BinaryReader)
Deserialize command data from binary reader Used for save/load and command replay Must reconstruct identical command state
public override void Deserialize(BinaryReader reader)
Parameters
readerBinaryReaderBinary reader to deserialize from
Dispose()
public void Dispose()
Execute(GameState)
Execute the command and modify game state Should emit appropriate events for other systems to react Must be deterministic for multiplayer compatibility
public override void Execute(GameState gameState)
Parameters
gameStateGameStateGame state to modify
GetChecksum()
public uint GetChecksum()
Returns
- uint
GetCreatedUnitID()
Get the created unit ID (only valid after Execute())
public ushort GetCreatedUnitID()
Returns
- ushort
GetSuccessMessage(GameState)
public string GetSuccessMessage(GameState gameState)
Parameters
gameStateGameState
Returns
- string
GetValidationError(GameState)
public string GetValidationError(GameState gameState)
Parameters
gameStateGameState
Returns
- string
Serialize(BinaryWriter)
Serialize command data to binary writer Used for save/load and command logging Must be deterministic - same command = same bytes
public override 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
public override 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.
public override bool Validate(GameState gameState)
Parameters
gameStateGameStateCurrent game state for validation
Returns
- bool
True if command can be executed