From 334bb15a0852a328da48ad5c8ef21cae111ffa3d Mon Sep 17 00:00:00 2001 From: = <=> Date: Fri, 21 Jun 2024 03:32:22 +0000 Subject: [PATCH 1/2] fixes multiple items getting same suffix --- contracts/loot/src/loot.cairo | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/contracts/loot/src/loot.cairo b/contracts/loot/src/loot.cairo index 5fc4f2c8b..9207e648c 100644 --- a/contracts/loot/src/loot.cairo +++ b/contracts/loot/src/loot.cairo @@ -1,5 +1,6 @@ use core::{ - serde::Serde, clone::Clone, option::OptionTrait, starknet::StorePacking, traits::{TryInto, Into} + serde::Serde, clone::Clone, option::OptionTrait, starknet::StorePacking, + traits::{TryInto, Into}, integer::u64_overflowing_add }; use combat::{combat::{ImplCombat, SpecialPowers}, constants::CombatEnums::{Type, Tier, Slot}}; @@ -67,7 +68,14 @@ impl ImplLoot of ILoot { // @return The naming seed. #[inline(always)] fn generate_naming_seed(item_id: u8, entropy: u64) -> u64 { - let rnd = entropy % NUM_ITEMS.into(); + let mut item_entropy = 1; + if (u64_overflowing_add(entropy, item_id.into()).is_ok()) { + item_entropy = entropy + item_id.into(); + } else { + item_entropy = entropy - item_id.into(); + } + + let rnd = item_entropy % NUM_ITEMS.into(); rnd * ImplLoot::get_slot_length(ImplLoot::get_slot(item_id)).into() + ImplLoot::get_item_index(item_id).into() } @@ -3267,7 +3275,7 @@ mod tests { } #[test] - #[available_gas(2176550)] + #[available_gas(2368710)] fn test_get_item_verify_tier() { let mut t1_items = ItemUtils::get_t1_items(); loop { From 7b3a1626e1aa7f4c4b84cce557cfd008e8a5346f Mon Sep 17 00:00:00 2001 From: = <=> Date: Fri, 21 Jun 2024 03:38:46 +0000 Subject: [PATCH 2/2] fix test (squash me) --- contracts/adventurer/src/adventurer.cairo | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/contracts/adventurer/src/adventurer.cairo b/contracts/adventurer/src/adventurer.cairo index 4b3d6b25f..ef33934fb 100644 --- a/contracts/adventurer/src/adventurer.cairo +++ b/contracts/adventurer/src/adventurer.cairo @@ -2660,7 +2660,7 @@ mod tests { } #[test] - #[available_gas(665600)] + #[available_gas(510840)] fn test_get_and_apply_stats() { let mut adventurer = Adventurer { health: 100, @@ -2691,12 +2691,12 @@ mod tests { }; let stat_boosts = adventurer.equipment.get_stat_boosts(1); - assert(stat_boosts.strength == 3, 'strength should be 3'); - assert(stat_boosts.vitality == 5, 'vitality should be 5'); - assert(stat_boosts.dexterity == 1, 'dexterity should be 1'); - assert(stat_boosts.intelligence == 0, 'intelligence should be 0'); - assert(stat_boosts.wisdom == 3, 'wisdom should be 3'); - assert(stat_boosts.charisma == 3, 'charisma should be 3'); + assert(stat_boosts.strength == 6, 'wrong strength'); + assert(stat_boosts.vitality == 1, 'wrong vitality'); + assert(stat_boosts.dexterity == 2, 'wrong dexterity'); + assert(stat_boosts.intelligence == 1, 'wrong intelligence'); + assert(stat_boosts.wisdom == 4, 'wrong wisdom'); + assert(stat_boosts.charisma == 1, 'wrong charisma'); } // test base case