Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix battle #2422

Merged
merged 2 commits into from
Dec 11, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading