diff --git a/contracts/src/models/combat.cairo b/contracts/src/models/combat.cairo index 79bf36823..6c9cecef2 100644 --- a/contracts/src/models/combat.cairo +++ b/contracts/src/models/combat.cairo @@ -167,6 +167,14 @@ impl TroopsImpl of TroopsTrait { return resource_precision_u64; } + fn assert_minimum_for_battle(self: Troops) { + let total = self.knight_count + self.paladin_count + self.crossbowman_count; + assert!( + total >= (100 * RESOURCE_PRECISION).try_into().unwrap(), + "you need to have at least have 100 troops for battle" + ); + } + fn assert_normalized(self: Troops) { assert!( self.knight_count % Self::normalization_factor() == 0, diff --git a/contracts/src/systems/combat/contracts/battle_systems.cairo b/contracts/src/systems/combat/contracts/battle_systems.cairo index d72940a5a..9aa9af35e 100644 --- a/contracts/src/systems/combat/contracts/battle_systems.cairo +++ b/contracts/src/systems/combat/contracts/battle_systems.cairo @@ -364,6 +364,7 @@ mod battle_systems { let mut attacking_army: Army = world.read_model(attacking_army_id); attacking_army.assert_not_in_battle(); + attacking_army.troops.assert_minimum_for_battle(); let attacking_army_entity_owner: EntityOwner = world.read_model(attacking_army_id); attacking_army_entity_owner.assert_caller_owner(world); @@ -877,6 +878,7 @@ mod battle_pillage_systems { // ensure attacking army is not in a battle let mut attacking_army: Army = world.read_model(army_id); attacking_army.assert_not_in_battle(); + attacking_army.troops.assert_minimum_for_battle(); // ensure army is at structure position let army_position: Position = world.read_model(army_id);