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

fixes multiple items getting same suffix #31

Merged
merged 2 commits into from
Jun 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
14 changes: 7 additions & 7 deletions contracts/adventurer/src/adventurer.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
14 changes: 11 additions & 3 deletions contracts/loot/src/loot.cairo
Original file line number Diff line number Diff line change
@@ -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}};
Expand Down Expand Up @@ -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()
}
Expand Down Expand Up @@ -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 {
Expand Down
Loading