From 6069cf20221638b7cde36cc1fc1dbe885d043efa Mon Sep 17 00:00:00 2001 From: loothero Date: Sat, 16 Sep 2023 03:08:34 +0000 Subject: [PATCH] fixes flee outcome not changing during battle --- .../adventurer/src/adventurer_utils.cairo | 22 +++++++++++++++++-- contracts/game/src/lib.cairo | 12 +++++----- 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/contracts/adventurer/src/adventurer_utils.cairo b/contracts/adventurer/src/adventurer_utils.cairo index 662b4c2a6..a93c5c26b 100644 --- a/contracts/adventurer/src/adventurer_utils.cairo +++ b/contracts/adventurer/src/adventurer_utils.cairo @@ -180,8 +180,8 @@ impl AdventurerUtils of IAdventurerUtils { // @param adventurer_entropy: adventurer entropy // @param global_entropy: global entropy // @return (u128, u128): tuple of randomness - fn get_randomness(adventurer_xp: u16, - adventurer_entropy: u128, global_entropy: u128 + fn get_randomness( + adventurer_xp: u16, adventurer_entropy: u128, global_entropy: u128 ) -> (u128, u128) { let mut hash_span = ArrayTrait::::new(); hash_span.append(adventurer_xp.into()); @@ -191,6 +191,24 @@ impl AdventurerUtils of IAdventurerUtils { AdventurerUtils::split_hash(poseidon) } + // @notice gets randomness for adventurer with health included in entropy + // @param adventurer_xp: adventurer xp + // @param adventurer_entropy: adventurer entropy + // @param adventurer_health: adventurer health + // @param global_entropy: global entropy + // @return (u128, u128): tuple of randomness + fn get_randomness_with_health( + adventurer_xp: u16, adventurer_health: u16, adventurer_entropy: u128, global_entropy: u128 + ) -> (u128, u128) { + let mut hash_span = ArrayTrait::::new(); + hash_span.append(adventurer_xp.into()); + hash_span.append(adventurer_health.into()); + hash_span.append(adventurer_entropy.into()); + hash_span.append(global_entropy.into()); + let poseidon = poseidon_hash_span(hash_span.span()); + AdventurerUtils::split_hash(poseidon) + } + // @notice splits hash into two u128s // @param felt_to_split: felt to split // @return (u128, u128): tuple of u128s diff --git a/contracts/game/src/lib.cairo b/contracts/game/src/lib.cairo index 48aee1cb8..ed9eeabd4 100644 --- a/contracts/game/src/lib.cairo +++ b/contracts/game/src/lib.cairo @@ -76,7 +76,6 @@ mod Game { _adventurer: LegacyMap::, _owner: LegacyMap::, _adventurer_meta: LegacyMap::, - _loot: LegacyMap::, _loot_special_names: LegacyMap::<(u256, u256), felt252>, _bag: LegacyMap::, _counter: u256, @@ -945,6 +944,8 @@ mod Game { contract_address: self._collectible_beasts.read() }; + let allow_list = collectible_beasts_contract.getWhitelist(); + let is_beast_minted = collectible_beasts_contract .isMinted( beast.id, beast.combat_spec.specials.special2, beast.combat_spec.specials.special3 @@ -1615,8 +1616,8 @@ mod Game { // When generating the beast, we need to ensure entropy remains fixed for the battle // for attacking however, we should change the entropy during battle so we use adventurer and beast health // to accomplish this - let (attack_rnd_1, attack_rnd_2) = AdventurerUtils::get_randomness( - adventurer.xp, adventurer_entropy, global_entropy + let (attack_rnd_1, attack_rnd_2) = AdventurerUtils::get_randomness_with_health( + adventurer.xp, adventurer.health, adventurer_entropy, global_entropy ); // get the damage dealt to the beast @@ -1825,8 +1826,8 @@ mod Game { flee_to_the_death: bool ) { // get flee and ambush entropy seeds - let (flee_entropy, ambush_entropy) = AdventurerUtils::get_randomness( - adventurer.xp, adventurer_entropy, global_entropy + let (flee_entropy, ambush_entropy) = AdventurerUtils::get_randomness_with_health( + adventurer.xp, adventurer.health, adventurer_entropy, global_entropy ); // attempt to flee @@ -3177,5 +3178,6 @@ mod Game { ref self: T, to: ContractAddress, beast: u8, prefix: u8, suffix: u8, level: felt252 ); fn isMinted(ref self: T, beast: u8, prefix: u8, suffix: u8) -> bool; + fn getWhitelist(self: @T) -> ContractAddress; } }