From 1d5dc26bfec685a06ad2abddf9ae8d24402a6a46 Mon Sep 17 00:00:00 2001 From: Credence Date: Wed, 11 Dec 2024 14:15:56 +0100 Subject: [PATCH 1/2] fix battle --- contracts/src/models/combat.cairo | 17 +++++++++++++++++ .../combat/contracts/battle_systems.cairo | 2 ++ 2 files changed, 19 insertions(+) diff --git a/contracts/src/models/combat.cairo b/contracts/src/models/combat.cairo index 79bf36823..e2bae926a 100644 --- a/contracts/src/models/combat.cairo +++ b/contracts/src/models/combat.cairo @@ -167,6 +167,23 @@ impl TroopsImpl of TroopsTrait { return resource_precision_u64; } + fn assert_minimum_for_battle(self: Troops) { + assert!( + self.knight_count >= (100 * RESOURCE_PRECISION).try_into().unwrap(), + "you need to at least have 100 knights to merge or battle" + ); + + assert!( + self.paladin_count >= (100 * RESOURCE_PRECISION).try_into().unwrap(), + "you need to at least have 100 paladins to merge or battle" + ); + + assert!( + self.crossbowman_count >= (100 * RESOURCE_PRECISION).try_into().unwrap(), + "you need to at least have 100 crossbowmen to merge or 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); From 2f697312ad3d1e7705e9bf180d620aeb1034226e Mon Sep 17 00:00:00 2001 From: Credence Date: Wed, 11 Dec 2024 14:19:44 +0100 Subject: [PATCH 2/2] fix battle --- contracts/src/models/combat.cairo | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/contracts/src/models/combat.cairo b/contracts/src/models/combat.cairo index e2bae926a..6c9cecef2 100644 --- a/contracts/src/models/combat.cairo +++ b/contracts/src/models/combat.cairo @@ -168,19 +168,10 @@ impl TroopsImpl of TroopsTrait { } fn assert_minimum_for_battle(self: Troops) { + let total = self.knight_count + self.paladin_count + self.crossbowman_count; assert!( - self.knight_count >= (100 * RESOURCE_PRECISION).try_into().unwrap(), - "you need to at least have 100 knights to merge or battle" - ); - - assert!( - self.paladin_count >= (100 * RESOURCE_PRECISION).try_into().unwrap(), - "you need to at least have 100 paladins to merge or battle" - ); - - assert!( - self.crossbowman_count >= (100 * RESOURCE_PRECISION).try_into().unwrap(), - "you need to at least have 100 crossbowmen to merge or battle" + total >= (100 * RESOURCE_PRECISION).try_into().unwrap(), + "you need to have at least have 100 troops for battle" ); }