Skip to content

Commit

Permalink
fix battle
Browse files Browse the repository at this point in the history
  • Loading branch information
credence0x committed Dec 11, 2024
1 parent 545c706 commit 1d5dc26
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
17 changes: 17 additions & 0 deletions contracts/src/models/combat.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -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,
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 1d5dc26

Please sign in to comment.