Skip to content

Commit

Permalink
Merge pull request #2422 from BibliothecaDAO/battle-fixxx
Browse files Browse the repository at this point in the history
fix battle
  • Loading branch information
ponderingdemocritus authored Dec 11, 2024
2 parents 545c706 + 2f69731 commit 54f1955
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
8 changes: 8 additions & 0 deletions contracts/src/models/combat.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions contracts/src/systems/combat/contracts/battle_systems.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 54f1955

Please sign in to comment.