Skip to content

Latest commit

 

History

History
70 lines (49 loc) · 2.41 KB

File metadata and controls

70 lines (49 loc) · 2.41 KB

CombatSystem Smart Contract

The CombatSystem contract manages in-game combat mechanics, including moving and attacking units on the battlefield. It validates player actions based on the match state and enforces game rules for movement and combat.

moveOrAttack

function moveOrAttack(
    bytes32 _matchEntity,
    bytes32 _entity,
    PositionData[] memory path
) external;

Executes a move or attack action for a unit, depending on the target path provided

  • Parameters:

    • matchEntity: A unique 32-byte identifier for the match (e.g., 0x1b2c3d4...5f6)
    • entity: A 32-byte identifier for the unit entity, representing a specific game unit or piece (e.g., 0x0000...001).
    • path: An array of PositionData structs representing the positions the unit will follow to move or attack.
  • Sample Code:

bytes32 matchEntity = 0x0000000000000000000000000000000000000000000000000000000000000001;
bytes32 entity = 0x0000000000000000000000000000000000000000000000000000000000000002;

PositionData[] path = new PositionData[](1)
path[0] = PositionData(1, 1);

world.tacticsWar__moveOrAttack(matchEntity, entity, path);

Note:

  • The PositionData array defines the coordinates for the unit's movement or attack path. Each position includes x and y coordinates on the game board.
  • If the target path's last array value (path[path.length - 1]) is occupied by an enemy unit, the action will execute an attack. Otherwise, the unit will move to the target position.

attack

function attack(
    bytes32 _matchEntity,
    bytes32 _entity,
    bytes32 _target
) external;

Initiates a combat action between two entities.

  • Parameters:

    • matchEntity: A unique 32-byte identifier for the match (e.g., 0x1b2c3d4...5f6)
    • entity: A unique 32-byte identifier for the entity initiating the attack (e.g., 0x0000...001).
    • target: A unique 32-byte identifier for the target entity being attacked (e.g., 0x0000...002).
  • Sample Code:

bytes32 matchEntity = 0x0000000000000000000000000000000000000000000000000000000000000001;
bytes32 entity = 0x0000000000000000000000000000000000000000000000000000000000000002;
bytes32 target = 0x0000000000000000000000000000000000000000000000000000000000000003;

world.tacticsWar__attack(matchEntity, entity, target);

Note: The entity represents the attacker, while target represents the entity being attacked.