diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 31cc2e516..efd2dd97e 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -22,7 +22,6 @@ jobs: market, obstacles, combat, - game_snapshot, ] steps: - uses: actions/checkout@v3 diff --git a/contracts/adventurer/src/adventurer.cairo b/contracts/adventurer/src/adventurer.cairo index e81edde93..817af00e0 100644 --- a/contracts/adventurer/src/adventurer.cairo +++ b/contracts/adventurer/src/adventurer.cairo @@ -6,9 +6,8 @@ use core::{ }; use super::{ - item_meta::{ItemSpecials, ItemSpecialsStorage, ImplItemSpecials}, stats::{Stats, StatsPacking}, - item_primitive::{ItemPrimitive, ItemPrimitivePacking}, adventurer_utils::{AdventurerUtils}, - exploration::ExploreUtils, bag::{Bag, IBag, ImplBag}, + stats::{Stats, StatsPacking}, item_primitive::{ItemPrimitive, ItemPrimitivePacking}, + adventurer_utils::{AdventurerUtils}, exploration::ExploreUtils, bag::{Bag, IBag, ImplBag}, constants::{ adventurer_constants::{ STARTING_GOLD, StatisticIndex, POTION_PRICE, STARTING_HEALTH, CHARISMA_POTION_DISCOUNT, @@ -46,14 +45,14 @@ struct Adventurer { xp: u16, // 14 bits stats: Stats, // 26 bits gold: u16, // 9 bits - weapon: ItemPrimitive, // 21 bits - chest: ItemPrimitive, // 21 bits - head: ItemPrimitive, // 21 bits - waist: ItemPrimitive, // 21 bits - foot: ItemPrimitive, // 21 bits - hand: ItemPrimitive, // 21 bits - neck: ItemPrimitive, // 21 bits - ring: ItemPrimitive, // 21 bits + weapon: ItemPrimitive, // 16 bits + chest: ItemPrimitive, // 16 bits + head: ItemPrimitive, // 16 bits + waist: ItemPrimitive, // 16 bits + foot: ItemPrimitive, // 16 bits + hand: ItemPrimitive, // 16 bits + neck: ItemPrimitive, // 16 bits + ring: ItemPrimitive, // 16 bits beast_health: u16, // 9 bits stat_points_available: u8, // 3 bits actions_per_block: u8, // 4 bits @@ -151,14 +150,14 @@ impl ImplAdventurer of IAdventurer { xp: 0, stats: StatUtils::new(), gold: STARTING_GOLD, - weapon: ItemPrimitive { id: starting_item, xp: 0, metadata: 1 }, - chest: ItemPrimitive { id: 0, xp: 0, metadata: 0 }, - head: ItemPrimitive { id: 0, xp: 0, metadata: 0 }, - waist: ItemPrimitive { id: 0, xp: 0, metadata: 0 }, - foot: ItemPrimitive { id: 0, xp: 0, metadata: 0 }, - hand: ItemPrimitive { id: 0, xp: 0, metadata: 0 }, - neck: ItemPrimitive { id: 0, xp: 0, metadata: 0 }, - ring: ItemPrimitive { id: 0, xp: 0, metadata: 0 }, + weapon: ItemPrimitive { id: starting_item, xp: 0 }, + chest: ItemPrimitive { id: 0, xp: 0 }, + head: ItemPrimitive { id: 0, xp: 0 }, + waist: ItemPrimitive { id: 0, xp: 0 }, + foot: ItemPrimitive { id: 0, xp: 0 }, + hand: ItemPrimitive { id: 0, xp: 0 }, + neck: ItemPrimitive { id: 0, xp: 0 }, + ring: ItemPrimitive { id: 0, xp: 0 }, beast_health: BeastSettings::STARTER_BEAST_HEALTH, stat_points_available: 0, actions_per_block: 0, @@ -232,7 +231,7 @@ impl ImplAdventurer of IAdventurer { #[inline(always)] fn get_item_at_slot(self: Adventurer, slot: Slot) -> ItemPrimitive { match slot { - Slot::None(()) => ItemPrimitive { id: 0, xp: 0, metadata: 0 }, + Slot::None(()) => ItemPrimitive { id: 0, xp: 0 }, Slot::Weapon(()) => self.weapon, Slot::Chest(()) => self.chest, Slot::Head(()) => self.head, @@ -825,109 +824,6 @@ impl ImplAdventurer of IAdventurer { } } - /// @notice Applies specials to an item. - /// @param self The primitive item data. - /// @param name_storage Reference to the item specials storage which will be updated - /// @param suffix_unlocked Flag indicating if the suffix is unlocked. - /// @param prefixes_unlocked Flag indicating if the prefixes are unlocked. - /// @param entropy Randomness input for generating item specials. - /// @return ItemSpecials instance with applied specials. - fn apply_specials( - self: ItemPrimitive, - ref name_storage: ItemSpecialsStorage, - suffix_unlocked: bool, - prefixes_unlocked: bool, - entropy: u128 - ) -> ItemSpecials { - if (suffix_unlocked && prefixes_unlocked) { - return self.apply_suffix_and_prefixes(ref name_storage, entropy); - } else if (suffix_unlocked) { - return self.apply_suffix(ref name_storage, entropy); - } else if (prefixes_unlocked) { - return self.apply_prefixes(ref name_storage, entropy); - } else { - panic_with_felt252('no specials unlocked') - } - } - - // @notice Applies suffix and prefixes to an item - // @param self The primitive item data. - // @param name_storage Reference to the item specials storage. - // @param entropy Randomness input for generating item specials. - // @return ItemSpecials instance with applied specials. - fn apply_suffix_and_prefixes( - self: ItemPrimitive, ref name_storage: ItemSpecialsStorage, entropy: u128 - ) -> ItemSpecials { - // get rnd for specials - let (specials_rnd1, special_rnd2) = AdventurerUtils::generate_item_special_entropy( - entropy, self.id - ); - - // generate special names - let specials = ItemSpecials { - special1: ImplLoot::get_special1(self.id, specials_rnd1), - special2: ImplLoot::generate_prefix1(self.id, special_rnd2), - special3: ImplLoot::generate_prefix2(self.id, specials_rnd1) - }; - - // set specials in storage - name_storage.set_specials(self, specials); - - // return specials - specials - } - - // @notice Applies suffix to an item. - // @param self The primitive item data. - // @param name_storage Reference to the item specials storage. - // @param entropy Randomness input for generating the item suffix. - // @return ItemSpecials instance with applied suffix. - fn apply_suffix( - self: ItemPrimitive, ref name_storage: ItemSpecialsStorage, entropy: u128 - ) -> ItemSpecials { - // get rnd for specials - let (specials_rnd1, _) = AdventurerUtils::generate_item_special_entropy(entropy, self.id); - - // generate special names - let specials = ItemSpecials { - special1: ImplLoot::get_special1(self.id, specials_rnd1), // set item suffix - special2: 0, - special3: 0, - }; - - // set specials in storage - name_storage.set_specials(self, specials); - - // return specials - specials - } - - // @dev Apply only the prefixes to an item while preserving any existing suffix. - // @param self The primitive item data. - // @param name_storage Reference to the item specials storage. - // @param entropy Randomness input for generating the item prefixes. - // @return ItemSpecials instance with applied prefixes. - fn apply_prefixes( - self: ItemPrimitive, ref name_storage: ItemSpecialsStorage, entropy: u128 - ) -> ItemSpecials { - // get rnd for specials - let (specials_rnd1, specials_rnd2) = AdventurerUtils::generate_item_special_entropy( - entropy, self.id - ); - // generate prefixes while preserving existing suffix - let specials = ItemSpecials { - special1: name_storage.get_specials(self).special1, - special2: ImplLoot::generate_prefix1(self.id, specials_rnd1), - special3: ImplLoot::generate_prefix2(self.id, specials_rnd2), - }; - - // set specials in storage - ImplItemSpecials::set_specials(ref name_storage, self, specials); - - // return specials - specials - } - // @notice provides a a beast seed that is fixed during battle. This function does not use // game entropy as that could change during battle resulting in the beast changing // @param self A reference to the Adventurer to get the beast seed for. @@ -1127,116 +1023,44 @@ impl ImplAdventurer of IAdventurer { // @notice gets stat boosts based on item specials // @param self The Adventurer to get stat boosts for. - // @param name_storage1 The first ItemSpecialsStorage to use for getting item specials. - // @param name_storage2 The second ItemSpecialsStorage to use for getting item specials. + // @param start_entropy The start entropy to use for getting item specials. // @return Returns the stat boosts for the adventurer. - fn get_stat_boosts( - self: Adventurer, name_storage1: ItemSpecialsStorage, name_storage2: ItemSpecialsStorage - ) -> Stats { + fn get_stat_boosts(self: Adventurer, start_entropy: u64) -> Stats { let mut stats = Stats { strength: 0, dexterity: 0, vitality: 0, charisma: 0, intelligence: 0, wisdom: 0, luck: 0 }; if (self.weapon.get_greatness() >= SUFFIX_UNLOCK_GREANTESS) { - stats - .apply_suffix_boost( - ImplItemSpecials::get_specials_full(name_storage1, name_storage2, self.weapon) - .special1 - ); + stats.apply_suffix_boost(ImplLoot::get_suffix(self.weapon.id, start_entropy)); } if (self.chest.get_greatness() >= SUFFIX_UNLOCK_GREANTESS) { - stats - .apply_suffix_boost( - ImplItemSpecials::get_specials_full(name_storage1, name_storage2, self.chest) - .special1 - ); + stats.apply_suffix_boost(ImplLoot::get_suffix(self.chest.id, start_entropy)); } if (self.head.get_greatness() >= SUFFIX_UNLOCK_GREANTESS) { - stats - .apply_suffix_boost( - ImplItemSpecials::get_specials_full(name_storage1, name_storage2, self.head) - .special1 - ); + stats.apply_suffix_boost(ImplLoot::get_suffix(self.head.id, start_entropy)); } if (self.waist.get_greatness() >= SUFFIX_UNLOCK_GREANTESS) { - stats - .apply_suffix_boost( - ImplItemSpecials::get_specials_full(name_storage1, name_storage2, self.waist) - .special1 - ); + stats.apply_suffix_boost(ImplLoot::get_suffix(self.waist.id, start_entropy)); } if (self.foot.get_greatness() >= SUFFIX_UNLOCK_GREANTESS) { - stats - .apply_suffix_boost( - ImplItemSpecials::get_specials_full(name_storage1, name_storage2, self.foot) - .special1 - ); + stats.apply_suffix_boost(ImplLoot::get_suffix(self.foot.id, start_entropy)); } if (self.hand.get_greatness() >= SUFFIX_UNLOCK_GREANTESS) { - stats - .apply_suffix_boost( - ImplItemSpecials::get_specials_full(name_storage1, name_storage2, self.hand) - .special1 - ); + stats.apply_suffix_boost(ImplLoot::get_suffix(self.hand.id, start_entropy)); } if (self.neck.get_greatness() >= SUFFIX_UNLOCK_GREANTESS) { - stats - .apply_suffix_boost( - ImplItemSpecials::get_specials_full(name_storage1, name_storage2, self.neck) - .special1 - ); + stats.apply_suffix_boost(ImplLoot::get_suffix(self.neck.id, start_entropy)); } if (self.ring.get_greatness() >= SUFFIX_UNLOCK_GREANTESS) { - stats - .apply_suffix_boost( - ImplItemSpecials::get_specials_full(name_storage1, name_storage2, self.ring) - .special1 - ); + stats.apply_suffix_boost(ImplLoot::get_suffix(self.ring.id, start_entropy)); } stats } - // @notice The `get_storage_index` function is a helper function that determines the storage index based on the metadata ID. - // @param meta_data_id The ID of the metadata. - // @return Returns 0 if the metadata ID is less than or equal to 10, otherwise returns 1. - #[inline(always)] - fn get_storage_index(meta_data_id: u8) -> u256 { - if (meta_data_id <= 10) { - 0 - } else { - 1 - } - } - - // @notice The `get_idle_blocks` function calculates the number of idle blocks by subtracting the last action from the - // current block (modulo 512). - // @param self A reference to the Adventurer instance. - // @param current_block The current block number. - // @return Returns the number of idle blocks. - #[inline(always)] - fn get_idle_blocks(self: Adventurer, current_block: u64) -> u16 { - // adventurer only has 9 bits of storage for block numbers - // the last_action_block on the adventurer is 0-511 which is based on - // the current starknet block % 512. As such, when calculating the number Of - // idle blocks, we need to % 512 the current block - let current_block_modulo_512: u16 = (current_block % MAX_ADVENTURER_BLOCKS.into()) - .try_into() - .unwrap(); - - // if the current block is greater than or equal to the last last_action_block - if (current_block_modulo_512 >= self.last_action_block) { - // we can just subtract the two to get idle blocks - current_block_modulo_512 - self.last_action_block - } else { - // otherwise we need to add the two and subtract 512 - MAX_ADVENTURER_BLOCKS - self.last_action_block + current_block_modulo_512 - } - } - // @notice gets the greatness of an item // @param self the ItemPrimitive to get the greatness of // @return u8: the greatness of the item @@ -1468,7 +1292,7 @@ impl ImplAdventurer of IAdventurer { self: Adventurer, beast: Beast, armor: ItemPrimitive, - armor_specials: ItemSpecials, + armor_specials: SpecialPowers, entropy: u128, ) -> (CombatResult, u16) { // adventurer strength isn't used for defense @@ -1478,13 +1302,6 @@ impl ImplAdventurer of IAdventurer { // get armor details let armor_details = ImplLoot::get_item(armor.id); - // convert ItemSpecials to SpecialPowers used by Combat System - let armor_specials = SpecialPowers { - special1: armor_specials.special1, - special2: armor_specials.special2, - special3: armor_specials.special3, - }; - // get combat spec for armor let armor_combat_spec = CombatSpec { tier: armor_details.tier, @@ -1765,8 +1582,7 @@ mod tests { use combat::{constants::CombatEnums::{Slot, Type}}; use beasts::{beast::{ImplBeast, Beast}, constants::BeastSettings}; use survivor::{ - adventurer::{IAdventurer, ImplAdventurer, Adventurer, AdventurerPacking}, - item_meta::{ItemSpecials, ItemSpecialsStorage, ImplItemSpecials}, stats::Stats, + adventurer::{IAdventurer, ImplAdventurer, Adventurer, AdventurerPacking}, stats::Stats, item_primitive::ItemPrimitive, adventurer_utils::{AdventurerUtils}, bag::{Bag, ImplBag}, constants::{ adventurer_constants::{ @@ -1808,7 +1624,7 @@ mod tests { ); // equip gold ring with G1 - let gold_ring = ItemPrimitive { id: ItemId::GoldRing, xp: 1, metadata: 1 }; + let gold_ring = ItemPrimitive { id: ItemId::GoldRing, xp: 1 }; adventurer.ring = gold_ring; let _bonus = adventurer.ring.jewelry_gold_bonus(base_gold_amount); assert(adventurer.ring.jewelry_gold_bonus(base_gold_amount) == 3, 'bonus should be 3'); @@ -1825,7 +1641,7 @@ mod tests { assert(adventurer.ring.jewelry_gold_bonus(0) == 0, 'bonus should be 0'); // change to platinum ring - let platinum_ring = ItemPrimitive { id: ItemId::PlatinumRing, xp: 1, metadata: 1 }; + let platinum_ring = ItemPrimitive { id: ItemId::PlatinumRing, xp: 1 }; adventurer.ring = platinum_ring; assert(adventurer.ring.jewelry_gold_bonus(0) == 0, 'no bonus with plat ring'); } @@ -1834,7 +1650,7 @@ mod tests { #[available_gas(173744)] fn test_get_bonus_luck_gas() { // instantiate silver ring - let silver_ring = ItemPrimitive { id: ItemId::SilverRing, xp: 1, metadata: 1 }; + let silver_ring = ItemPrimitive { id: ItemId::SilverRing, xp: 1 }; let _bonus_luck = silver_ring.jewelry_bonus_luck(); } @@ -1842,7 +1658,7 @@ mod tests { #[available_gas(194024)] fn test_get_bonus_luck() { // equip silver ring - let mut silver_ring = ItemPrimitive { id: ItemId::SilverRing, xp: 1, metadata: 1 }; + let mut silver_ring = ItemPrimitive { id: ItemId::SilverRing, xp: 1 }; assert( silver_ring.jewelry_bonus_luck() == SILVER_RING_LUCK_BONUS_PER_GREATNESS, 'wrong g1 bonus luck' @@ -1856,10 +1672,10 @@ mod tests { ); // verify none of the other rings provide a luck bonus - let gold_ring = ItemPrimitive { id: ItemId::GoldRing, xp: 400, metadata: 1 }; - let bronze_ring = ItemPrimitive { id: ItemId::BronzeRing, xp: 400, metadata: 1 }; - let platinum_ring = ItemPrimitive { id: ItemId::PlatinumRing, xp: 400, metadata: 1 }; - let titanium_ring = ItemPrimitive { id: ItemId::TitaniumRing, xp: 400, metadata: 1 }; + let gold_ring = ItemPrimitive { id: ItemId::GoldRing, xp: 400 }; + let bronze_ring = ItemPrimitive { id: ItemId::BronzeRing, xp: 400 }; + let platinum_ring = ItemPrimitive { id: ItemId::PlatinumRing, xp: 400 }; + let titanium_ring = ItemPrimitive { id: ItemId::TitaniumRing, xp: 400 }; assert(gold_ring.jewelry_bonus_luck() == 0, 'no bonus luck for gold ring'); assert(bronze_ring.jewelry_bonus_luck() == 0, 'no bonus luck for bronze ring'); @@ -1935,446 +1751,10 @@ mod tests { assert(prefixes_unlocked, 'prefixes should be unlocked'); } - #[test] - #[should_panic(expected: ('no specials unlocked',))] - #[available_gas(278330)] - fn test_apply_specials_panic() { - let suffix_unlocked = false; - let prefixes_unlocked = false; - let entropy = 12345; - - let blank_item_specials = ItemSpecials { special2: 0, special3: 0, special1: 0, }; - - let mut name_storage = ItemSpecialsStorage { - item_1: blank_item_specials, - item_2: blank_item_specials, - item_3: blank_item_specials, - item_4: blank_item_specials, - item_5: blank_item_specials, - item_6: blank_item_specials, - item_7: blank_item_specials, - item_8: blank_item_specials, - item_9: blank_item_specials, - item_10: blank_item_specials, - mutated: false - }; - - let katana = ItemPrimitive { id: ItemId::Katana, xp: 0, metadata: 0 }; - - // calling apply specials with suffix_unlock and prefixed_unlocked is not a valid - // apply_specials should panic in this case which the test is annotated to expect - katana.apply_specials(ref name_storage, suffix_unlocked, prefixes_unlocked, entropy); - } - - #[test] - #[available_gas(483540)] - fn test_apply_prefixes() { - let entropy = 12345; - - let katana_starting_specials = ItemSpecials { special1: 1, special2: 0, special3: 0 }; - let blank_item_specials = ItemSpecials { special2: 0, special3: 0, special1: 0, }; - - let mut name_storage = ItemSpecialsStorage { - item_1: katana_starting_specials, - item_2: blank_item_specials, - item_3: blank_item_specials, - item_4: blank_item_specials, - item_5: blank_item_specials, - item_6: blank_item_specials, - item_7: blank_item_specials, - item_8: blank_item_specials, - item_9: blank_item_specials, - item_10: blank_item_specials, - mutated: false - }; - - let katana = ItemPrimitive { id: ItemId::Katana, xp: 0, metadata: 1 }; - katana.apply_prefixes(ref name_storage, entropy); - - // verify special2 and special3 are now set in the name_storage - assert(name_storage.item_1.special1 != 0, 'katana special1 not preserved'); - assert(name_storage.item_1.special2 != 0, 'katana special2 not applied'); - assert(name_storage.item_1.special3 != 0, 'katana special3 not applied'); - - // assert all other specials for all other items is still 0 - assert(name_storage.item_2.special1 == 0, 'item2 special1 not blank'); - assert(name_storage.item_2.special2 == 0, 'item2 special2 not blank'); - assert(name_storage.item_2.special3 == 0, 'item2 special3 not blank'); - assert(name_storage.item_3.special1 == 0, 'item3 special1 not blank'); - assert(name_storage.item_3.special2 == 0, 'item3 special2 not blank'); - assert(name_storage.item_3.special3 == 0, 'item3 special3 not blank'); - assert(name_storage.item_4.special1 == 0, 'item4 special1 not blank'); - assert(name_storage.item_4.special2 == 0, 'item4 special2 not blank'); - assert(name_storage.item_4.special3 == 0, 'item4 special3 not blank'); - assert(name_storage.item_5.special1 == 0, 'item5 special1 not blank'); - assert(name_storage.item_5.special2 == 0, 'item5 special2 not blank'); - assert(name_storage.item_5.special3 == 0, 'item5 special3 not blank'); - assert(name_storage.item_6.special1 == 0, 'item6 special1 not blank'); - assert(name_storage.item_6.special2 == 0, 'item6 special2 not blank'); - assert(name_storage.item_6.special3 == 0, 'item6 special3 not blank'); - assert(name_storage.item_7.special1 == 0, 'item7 special1 not blank'); - assert(name_storage.item_7.special2 == 0, 'item7 special2 not blank'); - assert(name_storage.item_7.special3 == 0, 'item7 special3 not blank'); - assert(name_storage.item_8.special1 == 0, 'item8 special1 not blank'); - assert(name_storage.item_8.special2 == 0, 'item8 special2 not blank'); - assert(name_storage.item_8.special3 == 0, 'item8 special3 not blank'); - assert(name_storage.item_9.special1 == 0, 'item9 special1 not blank'); - assert(name_storage.item_9.special2 == 0, 'item9 special2 not blank'); - assert(name_storage.item_9.special3 == 0, 'item9 special3 not blank'); - assert(name_storage.item_10.special1 == 0, 'item10 special1 not blank'); - assert(name_storage.item_10.special2 == 0, 'item10 special2 not blank'); - assert(name_storage.item_10.special3 == 0, 'item10 special3 not blank'); - - let crown = ItemPrimitive { id: ItemId::Crown, xp: 0, metadata: 5 }; - crown.apply_prefixes(ref name_storage, entropy); - - // assert katana special2 and special3 are still set - assert(name_storage.item_1.special1 != 0, 'katana special1 not preserved'); - assert(name_storage.item_1.special2 != 0, 'katana special2 not preserved'); - assert(name_storage.item_1.special3 != 0, 'katana special3 not preserved'); - - // assert crown special2 and special3 are now set - assert(name_storage.item_5.special1 == 0, 'crown special1 not zero'); - assert(name_storage.item_5.special2 != 0, 'crown special2 not applied'); - assert(name_storage.item_5.special3 != 0, 'crown special3 not applied'); - - // assert all other specials for all other items are still 0 - assert(name_storage.item_2.special1 == 0, 'item2 special1 not blank'); - assert(name_storage.item_2.special2 == 0, 'item2 special2 not blank'); - assert(name_storage.item_2.special3 == 0, 'item2 special3 not blank'); - assert(name_storage.item_3.special1 == 0, 'item3 special1 not blank'); - assert(name_storage.item_3.special2 == 0, 'item3 special2 not blank'); - assert(name_storage.item_3.special3 == 0, 'item3 special3 not blank'); - assert(name_storage.item_4.special1 == 0, 'item4 special1 not blank'); - assert(name_storage.item_4.special2 == 0, 'item4 special2 not blank'); - assert(name_storage.item_4.special3 == 0, 'item4 special3 not blank'); - assert(name_storage.item_6.special1 == 0, 'item6 special1 not blank'); - assert(name_storage.item_6.special2 == 0, 'item6 special2 not blank'); - assert(name_storage.item_6.special3 == 0, 'item6 special3 not blank'); - assert(name_storage.item_7.special1 == 0, 'item7 special1 not blank'); - assert(name_storage.item_7.special2 == 0, 'item7 special2 not blank'); - assert(name_storage.item_7.special3 == 0, 'item7 special3 not blank'); - assert(name_storage.item_8.special1 == 0, 'item8 special1 not blank'); - assert(name_storage.item_8.special2 == 0, 'item8 special2 not blank'); - assert(name_storage.item_8.special3 == 0, 'item8 special3 not blank'); - assert(name_storage.item_9.special1 == 0, 'item9 special1 not blank'); - assert(name_storage.item_9.special2 == 0, 'item9 special2 not blank'); - assert(name_storage.item_9.special3 == 0, 'item9 special3 not blank'); - assert(name_storage.item_10.special1 == 0, 'item10 special1 not blank'); - assert(name_storage.item_10.special2 == 0, 'item10 special2 not blank'); - assert(name_storage.item_10.special3 == 0, 'item10 special3 not blank'); - } - #[test] - #[available_gas(310600)] - fn test_apply_suffix() { - let entropy = 12345; - - let blank_item_specials = ItemSpecials { special2: 0, special3: 0, special1: 0, }; - - let mut name_storage = ItemSpecialsStorage { - item_1: blank_item_specials, - item_2: blank_item_specials, - item_3: blank_item_specials, - item_4: blank_item_specials, - item_5: blank_item_specials, - item_6: blank_item_specials, - item_7: blank_item_specials, - item_8: blank_item_specials, - item_9: blank_item_specials, - item_10: blank_item_specials, - mutated: false - }; - - let katana = ItemPrimitive { id: ItemId::Katana, xp: 0, metadata: 1 }; - katana.apply_suffix(ref name_storage, entropy); - - // verify special2 and special3 are now set in the name_storage - assert(name_storage.item_1.special1 != 0, 'katana special1 not applied'); - assert(name_storage.item_1.special2 == 0, 'katana special2 not zero'); - assert(name_storage.item_1.special3 == 0, 'katana special3 not zero'); - - // assert special1, special2, and special3 for the other items are still 0 - assert(name_storage.item_2.special1 == 0, 'item2 special1 not blank'); - assert(name_storage.item_2.special2 == 0, 'item2 special2 not blank'); - assert(name_storage.item_2.special3 == 0, 'item2 special3 not blank'); - assert(name_storage.item_3.special1 == 0, 'item3 special1 not blank'); - assert(name_storage.item_3.special2 == 0, 'item3 special2 not blank'); - assert(name_storage.item_3.special3 == 0, 'item3 special3 not blank'); - - let crown = ItemPrimitive { id: ItemId::Crown, xp: 0, metadata: 5 }; - crown.apply_suffix(ref name_storage, entropy); - - // assert katana special1 is still set - assert(name_storage.item_1.special1 != 0, 'katana special1 not applied'); - // assert crown special1 is set - assert(name_storage.item_5.special1 != 0, 'crown special1 not applied'); - - // assert all other specials for all other items are still 0 - assert(name_storage.item_1.special2 == 0, 'katana special2 not zero'); - assert(name_storage.item_1.special3 == 0, 'katana special3 not zero'); - assert(name_storage.item_2.special1 == 0, 'item2 special1 not blank'); - assert(name_storage.item_2.special2 == 0, 'crown special2 not zero'); - assert(name_storage.item_2.special3 == 0, 'crown special3 not zero'); - assert(name_storage.item_3.special1 == 0, 'item3 special1 not blank'); - assert(name_storage.item_3.special2 == 0, 'item3 special2 not blank'); - assert(name_storage.item_3.special3 == 0, 'item3 special3 not blank'); - assert(name_storage.item_4.special1 == 0, 'item4 special1 not blank'); - assert(name_storage.item_4.special2 == 0, 'item4 special2 not blank'); - assert(name_storage.item_4.special3 == 0, 'item4 special3 not blank'); - assert(name_storage.item_5.special2 == 0, 'item5 special2 not blank'); - assert(name_storage.item_5.special3 == 0, 'item5 special3 not blank'); - assert(name_storage.item_6.special1 == 0, 'item6 special1 not blank'); - assert(name_storage.item_6.special2 == 0, 'item6 special2 not blank'); - assert(name_storage.item_6.special3 == 0, 'item6 special3 not blank'); - assert(name_storage.item_7.special1 == 0, 'item7 special1 not blank'); - assert(name_storage.item_7.special2 == 0, 'item7 special2 not blank'); - assert(name_storage.item_7.special3 == 0, 'item7 special3 not blank'); - assert(name_storage.item_8.special1 == 0, 'item8 special1 not blank'); - assert(name_storage.item_8.special2 == 0, 'item8 special2 not blank'); - assert(name_storage.item_8.special3 == 0, 'item8 special3 not blank'); - assert(name_storage.item_9.special1 == 0, 'item9 special1 not blank'); - assert(name_storage.item_9.special2 == 0, 'item9 special2 not blank'); - assert(name_storage.item_9.special3 == 0, 'item9 special3 not blank'); - assert(name_storage.item_10.special1 == 0, 'item10 special1 not blank'); - assert(name_storage.item_10.special2 == 0, 'item10 special2 not blank'); - assert(name_storage.item_10.special3 == 0, 'item10 special3 not blank'); - } - - #[test] - #[available_gas(285140)] - fn test_apply_suffix_and_prefixes() { - let entropy = 12345; - - // start katana with a special as would be the case in the game - let katana = ItemPrimitive { id: ItemId::Katana, xp: 0, metadata: 1 }; - let katana_starting_special = ItemSpecials { special1: 0, special2: 0, special3: 0 }; - let blank_item_specials = ItemSpecials { special1: 0, special2: 0, special3: 0 }; - - let mut name_storage = ItemSpecialsStorage { - item_1: katana_starting_special, - item_2: blank_item_specials, - item_3: blank_item_specials, - item_4: blank_item_specials, - item_5: blank_item_specials, - item_6: blank_item_specials, - item_7: blank_item_specials, - item_8: blank_item_specials, - item_9: blank_item_specials, - item_10: blank_item_specials, - mutated: false - }; - - // apply prefixes to katana - katana.apply_suffix_and_prefixes(ref name_storage, entropy); - - // verify special2 and special3 are now set in the name_storage - assert(name_storage.item_1.special1 != 0, 'katana special1 not applied'); - assert(name_storage.item_1.special2 != 0, 'katana special2 not applied'); - assert(name_storage.item_1.special3 != 0, 'katana special3 not applied'); - - // assert special1, special2, and special3 for the other items are still 0 - assert(name_storage.item_2.special1 == 0, 'item2 special1 not blank'); - assert(name_storage.item_2.special2 == 0, 'item2 special2 not blank'); - assert(name_storage.item_2.special3 == 0, 'item2 special3 not blank'); - assert(name_storage.item_3.special1 == 0, 'item3 special1 not blank'); - assert(name_storage.item_3.special2 == 0, 'item3 special2 not blank'); - assert(name_storage.item_3.special3 == 0, 'item3 special3 not blank'); - } - - #[test] - #[available_gas(299740)] - fn test_apply_specials_suffix_and_prefixes() { - let suffix_unlocked = true; - let prefixes_unlocked = true; - let entropy = 12345; - - // start katana with a special as would be the case in the game - let katana = ItemPrimitive { id: ItemId::Katana, xp: 0, metadata: 1 }; - let katana_starting_special = ItemSpecials { special1: 0, special2: 0, special3: 0 }; - let blank_item_specials = ItemSpecials { special1: 0, special2: 0, special3: 0 }; - - let mut name_storage = ItemSpecialsStorage { - item_1: katana_starting_special, - item_2: blank_item_specials, - item_3: blank_item_specials, - item_4: blank_item_specials, - item_5: blank_item_specials, - item_6: blank_item_specials, - item_7: blank_item_specials, - item_8: blank_item_specials, - item_9: blank_item_specials, - item_10: blank_item_specials, - mutated: false - }; - - // apply prefixes to katana - katana.apply_specials(ref name_storage, suffix_unlocked, prefixes_unlocked, entropy); - - // verify special2 and special3 are now set in the name_storage - assert(name_storage.item_1.special1 != 0, 'katana special1 not applied'); - assert(name_storage.item_1.special2 != 0, 'katana special2 not applied'); - assert(name_storage.item_1.special3 != 0, 'katana special3 not applied'); - - // assert special1, special2, and special3 for the other items are still 0 - assert(name_storage.item_2.special1 == 0, 'item2 special1 not blank'); - assert(name_storage.item_2.special2 == 0, 'item2 special2 not blank'); - assert(name_storage.item_2.special3 == 0, 'item2 special3 not blank'); - assert(name_storage.item_3.special1 == 0, 'item3 special1 not blank'); - assert(name_storage.item_3.special2 == 0, 'item3 special2 not blank'); - assert(name_storage.item_3.special3 == 0, 'item3 special3 not blank'); - assert(name_storage.item_4.special1 == 0, 'item4 special1 not blank'); - assert(name_storage.item_4.special2 == 0, 'item4 special2 not blank'); - assert(name_storage.item_4.special3 == 0, 'item4 special3 not blank'); - assert(name_storage.item_5.special1 == 0, 'item5 special1 not blank'); - assert(name_storage.item_5.special2 == 0, 'item5 special2 not blank'); - assert(name_storage.item_5.special3 == 0, 'item5 special3 not blank'); - assert(name_storage.item_6.special1 == 0, 'item6 special1 not blank'); - assert(name_storage.item_6.special2 == 0, 'item6 special2 not blank'); - assert(name_storage.item_6.special3 == 0, 'item6 special3 not blank'); - assert(name_storage.item_7.special1 == 0, 'item7 special1 not blank'); - assert(name_storage.item_7.special2 == 0, 'item7 special2 not blank'); - assert(name_storage.item_7.special3 == 0, 'item7 special3 not blank'); - assert(name_storage.item_8.special1 == 0, 'item8 special1 not blank'); - assert(name_storage.item_8.special2 == 0, 'item8 special2 not blank'); - assert(name_storage.item_8.special3 == 0, 'item8 special3 not blank'); - assert(name_storage.item_9.special1 == 0, 'item9 special1 not blank'); - assert(name_storage.item_9.special2 == 0, 'item9 special2 not blank'); - assert(name_storage.item_9.special3 == 0, 'item9 special3 not blank'); - assert(name_storage.item_10.special1 == 0, 'item10 special1 not blank'); - assert(name_storage.item_10.special2 == 0, 'item10 special2 not blank'); - assert(name_storage.item_10.special3 == 0, 'item10 special3 not blank'); - } - - #[test] - #[available_gas(299340)] - fn test_apply_specials_prefixes() { - let suffix_unlocked = false; - let prefixes_unlocked = true; - let entropy = 12345; - - // start katana with a special as would be the case in the game - let katana = ItemPrimitive { id: ItemId::Katana, xp: 0, metadata: 1 }; - let katana_starting_special = ItemSpecials { special1: 1, special2: 0, special3: 0 }; - let blank_item_specials = ItemSpecials { special1: 0, special2: 0, special3: 0 }; - - let mut name_storage = ItemSpecialsStorage { - item_1: katana_starting_special, - item_2: blank_item_specials, - item_3: blank_item_specials, - item_4: blank_item_specials, - item_5: blank_item_specials, - item_6: blank_item_specials, - item_7: blank_item_specials, - item_8: blank_item_specials, - item_9: blank_item_specials, - item_10: blank_item_specials, - mutated: false - }; - - // apply prefixes to katana - katana.apply_specials(ref name_storage, suffix_unlocked, prefixes_unlocked, entropy); - - // verify special2 and special3 are now set in the name_storage - assert(name_storage.item_1.special1 == 1, 'katana special1 not preserved'); - assert(name_storage.item_1.special2 != 0, 'katana special2 not applied'); - assert(name_storage.item_1.special3 != 0, 'katana special3 not applied'); - - // assert special1, special2, and special3 for the other items are still 0 - assert(name_storage.item_2.special1 == 0, 'item2 special1 not blank'); - assert(name_storage.item_2.special2 == 0, 'item2 special2 not blank'); - assert(name_storage.item_2.special3 == 0, 'item2 special3 not blank'); - assert(name_storage.item_3.special1 == 0, 'item3 special1 not blank'); - assert(name_storage.item_3.special2 == 0, 'item3 special2 not blank'); - assert(name_storage.item_3.special3 == 0, 'item3 special3 not blank'); - assert(name_storage.item_4.special1 == 0, 'item4 special1 not blank'); - assert(name_storage.item_4.special2 == 0, 'item4 special2 not blank'); - assert(name_storage.item_4.special3 == 0, 'item4 special3 not blank'); - assert(name_storage.item_5.special1 == 0, 'item5 special1 not blank'); - assert(name_storage.item_5.special2 == 0, 'item5 special2 not blank'); - assert(name_storage.item_5.special3 == 0, 'item5 special3 not blank'); - assert(name_storage.item_6.special1 == 0, 'item6 special1 not blank'); - assert(name_storage.item_6.special2 == 0, 'item6 special2 not blank'); - assert(name_storage.item_6.special3 == 0, 'item6 special3 not blank'); - assert(name_storage.item_7.special1 == 0, 'item7 special1 not blank'); - assert(name_storage.item_7.special2 == 0, 'item7 special2 not blank'); - assert(name_storage.item_7.special3 == 0, 'item7 special3 not blank'); - assert(name_storage.item_8.special1 == 0, 'item8 special1 not blank'); - assert(name_storage.item_8.special2 == 0, 'item8 special2 not blank'); - assert(name_storage.item_8.special3 == 0, 'item8 special3 not blank'); - assert(name_storage.item_9.special1 == 0, 'item9 special1 not blank'); - assert(name_storage.item_9.special2 == 0, 'item9 special2 not blank'); - assert(name_storage.item_9.special3 == 0, 'item9 special3 not blank'); - assert(name_storage.item_10.special1 == 0, 'item10 special1 not blank'); - assert(name_storage.item_10.special2 == 0, 'item10 special2 not blank'); - assert(name_storage.item_10.special3 == 0, 'item10 special3 not blank'); - } - - #[test] - #[available_gas(11278330)] - fn test_apply_specials_suffix() { - let suffix_unlocked = true; - let prefixes_unlocked = false; - let entropy = 12345; - - let blank_item_specials = ItemSpecials { special2: 0, special3: 0, special1: 0, }; - - let mut name_storage = ItemSpecialsStorage { - item_1: blank_item_specials, - item_2: blank_item_specials, - item_3: blank_item_specials, - item_4: blank_item_specials, - item_5: blank_item_specials, - item_6: blank_item_specials, - item_7: blank_item_specials, - item_8: blank_item_specials, - item_9: blank_item_specials, - item_10: blank_item_specials, - mutated: false - }; - - let katana = ItemPrimitive { id: ItemId::Katana, xp: 0, metadata: 1 }; - katana.apply_specials(ref name_storage, suffix_unlocked, prefixes_unlocked, entropy); - - // assert katana now has special1 set in the name_storage - assert(name_storage.item_1.special1 != 0, 'suffix not applied'); - // the katanas special2 and special3 should still be empty - assert(name_storage.item_1.special2 == 0, 'special2 not blank'); - assert(name_storage.item_1.special3 == 0, 'special3 not blank'); - - // as should the rest of the names in the storage - assert(name_storage.item_2.special1 == 0, 'special1 not blank'); - assert(name_storage.item_2.special2 == 0, 'special2 not blank'); - assert(name_storage.item_2.special3 == 0, 'special3 not blank'); - assert(name_storage.item_3.special1 == 0, 'special1 not blank'); - assert(name_storage.item_3.special2 == 0, 'special2 not blank'); - assert(name_storage.item_3.special3 == 0, 'special3 not blank'); - assert(name_storage.item_4.special1 == 0, 'special1 not blank'); - assert(name_storage.item_4.special2 == 0, 'special2 not blank'); - assert(name_storage.item_4.special3 == 0, 'special3 not blank'); - assert(name_storage.item_5.special1 == 0, 'special1 not blank'); - assert(name_storage.item_5.special2 == 0, 'special2 not blank'); - assert(name_storage.item_5.special3 == 0, 'special3 not blank'); - assert(name_storage.item_6.special1 == 0, 'special1 not blank'); - assert(name_storage.item_6.special2 == 0, 'special2 not blank'); - assert(name_storage.item_6.special3 == 0, 'special3 not blank'); - assert(name_storage.item_7.special1 == 0, 'special1 not blank'); - assert(name_storage.item_7.special2 == 0, 'special2 not blank'); - assert(name_storage.item_7.special3 == 0, 'special3 not blank'); - assert(name_storage.item_8.special1 == 0, 'special1 not blank'); - assert(name_storage.item_8.special2 == 0, 'special2 not blank'); - assert(name_storage.item_8.special3 == 0, 'special3 not blank'); - assert(name_storage.item_9.special1 == 0, 'special1 not blank'); - assert(name_storage.item_9.special2 == 0, 'special2 not blank'); - assert(name_storage.item_9.special3 == 0, 'special3 not blank'); - assert(name_storage.item_10.special1 == 0, 'special1 not blank'); - assert(name_storage.item_10.special2 == 0, 'special2 not blank'); - assert(name_storage.item_10.special3 == 0, 'special3 not blank'); - } - #[test] #[available_gas(14610)] fn test_jewelry_armor_bonus_gas() { - let amulet = ItemPrimitive { id: ItemId::Amulet, xp: 400, metadata: 1 }; + let amulet = ItemPrimitive { id: ItemId::Amulet, xp: 400 }; amulet.jewelry_armor_bonus(Type::Magic_or_Cloth(()), 100); } @@ -2382,7 +1762,7 @@ mod tests { #[available_gas(284000)] fn test_jewelry_armor_bonus() { // amulet test cases - let amulet = ItemPrimitive { id: ItemId::Amulet, xp: 400, metadata: 1 }; + let amulet = ItemPrimitive { id: ItemId::Amulet, xp: 400 }; assert(amulet.jewelry_armor_bonus(Type::None(()), 100) == 0, 'None Type gets 0 bonus'); assert( amulet.jewelry_armor_bonus(Type::Magic_or_Cloth(()), 100) == NECKLACE_ARMOR_BONUS.into() @@ -2403,7 +1783,7 @@ mod tests { assert(amulet.jewelry_armor_bonus(Type::Ring(()), 100) == 0, 'Ring Type gets 0 bonus'); // pendant test cases - let pendant = ItemPrimitive { id: ItemId::Pendant, xp: 400, metadata: 2 }; + let pendant = ItemPrimitive { id: ItemId::Pendant, xp: 400 }; assert(pendant.jewelry_armor_bonus(Type::None(()), 100) == 0, 'None Type gets 0 bonus'); assert( pendant.jewelry_armor_bonus(Type::Magic_or_Cloth(()), 100) == 0, @@ -2424,7 +1804,7 @@ mod tests { assert(pendant.jewelry_armor_bonus(Type::Ring(()), 100) == 0, 'Ring Type gets 0 bonus'); // necklace test cases - let necklace = ItemPrimitive { id: ItemId::Necklace, xp: 400, metadata: 3 }; + let necklace = ItemPrimitive { id: ItemId::Necklace, xp: 400 }; assert(necklace.jewelry_armor_bonus(Type::None(()), 100) == 0, 'None Type gets 0 bonus'); assert( necklace.jewelry_armor_bonus(Type::Magic_or_Cloth(()), 100) == 0, @@ -2447,7 +1827,7 @@ mod tests { assert(necklace.jewelry_armor_bonus(Type::Ring(()), 100) == 0, 'Ring Type gets 0 bonus'); // test non jewelry item - let katana = ItemPrimitive { id: ItemId::Katana, xp: 400, metadata: 1 }; + let katana = ItemPrimitive { id: ItemId::Katana, xp: 400 }; assert(katana.jewelry_armor_bonus(Type::None(()), 100) == 0, 'Katan does not boost armor'); } @@ -2455,7 +1835,7 @@ mod tests { #[test] #[available_gas(13510)] fn test_name_match_bonus_damage_gas() { - let platinum_ring = ItemPrimitive { id: ItemId::PlatinumRing, xp: 400, metadata: 6 }; + let platinum_ring = ItemPrimitive { id: ItemId::PlatinumRing, xp: 400 }; platinum_ring.name_match_bonus_damage(0); } @@ -2464,12 +1844,12 @@ mod tests { fn test_name_match_bonus_damage() { let base_damage = 100; - let titanium_ring = ItemPrimitive { id: ItemId::TitaniumRing, xp: 400, metadata: 6 }; + let titanium_ring = ItemPrimitive { id: ItemId::TitaniumRing, xp: 400 }; assert( titanium_ring.name_match_bonus_damage(base_damage) == 0, 'no bonus for titanium ring' ); - let platinum_ring = ItemPrimitive { id: ItemId::PlatinumRing, xp: 0, metadata: 6 }; + let platinum_ring = ItemPrimitive { id: ItemId::PlatinumRing, xp: 0 }; assert( platinum_ring .name_match_bonus_damage( @@ -2479,7 +1859,7 @@ mod tests { 'should be 3hp name bonus' ); - let platinum_ring = ItemPrimitive { id: ItemId::PlatinumRing, xp: 100, metadata: 6 }; + let platinum_ring = ItemPrimitive { id: ItemId::PlatinumRing, xp: 100 }; assert( platinum_ring .name_match_bonus_damage( @@ -2489,7 +1869,7 @@ mod tests { 'should be 30hp name bonus' ); - let platinum_ring = ItemPrimitive { id: ItemId::PlatinumRing, xp: 400, metadata: 6 }; + let platinum_ring = ItemPrimitive { id: ItemId::PlatinumRing, xp: 400 }; assert( platinum_ring .name_match_bonus_damage( @@ -2500,33 +1880,6 @@ mod tests { ); } - #[test] - #[available_gas(100000)] - fn test_get_storage_index() { - assert(ImplAdventurer::get_storage_index(0) == 0, 'storage index should be 0'); - assert(ImplAdventurer::get_storage_index(1) == 0, 'storage index should be 0'); - assert(ImplAdventurer::get_storage_index(2) == 0, 'storage index should be 0'); - assert(ImplAdventurer::get_storage_index(3) == 0, 'storage index should be 0'); - assert(ImplAdventurer::get_storage_index(4) == 0, 'storage index should be 0'); - assert(ImplAdventurer::get_storage_index(5) == 0, 'storage index should be 0'); - assert(ImplAdventurer::get_storage_index(6) == 0, 'storage index should be 0'); - assert(ImplAdventurer::get_storage_index(7) == 0, 'storage index should be 0'); - assert(ImplAdventurer::get_storage_index(8) == 0, 'storage index should be 0'); - assert(ImplAdventurer::get_storage_index(9) == 0, 'storage index should be 0'); - assert(ImplAdventurer::get_storage_index(10) == 0, 'storage index should be 0'); - assert(ImplAdventurer::get_storage_index(11) == 1, 'storage index should be 1'); - assert(ImplAdventurer::get_storage_index(12) == 1, 'storage index should be 1'); - assert(ImplAdventurer::get_storage_index(13) == 1, 'storage index should be 1'); - assert(ImplAdventurer::get_storage_index(14) == 1, 'storage index should be 1'); - assert(ImplAdventurer::get_storage_index(15) == 1, 'storage index should be 1'); - assert(ImplAdventurer::get_storage_index(16) == 1, 'storage index should be 1'); - assert(ImplAdventurer::get_storage_index(17) == 1, 'storage index should be 1'); - assert(ImplAdventurer::get_storage_index(18) == 1, 'storage index should be 1'); - assert(ImplAdventurer::get_storage_index(19) == 1, 'storage index should be 1'); - assert(ImplAdventurer::get_storage_index(20) == 1, 'storage index should be 1'); - } - - #[test] #[available_gas(275934)] fn test_get_beast_seed_gas() { @@ -2572,15 +1925,13 @@ mod tests { #[test] #[available_gas(70320)] fn test_get_greatness_gas() { - let _greatness = ImplAdventurer::get_greatness( - ItemPrimitive { id: 1, xp: 400, metadata: 1 } - ); + let _greatness = ImplAdventurer::get_greatness(ItemPrimitive { id: 1, xp: 400 }); } #[test] #[available_gas(70320)] fn test_get_greatness() { - let mut item = ItemPrimitive { id: 1, xp: 0, metadata: 0 }; + let mut item = ItemPrimitive { id: 1, xp: 0 }; // test 0 case (should be level 1) let greatness = ImplAdventurer::get_greatness(item); assert(greatness == 1, 'greatness should be 1'); @@ -2762,23 +2113,6 @@ mod tests { assert(potion_price == MINIMUM_POTION_PRICE, 'potion should be minimum price'); } - #[test] - #[available_gas(241584)] - fn test_get_idle_blocks() { - let mut adventurer = ImplAdventurer::new(ItemId::Wand); - adventurer.last_action_block = 1; - - // test with current block greater than last action - assert(adventurer.get_idle_blocks(3) == 2, 'idle blocks should be 2'); - assert(adventurer.get_idle_blocks(10) == 9, 'idle blocks should be 9'); - - // test with current block less than last action - assert(adventurer.get_idle_blocks(0) == 511, 'idle blocks should be 511'); - adventurer.last_action_block = 511; - assert(adventurer.get_idle_blocks(511) == 0, 'idle blocks should be 0'); - assert(adventurer.get_idle_blocks(0) == 1, 'idle blocks should be 1'); - } - #[test] #[available_gas(30020000)] fn test_packing_and_unpacking_adventurer() { @@ -2796,14 +2130,14 @@ mod tests { luck: 15 }, gold: 511, - weapon: ItemPrimitive { id: 127, xp: 511, metadata: 31, }, - chest: ItemPrimitive { id: 1, xp: 0, metadata: 0, }, - head: ItemPrimitive { id: 127, xp: 511, metadata: 31, }, - waist: ItemPrimitive { id: 87, xp: 511, metadata: 4, }, - foot: ItemPrimitive { id: 78, xp: 511, metadata: 5, }, - hand: ItemPrimitive { id: 34, xp: 511, metadata: 6, }, - neck: ItemPrimitive { id: 32, xp: 511, metadata: 7, }, - ring: ItemPrimitive { id: 1, xp: 511, metadata: 8, }, + weapon: ItemPrimitive { id: 127, xp: 511 }, + chest: ItemPrimitive { id: 1, xp: 0 }, + head: ItemPrimitive { id: 127, xp: 511 }, + waist: ItemPrimitive { id: 87, xp: 511 }, + foot: ItemPrimitive { id: 78, xp: 511 }, + hand: ItemPrimitive { id: 34, xp: 511 }, + neck: ItemPrimitive { id: 32, xp: 511 }, + ring: ItemPrimitive { id: 1, xp: 511 }, beast_health: 511, stat_points_available: 7, actions_per_block: 0, @@ -2823,28 +2157,20 @@ mod tests { assert(adventurer.gold == unpacked.gold, 'luck'); assert(adventurer.weapon.id == unpacked.weapon.id, 'weapon.id'); assert(adventurer.weapon.xp == unpacked.weapon.xp, 'weapon.xp'); - assert(adventurer.weapon.metadata == unpacked.weapon.metadata, 'weapon.metadata'); assert(adventurer.chest.id == unpacked.chest.id, 'chest.id'); assert(adventurer.chest.xp == unpacked.chest.xp, 'chest.xp'); - assert(adventurer.chest.metadata == unpacked.chest.metadata, 'chest.metadata'); assert(adventurer.head.id == unpacked.head.id, 'head.id'); assert(adventurer.head.xp == unpacked.head.xp, 'head.xp'); - assert(adventurer.head.metadata == unpacked.head.metadata, 'head.metadata'); assert(adventurer.waist.id == unpacked.waist.id, 'waist.id'); assert(adventurer.waist.xp == unpacked.waist.xp, 'waist.xp'); - assert(adventurer.waist.metadata == unpacked.waist.metadata, 'waist.metadata'); assert(adventurer.foot.id == unpacked.foot.id, 'foot.id'); assert(adventurer.foot.xp == unpacked.foot.xp, 'foot.xp'); - assert(adventurer.foot.metadata == unpacked.foot.metadata, 'foot.metadata'); assert(adventurer.hand.id == unpacked.hand.id, 'hand.id'); assert(adventurer.hand.xp == unpacked.hand.xp, 'hand.xp'); - assert(adventurer.hand.metadata == unpacked.hand.metadata, 'hand.metadata'); assert(adventurer.neck.id == unpacked.neck.id, 'neck.id'); assert(adventurer.neck.xp == unpacked.neck.xp, 'neck.xp'); - assert(adventurer.neck.metadata == unpacked.neck.metadata, 'neck.metadata'); assert(adventurer.ring.id == unpacked.ring.id, 'ring.id'); assert(adventurer.ring.xp == unpacked.ring.xp, 'ring.xp'); - assert(adventurer.ring.metadata == unpacked.ring.metadata, 'ring.metadata'); assert(adventurer.beast_health == unpacked.beast_health, 'beast_health'); assert( adventurer.stat_points_available == unpacked.stat_points_available, @@ -2865,14 +2191,14 @@ mod tests { luck: 15 }, gold: 511, - weapon: ItemPrimitive { id: 127, xp: 511, metadata: 31, }, - chest: ItemPrimitive { id: 1, xp: 0, metadata: 0, }, - head: ItemPrimitive { id: 127, xp: 511, metadata: 31, }, - waist: ItemPrimitive { id: 87, xp: 511, metadata: 4, }, - foot: ItemPrimitive { id: 78, xp: 511, metadata: 5, }, - hand: ItemPrimitive { id: 34, xp: 511, metadata: 6, }, - neck: ItemPrimitive { id: 32, xp: 511, metadata: 7, }, - ring: ItemPrimitive { id: 1, xp: 511, metadata: 8, }, + weapon: ItemPrimitive { id: 127, xp: 511 }, + chest: ItemPrimitive { id: 1, xp: 0 }, + head: ItemPrimitive { id: 127, xp: 511 }, + waist: ItemPrimitive { id: 87, xp: 511 }, + foot: ItemPrimitive { id: 78, xp: 511 }, + hand: ItemPrimitive { id: 34, xp: 511 }, + neck: ItemPrimitive { id: 32, xp: 511 }, + ring: ItemPrimitive { id: 1, xp: 511 }, beast_health: 511, stat_points_available: 7, actions_per_block: 0, @@ -2892,28 +2218,20 @@ mod tests { assert(adventurer.gold == unpacked.gold, 'luck'); assert(adventurer.weapon.id == unpacked.weapon.id, 'weapon.id'); assert(adventurer.weapon.xp == unpacked.weapon.xp, 'weapon.xp'); - assert(adventurer.weapon.metadata == unpacked.weapon.metadata, 'weapon.metadata'); assert(adventurer.chest.id == unpacked.chest.id, 'chest.id'); assert(adventurer.chest.xp == unpacked.chest.xp, 'chest.xp'); - assert(adventurer.chest.metadata == unpacked.chest.metadata, 'chest.metadata'); assert(adventurer.head.id == unpacked.head.id, 'head.id'); assert(adventurer.head.xp == unpacked.head.xp, 'head.xp'); - assert(adventurer.head.metadata == unpacked.head.metadata, 'head.metadata'); assert(adventurer.waist.id == unpacked.waist.id, 'waist.id'); assert(adventurer.waist.xp == unpacked.waist.xp, 'waist.xp'); - assert(adventurer.waist.metadata == unpacked.waist.metadata, 'waist.metadata'); assert(adventurer.foot.id == unpacked.foot.id, 'foot.id'); assert(adventurer.foot.xp == unpacked.foot.xp, 'foot.xp'); - assert(adventurer.foot.metadata == unpacked.foot.metadata, 'foot.metadata'); assert(adventurer.hand.id == unpacked.hand.id, 'hand.id'); assert(adventurer.hand.xp == unpacked.hand.xp, 'hand.xp'); - assert(adventurer.hand.metadata == unpacked.hand.metadata, 'hand.metadata'); assert(adventurer.neck.id == unpacked.neck.id, 'neck.id'); assert(adventurer.neck.xp == unpacked.neck.xp, 'neck.xp'); - assert(adventurer.neck.metadata == unpacked.neck.metadata, 'neck.metadata'); assert(adventurer.ring.id == unpacked.ring.id, 'ring.id'); assert(adventurer.ring.xp == unpacked.ring.xp, 'ring.xp'); - assert(adventurer.ring.metadata == unpacked.ring.metadata, 'ring.metadata'); assert(adventurer.beast_health == unpacked.beast_health, 'beast_health'); assert( adventurer.stat_points_available == unpacked.stat_points_available, @@ -3510,7 +2828,7 @@ mod tests { // }; // let mut adventurer = ImplAdventurer::new(ItemId::Wand); // // create demon crown item - // let item = ItemPrimitive { id: ItemId::DemonCrown, xp: 1, metadata: 0 }; + // let item = ItemPrimitive { id: ItemId::DemonCrown, xp: 1}; // // try to equip it to adventurer as a weapon // adventurer.equip_weapon(item); // // should panic with 'Item is not weapon' message @@ -3525,7 +2843,7 @@ mod tests { let mut adventurer = ImplAdventurer::new(ItemId::Wand); // Create Katana item - let item = ItemPrimitive { id: ItemId::Katana, xp: 1, metadata: 0 }; + let item = ItemPrimitive { id: ItemId::Katana, xp: 1 }; // Equip to adventurer as a weapon adventurer.equip_weapon(item); @@ -3533,7 +2851,6 @@ mod tests { // Assert item was equipped assert(adventurer.weapon.id == ItemId::Katana, 'did not equip weapon'); assert(adventurer.weapon.xp == 1, 'weapon xp is not 1'); - assert(adventurer.weapon.metadata == 0, 'weapon metadata is not 0'); } // TODO: Use conditional compilation to test this in the future @@ -3547,7 +2864,7 @@ mod tests { // }; // let mut adventurer = ImplAdventurer::new(ItemId::Wand); // // try to equip a Demon Crown as chest item - // let item = ItemPrimitive { id: ItemId::DemonCrown, xp: 1, metadata: 0 }; + // let item = ItemPrimitive { id: ItemId::DemonCrown, xp: 1}; // adventurer.equip_chest_armor(item); // // should panic with 'Item is not chest armor' message // // because Demon Crown is not chest armor @@ -3560,14 +2877,13 @@ mod tests { fn test_equip_valid_chest() { let mut adventurer = ImplAdventurer::new(ItemId::Wand); // equip Divine Robe as chest item - let item = ItemPrimitive { id: ItemId::DivineRobe, xp: 1, metadata: 0 }; + let item = ItemPrimitive { id: ItemId::DivineRobe, xp: 1 }; adventurer.equip_chest_armor(item); // this should not panic // assert item was equipped assert(adventurer.chest.id == ItemId::DivineRobe, 'did not equip chest armor'); assert(adventurer.chest.xp == 1, 'chest armor xp is not 1'); - assert(adventurer.chest.metadata == 0, 'chest armor metadata is not 0'); } // TODO: Use conditional compilation to test this in the future @@ -3581,7 +2897,7 @@ mod tests { // }; // let mut adventurer = ImplAdventurer::new(ItemId::Wand); // // try to equip a Katana as head item - // let item = ItemPrimitive { id: ItemId::Katana, xp: 1, metadata: 0 }; + // let item = ItemPrimitive { id: ItemId::Katana, xp: 1}; // adventurer.equip_head_armor(item); // // should panic with 'Item is not head armor' message // } @@ -3591,13 +2907,12 @@ mod tests { fn test_equip_valid_head() { let mut adventurer = ImplAdventurer::new(ItemId::Wand); // equip Crown as head item - let item = ItemPrimitive { id: ItemId::Crown, xp: 1, metadata: 0 }; + let item = ItemPrimitive { id: ItemId::Crown, xp: 1 }; adventurer.equip_head_armor(item); // this should not panic // assert item was equipped assert(adventurer.head.id == ItemId::Crown, 'did not equip head armor'); assert(adventurer.head.xp == 1, 'head armor xp is not 1'); - assert(adventurer.head.metadata == 0, 'head armor metadata is not 0'); } // TODO: Use conditional compilation to test this in the future @@ -3611,7 +2926,7 @@ mod tests { // }; // let mut adventurer = ImplAdventurer::new(ItemId::Wand); // // try to equip a Demon Crown as waist item - // let item = ItemPrimitive { id: ItemId::DemonCrown, xp: 1, metadata: 0 }; + // let item = ItemPrimitive { id: ItemId::DemonCrown, xp: 1}; // adventurer.equip_waist_armor(item); // // should panic with 'Item is not waist armor' message // } @@ -3622,14 +2937,13 @@ mod tests { let mut adventurer = ImplAdventurer::new(ItemId::Wand); // equip Wool Sash as waist item - let item = ItemPrimitive { id: ItemId::WoolSash, xp: 1, metadata: 0 }; + let item = ItemPrimitive { id: ItemId::WoolSash, xp: 1 }; adventurer.equip_waist_armor(item); // this should not panic // assert item was equipped assert(adventurer.waist.id == ItemId::WoolSash, 'did not equip waist armor'); assert(adventurer.waist.xp == 1, 'waist armor xp is not 1'); - assert(adventurer.waist.metadata == 0, 'waist armor metadata is not 0'); } // TODO: Use conditional compilation to test this in the future @@ -3643,7 +2957,7 @@ mod tests { // }; // let mut adventurer = ImplAdventurer::new(ItemId::Wand); // // try to equip a Demon Crown as foot item - // let item = ItemPrimitive { id: ItemId::DemonCrown, xp: 1, metadata: 0 }; + // let item = ItemPrimitive { id: ItemId::DemonCrown, xp: 1}; // adventurer.equip_foot_armor(item); // // should panic with 'Item is not foot armor' message // } @@ -3654,14 +2968,13 @@ mod tests { let mut adventurer = ImplAdventurer::new(ItemId::Wand); // equip Silk Slippers as foot item - let item = ItemPrimitive { id: ItemId::SilkSlippers, xp: 1, metadata: 0 }; + let item = ItemPrimitive { id: ItemId::SilkSlippers, xp: 1 }; adventurer.equip_foot_armor(item); // this should not panic // assert item was equipped assert(adventurer.foot.id == ItemId::SilkSlippers, 'did not equip foot armor'); assert(adventurer.foot.xp == 1, 'foot armor xp is not 1'); - assert(adventurer.foot.metadata == 0, 'foot armor metadata is not 0'); } // TODO: Use conditional compilation to test this in the future @@ -3676,7 +2989,7 @@ mod tests { // let mut adventurer = ImplAdventurer::new(ItemId::Wand); // // try to equip a Demon Crown as hand item - // let item = ItemPrimitive { id: ItemId::DemonCrown, xp: 1, metadata: 0 }; + // let item = ItemPrimitive { id: ItemId::DemonCrown, xp: 1}; // adventurer.equip_hand_armor(item); // // should panic with 'Item is not hand armor' message // } @@ -3687,14 +3000,13 @@ mod tests { let mut adventurer = ImplAdventurer::new(ItemId::Wand); // equip Divine Gloves as hand item - let item = ItemPrimitive { id: ItemId::DivineGloves, xp: 1, metadata: 0 }; + let item = ItemPrimitive { id: ItemId::DivineGloves, xp: 1 }; adventurer.equip_hand_armor(item); // this should not panic // assert item was equipped assert(adventurer.hand.id == ItemId::DivineGloves, 'did not equip hand armor'); assert(adventurer.hand.xp == 1, 'hand armor xp is not 1'); - assert(adventurer.hand.metadata == 0, 'hand armor metadata is not 0'); } // TODO: Use conditional compilation to test this in the future @@ -3709,7 +3021,7 @@ mod tests { // let mut adventurer = ImplAdventurer::new(ItemId::Wand); // // try to equip a Demon Crown as necklace - // let item = ItemPrimitive { id: ItemId::DemonCrown, xp: 1, metadata: 0 }; + // let item = ItemPrimitive { id: ItemId::DemonCrown, xp: 1}; // adventurer.equip_necklace(item); // // should panic with 'Item is not necklace' message // } @@ -3720,14 +3032,13 @@ mod tests { let mut adventurer = ImplAdventurer::new(ItemId::Wand); // equip Pendant as necklace - let item = ItemPrimitive { id: ItemId::Pendant, xp: 1, metadata: 0 }; + let item = ItemPrimitive { id: ItemId::Pendant, xp: 1 }; adventurer.equip_necklace(item); // this should not panic // assert item was equipped assert(adventurer.neck.id == ItemId::Pendant, 'did not equip necklace'); assert(adventurer.neck.xp == 1, 'necklace xp is not 1'); - assert(adventurer.neck.metadata == 0, 'necklace metadata is not 0'); } // TODO: Use conditional compilation to test this in the future @@ -3742,7 +3053,7 @@ mod tests { // let mut adventurer = ImplAdventurer::new(ItemId::Wand); // // try to equip a Demon Crown as ring - // let item = ItemPrimitive { id: ItemId::DemonCrown, xp: 1, metadata: 0 }; + // let item = ItemPrimitive { id: ItemId::DemonCrown, xp: 1}; // adventurer.equip_ring(item); // // should panic with 'Item is not a ring' message // } @@ -3751,11 +3062,10 @@ mod tests { #[available_gas(172184)] fn test_equip_valid_ring() { let mut adventurer = ImplAdventurer::new(ItemId::Wand); - let item = ItemPrimitive { id: ItemId::PlatinumRing, xp: 1, metadata: 0 }; + let item = ItemPrimitive { id: ItemId::PlatinumRing, xp: 1 }; adventurer.equip_ring(item); assert(adventurer.ring.id == ItemId::PlatinumRing, 'did not equip ring'); assert(adventurer.ring.xp == 1, 'ring xp is not 1'); - assert(adventurer.ring.metadata == 0, 'ring metadata is not 0'); } #[test] @@ -3835,7 +3145,7 @@ mod tests { assert(*starting_equipment.at(0).id == ItemId::Wand, 'adventurer starts with wand'); // equip chest armor - let chest = ItemPrimitive { id: ItemId::DivineRobe, xp: 1, metadata: 2 }; + let chest = ItemPrimitive { id: ItemId::DivineRobe, xp: 1 }; adventurer.equip_chest_armor(chest); // assert we now have two items equipped @@ -3845,7 +3155,7 @@ mod tests { assert(*equipped_items.at(1).id == ItemId::DivineRobe, 'should have robe equipped'); // equip head armor - let head = ItemPrimitive { id: ItemId::Crown, xp: 1, metadata: 3 }; + let head = ItemPrimitive { id: ItemId::Crown, xp: 1 }; adventurer.equip_head_armor(head); // assert we now have three items equipped @@ -3856,7 +3166,7 @@ mod tests { assert(*equipped_items.at(2).id == ItemId::Crown, 'should have crown equipped'); // equip waist armor - let waist = ItemPrimitive { id: ItemId::DemonhideBelt, xp: 1, metadata: 4 }; + let waist = ItemPrimitive { id: ItemId::DemonhideBelt, xp: 1 }; adventurer.equip_waist_armor(waist); // assert we now have four items equipped @@ -3868,7 +3178,7 @@ mod tests { assert(*equipped_items.at(3).id == ItemId::DemonhideBelt, 'should have belt equipped'); // equip foot armor - let foot = ItemPrimitive { id: ItemId::LeatherBoots, xp: 1, metadata: 5 }; + let foot = ItemPrimitive { id: ItemId::LeatherBoots, xp: 1 }; adventurer.equip_foot_armor(foot); // assert we now have five items equipped @@ -3881,7 +3191,7 @@ mod tests { assert(*equipped_items.at(4).id == ItemId::LeatherBoots, 'should have boots equipped'); // equip hand armor - let hand = ItemPrimitive { id: ItemId::LeatherGloves, xp: 1, metadata: 6 }; + let hand = ItemPrimitive { id: ItemId::LeatherGloves, xp: 1 }; adventurer.equip_hand_armor(hand); // assert we now have six items equipped @@ -3895,7 +3205,7 @@ mod tests { assert(*equipped_items.at(5).id == ItemId::LeatherGloves, 'should have gloves equipped'); // equip necklace - let neck = ItemPrimitive { id: ItemId::Amulet, xp: 1, metadata: 7 }; + let neck = ItemPrimitive { id: ItemId::Amulet, xp: 1 }; adventurer.equip_necklace(neck); // assert we now have seven items equipped @@ -3910,7 +3220,7 @@ mod tests { assert(*equipped_items.at(6).id == ItemId::Amulet, 'should have amulet equipped'); // equip ring - let ring = ItemPrimitive { id: ItemId::GoldRing, xp: 1, metadata: 8 }; + let ring = ItemPrimitive { id: ItemId::GoldRing, xp: 1 }; adventurer.equip_ring(ring); // assert we now have eight items equipped @@ -3926,7 +3236,7 @@ mod tests { assert(*equipped_items.at(7).id == ItemId::GoldRing, 'should have ring equipped'); // equip a different weapon - let weapon = ItemPrimitive { id: ItemId::Katana, xp: 1, metadata: 1 }; + let weapon = ItemPrimitive { id: ItemId::Katana, xp: 1 }; adventurer.equip_weapon(weapon); // assert we still have eight items equipped @@ -3996,14 +3306,14 @@ mod tests { let mut adventurer = ImplAdventurer::new(ItemId::Wand); // stage items - let weapon = ItemPrimitive { id: ItemId::Katana, xp: 1, metadata: 1 }; - let chest = ItemPrimitive { id: ItemId::DivineRobe, xp: 1, metadata: 2 }; - let head = ItemPrimitive { id: ItemId::Crown, xp: 1, metadata: 3 }; - let waist = ItemPrimitive { id: ItemId::DemonhideBelt, xp: 1, metadata: 4 }; - let foot = ItemPrimitive { id: ItemId::LeatherBoots, xp: 1, metadata: 5 }; - let hand = ItemPrimitive { id: ItemId::LeatherGloves, xp: 1, metadata: 6 }; - let neck = ItemPrimitive { id: ItemId::Amulet, xp: 1, metadata: 7 }; - let ring = ItemPrimitive { id: ItemId::GoldRing, xp: 1, metadata: 8 }; + let weapon = ItemPrimitive { id: ItemId::Katana, xp: 1 }; + let chest = ItemPrimitive { id: ItemId::DivineRobe, xp: 1 }; + let head = ItemPrimitive { id: ItemId::Crown, xp: 1 }; + let waist = ItemPrimitive { id: ItemId::DemonhideBelt, xp: 1 }; + let foot = ItemPrimitive { id: ItemId::LeatherBoots, xp: 1 }; + let hand = ItemPrimitive { id: ItemId::LeatherGloves, xp: 1 }; + let neck = ItemPrimitive { id: ItemId::Amulet, xp: 1 }; + let ring = ItemPrimitive { id: ItemId::GoldRing, xp: 1 }; // equip items adventurer.equip_weapon(weapon); @@ -4032,14 +3342,14 @@ mod tests { let mut adventurer = ImplAdventurer::new(ItemId::Wand); // stage items - let weapon = ItemPrimitive { id: ItemId::Katana, xp: 1, metadata: 1 }; - let chest = ItemPrimitive { id: ItemId::DivineRobe, xp: 1, metadata: 2 }; - let head = ItemPrimitive { id: ItemId::Crown, xp: 1, metadata: 3 }; - let waist = ItemPrimitive { id: ItemId::DemonhideBelt, xp: 1, metadata: 4 }; - let foot = ItemPrimitive { id: ItemId::LeatherBoots, xp: 1, metadata: 5 }; - let hand = ItemPrimitive { id: ItemId::LeatherGloves, xp: 1, metadata: 6 }; - let neck = ItemPrimitive { id: ItemId::Amulet, xp: 1, metadata: 7 }; - let ring = ItemPrimitive { id: ItemId::GoldRing, xp: 1, metadata: 8 }; + let weapon = ItemPrimitive { id: ItemId::Katana, xp: 1 }; + let chest = ItemPrimitive { id: ItemId::DivineRobe, xp: 1 }; + let head = ItemPrimitive { id: ItemId::Crown, xp: 1 }; + let waist = ItemPrimitive { id: ItemId::DemonhideBelt, xp: 1 }; + let foot = ItemPrimitive { id: ItemId::LeatherBoots, xp: 1 }; + let hand = ItemPrimitive { id: ItemId::LeatherGloves, xp: 1 }; + let neck = ItemPrimitive { id: ItemId::Amulet, xp: 1 }; + let ring = ItemPrimitive { id: ItemId::GoldRing, xp: 1 }; // equip half the items, adventurer will have nothing equipped for the other slots adventurer.equip_weapon(weapon); @@ -4584,7 +3894,7 @@ mod tests { } #[test] - #[available_gas(337900)] + #[available_gas(665600)] fn test_get_and_apply_stat_boosts() { let mut adventurer = Adventurer { last_action_block: 511, @@ -4600,78 +3910,27 @@ mod tests { luck: 0 }, gold: 40, - weapon: ItemPrimitive { id: 1, xp: 225, metadata: 1, }, - chest: ItemPrimitive { id: 2, xp: 65535, metadata: 2, }, - head: ItemPrimitive { id: 3, xp: 225, metadata: 3, }, - waist: ItemPrimitive { id: 4, xp: 225, metadata: 4, }, - foot: ItemPrimitive { id: 5, xp: 1000, metadata: 5, }, - hand: ItemPrimitive { id: 6, xp: 224, metadata: 6, }, - neck: ItemPrimitive { id: 7, xp: 1, metadata: 7, }, - ring: ItemPrimitive { id: 8, xp: 1, metadata: 8, }, + weapon: ItemPrimitive { id: 1, xp: 225 }, + chest: ItemPrimitive { id: 2, xp: 65535 }, + head: ItemPrimitive { id: 3, xp: 225 }, + waist: ItemPrimitive { id: 4, xp: 225 }, + foot: ItemPrimitive { id: 5, xp: 1000 }, + hand: ItemPrimitive { id: 6, xp: 224 }, + neck: ItemPrimitive { id: 7, xp: 1 }, + ring: ItemPrimitive { id: 8, xp: 1 }, beast_health: 20, stat_points_available: 0, actions_per_block: 0, mutated: false, }; - let item1_names = ItemSpecials { - special2: 0, special3: 0, special1: ItemSuffix::of_Power, - }; - let item2_names = ItemSpecials { - special2: 0, special3: 0, special1: ItemSuffix::of_Giant, - }; - let item3_names = ItemSpecials { - special2: 0, special3: 0, special1: ItemSuffix::of_Perfection, - }; - let item4_names = ItemSpecials { special2: 0, special3: 0, special1: ItemSuffix::of_Rage, }; - let item5_names = ItemSpecials { special2: 0, special3: 0, special1: ItemSuffix::of_Fury, }; - let item6_names = ItemSpecials { - special2: 0, special3: 0, special1: ItemSuffix::of_Skill, - }; - let item7_names = ItemSpecials { - special2: 0, special3: 0, special1: ItemSuffix::of_Vitriol, - }; - let item8_names = ItemSpecials { - special2: 0, special3: 0, special1: ItemSuffix::of_the_Fox, - }; - let item9_names = ItemSpecials { special2: 0, special3: 0, special1: 0, }; - let item10_names = ItemSpecials { special2: 0, special3: 0, special1: 0, }; - - let name_storage1 = ItemSpecialsStorage { - item_1: item1_names, - item_2: item2_names, - item_3: item3_names, - item_4: item4_names, - item_5: item5_names, - item_6: item6_names, - item_7: item7_names, - item_8: item8_names, - item_9: item9_names, - item_10: item10_names, - mutated: false - }; - - let name_storage2 = ItemSpecialsStorage { - item_1: item1_names, - item_2: item2_names, - item_3: item3_names, - item_4: item4_names, - item_5: item5_names, - item_6: item6_names, - item_7: item7_names, - item_8: item8_names, - item_9: item9_names, - item_10: item10_names, - mutated: false - }; - - let boost_stats = adventurer.get_stat_boosts(name_storage1, name_storage2); - assert(boost_stats.strength == 5, 'strength should be 5'); - assert(boost_stats.vitality == 5, 'vitality should be 5'); - assert(boost_stats.dexterity == 1, 'dexterity should be 1'); - assert(boost_stats.intelligence == 1, 'intelligence should be 1'); - assert(boost_stats.wisdom == 1, 'wisdom should be 1'); - assert(boost_stats.charisma == 2, 'charisma should be 2'); + let stat_boosts = adventurer.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'); } // test base case @@ -4755,14 +4014,14 @@ mod tests { luck: 0 }, gold: 40, - weapon: ItemPrimitive { id: 1, xp: 225, metadata: 1, }, - chest: ItemPrimitive { id: 2, xp: 65535, metadata: 2, }, - head: ItemPrimitive { id: 3, xp: 225, metadata: 3, }, - waist: ItemPrimitive { id: 4, xp: 225, metadata: 4, }, - foot: ItemPrimitive { id: 5, xp: 1000, metadata: 5, }, - hand: ItemPrimitive { id: 6, xp: 224, metadata: 6, }, - neck: ItemPrimitive { id: 7, xp: 1, metadata: 7, }, - ring: ItemPrimitive { id: 8, xp: 1, metadata: 8, }, + weapon: ItemPrimitive { id: 1, xp: 225 }, + chest: ItemPrimitive { id: 2, xp: 65535 }, + head: ItemPrimitive { id: 3, xp: 225 }, + waist: ItemPrimitive { id: 4, xp: 225 }, + foot: ItemPrimitive { id: 5, xp: 1000 }, + hand: ItemPrimitive { id: 6, xp: 224 }, + neck: ItemPrimitive { id: 7, xp: 1 }, + ring: ItemPrimitive { id: 8, xp: 1 }, beast_health: 20, stat_points_available: 0, actions_per_block: 0, @@ -4800,14 +4059,14 @@ mod tests { luck: 0 }, gold: 40, - weapon: ItemPrimitive { id: 1, xp: 225, metadata: 1, }, - chest: ItemPrimitive { id: 2, xp: 65535, metadata: 2, }, - head: ItemPrimitive { id: 3, xp: 225, metadata: 3, }, - waist: ItemPrimitive { id: 4, xp: 225, metadata: 4, }, - foot: ItemPrimitive { id: 5, xp: 1000, metadata: 5, }, - hand: ItemPrimitive { id: 6, xp: 224, metadata: 6, }, - neck: ItemPrimitive { id: 7, xp: 1, metadata: 7, }, - ring: ItemPrimitive { id: 8, xp: 1, metadata: 8, }, + weapon: ItemPrimitive { id: 1, xp: 225 }, + chest: ItemPrimitive { id: 2, xp: 65535 }, + head: ItemPrimitive { id: 3, xp: 225 }, + waist: ItemPrimitive { id: 4, xp: 225 }, + foot: ItemPrimitive { id: 5, xp: 1000 }, + hand: ItemPrimitive { id: 6, xp: 224 }, + neck: ItemPrimitive { id: 7, xp: 1 }, + ring: ItemPrimitive { id: 8, xp: 1 }, beast_health: 20, stat_points_available: 0, actions_per_block: 0, @@ -4844,14 +4103,14 @@ mod tests { luck: 0 }, gold: 40, - weapon: ItemPrimitive { id: 1, xp: 225, metadata: 1, }, - chest: ItemPrimitive { id: 2, xp: 65535, metadata: 2, }, - head: ItemPrimitive { id: 3, xp: 225, metadata: 3, }, - waist: ItemPrimitive { id: 4, xp: 225, metadata: 4, }, - foot: ItemPrimitive { id: 5, xp: 1000, metadata: 5, }, - hand: ItemPrimitive { id: 6, xp: 224, metadata: 6, }, - neck: ItemPrimitive { id: 7, xp: 1, metadata: 7, }, - ring: ItemPrimitive { id: 8, xp: 1, metadata: 8, }, + weapon: ItemPrimitive { id: 1, xp: 225 }, + chest: ItemPrimitive { id: 2, xp: 65535 }, + head: ItemPrimitive { id: 3, xp: 225 }, + waist: ItemPrimitive { id: 4, xp: 225 }, + foot: ItemPrimitive { id: 5, xp: 1000 }, + hand: ItemPrimitive { id: 6, xp: 224 }, + neck: ItemPrimitive { id: 7, xp: 1 }, + ring: ItemPrimitive { id: 8, xp: 1 }, beast_health: 20, stat_points_available: 0, actions_per_block: 0, @@ -4911,9 +4170,9 @@ mod tests { let mut adventurer = ImplAdventurer::new(ItemId::Wand); let bag = ImplBag::new(); - let neck = ItemPrimitive { id: ItemId::Amulet, xp: 1, metadata: 7 }; + let neck = ItemPrimitive { id: ItemId::Amulet, xp: 1 }; adventurer.equip_necklace(neck); - let ring = ItemPrimitive { id: ItemId::GoldRing, xp: 1, metadata: 8 }; + let ring = ItemPrimitive { id: ItemId::GoldRing, xp: 1 }; adventurer.equip_ring(ring); assert(adventurer.calculate_luck(bag) == 2, 'start with 2 luck'); } @@ -4926,17 +4185,17 @@ mod tests { assert(adventurer.calculate_luck(bag) == 2, 'start with 2 luck'); // equip a greatness 1 necklace - let neck = ItemPrimitive { id: ItemId::Amulet, xp: 1, metadata: 7 }; + let neck = ItemPrimitive { id: ItemId::Amulet, xp: 1 }; adventurer.equip_necklace(neck); assert(adventurer.calculate_luck(bag) == 2, 'still 2 luck'); // equip a greatness 1 ring - let ring = ItemPrimitive { id: ItemId::GoldRing, xp: 1, metadata: 8 }; + let ring = ItemPrimitive { id: ItemId::GoldRing, xp: 1 }; adventurer.equip_ring(ring); assert(adventurer.calculate_luck(bag) == 2, 'still 2 luck'); // equip a greatness 19 silver ring - let mut silver_ring = ItemPrimitive { id: ItemId::SilverRing, xp: 399, metadata: 8 }; + let mut silver_ring = ItemPrimitive { id: ItemId::SilverRing, xp: 399 }; adventurer.equip_ring(silver_ring); assert(adventurer.calculate_luck(bag) == 39, 'should be 39 luck'); @@ -4984,14 +4243,14 @@ mod tests { assert(adventurer.ring.id == 0, 'ring should be 0'); // stage items - let weapon = ItemPrimitive { id: ItemId::Katana, xp: 1, metadata: 1 }; - let chest = ItemPrimitive { id: ItemId::DivineRobe, xp: 1, metadata: 2 }; - let head = ItemPrimitive { id: ItemId::Crown, xp: 1, metadata: 3 }; - let waist = ItemPrimitive { id: ItemId::DemonhideBelt, xp: 1, metadata: 4 }; - let foot = ItemPrimitive { id: ItemId::LeatherBoots, xp: 1, metadata: 5 }; - let hand = ItemPrimitive { id: ItemId::LeatherGloves, xp: 1, metadata: 6 }; - let neck = ItemPrimitive { id: ItemId::Amulet, xp: 1, metadata: 7 }; - let ring = ItemPrimitive { id: ItemId::GoldRing, xp: 1, metadata: 8 }; + let weapon = ItemPrimitive { id: ItemId::Katana, xp: 1 }; + let chest = ItemPrimitive { id: ItemId::DivineRobe, xp: 1 }; + let head = ItemPrimitive { id: ItemId::Crown, xp: 1 }; + let waist = ItemPrimitive { id: ItemId::DemonhideBelt, xp: 1 }; + let foot = ItemPrimitive { id: ItemId::LeatherBoots, xp: 1 }; + let hand = ItemPrimitive { id: ItemId::LeatherGloves, xp: 1 }; + let neck = ItemPrimitive { id: ItemId::Amulet, xp: 1 }; + let ring = ItemPrimitive { id: ItemId::GoldRing, xp: 1 }; adventurer.equip_item(weapon); adventurer.equip_item(chest); @@ -5017,8 +4276,8 @@ mod tests { #[available_gas(1000000)] fn test_is_equipped() { let mut adventurer = ImplAdventurer::new(ItemId::Wand); - let wand = ItemPrimitive { id: ItemId::Wand, xp: 1, metadata: 1 }; - let demon_crown = ItemPrimitive { id: ItemId::DemonCrown, xp: 1, metadata: 2 }; + let wand = ItemPrimitive { id: ItemId::Wand, xp: 1 }; + let demon_crown = ItemPrimitive { id: ItemId::DemonCrown, xp: 1 }; // assert starting state assert(adventurer.weapon.id == wand.id, 'weapon should be wand'); @@ -5035,14 +4294,14 @@ mod tests { assert(adventurer.is_equipped(demon_crown.id) == false, 'demon crown is not equipped'); // stage items - let katana = ItemPrimitive { id: ItemId::Katana, xp: 1, metadata: 1 }; - let divine_robe = ItemPrimitive { id: ItemId::DivineRobe, xp: 1, metadata: 2 }; - let crown = ItemPrimitive { id: ItemId::Crown, xp: 1, metadata: 3 }; - let demonhide_belt = ItemPrimitive { id: ItemId::DemonhideBelt, xp: 1, metadata: 4 }; - let leather_boots = ItemPrimitive { id: ItemId::LeatherBoots, xp: 1, metadata: 5 }; - let leather_gloves = ItemPrimitive { id: ItemId::LeatherGloves, xp: 1, metadata: 6 }; - let amulet = ItemPrimitive { id: ItemId::Amulet, xp: 1, metadata: 7 }; - let gold_ring = ItemPrimitive { id: ItemId::GoldRing, xp: 1, metadata: 8 }; + let katana = ItemPrimitive { id: ItemId::Katana, xp: 1 }; + let divine_robe = ItemPrimitive { id: ItemId::DivineRobe, xp: 1 }; + let crown = ItemPrimitive { id: ItemId::Crown, xp: 1 }; + let demonhide_belt = ItemPrimitive { id: ItemId::DemonhideBelt, xp: 1 }; + let leather_boots = ItemPrimitive { id: ItemId::LeatherBoots, xp: 1 }; + let leather_gloves = ItemPrimitive { id: ItemId::LeatherGloves, xp: 1 }; + let amulet = ItemPrimitive { id: ItemId::Amulet, xp: 1 }; + let gold_ring = ItemPrimitive { id: ItemId::GoldRing, xp: 1 }; // Equip a katana and verify is_equipped returns true for katana and false everything else adventurer.equip_item(katana); @@ -5182,14 +4441,14 @@ mod tests { assert(adventurer.weapon.xp == 0, 'weapon xp should be 0'); // instantiate additional items - let weapon = ItemPrimitive { id: ItemId::Katana, xp: 1, metadata: 1 }; - let chest = ItemPrimitive { id: ItemId::DivineRobe, xp: 1, metadata: 2 }; - let head = ItemPrimitive { id: ItemId::Crown, xp: 1, metadata: 3 }; - let waist = ItemPrimitive { id: ItemId::DemonhideBelt, xp: 1, metadata: 4 }; - let foot = ItemPrimitive { id: ItemId::LeatherBoots, xp: 1, metadata: 5 }; - let hand = ItemPrimitive { id: ItemId::LeatherGloves, xp: 1, metadata: 6 }; - let neck = ItemPrimitive { id: ItemId::Amulet, xp: 1, metadata: 7 }; - let ring = ItemPrimitive { id: ItemId::GoldRing, xp: 1, metadata: 8 }; + let weapon = ItemPrimitive { id: ItemId::Katana, xp: 1 }; + let chest = ItemPrimitive { id: ItemId::DivineRobe, xp: 1 }; + let head = ItemPrimitive { id: ItemId::Crown, xp: 1 }; + let waist = ItemPrimitive { id: ItemId::DemonhideBelt, xp: 1 }; + let foot = ItemPrimitive { id: ItemId::LeatherBoots, xp: 1 }; + let hand = ItemPrimitive { id: ItemId::LeatherGloves, xp: 1 }; + let neck = ItemPrimitive { id: ItemId::Amulet, xp: 1 }; + let ring = ItemPrimitive { id: ItemId::GoldRing, xp: 1 }; // equip item adventurer.equip_item(weapon); diff --git a/contracts/adventurer/src/adventurer_meta.cairo b/contracts/adventurer/src/adventurer_meta.cairo index 5048709a4..e7c5a2e89 100644 --- a/contracts/adventurer/src/adventurer_meta.cairo +++ b/contracts/adventurer/src/adventurer_meta.cairo @@ -1,10 +1,11 @@ +use core::integer::u256_try_as_non_zero; use starknet::{StorePacking}; use traits::{TryInto, Into}; use super::stats::{Stats, StatsPacking, StatUtils}; #[derive(Drop, Copy, Serde)] struct AdventurerMetadata { - start_block: u64, // 64 bits in storage + start_entropy: u64, // 64 bits in storage starting_stats: Stats, // 24 bits in storage name: u128, // 128 bits in storage interface_camel: bool, // 1 bit bool in storage @@ -18,7 +19,7 @@ impl PackingAdventurerMetadata of StorePacking { 0 }; - (value.start_block.into() + (value.start_entropy.into() + StatsPacking::pack(value.starting_stats).into() * TWO_POW_64 + interface_camel_u256 * TWO_POW_91 + value.name.into() * TWO_POW_92) @@ -27,7 +28,7 @@ impl PackingAdventurerMetadata of StorePacking { } fn unpack(value: felt252) -> AdventurerMetadata { let packed = value.into(); - let (packed, start_block) = integer::U256DivRem::div_rem( + let (packed, start_entropy) = integer::U256DivRem::div_rem( packed, TWO_POW_64.try_into().unwrap() ); let (packed, starting_stats) = integer::U256DivRem::div_rem( @@ -41,7 +42,7 @@ impl PackingAdventurerMetadata of StorePacking { let interface_camel = interface_camel_u256 == 1; AdventurerMetadata { - start_block: start_block.try_into().unwrap(), + start_entropy: start_entropy.try_into().unwrap(), starting_stats: StatsPacking::unpack(starting_stats.try_into().unwrap()), name: name.try_into().unwrap(), interface_camel @@ -54,11 +55,17 @@ impl ImplAdventurerMetadata of IAdventurerMetadata { // @notice: Creates a new AdventurerMetadata struct // @dev: AdventurerMetadata is initialized without any starting stats // @param name: The name of the adventurer - // @param start_block: The block number at which the adventurer was created // @param interface_camel: Whether the players account is using a camelcase interface // @return: The newly created AdventurerMetadata struct - fn new(name: u128, start_block: u64, interface_camel: bool) -> AdventurerMetadata { - AdventurerMetadata { name, start_block, starting_stats: StatUtils::new(), interface_camel } + fn new(name: u128, interface_camel: bool) -> AdventurerMetadata { + AdventurerMetadata { name, start_entropy: 0, starting_stats: StatUtils::new(), interface_camel } + } + + fn generate_start_entropy(adventurer_entropy: felt252) -> u64 { + let (_, r) = integer::U256DivRem::div_rem( + adventurer_entropy.into(), u256_try_as_non_zero(U64_MAX.into()).unwrap() + ); + r.try_into().unwrap() } } @@ -71,6 +78,8 @@ const TWO_POW_128: u256 = 0x100000000000000000000000000000000; const TWO_POW_91: u256 = 0x80000000000000000000000; // 2^91 const TWO_POW_92: u256 = 0x100000000000000000000000; // 2^92 const TWO_POW_27: u256 = 0x8000000; // 2^27 +const U64_MAX: u64 = 18446744073709551615; + #[cfg(test)] #[test] @@ -91,7 +100,7 @@ fn test_adventurer_metadata_packing() { let interface_camel = true; let meta = AdventurerMetadata { - start_block: max_u64, + start_entropy: max_u64, starting_stats: max_starting_stats, name: max_name_length, interface_camel @@ -100,7 +109,7 @@ fn test_adventurer_metadata_packing() { let packed = PackingAdventurerMetadata::pack(meta); let unpacked: AdventurerMetadata = PackingAdventurerMetadata::unpack(packed); assert(meta.name == unpacked.name, 'name should be max'); - assert(meta.start_block == unpacked.start_block, 'sblock should be max u64'); + assert(meta.start_entropy == unpacked.start_entropy, 'sblock should be max u64'); assert( meta.starting_stats.strength == unpacked.starting_stats.strength, 'strength should be max' ); @@ -127,12 +136,12 @@ fn test_adventurer_metadata_packing() { }; let interface_camel = false; let meta = AdventurerMetadata { - start_block: 0, starting_stats: zero_starting_stats, name: 0, interface_camel + start_entropy: 0, starting_stats: zero_starting_stats, name: 0, interface_camel }; let packed = PackingAdventurerMetadata::pack(meta); let unpacked: AdventurerMetadata = PackingAdventurerMetadata::unpack(packed); assert(unpacked.name == 0, 'name should be 0'); - assert(unpacked.start_block == 0, 'entropy should be 0'); + assert(unpacked.start_entropy == 0, 'entropy should be 0'); assert( meta.starting_stats.strength == unpacked.starting_stats.strength, 'strength should be 0' ); diff --git a/contracts/adventurer/src/bag.cairo b/contracts/adventurer/src/bag.cairo index f16b76563..b4206d98a 100644 --- a/contracts/adventurer/src/bag.cairo +++ b/contracts/adventurer/src/bag.cairo @@ -2,8 +2,7 @@ use starknet::{StorePacking}; use lootitems::constants::ItemId; use super::{ adventurer::{Adventurer, ImplAdventurer}, - item_primitive::{ItemPrimitive, ImplItemPrimitive, ItemPrimitivePacking}, - item_meta::{ImplItemSpecials} + item_primitive::{ItemPrimitive, ImplItemPrimitive, ItemPrimitivePacking} }; // Bag is used for storing gear not equipped to the adventurer @@ -80,17 +79,17 @@ impl ImplBag of IBag { // @return The instance of the Bag fn new() -> Bag { Bag { - item_1: ItemPrimitive { id: 0, xp: 0, metadata: 0 }, - item_2: ItemPrimitive { id: 0, xp: 0, metadata: 0 }, - item_3: ItemPrimitive { id: 0, xp: 0, metadata: 0 }, - item_4: ItemPrimitive { id: 0, xp: 0, metadata: 0 }, - item_5: ItemPrimitive { id: 0, xp: 0, metadata: 0 }, - item_6: ItemPrimitive { id: 0, xp: 0, metadata: 0 }, - item_7: ItemPrimitive { id: 0, xp: 0, metadata: 0 }, - item_8: ItemPrimitive { id: 0, xp: 0, metadata: 0 }, - item_9: ItemPrimitive { id: 0, xp: 0, metadata: 0 }, - item_10: ItemPrimitive { id: 0, xp: 0, metadata: 0 }, - item_11: ItemPrimitive { id: 0, xp: 0, metadata: 0 }, + item_1: ItemPrimitive { id: 0, xp: 0 }, + item_2: ItemPrimitive { id: 0, xp: 0 }, + item_3: ItemPrimitive { id: 0, xp: 0 }, + item_4: ItemPrimitive { id: 0, xp: 0 }, + item_5: ItemPrimitive { id: 0, xp: 0 }, + item_6: ItemPrimitive { id: 0, xp: 0 }, + item_7: ItemPrimitive { id: 0, xp: 0 }, + item_8: ItemPrimitive { id: 0, xp: 0 }, + item_9: ItemPrimitive { id: 0, xp: 0 }, + item_10: ItemPrimitive { id: 0, xp: 0 }, + item_11: ItemPrimitive { id: 0, xp: 0 }, mutated: false } } @@ -129,14 +128,12 @@ impl ImplBag of IBag { } } - // @notice Adds a new item to a given adventurer's bag. - // @param self The reference to the Bag instance. - // @param adventurer The adventurer instance representing the owner of the bag. - // @param item_id The unique identifier for the item. - // @dev This function constructs a new item with the given item_id, sets its metadata using the Adventurer and Bag reference, and adds the item to the bag. + // @notice Adds a new item to the bag + // @param self The instance of the Bag + // @param adventurer The instance of the Adventurer + // @param item_id The id of the item to be added fn add_new_item(ref self: Bag, adventurer: Adventurer, item_id: u8) { let mut item = ImplItemPrimitive::new(item_id); - item.set_metadata_id(adventurer, self, false); self.add_item(item); } @@ -181,9 +178,6 @@ impl ImplBag of IBag { } // @notice Removes an item from the bag by its id - // @dev To remove an item we set it's id and xp to zero - // @dev We intentionally leave the previous metadata index in place - // @dev If the provided item id does not exist in the bag, this function throws an error // @param self The instance of the Bag // @param item_id The id of the item to be removed // @return The item that was removed from the bag @@ -300,7 +294,7 @@ impl ImplBag of IBag { } else if self.item_11.id == item_id { return (true, self.item_11); } else { - return (false, ItemPrimitive { id: 0, xp: 0, metadata: 0 }); + return (false, ItemPrimitive { id: 0, xp: 0 }); } } @@ -386,17 +380,17 @@ mod tests { #[test] #[available_gas(94030)] fn test_get_jewelry_greatness() { - let katana = ItemPrimitive { id: ItemId::Katana, xp: 1, metadata: 1 }; - let demon_crown = ItemPrimitive { id: ItemId::DemonCrown, xp: 2, metadata: 2 }; - let silk_robe = ItemPrimitive { id: ItemId::SilkRobe, xp: 3, metadata: 3 }; - let silver_ring = ItemPrimitive { id: ItemId::SilverRing, xp: 4, metadata: 4 }; - let ghost_wand = ItemPrimitive { id: ItemId::GhostWand, xp: 5, metadata: 5 }; - let leather_gloves = ItemPrimitive { id: ItemId::LeatherGloves, xp: 6, metadata: 6 }; - let silk_gloves = ItemPrimitive { id: ItemId::SilkGloves, xp: 7, metadata: 7 }; - let linen_gloves = ItemPrimitive { id: ItemId::LinenGloves, xp: 8, metadata: 8 }; - let crown = ItemPrimitive { id: ItemId::Crown, xp: 10, metadata: 9 }; - let amulet = ItemPrimitive { id: ItemId::Amulet, xp: 9, metadata: 10 }; - let pendant = ItemPrimitive { id: ItemId::Pendant, xp: 16, metadata: 11 }; + let katana = ItemPrimitive { id: ItemId::Katana, xp: 1 }; + let demon_crown = ItemPrimitive { id: ItemId::DemonCrown, xp: 2 }; + let silk_robe = ItemPrimitive { id: ItemId::SilkRobe, xp: 3 }; + let silver_ring = ItemPrimitive { id: ItemId::SilverRing, xp: 4 }; + let ghost_wand = ItemPrimitive { id: ItemId::GhostWand, xp: 5 }; + let leather_gloves = ItemPrimitive { id: ItemId::LeatherGloves, xp: 6 }; + let silk_gloves = ItemPrimitive { id: ItemId::SilkGloves, xp: 7 }; + let linen_gloves = ItemPrimitive { id: ItemId::LinenGloves, xp: 8 }; + let crown = ItemPrimitive { id: ItemId::Crown, xp: 10 }; + let amulet = ItemPrimitive { id: ItemId::Amulet, xp: 9 }; + let pendant = ItemPrimitive { id: ItemId::Pendant, xp: 16 }; let bag = Bag { item_1: katana, item_2: demon_crown, @@ -418,17 +412,17 @@ mod tests { #[test] #[available_gas(107010)] fn test_get_jewelry_gas() { - let katana = ItemPrimitive { id: ItemId::Katana, xp: 1, metadata: 1 }; - let demon_crown = ItemPrimitive { id: ItemId::DemonCrown, xp: 2, metadata: 2 }; - let silk_robe = ItemPrimitive { id: ItemId::SilkRobe, xp: 3, metadata: 3 }; - let silver_ring = ItemPrimitive { id: ItemId::SilverRing, xp: 4, metadata: 4 }; - let ghost_wand = ItemPrimitive { id: ItemId::GhostWand, xp: 5, metadata: 5 }; - let leather_gloves = ItemPrimitive { id: ItemId::LeatherGloves, xp: 6, metadata: 6 }; - let silk_gloves = ItemPrimitive { id: ItemId::SilkGloves, xp: 7, metadata: 7 }; - let linen_gloves = ItemPrimitive { id: ItemId::LinenGloves, xp: 8, metadata: 8 }; - let crown = ItemPrimitive { id: ItemId::Crown, xp: 10, metadata: 9 }; - let amulet = ItemPrimitive { id: ItemId::Amulet, xp: 10, metadata: 10 }; - let pendant = ItemPrimitive { id: ItemId::Pendant, xp: 10, metadata: 11 }; + let katana = ItemPrimitive { id: ItemId::Katana, xp: 1 }; + let demon_crown = ItemPrimitive { id: ItemId::DemonCrown, xp: 2 }; + let silk_robe = ItemPrimitive { id: ItemId::SilkRobe, xp: 3 }; + let silver_ring = ItemPrimitive { id: ItemId::SilverRing, xp: 4 }; + let ghost_wand = ItemPrimitive { id: ItemId::GhostWand, xp: 5 }; + let leather_gloves = ItemPrimitive { id: ItemId::LeatherGloves, xp: 6 }; + let silk_gloves = ItemPrimitive { id: ItemId::SilkGloves, xp: 7 }; + let linen_gloves = ItemPrimitive { id: ItemId::LinenGloves, xp: 8 }; + let crown = ItemPrimitive { id: ItemId::Crown, xp: 10 }; + let amulet = ItemPrimitive { id: ItemId::Amulet, xp: 10 }; + let pendant = ItemPrimitive { id: ItemId::Pendant, xp: 10 }; let bag = Bag { item_1: katana, item_2: demon_crown, @@ -450,17 +444,17 @@ mod tests { #[test] #[available_gas(41710)] fn test_get_jewelry() { - let katana = ItemPrimitive { id: ItemId::Katana, xp: 1, metadata: 1 }; - let demon_crown = ItemPrimitive { id: ItemId::DemonCrown, xp: 2, metadata: 2 }; - let silk_robe = ItemPrimitive { id: ItemId::SilkRobe, xp: 3, metadata: 3 }; - let silver_ring = ItemPrimitive { id: ItemId::SilverRing, xp: 4, metadata: 4 }; - let ghost_wand = ItemPrimitive { id: ItemId::GhostWand, xp: 5, metadata: 5 }; - let leather_gloves = ItemPrimitive { id: ItemId::LeatherGloves, xp: 6, metadata: 6 }; - let silk_gloves = ItemPrimitive { id: ItemId::SilkGloves, xp: 7, metadata: 7 }; - let linen_gloves = ItemPrimitive { id: ItemId::LinenGloves, xp: 8, metadata: 8 }; - let crown = ItemPrimitive { id: ItemId::Crown, xp: 10, metadata: 9 }; - let amulet = ItemPrimitive { id: ItemId::Amulet, xp: 10, metadata: 10 }; - let pendant = ItemPrimitive { id: ItemId::Pendant, xp: 10, metadata: 11 }; + let katana = ItemPrimitive { id: ItemId::Katana, xp: 1 }; + let demon_crown = ItemPrimitive { id: ItemId::DemonCrown, xp: 2 }; + let silk_robe = ItemPrimitive { id: ItemId::SilkRobe, xp: 3 }; + let silver_ring = ItemPrimitive { id: ItemId::SilverRing, xp: 4 }; + let ghost_wand = ItemPrimitive { id: ItemId::GhostWand, xp: 5 }; + let leather_gloves = ItemPrimitive { id: ItemId::LeatherGloves, xp: 6 }; + let silk_gloves = ItemPrimitive { id: ItemId::SilkGloves, xp: 7 }; + let linen_gloves = ItemPrimitive { id: ItemId::LinenGloves, xp: 8 }; + let crown = ItemPrimitive { id: ItemId::Crown, xp: 10 }; + let amulet = ItemPrimitive { id: ItemId::Amulet, xp: 10 }; + let pendant = ItemPrimitive { id: ItemId::Pendant, xp: 10 }; let bag = Bag { item_1: katana, item_2: demon_crown, @@ -487,15 +481,15 @@ mod tests { #[should_panic(expected: ('Item ID cannot be 0',))] #[available_gas(6900)] fn test_contains_invalid_zero() { - let katana = ItemPrimitive { id: ItemId::Katana, xp: 1, metadata: 1 }; - let demon_crown = ItemPrimitive { id: ItemId::DemonCrown, xp: 2, metadata: 2 }; - let silk_robe = ItemPrimitive { id: ItemId::SilkRobe, xp: 3, metadata: 3 }; - let silver_ring = ItemPrimitive { id: ItemId::SilverRing, xp: 4, metadata: 4 }; - let ghost_wand = ItemPrimitive { id: ItemId::GhostWand, xp: 5, metadata: 5 }; - let leather_gloves = ItemPrimitive { id: ItemId::LeatherGloves, xp: 6, metadata: 6 }; - let silk_gloves = ItemPrimitive { id: ItemId::SilkGloves, xp: 7, metadata: 7 }; - let linen_gloves = ItemPrimitive { id: ItemId::LinenGloves, xp: 8, metadata: 8 }; - let crown = ItemPrimitive { id: ItemId::Crown, xp: 10, metadata: 9 }; + let katana = ItemPrimitive { id: ItemId::Katana, xp: 1 }; + let demon_crown = ItemPrimitive { id: ItemId::DemonCrown, xp: 2 }; + let silk_robe = ItemPrimitive { id: ItemId::SilkRobe, xp: 3 }; + let silver_ring = ItemPrimitive { id: ItemId::SilverRing, xp: 4 }; + let ghost_wand = ItemPrimitive { id: ItemId::GhostWand, xp: 5 }; + let leather_gloves = ItemPrimitive { id: ItemId::LeatherGloves, xp: 6 }; + let silk_gloves = ItemPrimitive { id: ItemId::SilkGloves, xp: 7 }; + let linen_gloves = ItemPrimitive { id: ItemId::LinenGloves, xp: 8 }; + let crown = ItemPrimitive { id: ItemId::Crown, xp: 10 }; let bag = Bag { item_1: katana, item_2: demon_crown, @@ -506,8 +500,8 @@ mod tests { item_7: silk_gloves, item_8: linen_gloves, item_9: crown, - item_10: ItemPrimitive { id: 0, xp: 0, metadata: 0 }, - item_11: ItemPrimitive { id: 0, xp: 0, metadata: 0 }, + item_10: ItemPrimitive { id: 0, xp: 0 }, + item_11: ItemPrimitive { id: 0, xp: 0 }, mutated: false }; bag.contains(0); @@ -516,15 +510,15 @@ mod tests { #[test] #[available_gas(66400)] fn test_contains() { - let katana = ItemPrimitive { id: ItemId::Katana, xp: 1, metadata: 1 }; - let demon_crown = ItemPrimitive { id: ItemId::DemonCrown, xp: 2, metadata: 2 }; - let silk_robe = ItemPrimitive { id: ItemId::SilkRobe, xp: 3, metadata: 3 }; - let silver_ring = ItemPrimitive { id: ItemId::SilverRing, xp: 4, metadata: 4 }; - let ghost_wand = ItemPrimitive { id: ItemId::GhostWand, xp: 5, metadata: 5 }; - let leather_gloves = ItemPrimitive { id: ItemId::LeatherGloves, xp: 6, metadata: 6 }; - let silk_gloves = ItemPrimitive { id: ItemId::SilkGloves, xp: 7, metadata: 7 }; - let linen_gloves = ItemPrimitive { id: ItemId::LinenGloves, xp: 8, metadata: 8 }; - let crown = ItemPrimitive { id: ItemId::Crown, xp: 10, metadata: 9 }; + let katana = ItemPrimitive { id: ItemId::Katana, xp: 1 }; + let demon_crown = ItemPrimitive { id: ItemId::DemonCrown, xp: 2 }; + let silk_robe = ItemPrimitive { id: ItemId::SilkRobe, xp: 3 }; + let silver_ring = ItemPrimitive { id: ItemId::SilverRing, xp: 4 }; + let ghost_wand = ItemPrimitive { id: ItemId::GhostWand, xp: 5 }; + let leather_gloves = ItemPrimitive { id: ItemId::LeatherGloves, xp: 6 }; + let silk_gloves = ItemPrimitive { id: ItemId::SilkGloves, xp: 7 }; + let linen_gloves = ItemPrimitive { id: ItemId::LinenGloves, xp: 8 }; + let crown = ItemPrimitive { id: ItemId::Crown, xp: 10 }; let bag = Bag { item_1: katana, item_2: demon_crown, @@ -535,8 +529,8 @@ mod tests { item_7: silk_gloves, item_8: linen_gloves, item_9: crown, - item_10: ItemPrimitive { id: 0, xp: 0, metadata: 0 }, - item_11: ItemPrimitive { id: 0, xp: 0, metadata: 0 }, + item_10: ItemPrimitive { id: 0, xp: 0 }, + item_11: ItemPrimitive { id: 0, xp: 0 }, mutated: false }; @@ -544,55 +538,46 @@ mod tests { assert(contains == true, 'katans should be in bag'); assert(item.id == katana.id, 'item id should be katana'); assert(item.xp == katana.xp, 'item xp should be katana'); - assert(item.metadata == katana.metadata, 'item metadata should be katana'); let (contains, item) = bag.contains(demon_crown.id); assert(contains == true, 'demon crown should be in bag'); assert(item.id == demon_crown.id, 'item id should be demon crown'); assert(item.xp == demon_crown.xp, 'item xp should be demon crown'); - assert(item.metadata == demon_crown.metadata, 'demon crown metadata'); let (contains, item) = bag.contains(silk_robe.id); assert(contains == true, 'silk robe should be in bag'); assert(item.id == silk_robe.id, 'item id should be silk robe'); assert(item.xp == silk_robe.xp, 'item xp should be silk robe'); - assert(item.metadata == silk_robe.metadata, 'silk robe metadata'); let (contains, item) = bag.contains(silver_ring.id); assert(contains == true, 'silver ring should be in bag'); assert(item.id == silver_ring.id, 'item id should be silver ring'); assert(item.xp == silver_ring.xp, 'item xp should be silver ring'); - assert(item.metadata == silver_ring.metadata, 'silver ring metadata'); let (contains, item) = bag.contains(ghost_wand.id); assert(contains == true, 'ghost wand should be in bag'); assert(item.id == ghost_wand.id, 'item id should be ghost wand'); assert(item.xp == ghost_wand.xp, 'item xp should be ghost wand'); - assert(item.metadata == ghost_wand.metadata, 'ghost wand metadata'); let (contains, item) = bag.contains(leather_gloves.id); assert(contains == true, 'leather gloves should be in bag'); assert(item.id == leather_gloves.id, 'leather gloves id'); assert(item.xp == leather_gloves.xp, 'leather gloves xp'); - assert(item.metadata == leather_gloves.metadata, 'leather gloves metadata'); let (contains, item) = bag.contains(silk_gloves.id); assert(contains == true, 'silk gloves should be in bag'); assert(item.id == silk_gloves.id, 'item id should be silk gloves'); assert(item.xp == silk_gloves.xp, 'item xp should be silk gloves'); - assert(item.metadata == silk_gloves.metadata, 'silk gloves metadata'); let (contains, item) = bag.contains(linen_gloves.id); assert(contains == true, 'linen gloves should be in bag'); assert(item.id == linen_gloves.id, 'item id should be linen gloves'); assert(item.xp == linen_gloves.xp, 'item xp should be linen gloves'); - assert(item.metadata == linen_gloves.metadata, 'linen gloves metadata'); let (contains, item) = bag.contains(crown.id); assert(contains == true, 'crown should be in bag'); assert(item.id == crown.id, 'item id should be crown'); assert(item.xp == crown.xp, 'item xp should be crown'); - assert(item.metadata == crown.metadata, 'item metadata should be crown'); let (contains, item) = bag.contains(ItemId::Maul); assert(contains == false, 'maul should not be in bag'); @@ -604,17 +589,17 @@ mod tests { #[available_gas(2383150)] fn test_save_bag() { let mut bag = Bag { - item_1: ItemPrimitive { id: 127, xp: 511, metadata: 31 }, - item_2: ItemPrimitive { id: 127, xp: 511, metadata: 31 }, - item_3: ItemPrimitive { id: 127, xp: 511, metadata: 31 }, - item_4: ItemPrimitive { id: 127, xp: 511, metadata: 31 }, - item_5: ItemPrimitive { id: 127, xp: 511, metadata: 31 }, - item_6: ItemPrimitive { id: 127, xp: 511, metadata: 31 }, - item_7: ItemPrimitive { id: 127, xp: 511, metadata: 31 }, - item_8: ItemPrimitive { id: 127, xp: 511, metadata: 31 }, - item_9: ItemPrimitive { id: 127, xp: 511, metadata: 31 }, - item_10: ItemPrimitive { id: 127, xp: 511, metadata: 31 }, - item_11: ItemPrimitive { id: 127, xp: 511, metadata: 31 }, + item_1: ItemPrimitive { id: 127, xp: 511 }, + item_2: ItemPrimitive { id: 127, xp: 511 }, + item_3: ItemPrimitive { id: 127, xp: 511 }, + item_4: ItemPrimitive { id: 127, xp: 511 }, + item_5: ItemPrimitive { id: 127, xp: 511 }, + item_6: ItemPrimitive { id: 127, xp: 511 }, + item_7: ItemPrimitive { id: 127, xp: 511 }, + item_8: ItemPrimitive { id: 127, xp: 511 }, + item_9: ItemPrimitive { id: 127, xp: 511 }, + item_10: ItemPrimitive { id: 127, xp: 511 }, + item_11: ItemPrimitive { id: 127, xp: 511 }, mutated: false, }; @@ -622,47 +607,36 @@ mod tests { assert(packed_bag.item_1.id == 127, 'Loot 1 ID is not 127'); assert(packed_bag.item_1.xp == 511, 'Loot 1 XP is not 511'); - assert(packed_bag.item_1.metadata == 31, ' metadata is not 31'); assert(packed_bag.item_2.id == 127, 'Loot 2 ID is not 127'); assert(packed_bag.item_2.xp == 511, 'Loot 2 XP is not 511'); - assert(packed_bag.item_2.metadata == 31, ' 2 metadata is not 31'); assert(packed_bag.item_3.id == 127, 'Loot 3 ID is not 127'); assert(packed_bag.item_3.xp == 511, 'Loot 3 XP is not 511'); - assert(packed_bag.item_3.metadata == 31, ' 3 metadata is not 31'); assert(packed_bag.item_4.id == 127, 'Loot 4 ID is not 127'); assert(packed_bag.item_4.xp == 511, 'Loot 4 XP is not 511'); - assert(packed_bag.item_4.metadata == 31, ' 4 metadata is not 31'); assert(packed_bag.item_5.id == 127, 'Loot 5 ID is not 127'); assert(packed_bag.item_5.xp == 511, 'Loot 5 XP is not 511'); - assert(packed_bag.item_5.metadata == 31, ' 5 metadata is not 31'); assert(packed_bag.item_6.id == 127, 'Loot 6 ID is not 127'); assert(packed_bag.item_6.xp == 511, 'Loot 6 XP is not 511'); - assert(packed_bag.item_6.metadata == 31, ' 6 metadata is not 31'); assert(packed_bag.item_7.id == 127, 'Loot 7 ID is not 127'); assert(packed_bag.item_7.xp == 511, 'Loot 7 XP is not 511'); - assert(packed_bag.item_7.metadata == 31, ' 7 metadata is not 31'); assert(packed_bag.item_8.id == 127, 'Loot 8 ID is not 127'); assert(packed_bag.item_8.xp == 511, 'Loot 8 XP is not 511'); - assert(packed_bag.item_8.metadata == 31, ' 8 metadata is not 31'); assert(packed_bag.item_9.id == 127, 'Loot 9 ID is not 127'); assert(packed_bag.item_9.xp == 511, 'Loot 9 XP is not 511'); - assert(packed_bag.item_9.metadata == 31, ' 9 metadata is not 31'); assert(packed_bag.item_10.id == 127, 'Loot 10 ID is not 127'); assert(packed_bag.item_10.xp == 511, 'Loot 10 XP is not 511'); - assert(packed_bag.item_10.metadata == 31, ' 10 metadata is not 31'); assert(packed_bag.item_11.id == 127, 'Loot 11 ID is not 127'); assert(packed_bag.item_11.xp == 511, 'Loot 11 XP is not 511'); - assert(packed_bag.item_11.metadata == 31, ' 11 metadata is not 31'); } #[test] @@ -671,24 +645,24 @@ mod tests { fn test_add_item_blank_item() { // start with full bag let mut bag = Bag { - item_1: ItemPrimitive { id: 1, xp: 1, metadata: 1 }, - item_2: ItemPrimitive { id: 2, xp: 1, metadata: 2 }, - item_3: ItemPrimitive { id: 3, xp: 1, metadata: 3 }, - item_4: ItemPrimitive { id: 4, xp: 1, metadata: 4 }, - item_5: ItemPrimitive { id: 5, xp: 1, metadata: 5 }, - item_6: ItemPrimitive { id: 6, xp: 1, metadata: 6 }, - item_7: ItemPrimitive { id: 7, xp: 1, metadata: 7 }, - item_8: ItemPrimitive { id: 8, xp: 1, metadata: 8 }, - item_9: ItemPrimitive { id: 9, xp: 1, metadata: 9 }, - item_10: ItemPrimitive { id: 10, xp: 1, metadata: 10 }, - item_11: ItemPrimitive { id: 0, xp: 0, metadata: 0 }, + item_1: ItemPrimitive { id: 1, xp: 1 }, + item_2: ItemPrimitive { id: 2, xp: 1 }, + item_3: ItemPrimitive { id: 3, xp: 1 }, + item_4: ItemPrimitive { id: 4, xp: 1 }, + item_5: ItemPrimitive { id: 5, xp: 1 }, + item_6: ItemPrimitive { id: 6, xp: 1 }, + item_7: ItemPrimitive { id: 7, xp: 1 }, + item_8: ItemPrimitive { id: 8, xp: 1 }, + item_9: ItemPrimitive { id: 9, xp: 1 }, + item_10: ItemPrimitive { id: 10, xp: 1 }, + item_11: ItemPrimitive { id: 0, xp: 0 }, mutated: false }; // try adding an empty item to the bag // this should panic with 'Item ID cannot be 0' // which this test is annotated to expect - bag.add_item(ItemPrimitive { id: 0, xp: 1, metadata: 1 }); + bag.add_item(ItemPrimitive { id: 0, xp: 1 }); } #[test] @@ -697,24 +671,24 @@ mod tests { fn test_add_item_full_bag() { // start with full bag let mut bag = Bag { - item_1: ItemPrimitive { id: 1, xp: 1, metadata: 1 }, - item_2: ItemPrimitive { id: 2, xp: 1, metadata: 2 }, - item_3: ItemPrimitive { id: 3, xp: 1, metadata: 3 }, - item_4: ItemPrimitive { id: 4, xp: 1, metadata: 4 }, - item_5: ItemPrimitive { id: 5, xp: 1, metadata: 5 }, - item_6: ItemPrimitive { id: 6, xp: 1, metadata: 6 }, - item_7: ItemPrimitive { id: 7, xp: 1, metadata: 7 }, - item_8: ItemPrimitive { id: 8, xp: 1, metadata: 8 }, - item_9: ItemPrimitive { id: 9, xp: 1, metadata: 9 }, - item_10: ItemPrimitive { id: 10, xp: 1, metadata: 10 }, - item_11: ItemPrimitive { id: 11, xp: 1, metadata: 11 }, + item_1: ItemPrimitive { id: 1, xp: 1 }, + item_2: ItemPrimitive { id: 2, xp: 1 }, + item_3: ItemPrimitive { id: 3, xp: 1 }, + item_4: ItemPrimitive { id: 4, xp: 1 }, + item_5: ItemPrimitive { id: 5, xp: 1 }, + item_6: ItemPrimitive { id: 6, xp: 1 }, + item_7: ItemPrimitive { id: 7, xp: 1 }, + item_8: ItemPrimitive { id: 8, xp: 1 }, + item_9: ItemPrimitive { id: 9, xp: 1 }, + item_10: ItemPrimitive { id: 10, xp: 1 }, + item_11: ItemPrimitive { id: 11, xp: 1 }, mutated: false }; // try adding an item to a full bag // this should panic with 'Bag is full' // which this test is annotated to expect - bag.add_item(ItemPrimitive { id: ItemId::Katana, xp: 1, metadata: 1 }); + bag.add_item(ItemPrimitive { id: ItemId::Katana, xp: 1 }); } #[test] @@ -722,32 +696,32 @@ mod tests { fn test_add_item() { // start with empty bag let mut bag = Bag { - item_1: ItemPrimitive { id: 0, xp: 0, metadata: 0 }, - item_2: ItemPrimitive { id: 0, xp: 0, metadata: 0 }, - item_3: ItemPrimitive { id: 0, xp: 0, metadata: 0 }, - item_4: ItemPrimitive { id: 0, xp: 0, metadata: 0 }, - item_5: ItemPrimitive { id: 0, xp: 0, metadata: 0 }, - item_6: ItemPrimitive { id: 0, xp: 0, metadata: 0 }, - item_7: ItemPrimitive { id: 0, xp: 0, metadata: 0 }, - item_8: ItemPrimitive { id: 0, xp: 0, metadata: 0 }, - item_9: ItemPrimitive { id: 0, xp: 0, metadata: 0 }, - item_10: ItemPrimitive { id: 0, xp: 0, metadata: 0 }, - item_11: ItemPrimitive { id: 0, xp: 0, metadata: 0 }, + item_1: ItemPrimitive { id: 0, xp: 0 }, + item_2: ItemPrimitive { id: 0, xp: 0 }, + item_3: ItemPrimitive { id: 0, xp: 0 }, + item_4: ItemPrimitive { id: 0, xp: 0 }, + item_5: ItemPrimitive { id: 0, xp: 0 }, + item_6: ItemPrimitive { id: 0, xp: 0 }, + item_7: ItemPrimitive { id: 0, xp: 0 }, + item_8: ItemPrimitive { id: 0, xp: 0 }, + item_9: ItemPrimitive { id: 0, xp: 0 }, + item_10: ItemPrimitive { id: 0, xp: 0 }, + item_11: ItemPrimitive { id: 0, xp: 0 }, mutated: false }; // initialize items - let katana = ItemPrimitive { id: ItemId::Katana, xp: 1, metadata: 1 }; - let demon_crown = ItemPrimitive { id: ItemId::DemonCrown, xp: 1, metadata: 2 }; - let silk_robe = ItemPrimitive { id: ItemId::SilkRobe, xp: 1, metadata: 3 }; - let silver_ring = ItemPrimitive { id: ItemId::SilverRing, xp: 1, metadata: 4 }; - let ghost_wand = ItemPrimitive { id: ItemId::GhostWand, xp: 1, metadata: 5 }; - let leather_gloves = ItemPrimitive { id: ItemId::LeatherGloves, xp: 1, metadata: 6 }; - let silk_gloves = ItemPrimitive { id: ItemId::SilkGloves, xp: 1, metadata: 7 }; - let linen_gloves = ItemPrimitive { id: ItemId::LinenGloves, xp: 1, metadata: 8 }; - let crown = ItemPrimitive { id: ItemId::Crown, xp: 1, metadata: 9 }; - let divine_slippers = ItemPrimitive { id: ItemId::DivineSlippers, xp: 1, metadata: 10 }; - let warhammer = ItemPrimitive { id: ItemId::Warhammer, xp: 1, metadata: 11 }; + let katana = ItemPrimitive { id: ItemId::Katana, xp: 1 }; + let demon_crown = ItemPrimitive { id: ItemId::DemonCrown, xp: 1 }; + let silk_robe = ItemPrimitive { id: ItemId::SilkRobe, xp: 1 }; + let silver_ring = ItemPrimitive { id: ItemId::SilverRing, xp: 1 }; + let ghost_wand = ItemPrimitive { id: ItemId::GhostWand, xp: 1 }; + let leather_gloves = ItemPrimitive { id: ItemId::LeatherGloves, xp: 1 }; + let silk_gloves = ItemPrimitive { id: ItemId::SilkGloves, xp: 1 }; + let linen_gloves = ItemPrimitive { id: ItemId::LinenGloves, xp: 1 }; + let crown = ItemPrimitive { id: ItemId::Crown, xp: 1 }; + let divine_slippers = ItemPrimitive { id: ItemId::DivineSlippers, xp: 1 }; + let warhammer = ItemPrimitive { id: ItemId::Warhammer, xp: 1 }; // add items to bag bag.add_item(katana); @@ -781,17 +755,17 @@ mod tests { fn test_is_full() { // start with full bag let mut bag = Bag { - item_1: ItemPrimitive { id: 1, xp: 0, metadata: 0 }, - item_2: ItemPrimitive { id: 2, xp: 0, metadata: 0 }, - item_3: ItemPrimitive { id: 3, xp: 0, metadata: 0 }, - item_4: ItemPrimitive { id: 4, xp: 0, metadata: 0 }, - item_5: ItemPrimitive { id: 5, xp: 0, metadata: 0 }, - item_6: ItemPrimitive { id: 8, xp: 0, metadata: 0 }, - item_7: ItemPrimitive { id: 9, xp: 0, metadata: 0 }, - item_8: ItemPrimitive { id: 11, xp: 0, metadata: 0 }, - item_9: ItemPrimitive { id: 12, xp: 0, metadata: 0 }, - item_10: ItemPrimitive { id: 13, xp: 0, metadata: 0 }, - item_11: ItemPrimitive { id: 14, xp: 0, metadata: 0 }, + item_1: ItemPrimitive { id: 1, xp: 0 }, + item_2: ItemPrimitive { id: 2, xp: 0 }, + item_3: ItemPrimitive { id: 3, xp: 0 }, + item_4: ItemPrimitive { id: 4, xp: 0 }, + item_5: ItemPrimitive { id: 5, xp: 0 }, + item_6: ItemPrimitive { id: 8, xp: 0 }, + item_7: ItemPrimitive { id: 9, xp: 0 }, + item_8: ItemPrimitive { id: 11, xp: 0 }, + item_9: ItemPrimitive { id: 12, xp: 0 }, + item_10: ItemPrimitive { id: 13, xp: 0 }, + item_11: ItemPrimitive { id: 14, xp: 0 }, mutated: false }; @@ -805,7 +779,7 @@ mod tests { assert(bag.is_full() == false, 'Bag should be not full'); // add a new item - let mut warhammer = ItemPrimitive { id: ItemId::Warhammer, xp: 1, metadata: 11 }; + let mut warhammer = ItemPrimitive { id: ItemId::Warhammer, xp: 1 }; bag.add_item(warhammer); // assert bag is full again @@ -816,17 +790,17 @@ mod tests { #[should_panic(expected: ('Item not in bag',))] #[available_gas(7820)] fn test_get_item_not_in_bag() { - let item_1 = ItemPrimitive { id: 11, xp: 0, metadata: 0 }; - let item_2 = ItemPrimitive { id: 12, xp: 0, metadata: 0 }; - let item_3 = ItemPrimitive { id: 13, xp: 0, metadata: 0 }; - let item_4 = ItemPrimitive { id: 14, xp: 0, metadata: 0 }; - let item_5 = ItemPrimitive { id: 15, xp: 0, metadata: 0 }; - let item_6 = ItemPrimitive { id: 16, xp: 0, metadata: 0 }; - let item_7 = ItemPrimitive { id: 17, xp: 0, metadata: 0 }; - let item_8 = ItemPrimitive { id: 18, xp: 0, metadata: 0 }; - let item_9 = ItemPrimitive { id: 19, xp: 0, metadata: 0 }; - let item_10 = ItemPrimitive { id: 20, xp: 0, metadata: 0 }; - let item_11 = ItemPrimitive { id: 21, xp: 0, metadata: 0 }; + let item_1 = ItemPrimitive { id: 11, xp: 0 }; + let item_2 = ItemPrimitive { id: 12, xp: 0 }; + let item_3 = ItemPrimitive { id: 13, xp: 0 }; + let item_4 = ItemPrimitive { id: 14, xp: 0 }; + let item_5 = ItemPrimitive { id: 15, xp: 0 }; + let item_6 = ItemPrimitive { id: 16, xp: 0 }; + let item_7 = ItemPrimitive { id: 17, xp: 0 }; + let item_8 = ItemPrimitive { id: 18, xp: 0 }; + let item_9 = ItemPrimitive { id: 19, xp: 0 }; + let item_10 = ItemPrimitive { id: 20, xp: 0 }; + let item_11 = ItemPrimitive { id: 21, xp: 0 }; let bag = Bag { item_1: item_1, @@ -853,17 +827,17 @@ mod tests { #[test] #[available_gas(61100)] fn test_get_item() { - let item_1 = ItemPrimitive { id: 11, xp: 0, metadata: 0 }; - let item_2 = ItemPrimitive { id: 12, xp: 0, metadata: 0 }; - let item_3 = ItemPrimitive { id: 13, xp: 0, metadata: 0 }; - let item_4 = ItemPrimitive { id: 14, xp: 0, metadata: 0 }; - let item_5 = ItemPrimitive { id: 15, xp: 0, metadata: 0 }; - let item_6 = ItemPrimitive { id: 16, xp: 0, metadata: 0 }; - let item_7 = ItemPrimitive { id: 17, xp: 0, metadata: 0 }; - let item_8 = ItemPrimitive { id: 18, xp: 0, metadata: 0 }; - let item_9 = ItemPrimitive { id: 19, xp: 0, metadata: 0 }; - let item_10 = ItemPrimitive { id: 20, xp: 0, metadata: 0 }; - let item_11 = ItemPrimitive { id: 21, xp: 0, metadata: 0 }; + let item_1 = ItemPrimitive { id: 11, xp: 0 }; + let item_2 = ItemPrimitive { id: 12, xp: 0 }; + let item_3 = ItemPrimitive { id: 13, xp: 0 }; + let item_4 = ItemPrimitive { id: 14, xp: 0 }; + let item_5 = ItemPrimitive { id: 15, xp: 0 }; + let item_6 = ItemPrimitive { id: 16, xp: 0 }; + let item_7 = ItemPrimitive { id: 17, xp: 0 }; + let item_8 = ItemPrimitive { id: 18, xp: 0 }; + let item_9 = ItemPrimitive { id: 19, xp: 0 }; + let item_10 = ItemPrimitive { id: 20, xp: 0 }; + let item_11 = ItemPrimitive { id: 21, xp: 0 }; let bag = Bag { item_1: item_1, @@ -918,17 +892,17 @@ mod tests { #[available_gas(15700)] fn test_remove_item() { let mut bag = Bag { - item_1: ItemPrimitive { id: 1, xp: 0, metadata: 0 }, - item_2: ItemPrimitive { id: 2, xp: 0, metadata: 0 }, - item_3: ItemPrimitive { id: 3, xp: 0, metadata: 0 }, - item_4: ItemPrimitive { id: 4, xp: 0, metadata: 0 }, - item_5: ItemPrimitive { id: 5, xp: 0, metadata: 0 }, - item_6: ItemPrimitive { id: 6, xp: 0, metadata: 0 }, - item_7: ItemPrimitive { id: 7, xp: 0, metadata: 0 }, - item_8: ItemPrimitive { id: 8, xp: 1, metadata: 1 }, - item_9: ItemPrimitive { id: 9, xp: 0, metadata: 0 }, - item_10: ItemPrimitive { id: 10, xp: 0, metadata: 0 }, - item_11: ItemPrimitive { id: 11, xp: 0, metadata: 0 }, + item_1: ItemPrimitive { id: 1, xp: 0 }, + item_2: ItemPrimitive { id: 2, xp: 0 }, + item_3: ItemPrimitive { id: 3, xp: 0 }, + item_4: ItemPrimitive { id: 4, xp: 0 }, + item_5: ItemPrimitive { id: 5, xp: 0 }, + item_6: ItemPrimitive { id: 6, xp: 0 }, + item_7: ItemPrimitive { id: 7, xp: 0 }, + item_8: ItemPrimitive { id: 8, xp: 1 }, + item_9: ItemPrimitive { id: 9, xp: 0 }, + item_10: ItemPrimitive { id: 10, xp: 0 }, + item_11: ItemPrimitive { id: 11, xp: 0 }, mutated: false }; @@ -938,7 +912,6 @@ mod tests { // verify it has been removed assert(bag.item_6.id == 0, 'id should be 0'); assert(bag.item_6.xp == 0, 'xp should be 0'); - assert(bag.item_6.metadata == 0, 'metadata should be 0'); assert(removed_item.id == 6, 'removed item is wrong'); } @@ -948,17 +921,17 @@ mod tests { fn test_remove_item_not_in_bag() { // initialize bag let mut bag = Bag { - item_1: ItemPrimitive { id: 1, xp: 0, metadata: 0 }, - item_2: ItemPrimitive { id: 2, xp: 0, metadata: 0 }, - item_3: ItemPrimitive { id: 3, xp: 0, metadata: 0 }, - item_4: ItemPrimitive { id: 4, xp: 0, metadata: 0 }, - item_5: ItemPrimitive { id: 5, xp: 0, metadata: 0 }, - item_6: ItemPrimitive { id: 8, xp: 0, metadata: 0 }, - item_7: ItemPrimitive { id: 9, xp: 0, metadata: 0 }, - item_8: ItemPrimitive { id: 11, xp: 0, metadata: 0 }, - item_9: ItemPrimitive { id: 12, xp: 0, metadata: 0 }, - item_10: ItemPrimitive { id: 13, xp: 0, metadata: 0 }, - item_11: ItemPrimitive { id: 14, xp: 0, metadata: 0 }, + item_1: ItemPrimitive { id: 1, xp: 0 }, + item_2: ItemPrimitive { id: 2, xp: 0 }, + item_3: ItemPrimitive { id: 3, xp: 0 }, + item_4: ItemPrimitive { id: 4, xp: 0 }, + item_5: ItemPrimitive { id: 5, xp: 0 }, + item_6: ItemPrimitive { id: 8, xp: 0 }, + item_7: ItemPrimitive { id: 9, xp: 0 }, + item_8: ItemPrimitive { id: 11, xp: 0 }, + item_9: ItemPrimitive { id: 12, xp: 0 }, + item_10: ItemPrimitive { id: 13, xp: 0 }, + item_11: ItemPrimitive { id: 14, xp: 0 }, mutated: false }; diff --git a/contracts/adventurer/src/item_meta.cairo b/contracts/adventurer/src/item_meta.cairo deleted file mode 100644 index 51b8d9739..000000000 --- a/contracts/adventurer/src/item_meta.cairo +++ /dev/null @@ -1,1160 +0,0 @@ -use starknet::{StorePacking}; -use lootitems::{constants::{ItemId, ItemSuffix}, loot::ImplLoot}; -use combat::combat::Slot; -use super::{ - adventurer::{Adventurer, IAdventurer, ImplAdventurer}, item_primitive::ItemPrimitive, - stats::Stats, bag::{Bag, IBag} -}; - -#[derive(PartialEq, Drop, Copy, Serde)] -struct ItemSpecials { - special1: u8, // 4 bits in storage - special2: u8, // 7 bits in storage - special3: u8, // 5 bits in storage -} - -// Fixed size to fit optimally in felt252 -#[derive(Drop, Copy, Serde)] -struct ItemSpecialsStorage { - item_1: ItemSpecials, - item_2: ItemSpecials, - item_3: ItemSpecials, - item_4: ItemSpecials, - item_5: ItemSpecials, - item_6: ItemSpecials, - item_7: ItemSpecials, - item_8: ItemSpecials, - item_9: ItemSpecials, - item_10: ItemSpecials, - mutated: bool, -} - -impl ItemSpecialsPacking of StorePacking { - fn pack(value: ItemSpecials) -> felt252 { - (value.special2.into() - + value.special3.into() * TWO_POW_7 - + value.special1.into() * TWO_POW_12) - .try_into() - .unwrap() - } - - fn unpack(value: felt252) -> ItemSpecials { - let packed = value.into(); - let (packed, special2) = integer::U256DivRem::div_rem( - packed, TWO_POW_7.try_into().unwrap() - ); - let (packed, special3) = integer::U256DivRem::div_rem( - packed, TWO_POW_5.try_into().unwrap() - ); - let (_, special1) = integer::U256DivRem::div_rem(packed, TWO_POW_4.try_into().unwrap()); - - ItemSpecials { - special2: special2.try_into().expect('unpack LISN special2'), - special3: special3.try_into().expect('unpack LISN special3'), - special1: special1.try_into().expect('unpack LISN special1') - } - } -} - -impl ItemSpecialsStoragePacking of StorePacking { - fn pack(value: ItemSpecialsStorage) -> felt252 { - (ItemSpecialsPacking::pack(value.item_1).into() - + ItemSpecialsPacking::pack(value.item_2).into() * TWO_POW_16 - + ItemSpecialsPacking::pack(value.item_3).into() * TWO_POW_32 - + ItemSpecialsPacking::pack(value.item_4).into() * TWO_POW_48 - + ItemSpecialsPacking::pack(value.item_5).into() * TWO_POW_64 - + ItemSpecialsPacking::pack(value.item_6).into() * TWO_POW_80 - + ItemSpecialsPacking::pack(value.item_7).into() * TWO_POW_96 - + ItemSpecialsPacking::pack(value.item_8).into() * TWO_POW_112 - + ItemSpecialsPacking::pack(value.item_9).into() * TWO_POW_128 - + ItemSpecialsPacking::pack(value.item_10).into() * TWO_POW_144) - .try_into() - .unwrap() - } - - fn unpack(value: felt252) -> ItemSpecialsStorage { - let packed = value.into(); - let (packed, item_1) = integer::U256DivRem::div_rem(packed, TWO_POW_16.try_into().unwrap()); - let (packed, item_2) = integer::U256DivRem::div_rem(packed, TWO_POW_16.try_into().unwrap()); - let (packed, item_3) = integer::U256DivRem::div_rem(packed, TWO_POW_16.try_into().unwrap()); - let (packed, item_4) = integer::U256DivRem::div_rem(packed, TWO_POW_16.try_into().unwrap()); - let (packed, item_5) = integer::U256DivRem::div_rem(packed, TWO_POW_16.try_into().unwrap()); - let (packed, item_6) = integer::U256DivRem::div_rem(packed, TWO_POW_16.try_into().unwrap()); - let (packed, item_7) = integer::U256DivRem::div_rem(packed, TWO_POW_16.try_into().unwrap()); - let (packed, item_8) = integer::U256DivRem::div_rem(packed, TWO_POW_16.try_into().unwrap()); - let (packed, item_9) = integer::U256DivRem::div_rem(packed, TWO_POW_16.try_into().unwrap()); - let (_, item_10) = integer::U256DivRem::div_rem(packed, TWO_POW_16.try_into().unwrap()); - - ItemSpecialsStorage { - item_1: ItemSpecialsPacking::unpack(item_1.try_into().unwrap()), - item_2: ItemSpecialsPacking::unpack(item_2.try_into().unwrap()), - item_3: ItemSpecialsPacking::unpack(item_3.try_into().unwrap()), - item_4: ItemSpecialsPacking::unpack(item_4.try_into().unwrap()), - item_5: ItemSpecialsPacking::unpack(item_5.try_into().unwrap()), - item_6: ItemSpecialsPacking::unpack(item_6.try_into().unwrap()), - item_7: ItemSpecialsPacking::unpack(item_7.try_into().unwrap()), - item_8: ItemSpecialsPacking::unpack(item_8.try_into().unwrap()), - item_9: ItemSpecialsPacking::unpack(item_9.try_into().unwrap()), - item_10: ItemSpecialsPacking::unpack(item_10.try_into().unwrap()), - mutated: false, - } - } -} - -#[generate_trait] -impl ImplItemSpecials of IItemSpecials { - // @notice gets item specials from storage using the items meta data pointer - // @param self A reference to ItemSpecialsStorage which stores all special items. - // @param item An instance of ItemPrimitive that contains metadata used for item retrieval. - // @return An instance of ItemSpecials corresponding to the metadata in item. - // @throws 'item specials not in storage' if the item doesn't have specials in storage - fn get_specials(self: ItemSpecialsStorage, item: ItemPrimitive) -> ItemSpecials { - // @dev Since this function doesn't know which name storage it has been given - // it needs to consider both storage 1 and storage 2. In the current system - // which is rigid because it's highly gas optimized, storage 1 is used for the first 10 items - // and name storage 2 is used for the next 9 items. As such, if this function - // is called for an item with meta data 1, it will be in the first slot of - // storage. Similarly, if this function is called with an item with meta data 11 - // it will be in the first slot of storage 2. This is why we need to check for - // both storage 1 and storage 2. If you add more storage slots, you will need - // to update this function accordingly - if item.metadata == STORAGE::INDEX_1 || item.metadata == STORAGE::INDEX_11 { - self.item_1 - } else if item.metadata == STORAGE::INDEX_2 || item.metadata == STORAGE::INDEX_12 { - self.item_2 - } else if item.metadata == STORAGE::INDEX_3 || item.metadata == STORAGE::INDEX_13 { - self.item_3 - } else if item.metadata == STORAGE::INDEX_4 || item.metadata == STORAGE::INDEX_14 { - self.item_4 - } else if item.metadata == STORAGE::INDEX_5 || item.metadata == STORAGE::INDEX_15 { - self.item_5 - } else if item.metadata == STORAGE::INDEX_6 || item.metadata == STORAGE::INDEX_16 { - self.item_6 - } else if item.metadata == STORAGE::INDEX_7 || item.metadata == STORAGE::INDEX_17 { - self.item_7 - } else if item.metadata == STORAGE::INDEX_8 || item.metadata == STORAGE::INDEX_18 { - self.item_8 - } else if item.metadata == STORAGE::INDEX_9 || item.metadata == STORAGE::INDEX_19 { - self.item_9 - } else if item.metadata == STORAGE::INDEX_10 { - // storage 2 only has 9 items in it because we only support 19 Items - // so we don't need to check INDEX_20 (that doesn't exist) - self.item_10 - } else { - // assert at the top of the function should prevent this outcome - // but just in case throw a panic to ensure this function is - // behaving as intended - panic_with_felt252('item specials not in storage') - } - } - - fn get_specials_full( - specials_storage1: ItemSpecialsStorage, - specials_storage2: ItemSpecialsStorage, - item: ItemPrimitive - ) -> ItemSpecials { - if item.metadata == STORAGE::INDEX_1 { - specials_storage1.item_1 - } else if item.metadata == STORAGE::INDEX_2 { - specials_storage1.item_2 - } else if item.metadata == STORAGE::INDEX_3 { - specials_storage1.item_3 - } else if item.metadata == STORAGE::INDEX_4 { - specials_storage1.item_4 - } else if item.metadata == STORAGE::INDEX_5 { - specials_storage1.item_5 - } else if item.metadata == STORAGE::INDEX_6 { - specials_storage1.item_6 - } else if item.metadata == STORAGE::INDEX_7 { - specials_storage1.item_7 - } else if item.metadata == STORAGE::INDEX_8 { - specials_storage1.item_8 - } else if item.metadata == STORAGE::INDEX_9 { - specials_storage1.item_9 - } else if item.metadata == STORAGE::INDEX_10 { - specials_storage1.item_10 - } else if item.metadata == STORAGE::INDEX_11 { - specials_storage2.item_1 - } else if item.metadata == STORAGE::INDEX_12 { - specials_storage2.item_2 - } else if item.metadata == STORAGE::INDEX_13 { - specials_storage2.item_3 - } else if item.metadata == STORAGE::INDEX_14 { - specials_storage2.item_4 - } else if item.metadata == STORAGE::INDEX_15 { - specials_storage2.item_5 - } else if item.metadata == STORAGE::INDEX_16 { - specials_storage2.item_6 - } else if item.metadata == STORAGE::INDEX_17 { - specials_storage2.item_7 - } else if item.metadata == STORAGE::INDEX_18 { - specials_storage2.item_8 - } else if item.metadata == STORAGE::INDEX_19 { - specials_storage2.item_9 - } else { - panic_with_felt252('item specials not in storage') - } - } - - // @dev This function sets special attributes for a given item in storage. - // - // @notice It uses the metadata of an item to decide where to place the special attributes - // in the storage. If the item's metadata matches one of the predefined indices (from 1 to 10), - // it assigns the specials to the corresponding slot in the storage. - // If the item's metadata doesn't match any of the predefined indices, it triggers a panic with the message 'item not in bag'. - // - // @param self A mutable reference to ItemSpecialsStorage which stores all special items. - // @param item An instance of ItemPrimitive whose metadata is used for placing the item. - // @param specials An instance of ItemSpecials which contains the special attributes to be placed in storage. - // - // @throws This function will throw an error if the metadata in item doesn't match any of the predefined indices. - fn set_specials(ref self: ItemSpecialsStorage, item: ItemPrimitive, specials: ItemSpecials) { - // @dev Since this function doesn't know which name storage it has been given - // it needs to consider both storage 1 and storage 2. In the current system - // which is relatively rigid (wip), name storage 1 is used for the first 10 items - // and name storage 2 is used for the next 9 items. As such, if this function - // is called for an item with meta data is 1, it will be in the first slot of - // storage. Similarly, if this function is called with an item with meta data 11 - // it will be in the first slot of storage 2. This is why we need to check for - // both storage 1 and storage 2. If we add more storage slots in the future - // we will need to update this function to check for those as well. - // I have a TODO at the top to restructure our ItemSpecialStorage struct to include - // an explicit storage id and size so we can provide a more flexible and robust - // solution to this problem. - if item.metadata == STORAGE::INDEX_1 || item.metadata == STORAGE::INDEX_11 { - self.item_1 = specials; - } else if item.metadata == STORAGE::INDEX_2 || item.metadata == STORAGE::INDEX_12 { - self.item_2 = specials; - } else if item.metadata == STORAGE::INDEX_3 || item.metadata == STORAGE::INDEX_13 { - self.item_3 = specials; - } else if item.metadata == STORAGE::INDEX_4 || item.metadata == STORAGE::INDEX_14 { - self.item_4 = specials; - } else if item.metadata == STORAGE::INDEX_5 || item.metadata == STORAGE::INDEX_15 { - self.item_5 = specials; - } else if item.metadata == STORAGE::INDEX_6 || item.metadata == STORAGE::INDEX_16 { - self.item_6 = specials; - } else if item.metadata == STORAGE::INDEX_7 || item.metadata == STORAGE::INDEX_17 { - self.item_7 = specials; - } else if item.metadata == STORAGE::INDEX_8 || item.metadata == STORAGE::INDEX_18 { - self.item_8 = specials; - } else if item.metadata == STORAGE::INDEX_9 || item.metadata == STORAGE::INDEX_19 { - self.item_9 = specials; - } else if item.metadata == STORAGE::INDEX_10 { - // storage 2 only has 9 items in it because we only support 19 Items - // so we don't need to check INDEX_20 (that doesn't exist) - self.item_10 = specials; - } else { - // assert at the top of the function should prevent this outcome - // but just in case throw a panic to ensure this function is - // behaving as intended - panic_with_felt252('meta data id not in storage') - } - - // flag storage as mutated so we know we need to write it to storage - self.mutated = true; - } - - /// @title get_recycled_metadata - /// - /// @notice This function is used to find and return the metadata of the first item that has been dropped by the adventurer. - /// An item is considered dropped if its id is 0 but its metadata is not 0. - /// - /// @dev The function iterates through the adventurer's equipment and the bag's items in a specific order. - /// The order is: weapon, head, chest, hand, foot, ring, neck, waist, and then items 1 to 11 in the bag. - /// It returns the metadata of the first item it finds that has been dropped. - /// If no dropped items are found, it returns 0. - /// - /// @param item The Item we are assigning a metadata id to. - /// @param adventurer The adventurer object, which contains the metadata and id for each piece of equipment the adventurer has. - /// @param bag The bag object, which contains the metadata and id for each item in the bag. - /// @param equipping A boolean that indicates whether the item is being equipped or placed in the bag. - /// - /// @return The metadata of the first dropped item found, or 0 if no dropped items are found. - fn get_recycled_metadata( - item: ItemPrimitive, adventurer: Adventurer, bag: Bag, equipping: bool - ) -> u8 { - // if the item is being equipped - if equipping { - // look for available metadata slots in the adventurer's equipment - if (ImplLoot::get_slot(item.id) == Slot::Weapon(()) - && adventurer.weapon.id == 0 - && adventurer.weapon.metadata != 0) { - adventurer.weapon.metadata - } else if (ImplLoot::get_slot(item.id) == Slot::Head(()) - && adventurer.head.id == 0 - && adventurer.head.metadata != 0) { - adventurer.head.metadata - } else if (ImplLoot::get_slot(item.id) == Slot::Chest(()) - && adventurer.chest.id == 0 - && adventurer.chest.metadata != 0) { - adventurer.chest.metadata - } else if (ImplLoot::get_slot(item.id) == Slot::Waist(()) - && adventurer.waist.id == 0 - && adventurer.waist.metadata != 0) { - adventurer.waist.metadata - } else if (ImplLoot::get_slot(item.id) == Slot::Hand(()) - && adventurer.hand.id == 0 - && adventurer.hand.metadata != 0) { - adventurer.hand.metadata - } else if (ImplLoot::get_slot(item.id) == Slot::Foot(()) - && adventurer.foot.id == 0 - && adventurer.foot.metadata != 0) { - adventurer.foot.metadata - } else if (ImplLoot::get_slot(item.id) == Slot::Ring(()) - && adventurer.ring.id == 0 - && adventurer.ring.metadata != 0) { - adventurer.ring.metadata - } else if (ImplLoot::get_slot(item.id) == Slot::Neck(()) - && adventurer.neck.id == 0 - && adventurer.neck.metadata != 0) { - adventurer.neck.metadata - } else { - 0 - } - // otherwise item is going into bag - } else { - // so look for free metadata available in bag - if (bag.item_1.id == 0 && bag.item_1.metadata != 0) { - bag.item_1.metadata - } else if (bag.item_2.id == 0 && bag.item_2.metadata != 0) { - bag.item_2.metadata - } else if (bag.item_3.id == 0 && bag.item_3.metadata != 0) { - bag.item_3.metadata - } else if (bag.item_4.id == 0 && bag.item_4.metadata != 0) { - bag.item_4.metadata - } else if (bag.item_5.id == 0 && bag.item_5.metadata != 0) { - bag.item_5.metadata - } else if (bag.item_6.id == 0 && bag.item_6.metadata != 0) { - bag.item_6.metadata - } else if (bag.item_7.id == 0 && bag.item_7.metadata != 0) { - bag.item_7.metadata - } else if (bag.item_8.id == 0 && bag.item_8.metadata != 0) { - bag.item_8.metadata - } else if (bag.item_9.id == 0 && bag.item_9.metadata != 0) { - bag.item_9.metadata - } else if (bag.item_10.id == 0 && bag.item_10.metadata != 0) { - bag.item_10.metadata - } else if (bag.item_11.id == 0 && bag.item_11.metadata != 0) { - bag.item_11.metadata - } else { - 0 - } - } - } - - /// @title get_next_metadata - /// - /// @notice This function is used to find the highest metadata value currently in use by the adventurer's equipment or the bag's items, and then returns the next available metadata value. - /// - /// @dev The function iterates through the adventurer's equipment and the bag's items in a specific order. - /// The order is: weapon, head, chest, hand, foot, ring, neck, waist, and then items 1 to 11 in the bag. - /// It keeps track of the highest metadata value it finds, and then increments it by 1 to get the next available metadata value. - /// If the next available metadata value is greater than the maximum allowed storage slots, it triggers a panic with the error code 'out of metadata storage slots'. - /// - /// @param adventurer The adventurer object, which contains the metadata for each piece of equipment the adventurer has. - /// @param bag The bag object, which contains the metadata for each item in the bag. - /// - /// @return The next available metadata value, or triggers a panic if no more metadata storage slots are available. - fn get_next_metadata(adventurer: Adventurer, bag: Bag) -> u8 { - let mut latest_metadata = 1; - if adventurer.weapon.metadata >= latest_metadata { - latest_metadata = adventurer.weapon.metadata; - } - if adventurer.head.metadata >= latest_metadata { - latest_metadata = adventurer.head.metadata; - } - if adventurer.chest.metadata >= latest_metadata { - latest_metadata = adventurer.chest.metadata; - } - if adventurer.hand.metadata >= latest_metadata { - latest_metadata = adventurer.hand.metadata; - } - if adventurer.foot.metadata >= latest_metadata { - latest_metadata = adventurer.foot.metadata; - } - if adventurer.ring.metadata >= latest_metadata { - latest_metadata = adventurer.ring.metadata; - } - if adventurer.neck.metadata >= latest_metadata { - latest_metadata = adventurer.neck.metadata; - } - if adventurer.waist.metadata >= latest_metadata { - latest_metadata = adventurer.waist.metadata; - } - if bag.item_1.metadata >= latest_metadata { - latest_metadata = bag.item_1.metadata; - } - if bag.item_2.metadata >= latest_metadata { - latest_metadata = bag.item_2.metadata; - } - if bag.item_3.metadata >= latest_metadata { - latest_metadata = bag.item_3.metadata; - } - if bag.item_4.metadata >= latest_metadata { - latest_metadata = bag.item_4.metadata; - } - if bag.item_5.metadata >= latest_metadata { - latest_metadata = bag.item_5.metadata; - } - if bag.item_6.metadata >= latest_metadata { - latest_metadata = bag.item_6.metadata; - } - if bag.item_7.metadata >= latest_metadata { - latest_metadata = bag.item_7.metadata; - } - if bag.item_8.metadata >= latest_metadata { - latest_metadata = bag.item_8.metadata; - } - if bag.item_9.metadata >= latest_metadata { - latest_metadata = bag.item_9.metadata; - } - if bag.item_10.metadata >= latest_metadata { - latest_metadata = bag.item_10.metadata; - } - if bag.item_11.metadata >= latest_metadata { - latest_metadata = bag.item_11.metadata; - } - - // if the slot is less than the max storage slots, assign the new metadata id - let next_metadata = latest_metadata + 1; - if next_metadata <= STORAGE::MAX_TOTAL_STORAGE_SPECIALS { - next_metadata - } else { - panic_with_felt252('out of metadata storage slots') - } - } - - /// @title set_metadata_id - /// - /// @notice This function is used to set the metadata of an item. It first tries to reuse the metadata of a dropped item. If no dropped items are found, it gets the next available metadata value. - /// - /// @dev The function first calls the `get_recycled_metadata` function, which returns the metadata of the first dropped item it finds, or 0 if no dropped items are found. - /// If `get_recycled_metadata` returns a value greater than 0, the function sets the item's metadata to this value. - /// If `get_recycled_metadata` returns 0, the function calls the `get_next_metadata` function, which returns the next available metadata value, and sets the item's metadata to this value. - /// - /// @param self The item object, which contains the metadata for the item. - /// @param adventurer The adventurer object, which contains the metadata for each piece of equipment the adventurer has. - /// @param bag The bag object, which contains the metadata for each item in the bag. - /// - /// @return None. The function modifies the item's metadata in place. - fn set_metadata_id(ref self: ItemPrimitive, adventurer: Adventurer, bag: Bag, equipping: bool) { - let reused_metadata = ImplItemSpecials::get_recycled_metadata( - self, adventurer, bag, equipping - ); - if reused_metadata > 0 { - self.metadata = reused_metadata; - } else { - self.metadata = ImplItemSpecials::get_next_metadata(adventurer, bag); - } - } -} - -mod STORAGE { - // First 10 indexes are stored in storage 1 - const INDEX_1: u8 = 1; - const INDEX_2: u8 = 2; - const INDEX_3: u8 = 3; - const INDEX_4: u8 = 4; - const INDEX_5: u8 = 5; - const INDEX_6: u8 = 6; - const INDEX_7: u8 = 7; - const INDEX_8: u8 = 8; - const INDEX_9: u8 = 9; - const INDEX_10: u8 = 10; - - // next 9 indexes are stored in storage 2 - const INDEX_11: u8 = 11; - const INDEX_12: u8 = 12; - const INDEX_13: u8 = 13; - const INDEX_14: u8 = 14; - const INDEX_15: u8 = 15; - const INDEX_16: u8 = 16; - const INDEX_17: u8 = 17; - const INDEX_18: u8 = 18; - const INDEX_19: u8 = 19; - - // make sure to update this if you add more storage slots - const MAX_TOTAL_STORAGE_SPECIALS: u8 = 19; - const MAX_SPECIALS_PER_STORAGE: u8 = 10; -} - -const TWO_POW_4: u256 = 0x10; -const TWO_POW_5: u256 = 0x20; -const TWO_POW_7: u256 = 0x80; -const TWO_POW_12: u256 = 0x1000; -const TWO_POW_16: u256 = 0x10000; -const TWO_POW_32: u256 = 0x100000000; -const TWO_POW_48: u256 = 0x1000000000000; -const TWO_POW_64: u256 = 0x10000000000000000; -const TWO_POW_80: u256 = 0x100000000000000000000; -const TWO_POW_96: u256 = 0x1000000000000000000000000; -const TWO_POW_112: u256 = 0x10000000000000000000000000000; -const TWO_POW_128: u256 = 0x100000000000000000000000000000000; -const TWO_POW_144: u256 = 0x1000000000000000000000000000000000000; - -// --------------------------- -// ---------- Tests ---------- -// --------------------------- -#[cfg(test)] -mod tests { - use lootitems::constants::{ItemId}; - use survivor::{ - adventurer::{ImplAdventurer}, item_primitive::ItemPrimitive, stats::Stats, bag::{Bag, IBag}, - item_meta::{ - ImplItemSpecials, ItemSpecialsStorage, ItemSpecials, ItemSpecialsStoragePacking, STORAGE - }, - }; - - #[test] - #[available_gas(3000000)] - fn test_item_meta_packing() { - // initailize ItemSpecialsStorage with strategic test values - let storage = ItemSpecialsStorage { - item_1: ItemSpecials { special1: 0, special2: 0, special3: 0 // zero case - }, - item_2: ItemSpecials { special1: 1, special2: 2, special3: 3 // uniqueness - }, - item_3: ItemSpecials { special1: 4, special2: 4, special3: 4 // all same - }, - item_4: ItemSpecials { - special1: 15, special2: 127, special3: 31 // max packable values - }, - item_5: ItemSpecials { special1: 4, special2: 23, special3: 2 }, - item_6: ItemSpecials { special1: 5, special2: 5, special3: 5 }, - item_7: ItemSpecials { special1: 6, special2: 6, special3: 6 }, - item_8: ItemSpecials { special1: 7, special2: 7, special3: 7 }, - item_9: ItemSpecials { special1: 8, special2: 8, special3: 8 }, - item_10: ItemSpecials { special1: 9, special2: 9, special3: 9 }, - mutated: false, - }; - - // pack and then unpack the specials - let unpacked: ItemSpecialsStorage = ItemSpecialsStoragePacking::unpack( - ItemSpecialsStoragePacking::pack(storage) - ); - - // assert the values were not altered using PartialEq - assert(unpacked.item_1 == storage.item_1, 'item 1 packing error'); - assert(unpacked.item_2 == storage.item_2, 'item 2 packing error'); - assert(unpacked.item_3 == storage.item_3, 'item 3 packing error'); - assert(unpacked.item_4 == storage.item_4, 'item 4 packing error'); - assert(unpacked.item_5 == storage.item_5, 'item 5 packing error'); - assert(unpacked.item_6 == storage.item_6, 'item 6 packing error'); - assert(unpacked.item_7 == storage.item_7, 'item 7 packing error'); - assert(unpacked.item_8 == storage.item_8, 'item 8 packing error'); - assert(unpacked.item_9 == storage.item_9, 'item 9 packing error'); - assert(unpacked.item_10 == storage.item_10, 'item 10 packing error'); - } - - #[test] - #[available_gas(40000000)] - fn test_set_metadata_id() { - // start test with a new adventurer wielding a wand - let mut adventurer = ImplAdventurer::new(ItemId::Wand); - - // assert adventurer starter weapon has meta data id 1 - assert(adventurer.weapon.metadata == 1, 'advntr wpn meta data shld be 1'); - - // generate starter wand - let mut starter_wand = ItemPrimitive { id: ItemId::Wand, xp: 1, metadata: 1 }; - - // and an empty bag - let mut bag = Bag { - item_1: ItemPrimitive { id: 0, xp: 0, metadata: 0, }, - item_2: ItemPrimitive { id: 0, xp: 0, metadata: 0, }, - item_3: ItemPrimitive { id: 0, xp: 0, metadata: 0, }, - item_4: ItemPrimitive { id: 0, xp: 0, metadata: 0, }, - item_5: ItemPrimitive { id: 0, xp: 0, metadata: 0, }, - item_6: ItemPrimitive { id: 0, xp: 0, metadata: 0, }, - item_7: ItemPrimitive { id: 0, xp: 0, metadata: 0, }, - item_8: ItemPrimitive { id: 0, xp: 0, metadata: 0, }, - item_9: ItemPrimitive { id: 0, xp: 0, metadata: 0, }, - item_10: ItemPrimitive { id: 0, xp: 0, metadata: 0, }, - item_11: ItemPrimitive { id: 0, xp: 0, metadata: 0, }, - mutated: false - }; - - // stage a bunch of gear - let mut katana = ItemPrimitive { id: ItemId::Katana, xp: 1, metadata: 0 }; - let mut demon_crown = ItemPrimitive { id: ItemId::DemonCrown, xp: 1, metadata: 0 }; - let mut silk_robe = ItemPrimitive { id: ItemId::SilkRobe, xp: 1, metadata: 0 }; - let mut demon_hands = ItemPrimitive { id: ItemId::DemonsHands, xp: 1, metadata: 0 }; - let mut shoes = ItemPrimitive { id: ItemId::Shoes, xp: 1, metadata: 0 }; - let mut brightsilk_sash = ItemPrimitive { id: ItemId::BrightsilkSash, xp: 1, metadata: 0 }; - let mut silk_gloves = ItemPrimitive { id: ItemId::SilkGloves, xp: 1, metadata: 0 }; - let mut linen_gloves = ItemPrimitive { id: ItemId::LinenGloves, xp: 1, metadata: 0 }; - let mut crown = ItemPrimitive { id: ItemId::Crown, xp: 1, metadata: 0 }; - let mut divine_slippers = ItemPrimitive { id: ItemId::DivineSlippers, xp: 1, metadata: 0 }; - let mut warhammer = ItemPrimitive { id: ItemId::Warhammer, xp: 1, metadata: 0 }; - let mut ancient_helm = ItemPrimitive { id: ItemId::AncientHelm, xp: 1, metadata: 0 }; - let mut divine_robe = ItemPrimitive { id: ItemId::DivineRobe, xp: 1, metadata: 0 }; - let mut holy_chestplate = ItemPrimitive { id: ItemId::HolyChestplate, xp: 1, metadata: 0 }; - let mut holy_greaves = ItemPrimitive { id: ItemId::HolyGreaves, xp: 1, metadata: 0 }; - let mut demonhide_boots = ItemPrimitive { id: ItemId::DemonhideBoots, xp: 1, metadata: 0 }; - let mut _holy_gauntlets = ItemPrimitive { id: ItemId::HolyGauntlets, xp: 1, metadata: 0 }; - let mut _demonhide_belt = ItemPrimitive { id: ItemId::DemonhideBelt, xp: 1, metadata: 0 }; - - // take the common start with T1 Katana - katana.set_metadata_id(adventurer, bag, false); - - // toss starter wand in bag - bag.add_item(starter_wand); - - // equip katana - adventurer.equip_item(katana); - - // katana should pickup new metadata pointer 2 - assert(katana.metadata == 2, 'wrong katana metadata'); - - // starter wand should now be item1 in bag and meta data should have moved with it - assert( - bag.item_1.id == starter_wand.id && bag.item_1.metadata == 1, - 'wrong starter wand bag data' - ); - - // proceed to buy armor for the adventurer, verifying meta data pointers for each item - demon_crown.set_metadata_id(adventurer, bag, true); - adventurer.equip_item(demon_crown); - assert(demon_crown.metadata == 3, 'wrong demon crown metadata'); - - silk_robe.set_metadata_id(adventurer, bag, true); - adventurer.equip_item(silk_robe); - assert(silk_robe.metadata == 4, 'wrong silk robe metadata'); - - demon_hands.set_metadata_id(adventurer, bag, true); - adventurer.equip_item(demon_hands); - assert(demon_hands.metadata == 5, 'wrong demonhands metadata'); - - shoes.set_metadata_id(adventurer, bag, true); - adventurer.equip_item(shoes); - assert(shoes.metadata == 6, 'wrong shoes metadata'); - - brightsilk_sash.set_metadata_id(adventurer, bag, true); - adventurer.equip_item(brightsilk_sash); - assert(brightsilk_sash.metadata == 7, 'wrong leather gloves metadata'); - - // Adventurer now has full armor (we are intentionally deferring jewlery) - // so now start buying items for the bag, filling it up to one less than capacity - silk_gloves.set_metadata_id(adventurer, bag, false); - bag.add_item(silk_gloves); - assert( - bag.item_2 == silk_gloves && silk_gloves.metadata == 8, 'wrong silk gloves metadata' - ); - - linen_gloves.set_metadata_id(adventurer, bag, false); - bag.add_item(linen_gloves); - assert( - bag.item_3 == linen_gloves && linen_gloves.metadata == 9, 'wrong linen gloves metadata' - ); - - crown.set_metadata_id(adventurer, bag, false); - bag.add_item(crown); - assert(bag.item_4 == crown && crown.metadata == 10, 'wrong crown metadata'); - - divine_slippers.set_metadata_id(adventurer, bag, false); - bag.add_item(divine_slippers); - assert( - bag.item_5 == divine_slippers && divine_slippers.metadata == 11, - 'wrong divine slippers metadata' - ); - - warhammer.set_metadata_id(adventurer, bag, false); - bag.add_item(warhammer); - assert(bag.item_6 == warhammer && warhammer.metadata == 12, 'wrong warhammer metadata'); - - ancient_helm.set_metadata_id(adventurer, bag, false); - bag.add_item(ancient_helm); - assert( - bag.item_7 == ancient_helm && ancient_helm.metadata == 13, 'wrong ancient helm metadata' - ); - - divine_robe.set_metadata_id(adventurer, bag, false); - bag.add_item(divine_robe); - assert( - bag.item_8 == divine_robe && divine_robe.metadata == 14, 'wrong divine robe metadata' - ); - - holy_chestplate.set_metadata_id(adventurer, bag, false); - bag.add_item(holy_chestplate); - assert( - bag.item_9 == holy_chestplate && holy_chestplate.metadata == 15, - 'wrong holy chestplate metadata' - ); - - holy_greaves.set_metadata_id(adventurer, bag, false); - bag.add_item(holy_greaves); - assert( - bag.item_10 == holy_greaves && holy_greaves.metadata == 16, - 'wrong holy greaves metadata' - ); - - demonhide_boots.set_metadata_id(adventurer, bag, false); - bag.add_item(demonhide_boots); - assert( - bag.item_11 == demonhide_boots && demonhide_boots.metadata == 17, - 'wrong demonhide boots metadata' - ); - - // before we proceed to test drop and buy, double check meta data pointers - assert(starter_wand.metadata == 1, 'wrong starter wand metadata'); - assert(katana.metadata == 2, 'wrong katana metadata'); - assert(demon_crown.metadata == 3, 'wrong demon crown metadata'); - assert(silk_robe.metadata == 4, 'wrong silk robe metadata'); - assert(demon_hands.metadata == 5, 'wrong silver ring metadata'); - assert(shoes.metadata == 6, 'wrong ghost wand metadata'); - assert(brightsilk_sash.metadata == 7, 'wrong leather gloves metadata'); - assert(silk_gloves.metadata == 8, 'wrong silk gloves metadata'); - assert(linen_gloves.metadata == 9, 'wrong linen gloves metadata'); - assert(crown.metadata == 10, 'wrong crown metadata'); - assert(divine_slippers.metadata == 11, 'wrong divine slippers metadata'); - assert(warhammer.metadata == 12, 'wrong warhammer metadata'); - assert(ancient_helm.metadata == 13, 'wrong ancient helm metadata'); - assert(divine_robe.metadata == 14, 'wrong divine robe metadata'); - assert(holy_chestplate.metadata == 15, 'wrong holy chestplate metadata'); - assert(holy_greaves.metadata == 16, 'wrong holy greaves metadata'); - assert(demonhide_boots.metadata == 17, 'wrong demonhide boots metadata'); - - // drop wand from bag and verify ID and XP get zero'd out but metadata stays the same - bag.remove_item(starter_wand.id); - assert(bag.item_1.id == 0, 'wand not zerod out'); - assert(bag.item_1.xp == 0, 'wand xp not zerod out'); - assert(bag.item_1.metadata == 1, 'wand metadata should not change'); - - // buy another item for the bag and verify it fills the spot of the dropped wand and uses the same metadata - let mut demonhide_belt = ItemPrimitive { id: ItemId::DemonhideBelt, xp: 1, metadata: 0 }; - demonhide_belt.set_metadata_id(adventurer, bag, false); - bag.add_item(demonhide_belt); - assert( - bag.item_1 == demonhide_belt && demonhide_belt.metadata == 1, - 'wrong demonhide belt metadata' - ); - - // same test but this time dropping two items from bag and verifying the new items fill the spots and use the same metadata - let item_2_metadata = bag.item_2.metadata; - let item_3_metadata = bag.item_3.metadata; - bag.remove_item(bag.item_2.id); - bag.remove_item(bag.item_3.id); - let mut book = ItemPrimitive { id: ItemId::Book, xp: 1, metadata: 0 }; - book.set_metadata_id(adventurer, bag, false); - bag.add_item(book); - let mut tome = ItemPrimitive { id: ItemId::Tome, xp: 1, metadata: 0 }; - tome.set_metadata_id(adventurer, bag, false); - bag.add_item(tome); - assert(bag.item_2 == book && book.metadata == item_2_metadata, 'wrong book metadata'); - assert(bag.item_3 == tome && tome.metadata == item_3_metadata, 'wrong tome metadata'); - - // with the holes filled, purchase remaining jewelry items - - // necklace should pickup metadata 18 - let mut necklace = ItemPrimitive { id: ItemId::Necklace, xp: 1, metadata: 0 }; - necklace.set_metadata_id(adventurer, bag, true); - adventurer.equip_necklace(necklace); - assert(adventurer.neck == necklace && necklace.metadata == 18, 'wrong necklace metadata'); - - // and ring should get the last metadata spot of 19 - let mut gold_ring = ItemPrimitive { id: ItemId::GoldRing, xp: 1, metadata: 0 }; - gold_ring.set_metadata_id(adventurer, bag, true); - adventurer.equip_ring(gold_ring); - assert( - adventurer.ring == gold_ring && gold_ring.metadata == 19, 'wrong gold ring metadata' - ); - - // drop adventurers katana and buy a grimoire and verify the metadata is reused - adventurer.drop_item(adventurer.weapon.id); - let mut grimoire = ItemPrimitive { id: ItemId::Grimoire, xp: 1, metadata: 0 }; - grimoire.set_metadata_id(adventurer, bag, true); - adventurer.equip_item(grimoire); - assert(adventurer.weapon == grimoire && grimoire.metadata == 2, 'wrong grimoire metadata'); - } - - #[test] - #[available_gas(500000)] - fn test_get_specials() { - // create 19 items to be used for the test - let wand = ItemPrimitive { id: ItemId::Wand, xp: 1, metadata: 1 }; - let katana = ItemPrimitive { id: ItemId::Katana, xp: 1, metadata: 2 }; - let demon_crown = ItemPrimitive { id: ItemId::DemonCrown, xp: 1, metadata: 3 }; - let silk_robe = ItemPrimitive { id: ItemId::SilkRobe, xp: 1, metadata: 4 }; - let silver_ring = ItemPrimitive { id: ItemId::SilverRing, xp: 1, metadata: 5 }; - let ghost_wand = ItemPrimitive { id: ItemId::GhostWand, xp: 1, metadata: 6 }; - let leather_gloves = ItemPrimitive { id: ItemId::LeatherGloves, xp: 1, metadata: 7 }; - let silk_gloves = ItemPrimitive { id: ItemId::SilkGloves, xp: 1, metadata: 8 }; - let linen_gloves = ItemPrimitive { id: ItemId::LinenGloves, xp: 1, metadata: 9 }; - let crown = ItemPrimitive { id: ItemId::Crown, xp: 1, metadata: 10 }; - let divine_slippers = ItemPrimitive { id: ItemId::DivineSlippers, xp: 1, metadata: 11 }; - let warhammer = ItemPrimitive { id: ItemId::Warhammer, xp: 1, metadata: 12 }; - let ancient_helm = ItemPrimitive { id: ItemId::AncientHelm, xp: 1, metadata: 13 }; - let divine_robe = ItemPrimitive { id: ItemId::DivineRobe, xp: 1, metadata: 14 }; - let holy_chestplate = ItemPrimitive { id: ItemId::HolyChestplate, xp: 1, metadata: 15 }; - let holy_greaves = ItemPrimitive { id: ItemId::HolyGreaves, xp: 1, metadata: 16 }; - let _demonhide_boots = ItemPrimitive { id: ItemId::DemonhideBoots, xp: 1, metadata: 17 }; - let holy_gauntlets = ItemPrimitive { id: ItemId::HolyGauntlets, xp: 1, metadata: 18 }; - let demonhide_boots = ItemPrimitive { id: ItemId::DemonhideBoots, xp: 1, metadata: 19 }; - - // generate unique specials for each item - let wand_specials = ItemSpecials { special1: 1, special2: 1, special3: 1 }; - let katana_specials = ItemSpecials { special1: 2, special2: 2, special3: 2 }; - let demon_crown_specials = ItemSpecials { special1: 3, special2: 3, special3: 3 }; - let silk_robe_specials = ItemSpecials { special1: 4, special2: 4, special3: 4 }; - let silver_ring_specials = ItemSpecials { special1: 5, special2: 5, special3: 5 }; - let ghost_wand_specials = ItemSpecials { special1: 6, special2: 6, special3: 6 }; - let leather_gloves_specials = ItemSpecials { special1: 7, special2: 7, special3: 7 }; - let silk_gloves_specials = ItemSpecials { special1: 8, special2: 8, special3: 8 }; - let linen_gloves_specials = ItemSpecials { special1: 9, special2: 9, special3: 9 }; - let crown_specials = ItemSpecials { special1: 10, special2: 10, special3: 10 }; - let divine_slippers_specials = ItemSpecials { special1: 11, special2: 11, special3: 11 }; - let warhammer_specials = ItemSpecials { special1: 12, special2: 12, special3: 12 }; - let ancient_helm_specials = ItemSpecials { special1: 13, special2: 13, special3: 13 }; - let divine_robe_specials = ItemSpecials { special1: 14, special2: 14, special3: 14 }; - let holy_chestplate_specials = ItemSpecials { special1: 15, special2: 15, special3: 15 }; - let holy_greaves_specials = ItemSpecials { special1: 1, special2: 16, special3: 16 }; - let _demonhide_boots_specials = ItemSpecials { special1: 2, special2: 17, special3: 17 }; - let holy_gauntlets_specials = ItemSpecials { special1: 3, special2: 18, special3: 18 }; - let demonhide_boots_specials = ItemSpecials { special1: 4, special2: 19, special3: 19 }; - - // initialize special storage 1 with first 10 items - let storage1 = ItemSpecialsStorage { - item_1: wand_specials, - item_2: katana_specials, - item_3: demon_crown_specials, - item_4: silk_robe_specials, - item_5: silver_ring_specials, - item_6: ghost_wand_specials, - item_7: leather_gloves_specials, - item_8: silk_gloves_specials, - item_9: linen_gloves_specials, - item_10: crown_specials, - mutated: false - }; - - // initialize special storage 2 with remaining 9 items - let storage2 = ItemSpecialsStorage { - item_1: divine_slippers_specials, - item_2: warhammer_specials, - item_3: ancient_helm_specials, - item_4: divine_robe_specials, - item_5: holy_chestplate_specials, - item_6: holy_greaves_specials, - item_7: demonhide_boots_specials, - item_8: holy_gauntlets_specials, - item_9: demonhide_boots_specials, - item_10: ItemSpecials { // no item 10 in storage2 - special1: 0, special2: 0, special3: 0 - }, - mutated: false - }; - - // assert calling get_special for each item returns the expected specials - // we use PartialEq for comparision so if any of the attributes of ItemSpecials are - // different the assert will fail - assert(storage1.get_specials(wand) == wand_specials, 'wrong wand specials'); - assert(storage1.get_specials(katana) == katana_specials, 'wrong katana specials'); - assert( - storage1.get_specials(demon_crown) == demon_crown_specials, 'wrong demon crown specials' - ); - assert(storage1.get_specials(silk_robe) == silk_robe_specials, 'wrong silk robe specials'); - assert( - storage1.get_specials(silver_ring) == silver_ring_specials, 'wrong silver ring specials' - ); - assert( - storage1.get_specials(ghost_wand) == ghost_wand_specials, 'wrong ghost wand specials' - ); - assert( - storage1.get_specials(leather_gloves) == leather_gloves_specials, - 'wrong leather gloves specials' - ); - assert( - storage1.get_specials(silk_gloves) == silk_gloves_specials, 'wrong silk gloves specials' - ); - assert( - storage1.get_specials(linen_gloves) == linen_gloves_specials, - 'wrong linen gloves specials' - ); - assert(storage1.get_specials(crown) == crown_specials, 'wrong crown specials'); - assert( - storage2.get_specials(divine_slippers) == divine_slippers_specials, - 'wrong divine slippers specials' - ); - assert(storage2.get_specials(warhammer) == warhammer_specials, 'wrong warhammer specials'); - assert( - storage2.get_specials(ancient_helm) == ancient_helm_specials, - 'wrong ancient helm specials' - ); - assert( - storage2.get_specials(divine_robe) == divine_robe_specials, 'wrong divine robe specials' - ); - assert( - storage2.get_specials(holy_chestplate) == holy_chestplate_specials, - 'wrong holy chestplate specials' - ); - assert( - storage2.get_specials(holy_greaves) == holy_greaves_specials, - 'wrong holy greaves specials' - ); - assert( - storage2.get_specials(demonhide_boots) == demonhide_boots_specials, - 'wrong demonhide boots specials' - ); - assert( - storage2.get_specials(holy_gauntlets) == holy_gauntlets_specials, - 'wrong holy gauntlets specials' - ); - assert( - storage2.get_specials(demonhide_boots) == demonhide_boots_specials, - 'wrong demonhide boots specials' - ); - } - - #[test] - #[should_panic(expected: ('item specials not in storage',))] - #[available_gas(30000)] - fn test_get_specials_overflow_fail() { - // initialize ItemSpecialsStorage with all empty ItemSpecials - // as we don't need them for this test - let name_storage1 = ItemSpecialsStorage { - item_1: ItemSpecials { special2: 0, special3: 0, special1: 0 }, - item_2: ItemSpecials { special2: 0, special3: 0, special1: 0 }, - item_3: ItemSpecials { special2: 0, special3: 0, special1: 0 }, - item_4: ItemSpecials { special2: 0, special3: 0, special1: 0 }, - item_5: ItemSpecials { special2: 0, special3: 0, special1: 0 }, - item_6: ItemSpecials { special2: 0, special3: 0, special1: 0 }, - item_7: ItemSpecials { special2: 0, special3: 0, special1: 0 }, - item_8: ItemSpecials { special2: 0, special3: 0, special1: 0 }, - item_9: ItemSpecials { special2: 0, special3: 0, special1: 0 }, - item_10: ItemSpecials { special2: 0, special3: 0, special1: 0 }, - mutated: false - }; - - // initialze an item whose meta data exceeds the max storage slot for the special storage - let meta_data_id = STORAGE::MAX_TOTAL_STORAGE_SPECIALS + 1; - let item_11 = ItemPrimitive { id: 10, xp: 1, metadata: meta_data_id }; - - // attempt to get specials for this item - // this should throw a panic with the error 'metadata id out of bounds' - // this test is annotated to expect this error and will fail - // if it is not thrown - let _meta_data = name_storage1.get_specials(item_11); - } - - #[test] - #[should_panic(expected: ('item specials not in storage',))] - #[available_gas(30000)] - fn test_get_specials_zero_fail() { - // initialize ItemSpecialsStorage with all empty ItemSpecials - // as we don't need them for this test - let name_storage1 = ItemSpecialsStorage { - item_1: ItemSpecials { special2: 0, special3: 0, special1: 0 }, - item_2: ItemSpecials { special2: 0, special3: 0, special1: 0 }, - item_3: ItemSpecials { special2: 0, special3: 0, special1: 0 }, - item_4: ItemSpecials { special2: 0, special3: 0, special1: 0 }, - item_5: ItemSpecials { special2: 0, special3: 0, special1: 0 }, - item_6: ItemSpecials { special2: 0, special3: 0, special1: 0 }, - item_7: ItemSpecials { special2: 0, special3: 0, special1: 0 }, - item_8: ItemSpecials { special2: 0, special3: 0, special1: 0 }, - item_9: ItemSpecials { special2: 0, special3: 0, special1: 0 }, - item_10: ItemSpecials { special2: 0, special3: 0, special1: 0 }, - mutated: false - }; - - // initialze an item whose meta data exceeds the max storage slot for the special storage - let meta_data_id_zero = 0; - let item_11 = ItemPrimitive { id: 10, xp: 1, metadata: meta_data_id_zero }; - - // attempt to get specials for this item which has meta data id 0 - // this should throw a panic with the error 'metadata id out of bounds' - // this test is annotated to expect this error - let _meta_data = name_storage1.get_specials(item_11); - } - - #[test] - #[available_gas(600000)] - fn test_set_specials() { - let mut storage1 = ItemSpecialsStorage { - item_1: ItemSpecials { special2: 0, special3: 0, special1: 0, }, - item_2: ItemSpecials { special2: 0, special3: 0, special1: 0, }, - item_3: ItemSpecials { special2: 0, special3: 0, special1: 0, }, - item_4: ItemSpecials { special2: 0, special3: 0, special1: 0, }, - item_5: ItemSpecials { special2: 0, special3: 0, special1: 0, }, - item_6: ItemSpecials { special2: 0, special3: 0, special1: 0, }, - item_7: ItemSpecials { special2: 0, special3: 0, special1: 0, }, - item_8: ItemSpecials { special2: 0, special3: 0, special1: 0, }, - item_9: ItemSpecials { special2: 0, special3: 0, special1: 0, }, - item_10: ItemSpecials { special2: 0, special3: 0, special1: 0, }, - mutated: false - }; - - let mut storage2 = ItemSpecialsStorage { - item_1: ItemSpecials { special2: 0, special3: 0, special1: 0, }, - item_2: ItemSpecials { special2: 0, special3: 0, special1: 0, }, - item_3: ItemSpecials { special2: 0, special3: 0, special1: 0, }, - item_4: ItemSpecials { special2: 0, special3: 0, special1: 0, }, - item_5: ItemSpecials { special2: 0, special3: 0, special1: 0, }, - item_6: ItemSpecials { special2: 0, special3: 0, special1: 0, }, - item_7: ItemSpecials { special2: 0, special3: 0, special1: 0, }, - item_8: ItemSpecials { special2: 0, special3: 0, special1: 0, }, - item_9: ItemSpecials { special2: 0, special3: 0, special1: 0, }, - item_10: ItemSpecials { special2: 0, special3: 0, special1: 0, }, - mutated: false - }; - - // Storage 1 Tests - let wand = ItemPrimitive { id: ItemId::Wand, xp: 0, metadata: 1 }; - let wand_specials = ItemSpecials { special2: 12, special3: 2, special1: 5 }; - storage1.set_specials(wand, wand_specials); - assert(storage1.item_1 == wand_specials, 'wand set specials error'); - - let katana = ItemPrimitive { id: ItemId::Wand, xp: 0, metadata: 2 }; - let katana_specials = ItemSpecials { special2: 1, special3: 2, special1: 3 }; - storage1.set_specials(katana, katana_specials); - assert(storage1.item_2 == katana_specials, 'katana set specials error'); - - let demon_crown = ItemPrimitive { id: ItemId::DemonCrown, xp: 0, metadata: 3 }; - let demon_crown_specials = ItemSpecials { special2: 2, special3: 3, special1: 4 }; - storage1.set_specials(demon_crown, demon_crown_specials); - assert(storage1.item_3 == demon_crown_specials, 'demon crown set specials error'); - - let silk_robe = ItemPrimitive { id: ItemId::SilkRobe, xp: 0, metadata: 4 }; - let silk_robe_specials = ItemSpecials { special2: 3, special3: 4, special1: 5 }; - storage1.set_specials(silk_robe, silk_robe_specials); - assert(storage1.item_4 == silk_robe_specials, 'silk robe set specials error'); - - let brightsilk_sash = ItemPrimitive { id: ItemId::BrightsilkSash, xp: 0, metadata: 5 }; - let brightsilk_sash_specials = ItemSpecials { special2: 4, special3: 5, special1: 6 }; - storage1.set_specials(brightsilk_sash, brightsilk_sash_specials); - assert(storage1.item_5 == brightsilk_sash_specials, 'sash set specials error'); - - let divine_gloves = ItemPrimitive { id: ItemId::DivineGloves, xp: 0, metadata: 6 }; - let divine_gloves_specials = ItemSpecials { special2: 5, special3: 6, special1: 7 }; - storage1.set_specials(divine_gloves, divine_gloves_specials); - assert(storage1.item_6 == divine_gloves_specials, 'divine gloves set specials err'); - - let shoes = ItemPrimitive { id: ItemId::Shoes, xp: 0, metadata: 7 }; - let shoes_specials = ItemSpecials { special2: 6, special3: 7, special1: 8 }; - storage1.set_specials(shoes, shoes_specials); - assert(storage1.item_7 == shoes_specials, 'shoes set specials error'); - - let silver_ring = ItemPrimitive { id: ItemId::SilverRing, xp: 0, metadata: 8 }; - let silver_ring_specials = ItemSpecials { special2: 4, special3: 5, special1: 6 }; - storage1.set_specials(silver_ring, silver_ring_specials); - assert(storage1.item_5 == silver_ring_specials, 'silver ring set specials error'); - - let necklace = ItemPrimitive { id: ItemId::Necklace, xp: 0, metadata: 9 }; - let necklace_specials = ItemSpecials { special2: 8, special3: 9, special1: 10 }; - storage1.set_specials(necklace, necklace_specials); - assert(storage1.item_9 == necklace_specials, 'necklace set specials error'); - - let linen_gloves = ItemPrimitive { id: ItemId::LinenGloves, xp: 0, metadata: 10 }; - let linen_gloves_specials = ItemSpecials { special2: 9, special3: 10, special1: 11 }; - storage1.set_specials(linen_gloves, linen_gloves_specials); - assert(storage1.item_10 == linen_gloves_specials, 'linen gloves set specials error'); - - // Repeat for Storage 2 with meta data ids in the 11-19 range - let wand = ItemPrimitive { id: ItemId::Wand, xp: 0, metadata: 11 }; - let wand_specials = ItemSpecials { special2: 12, special3: 2, special1: 5 }; - storage2.set_specials(wand, wand_specials); - assert(storage2.item_1 == wand_specials, 'wand set specials error'); - - let katana = ItemPrimitive { id: ItemId::Wand, xp: 0, metadata: 12 }; - let katana_specials = ItemSpecials { special2: 1, special3: 2, special1: 3 }; - storage2.set_specials(katana, katana_specials); - assert(storage2.item_2 == katana_specials, 'katana set specials error'); - - let demon_crown = ItemPrimitive { id: ItemId::DemonCrown, xp: 0, metadata: 13 }; - let demon_crown_specials = ItemSpecials { special2: 2, special3: 3, special1: 4 }; - storage2.set_specials(demon_crown, demon_crown_specials); - assert(storage2.item_3 == demon_crown_specials, 'demon crown set specials error'); - - let silk_robe = ItemPrimitive { id: ItemId::SilkRobe, xp: 0, metadata: 14 }; - let silk_robe_specials = ItemSpecials { special2: 3, special3: 4, special1: 5 }; - storage2.set_specials(silk_robe, silk_robe_specials); - assert(storage2.item_4 == silk_robe_specials, 'silk robe set specials error'); - - let brightsilk_sash = ItemPrimitive { id: ItemId::BrightsilkSash, xp: 0, metadata: 15 }; - let brightsilk_sash_specials = ItemSpecials { special2: 4, special3: 5, special1: 6 }; - storage2.set_specials(brightsilk_sash, brightsilk_sash_specials); - assert(storage2.item_5 == brightsilk_sash_specials, 'sash set specials error'); - - let divine_gloves = ItemPrimitive { id: ItemId::DivineGloves, xp: 0, metadata: 16 }; - let divine_gloves_specials = ItemSpecials { special2: 5, special3: 6, special1: 7 }; - storage2.set_specials(divine_gloves, divine_gloves_specials); - assert(storage2.item_6 == divine_gloves_specials, 'divine gloves set specials err'); - - let shoes = ItemPrimitive { id: ItemId::Shoes, xp: 0, metadata: 17 }; - let shoes_specials = ItemSpecials { special2: 6, special3: 7, special1: 8 }; - storage2.set_specials(shoes, shoes_specials); - assert(storage2.item_7 == shoes_specials, 'shoes set specials error'); - - let silver_ring = ItemPrimitive { id: ItemId::SilverRing, xp: 0, metadata: 18 }; - let silver_ring_specials = ItemSpecials { special2: 4, special3: 5, special1: 6 }; - storage2.set_specials(silver_ring, silver_ring_specials); - assert(storage2.item_5 == silver_ring_specials, 'silver ring set specials error'); - - let necklace = ItemPrimitive { id: ItemId::Necklace, xp: 0, metadata: 19 }; - let necklace_specials = ItemSpecials { special2: 8, special3: 9, special1: 10 }; - storage2.set_specials(necklace, necklace_specials); - assert(storage2.item_9 == necklace_specials, 'necklace set specials error'); - } - - #[test] - #[should_panic(expected: ('meta data id not in storage',))] - #[available_gas(40000)] - fn test_set_specials_storage_zero_fail() { - // initialize ItemSpecialsStorage with all empty ItemSpecials - // as we don't need them for this test - let mut name_storage1 = ItemSpecialsStorage { - item_1: ItemSpecials { special2: 0, special3: 0, special1: 0 }, - item_2: ItemSpecials { special2: 0, special3: 0, special1: 0 }, - item_3: ItemSpecials { special2: 0, special3: 0, special1: 0 }, - item_4: ItemSpecials { special2: 0, special3: 0, special1: 0 }, - item_5: ItemSpecials { special2: 0, special3: 0, special1: 0 }, - item_6: ItemSpecials { special2: 0, special3: 0, special1: 0 }, - item_7: ItemSpecials { special2: 0, special3: 0, special1: 0 }, - item_8: ItemSpecials { special2: 0, special3: 0, special1: 0 }, - item_9: ItemSpecials { special2: 0, special3: 0, special1: 0 }, - item_10: ItemSpecials { special2: 0, special3: 0, special1: 0 }, - mutated: false - }; - - // initialze an item with meta data id zero - let meta_data_zero = 0; - let item_11 = ItemPrimitive { id: 10, xp: 1, metadata: meta_data_zero }; - let item_11_specials = ItemSpecials { special2: 1, special3: 1, special1: 1 }; - - // attempt to set specials for an item with meta data id zero - // since this is not possible, we expect set_specials to panic - // with 'metadata id out of bounds' - let _meta_data = name_storage1.set_specials(item_11, item_11_specials); - } - - #[test] - #[should_panic(expected: ('meta data id not in storage',))] - #[available_gas(40000)] - fn test_set_specials_storage_overflow_fail() { - // initialize ItemSpecialsStorage with all empty ItemSpecials - // as we don't need them for this test - let mut name_storage1 = ItemSpecialsStorage { - item_1: ItemSpecials { special2: 0, special3: 0, special1: 0 }, - item_2: ItemSpecials { special2: 0, special3: 0, special1: 0 }, - item_3: ItemSpecials { special2: 0, special3: 0, special1: 0 }, - item_4: ItemSpecials { special2: 0, special3: 0, special1: 0 }, - item_5: ItemSpecials { special2: 0, special3: 0, special1: 0 }, - item_6: ItemSpecials { special2: 0, special3: 0, special1: 0 }, - item_7: ItemSpecials { special2: 0, special3: 0, special1: 0 }, - item_8: ItemSpecials { special2: 0, special3: 0, special1: 0 }, - item_9: ItemSpecials { special2: 0, special3: 0, special1: 0 }, - item_10: ItemSpecials { special2: 0, special3: 0, special1: 0 }, - mutated: false - }; - - // initialze an item whose meta data exceeds the max storage slot for the special storage - let meta_data_id = STORAGE::MAX_TOTAL_STORAGE_SPECIALS + 1; - let item_11 = ItemPrimitive { id: 10, xp: 1, metadata: meta_data_id }; - let item_11_specials = ItemSpecials { special2: 1, special3: 1, special1: 1 }; - - // attempt to set specials for this item which is not possible because - // it's meta data exceeds the max storage slot for the special storage system - // this should throw a panic with the error 'metadata id out of bounds' - // this test is annotated to expect this error - let _meta_data = name_storage1.set_specials(item_11, item_11_specials); - } -} diff --git a/contracts/adventurer/src/item_primitive.cairo b/contracts/adventurer/src/item_primitive.cairo index e3f03eca8..18c77e2a2 100644 --- a/contracts/adventurer/src/item_primitive.cairo +++ b/contracts/adventurer/src/item_primitive.cairo @@ -5,27 +5,19 @@ use lootitems::loot::{ItemId}; struct ItemPrimitive { // 21 storage bits id: u8, // 7 bits xp: u16, // 9 bits - metadata: u8, // 5 bits } impl ItemPrimitivePacking of StorePacking { fn pack(value: ItemPrimitive) -> felt252 { - (value.id.into() + value.xp.into() * TWO_POW_7 + value.metadata.into() * TWO_POW_16) - .try_into() - .unwrap() + (value.id.into() + value.xp.into() * TWO_POW_7).try_into().unwrap() } fn unpack(value: felt252) -> ItemPrimitive { let packed = value.into(); let (packed, id) = integer::U256DivRem::div_rem(packed, TWO_POW_7.try_into().unwrap()); - let (packed, xp) = integer::U256DivRem::div_rem(packed, TWO_POW_9.try_into().unwrap()); - let (_, metadata) = integer::U256DivRem::div_rem(packed, TWO_POW_5.try_into().unwrap()); + let (_, xp) = integer::U256DivRem::div_rem(packed, TWO_POW_9.try_into().unwrap()); - ItemPrimitive { - id: id.try_into().unwrap(), - xp: xp.try_into().unwrap(), - metadata: metadata.try_into().unwrap() - } + ItemPrimitive { id: id.try_into().unwrap(), xp: xp.try_into().unwrap(), } } } @@ -35,7 +27,7 @@ impl ImplItemPrimitive of IItemPrimitive { // @param item_id the id of the item // @return the new ItemPrimitive fn new(item_id: u8) -> ItemPrimitive { - ItemPrimitive { id: item_id, xp: 0, metadata: 0 } + ItemPrimitive { id: item_id, xp: 0 } } #[inline(always)] @@ -116,48 +108,42 @@ mod tests { let item = IItemPrimitive::new(0); assert(item.id == 0, 'id should be 0'); assert(item.xp == 0, 'xp should be 0'); - assert(item.metadata == 0, 'metadata should be 0'); // base case let item = IItemPrimitive::new(1); assert(item.id == 1, 'id should be 1'); assert(item.xp == 0, 'xp should be 0'); - assert(item.metadata == 0, 'metadata should be 0'); // max u8 case let item = IItemPrimitive::new(255); assert(item.id == 255, 'id should be 255'); assert(item.xp == 0, 'xp should be 0'); - assert(item.metadata == 0, 'metadata should be 0'); } #[test] #[available_gas(500000)] fn test_item_primitive_packing() { - let item = ItemPrimitive { id: 1, xp: 2, metadata: 3 }; + let item = ItemPrimitive { id: 1, xp: 2 }; let packed = ItemPrimitivePacking::pack(item); let unpacked = ItemPrimitivePacking::unpack(packed); assert(item.id == unpacked.id, 'id should be the same'); assert(item.xp == unpacked.xp, 'xp should be the same'); - assert(item.metadata == unpacked.metadata, 'metadata should be the same'); // max value case - let item = ItemPrimitive { id: 127, xp: 511, metadata: 31 }; + let item = ItemPrimitive { id: 127, xp: 511 }; let packed = ItemPrimitivePacking::pack(item); let unpacked = ItemPrimitivePacking::unpack(packed); assert(item.id == unpacked.id, 'id should be the same'); assert(item.xp == unpacked.xp, 'xp should be the same'); - assert(item.metadata == unpacked.metadata, 'metadata should be the same'); // overflow case - let item = ItemPrimitive { id: 128, xp: 512, metadata: 32 }; + let item = ItemPrimitive { id: 128, xp: 512 }; let packed = ItemPrimitivePacking::pack(item); let unpacked = ItemPrimitivePacking::unpack(packed); assert(unpacked.id == 0, 'id should overflow to 0'); assert(unpacked.xp == 1, 'xp should overflow to 1'); - assert(unpacked.metadata == 1, 'metadata should overflow to 1'); } } diff --git a/contracts/adventurer/src/lib.cairo b/contracts/adventurer/src/lib.cairo index 962f46c8b..6ac09f680 100644 --- a/contracts/adventurer/src/lib.cairo +++ b/contracts/adventurer/src/lib.cairo @@ -3,7 +3,6 @@ mod adventurer_meta; mod adventurer_utils; mod stats; mod item_primitive; -mod item_meta; mod exploration; mod bag; mod constants { diff --git a/contracts/game/src/game/interfaces.cairo b/contracts/game/src/game/interfaces.cairo index 741a2e266..8922fdaeb 100644 --- a/contracts/game/src/game/interfaces.cairo +++ b/contracts/game/src/game/interfaces.cairo @@ -4,8 +4,7 @@ use beasts::beast::Beast; use market::market::{ItemPurchase}; use survivor::{ bag::Bag, adventurer::{Adventurer, Stats}, adventurer_meta::AdventurerMetadata, - item_meta::{ItemSpecials, ItemSpecialsStorage}, leaderboard::Leaderboard, - item_primitive::{ItemPrimitive} + leaderboard::Leaderboard, item_primitive::{ItemPrimitive} }; #[starknet::interface] @@ -88,9 +87,6 @@ trait IGame { // bag and specials fn get_bag(self: @TContractState, adventurer_id: felt252) -> Bag; - fn get_special_storage( - self: @TContractState, adventurer_id: felt252, storage_index: u8 - ) -> ItemSpecialsStorage; // // item details // fn get_weapon_specials(self: @TContractState, adventurer_id: felt252) -> ItemSpecials; @@ -209,9 +205,6 @@ trait IViewGame { // ------ View Functions ------ // // bag and specials // fn get_bag(self: @TContractState, adventurer_id: felt252) -> Bag; - // fn get_special_storage( - // self: @TContractState, adventurer_id: felt252, storage_index: u8 - // ) -> ItemSpecialsStorage; // // item details // fn get_weapon_specials(self: @TContractState, adventurer_id: felt252) -> ItemSpecials; diff --git a/contracts/game/src/lib.cairo b/contracts/game/src/lib.cairo index b8f1c7b83..0c6b87840 100644 --- a/contracts/game/src/lib.cairo +++ b/contracts/game/src/lib.cairo @@ -16,8 +16,6 @@ mod Game { const MAINNET_CHAIN_ID: felt252 = 0x534e5f4d41494e; const SEPOLIA_CHAIN_ID: felt252 = 0x534e5f5345504f4c4941; const MINIMUM_SCORE_FOR_PAYOUTS: u16 = 200; - const LOOT_NAME_STORAGE_INDEX_1: u8 = 0; - const LOOT_NAME_STORAGE_INDEX_2: u8 = 1; const SECONDS_IN_HOUR: u32 = 3600; const SECONDS_IN_DAY: u32 = 86400; const SECONDS_IN_WEEK: u32 = 604800; @@ -86,7 +84,6 @@ mod Game { OBSTACLE_CRITICAL_HIT_CHANCE, MAX_STAT_UPGRADE_POINTS } }, - item_meta::{ImplItemSpecials, ItemSpecials, IItemSpecials, ItemSpecialsStorage}, adventurer_utils::AdventurerUtils, leaderboard::{Score, Leaderboard}, }; use openzeppelin::token::erc20::{interface::{IERC20Dispatcher, IERC20DispatcherTrait}}; @@ -115,7 +112,6 @@ mod Game { _leaderboard: Leaderboard, _lords: ContractAddress, _owner: LegacyMap::, - _item_specials: LegacyMap::<(felt252, u8), ItemSpecialsStorage>, _golden_token_last_use: LegacyMap::, _golden_token: ContractAddress, _cost_to_play: u128, @@ -232,8 +228,10 @@ mod Game { let adventurer_level = adventurer.get_level(); // If the adventurer is on level 2, they are waiting on this entropy to come in for the market to be available - if adventurer_level== 2 { - process_initial_entropy(ref self, ref adventurer, adventurer_id, adventurer_entropy); + if adventurer_level == 2 { + process_initial_entropy( + ref self, ref adventurer, adventurer_id, adventurer_entropy + ); // we only need to save adventurer is they received Vitality as part of starting stats if adventurer.stats.vitality > 0 { _save_adventurer(ref self, ref adventurer, adventurer_id); @@ -337,7 +335,10 @@ mod Game { } // get weapon specials - let weapon_specials = _get_item_specials(@self, adventurer_id, adventurer.weapon); + let start_entropy = _load_adventurer_metadata(@self, adventurer_id).start_entropy; + let weapon_specials = ImplLoot::get_specials( + adventurer.weapon.id, adventurer.weapon.get_greatness(), start_entropy + ); // get beast and beast seed let (beast, beast_seed) = adventurer.get_beast(adventurer_entropy); @@ -348,11 +349,7 @@ mod Game { tier: weapon.tier, item_type: weapon.item_type, level: adventurer.weapon.get_greatness().into(), - specials: SpecialPowers { - special1: weapon_specials.special1, - special2: weapon_specials.special2, - special3: weapon_specials.special3 - } + specials: weapon_specials }; _attack( @@ -361,6 +358,7 @@ mod Game { weapon_combat_spec, adventurer_id, adventurer_entropy, + start_entropy, beast, beast_seed, to_the_death @@ -451,8 +449,16 @@ mod Game { ); // process beast attack + let start_entropy = _load_adventurer_metadata(@self, adventurer_id).start_entropy; let beast_battle_details = _beast_attack( - ref self, ref adventurer, adventurer_id, beast, beast_seed, rnd1, rnd2, + ref self, + ref adventurer, + adventurer_id, + beast, + beast_seed, + start_entropy, + rnd1, + rnd2, ); // emit attacked by beast event @@ -620,38 +626,6 @@ mod Game { fn get_bag(self: @ContractState, adventurer_id: felt252) -> Bag { _load_bag(self, adventurer_id) } - // fn get_weapon_specials(self: @ContractState, adventurer_id: felt252) -> ItemSpecials { - // let adventurer = _load_adventurer_no_boosts(self, adventurer_id); - // _get_item_specials(self, adventurer_id, adventurer.weapon) - // } - // fn get_chest_specials(self: @ContractState, adventurer_id: felt252) -> ItemSpecials { - // let adventurer = _load_adventurer_no_boosts(self, adventurer_id); - // _get_item_specials(self, adventurer_id, adventurer.chest) - // } - // fn get_head_specials(self: @ContractState, adventurer_id: felt252) -> ItemSpecials { - // let adventurer = _load_adventurer_no_boosts(self, adventurer_id); - // _get_item_specials(self, adventurer_id, adventurer.head) - // } - // fn get_waist_specials(self: @ContractState, adventurer_id: felt252) -> ItemSpecials { - // let adventurer = _load_adventurer_no_boosts(self, adventurer_id); - // _get_item_specials(self, adventurer_id, adventurer.waist) - // } - // fn get_foot_specials(self: @ContractState, adventurer_id: felt252) -> ItemSpecials { - // let adventurer = _load_adventurer_no_boosts(self, adventurer_id); - // _get_item_specials(self, adventurer_id, adventurer.foot) - // } - // fn get_hand_specials(self: @ContractState, adventurer_id: felt252) -> ItemSpecials { - // let adventurer = _load_adventurer_no_boosts(self, adventurer_id); - // _get_item_specials(self, adventurer_id, adventurer.hand) - // } - // fn get_necklace_specials(self: @ContractState, adventurer_id: felt252) -> ItemSpecials { - // let adventurer = _load_adventurer_no_boosts(self, adventurer_id); - // _get_item_specials(self, adventurer_id, adventurer.neck) - // } - // fn get_ring_specials(self: @ContractState, adventurer_id: felt252) -> ItemSpecials { - // let adventurer = _load_adventurer_no_boosts(self, adventurer_id); - // _get_item_specials(self, adventurer_id, adventurer.ring) - // } fn get_items_on_market(self: @ContractState, adventurer_id: felt252) -> Array { let adventurer = _load_adventurer_no_boosts(self, adventurer_id); _assert_upgrades_available(adventurer); @@ -862,11 +836,6 @@ mod Game { // fn get_charisma(self: @ContractState, adventurer_id: felt252) -> u8 { // _load_adventurer(self, adventurer_id).stats.charisma // } - fn get_special_storage( - self: @ContractState, adventurer_id: felt252, storage_index: u8 - ) -> ItemSpecialsStorage { - self._item_specials.read((adventurer_id, storage_index)) - } fn get_beast_type(self: @ContractState, beast_id: u8) -> u8 { ImplCombat::type_to_u8(ImplBeast::get_type(beast_id)) } @@ -1050,8 +1019,9 @@ mod Game { // items use adventurer xp with an item multplier so they level faster than Adventurer let xp_earned_items = xp_earned_adventurer * ITEM_XP_MULTIPLIER_BEASTS; // assigning xp to items is more complex so we delegate to an internal function + let start_entropy = _load_adventurer_metadata(@self, adventurer_id).start_entropy; let items_leveled_up = _grant_xp_to_equipped_items( - ref self, ref adventurer, adventurer_id, xp_earned_items, attack_rnd_2 + ref self, ref adventurer, adventurer_id, xp_earned_items, start_entropy ); // emit slayed beast event @@ -1127,6 +1097,8 @@ mod Game { let mut adventurer_meta = _load_adventurer_metadata(self, adventurer_id); adventurer_meta.starting_stats = starting_stats; adventurer_meta + .start_entropy = ImplAdventurerMetadata::generate_start_entropy(adventurer_entropy); + adventurer_meta } fn _mint_beast(self: @ContractState, beast: Beast, to_address: ContractAddress) { @@ -1181,17 +1153,6 @@ mod Game { } } - // @title Assert Valid Block Hash Availability - // @notice This function asserts that a valid block hash is available for the given adventurer. - // @dev If this function is called prior to 2 blocks from the start of the game for the given adventurer, an exception will be thrown. - // @param adventurer_id The ID of the adventurer for which to check the block hash availability. - fn _assert_valid_block_hash_available(self: @ContractState, adventurer_id: felt252) { - let current_block = starknet::get_block_info().unbox().block_number; - let adventurer_start_block = _load_adventurer_metadata(self, adventurer_id).start_block; - let block_hash_available = adventurer_start_block + 2; - assert(current_block >= block_hash_available, messages::VALID_BLOCK_HASH_UNAVAILABLE); - } - fn _golden_token_dispatcher(ref self: ContractState) -> IERC721Dispatcher { IERC721Dispatcher { contract_address: self._golden_token.read() } } @@ -1361,17 +1322,14 @@ mod Game { // increment adventurer id (first adventurer is id 1) let adventurer_id = self._game_counter.read() + 1; - // use current starknet block number and timestamp as entropy sources - let current_block = starknet::get_block_info().unbox().block_number; - // randomness for starter beast isn't sensitive so we can use basic entropy - let starter_beast_rnd = _get_basic_entropy(adventurer_id, current_block); + let starter_beast_rnd = _get_basic_entropy(adventurer_id); // generate a new adventurer using the provided started weapon let mut adventurer = ImplAdventurer::new(weapon); // create meta data for the adventurer - let adventurer_meta = ImplAdventurerMetadata::new(name, current_block, interface_camel); + let adventurer_meta = ImplAdventurerMetadata::new(name, interface_camel); // adventurer immediately gets ambushed by a starter beast let beast_battle_details = _starter_beast_ambush( @@ -1519,8 +1477,16 @@ mod Game { // if adventurer was ambushed if (is_ambushed) { // process beast attack + let start_entropy = _load_adventurer_metadata(@self, adventurer_id).start_entropy; let beast_battle_details = _beast_attack( - ref self, ref adventurer, adventurer_id, beast, beast_seed, entropy, entropy + ref self, + ref adventurer, + adventurer_id, + beast, + beast_seed, + start_entropy, + entropy, + entropy ); __event_AmbushedByBeast(ref self, adventurer, adventurer_id, beast_battle_details); if (adventurer.health == 0) { @@ -1593,8 +1559,9 @@ mod Game { let (previous_level, new_level) = adventurer.increase_adventurer_xp(base_reward); // grant items xp and get array of items that leveled up + let start_entropy = _load_adventurer_metadata(@self, adventurer_id).start_entropy; let items_leveled_up = _grant_xp_to_equipped_items( - ref self, ref adventurer, adventurer_id, item_xp_reward, entropy + ref self, ref adventurer, adventurer_id, item_xp_reward, start_entropy ); // emit obstacle encounter event after granting xp to adventurer and items @@ -1629,9 +1596,8 @@ mod Game { ref adventurer: Adventurer, adventurer_id: felt252, xp_amount: u16, - entropy: u128 + start_entropy: u64 ) -> Array { - let (mut name_storage1, mut name_storage2) = _get_special_storages(@self, adventurer_id); let mut items_leveled_up = ArrayTrait::::new(); let equipped_items = adventurer.get_equipped_items(); let mut item_index: u32 = 0; @@ -1648,14 +1614,7 @@ mod Game { if new_level > previous_level { // process level up let updated_item = _process_item_level_up( - ref self, - ref adventurer, - ref name_storage1, - ref name_storage2, - item, - previous_level, - new_level, - entropy + ref self, ref adventurer, item, previous_level, new_level, start_entropy ); // add item to list of items that leveled up to be emitted in event @@ -1665,28 +1624,19 @@ mod Game { item_index += 1; }; - if (name_storage1.mutated) { - _save_item_specials(ref self, adventurer_id, LOOT_NAME_STORAGE_INDEX_1, name_storage1); - } - if (name_storage2.mutated) { - _save_item_specials(ref self, adventurer_id, LOOT_NAME_STORAGE_INDEX_2, name_storage2); - } - items_leveled_up } fn _process_item_level_up( ref self: ContractState, ref adventurer: Adventurer, - ref name_storage1: ItemSpecialsStorage, - ref name_storage2: ItemSpecialsStorage, item: ItemPrimitive, previous_level: u8, new_level: u8, - entropy: u128 + start_entropy: u64 ) -> ItemLeveledUp { // init specials with no specials - let mut specials = ItemSpecials { special1: 0, special2: 0, special3: 0 }; + let mut specials = SpecialPowers { special1: 0, special2: 0, special3: 0 }; // check if item reached greatness 20 if (new_level == ITEM_MAX_GREATNESS) { @@ -1702,13 +1652,8 @@ mod Game { // if specials were unlocked if (suffix_unlocked || prefixes_unlocked) { // apply them and record the new specials so we can include them in event - if (_get_storage_index(@self, item.metadata) == LOOT_NAME_STORAGE_INDEX_1) { - specials = item - .apply_specials(ref name_storage1, suffix_unlocked, prefixes_unlocked, entropy); - } else { - specials = item - .apply_specials(ref name_storage2, suffix_unlocked, prefixes_unlocked, entropy); - } + + specials = ImplLoot::get_specials(item.id, item.get_greatness(), start_entropy); // if item received a suffix as part of the level up if (suffix_unlocked) { @@ -1750,6 +1695,7 @@ mod Game { weapon_combat_spec: CombatSpec, adventurer_id: felt252, adventurer_entropy: felt252, + start_entropy: u64, beast: Beast, beast_seed: u128, fight_to_the_death: bool, @@ -1784,7 +1730,14 @@ mod Game { // process beast counter attack let attacked_by_beast_details = _beast_attack( - ref self, ref adventurer, adventurer_id, beast, beast_seed, rnd1, rnd2, + ref self, + ref adventurer, + adventurer_id, + beast, + beast_seed, + start_entropy, + rnd1, + rnd2, ); // emit events @@ -1818,6 +1771,7 @@ mod Game { weapon_combat_spec, adventurer_id, adventurer_entropy, + start_entropy, beast, beast_seed, true @@ -1842,7 +1796,8 @@ mod Game { adventurer_id: felt252, beast: Beast, beast_seed: u128, - entropy: u128, + start_entropy: u64, + battle_entropy: u128, attack_location_rnd: u128, ) -> BattleDetails { // beasts attack random location on adventurer @@ -1854,11 +1809,11 @@ mod Game { let armor = adventurer.get_item_at_slot(attack_location); // get armor specials - let armor_specials = _get_item_specials(@self, adventurer_id, armor); + let armor_specials = ImplLoot::get_specials(armor.id, armor.get_greatness(), start_entropy); // process beast attack let (combat_result, _jewlery_armor_bonus) = adventurer - .defend(beast, armor, armor_specials, entropy); + .defend(beast, armor, armor_specials, battle_entropy); // deduct damage taken from adventurer's health adventurer.decrease_health(combat_result.total_damage); @@ -1920,12 +1875,14 @@ mod Game { } } else { // if the flee attempt failed, beast counter attacks + let start_entropy = _load_adventurer_metadata(@self, adventurer_id).start_entropy; let beast_battle_details = _beast_attack( ref self, ref adventurer, adventurer_id, beast, beast_seed, + start_entropy, ambush_entropy, ambush_entropy, ); @@ -2028,7 +1985,6 @@ mod Game { // create new item, equip it, and record if we need unequipped an item let mut new_item = ImplItemPrimitive::new(item_id); - new_item.set_metadata_id(adventurer, bag, true); unequipped_item_id = _equip_item(contract_state, ref adventurer, ref bag, adventurer_id, new_item); } else { @@ -2332,9 +2288,9 @@ mod Game { adventurer_id: felt252, item: ItemPrimitive ) { - let (name_storage1, name_storage2) = _get_special_storages(self, adventurer_id); - let item_specials = ImplItemSpecials::get_specials_full(name_storage1, name_storage2, item); - adventurer.stats.apply_suffix_boost(item_specials.special1); + let start_entropy = _load_adventurer_metadata(self, adventurer_id).start_entropy; + let item_suffix = ImplLoot::get_suffix(item.id, start_entropy); + adventurer.stats.apply_suffix_boost(item_suffix); } fn _remove_item_stat_boost( @@ -2343,9 +2299,9 @@ mod Game { adventurer_id: felt252, item: ItemPrimitive ) { - let (name_storage1, name_storage2) = _get_special_storages(self, adventurer_id); - let item_specials = ImplItemSpecials::get_specials_full(name_storage1, name_storage2, item); - adventurer.stats.remove_suffix_boost(item_specials.special1); + let start_entropy = _load_adventurer_metadata(self, adventurer_id).start_entropy; + let item_suffix = ImplLoot::get_suffix(item.id, start_entropy); + adventurer.stats.remove_suffix_boost(item_suffix); // if the adventurer's health is now above the max health due to a change in Vitality let max_health = AdventurerUtils::get_max_health(adventurer.stats.vitality); @@ -2359,11 +2315,8 @@ mod Game { self: @ContractState, ref adventurer: Adventurer, adventurer_id: felt252 ) { if adventurer.has_item_specials() { - // get specials from storage - let (name_storage1, name_storage2) = _get_special_storages(self, adventurer_id); - // get stat boosts from item specials - let item_stat_boosts = adventurer.get_stat_boosts(name_storage1, name_storage2); - // apply item stat boosts + let start_entropy = _load_adventurer_metadata(self, adventurer_id).start_entropy; + let item_stat_boosts = adventurer.get_stat_boosts(start_entropy); adventurer.apply_stat_boosts(item_stat_boosts); } } @@ -2372,11 +2325,8 @@ mod Game { self: @ContractState, ref adventurer: Adventurer, adventurer_id: felt252 ) { if adventurer.has_item_specials() { - // get specials from storage - let (name_storage1, name_storage2) = _get_special_storages(self, adventurer_id); - // get stat boosts from item specials - let item_stat_boosts = adventurer.get_stat_boosts(name_storage1, name_storage2); - // remove item stat boosts + let start_entropy = _load_adventurer_metadata(self, adventurer_id).start_entropy; + let item_stat_boosts = adventurer.get_stat_boosts(start_entropy); adventurer.remove_stat_boosts(item_stat_boosts); } } @@ -2414,7 +2364,9 @@ mod Game { // if we already have adventurer entropy from VRF if (adventurer_entropy != 0) { // process initial entropy which will reveal starting stats and emit starting market - process_initial_entropy(ref self, ref adventurer, adventurer_id, adventurer_entropy); + process_initial_entropy( + ref self, ref adventurer, adventurer_id, adventurer_entropy + ); } } else if (new_level > previous_level) { // if this is any level up beyond the starter beast @@ -2426,8 +2378,6 @@ mod Game { if (previous_level / randomness_rotation_interval < new_level / randomness_rotation_interval) { - - // if they have, zero out current entropy self._adventurer_entropy.write(adventurer_id, 0); @@ -2450,47 +2400,6 @@ mod Game { __event_AdventurerLeveledUp(ref self, adventurer_state, previous_level, new_level); } } - - #[inline(always)] - fn _save_item_specials( - ref self: ContractState, - adventurer_id: felt252, - storage_index: u8, - loot_special_names_storage: ItemSpecialsStorage, - ) { - self._item_specials.write((adventurer_id, storage_index), loot_special_names_storage); - } - - #[inline(always)] - fn _get_special_storages( - self: @ContractState, adventurer_id: felt252 - ) -> (ItemSpecialsStorage, ItemSpecialsStorage) { - ( - _get_specials_storage(self, adventurer_id, LOOT_NAME_STORAGE_INDEX_1), - _get_specials_storage(self, adventurer_id, LOOT_NAME_STORAGE_INDEX_2), - ) - } - - #[inline(always)] - fn _get_specials_storage( - self: @ContractState, adventurer_id: felt252, storage_index: u8 - ) -> ItemSpecialsStorage { - self._item_specials.read((adventurer_id, storage_index)) - } - - #[inline(always)] - fn _get_item_specials( - self: @ContractState, adventurer_id: felt252, item: ItemPrimitive - ) -> ItemSpecials { - if (item.get_greatness() >= SUFFIX_UNLOCK_GREANTESS) { - ImplItemSpecials::get_specials( - _get_specials_storage(self, adventurer_id, _get_storage_index(self, item.metadata)), - item - ) - } else { - ItemSpecials { special1: 0, special2: 0, special3: 0 } - } - } #[inline(always)] fn _owner_of(self: @ContractState, adventurer_id: felt252) -> ContractAddress { self._owner.read(adventurer_id) @@ -2654,76 +2563,14 @@ mod Game { beast } - #[inline(always)] - fn _get_storage_index(self: @ContractState, meta_data_id: u8) -> u8 { - if (meta_data_id <= 10) { - LOOT_NAME_STORAGE_INDEX_1 - } else { - LOOT_NAME_STORAGE_INDEX_2 - } - } - - // @notice returns the combat spec for an item so it can be used with combat module - // @param self - read-only reference to the contract state - // @param adventurer_id - the id of the adventurer - // @param item - the item to get the combat spec for - fn _get_combat_spec( - self: @ContractState, adventurer_id: felt252, item: ItemPrimitive - ) -> CombatSpec { - // if item is 0, return a default combat spec - if (item.id == 0) { - CombatSpec { - tier: Tier::None(()), - item_type: Type::None(()), - level: 1, - specials: SpecialPowers { special1: 0, special2: 0, special3: 0 } - } - } else { - // otherwise get the loot item from the item id - let loot_item = ImplLoot::get_item(item.id); - - // if the item is lower than G15 - if item.get_greatness() < 15 { - // we don't need to fetch item specials from storage - CombatSpec { - tier: loot_item.tier, - item_type: loot_item.item_type, - level: item.get_greatness().into(), - specials: SpecialPowers { special1: 0, special2: 0, special3: 0 } - } - } else { - // if item is G15 or above, we need to fetch specials - let item_details = ImplItemSpecials::get_specials( - _get_specials_storage( - self, adventurer_id, _get_storage_index(self, item.metadata) - ), - item - ); - let specials = SpecialPowers { - special1: item_details.special1, - special2: item_details.special2, - special3: item_details.special3 - }; - // and return a CombatSpec with those specials - CombatSpec { - tier: loot_item.tier, - item_type: loot_item.item_type, - level: item.get_greatness().into(), - specials - } - } - } - } - #[inline(always)] fn _get_adventurer_entropy(self: @ContractState, adventurer_id: felt252) -> felt252 { self._adventurer_entropy.read(adventurer_id) } #[inline(always)] - fn _get_basic_entropy(adventurer_id: felt252, start_block: u64) -> felt252 { + fn _get_basic_entropy(adventurer_id: felt252) -> felt252 { let mut hash_span = ArrayTrait::new(); - hash_span.append(start_block.into()); hash_span.append(adventurer_id); poseidon_hash_span(hash_span.span()) } @@ -2957,7 +2804,7 @@ mod Game { new_level: u8, suffix_unlocked: bool, prefixes_unlocked: bool, - specials: ItemSpecials + specials: SpecialPowers } #[derive(Drop, starknet::Event)] @@ -2966,14 +2813,6 @@ mod Game { items: Array, } - #[derive(Drop, starknet::Event)] - struct ItemSpecialUnlocked { - adventurer_state: AdventurerState, - id: u8, - level: u8, - specials: ItemSpecials - } - #[derive(Drop, starknet::Event)] struct NewHighScore { adventurer_state: AdventurerState, diff --git a/contracts/game/src/tests/test_game.cairo b/contracts/game/src/tests/test_game.cairo index dc928e8f3..76187fd8b 100644 --- a/contracts/game/src/tests/test_game.cairo +++ b/contracts/game/src/tests/test_game.cairo @@ -1435,186 +1435,6 @@ mod tests { ); } - // To run this test we need to increase starting gold so we can buy max number of items - // We either need to use cheat codes to accomplish this or have the contract take in - // game settings in the constructor. Commenting this out for now so our CI doesn't run it - // #[test] - // #[available_gas(80000000000)] - // fn test_metadata_unique() { - // // start game on level 2 so we have access to the market - // let mut game = new_adventurer_lvl2(1000, 1696201757, 0); - - // // get items from market - // let mut market_item_ids = game.get_items_on_market(ADVENTURER_ID); - - // let mut purchased_chest: u8 = 0; - // let mut purchased_head: u8 = 0; - // let mut purchased_waist: u8 = 0; - // let mut purchased_foot: u8 = 0; - // let mut purchased_hand: u8 = 0; - // let mut purchased_ring: u8 = 0; - // let mut purchased_necklace: u8 = 0; - // let mut shopping_cart = ArrayTrait::::new(); - - // let mut bagged_items: u8 = 0; - - // loop { - // match market_item_ids.pop_front() { - // Option::Some(item_id) => { - // let market_item = ImplLoot::get_item(item_id); - // // fill up all equipment slots - // if (market_item.slot == Slot::Chest(()) && purchased_chest == 0) { - // shopping_cart.append(ItemPurchase { item_id: market_item.id, equip: true }); - // purchased_chest = market_item.id; - // } else if (market_item.slot == Slot::Head(()) && purchased_head == 0) { - // shopping_cart.append(ItemPurchase { item_id: market_item.id, equip: true }); - // purchased_head = market_item.id; - // } else if (market_item.slot == Slot::Waist(()) && purchased_waist == 0) { - // shopping_cart.append(ItemPurchase { item_id: market_item.id, equip: true }); - // purchased_waist = market_item.id; - // } else if (market_item.slot == Slot::Foot(()) && purchased_foot == 0) { - // shopping_cart.append(ItemPurchase { item_id: market_item.id, equip: true }); - // purchased_foot = market_item.id; - // } else if (market_item.slot == Slot::Hand(()) && purchased_hand == 0) { - // shopping_cart.append(ItemPurchase { item_id: market_item.id, equip: true }); - // purchased_hand = market_item.id; - // } else if (market_item.slot == Slot::Ring(()) && purchased_ring == 0) { - // shopping_cart.append(ItemPurchase { item_id: market_item.id, equip: true }); - // purchased_ring = market_item.id; - // } else if (market_item.slot == Slot::Neck(()) && purchased_necklace == 0) { - // shopping_cart.append(ItemPurchase { item_id: market_item.id, equip: true }); - // purchased_necklace = market_item.id; - // } else if bagged_items < 11 && item_id != ItemId::Wand { - // shopping_cart - // .append(ItemPurchase { item_id: market_item.id, equip: false }); - // bagged_items += 1; - // } - // }, - // Option::None => { break; }, - // } - // }; - - // assert( - // purchased_chest != 0 - // && purchased_head != 0 - // && purchased_waist != 0 - // && purchased_foot != 0 - // && purchased_hand != 0 - // && purchased_ring != 0 - // && purchased_necklace != 0 - // && bagged_items == 11, - // 'did not purchase all items' - // ); - - // // buy items in shopping cart which will fully equip the adventurer - // // and fill their bag - // let potions = 0; - // let stat_upgrades = Stats { - // strength: 0, dexterity: 0, vitality: 0, intelligence: 0, wisdom: 0, charisma: 1, luck: 0 - // }; - // game.upgrade(ADVENTURER_ID, potions, stat_upgrades, shopping_cart); - - // // verify adventurer is fully equipped except for ring - // let updated_adventurer = game.get_adventurer(ADVENTURER_ID); - // assert(updated_adventurer.is_equipped(purchased_chest), 'chest not equipped'); - // assert(updated_adventurer.is_equipped(purchased_head), 'head not equipped'); - // assert(updated_adventurer.is_equipped(purchased_waist), 'waist not equipped'); - // assert(updated_adventurer.is_equipped(purchased_foot), 'foot not equipped'); - // assert(updated_adventurer.is_equipped(purchased_hand), 'hand not equipped'); - // assert(updated_adventurer.is_equipped(purchased_ring), 'ring not equipped'); - // assert(updated_adventurer.is_equipped(purchased_necklace), 'necklace not equipped'); - - // // verify bag is full - // let bag = game.get_bag(ADVENTURER_ID); - // assert(bag.item_1.id != 0, 'bag item1 is empty'); - // assert(bag.item_2.id != 0, 'bag item2 is empty'); - // assert(bag.item_3.id != 0, 'bag item3 is empty'); - // assert(bag.item_4.id != 0, 'bag item4 is empty'); - // assert(bag.item_5.id != 0, 'bag item5 is empty'); - // assert(bag.item_6.id != 0, 'bag item6 is empty'); - // assert(bag.item_7.id != 0, 'bag item7 is empty'); - // assert(bag.item_8.id != 0, 'bag item8 is empty'); - // assert(bag.item_9.id != 0, 'bag item9 is empty'); - // assert(bag.item_10.id != 0, 'bag item10 is empty'); - // assert(bag.item_11.id != 0, 'bag item11 is empty'); - - // // drop first two items in our bag - // game.drop(ADVENTURER_ID, array![bag.item_1.id, bag.item_2.id, updated_adventurer.neck.id]); - - // // get updated bag and verify item_1 is now 0 - // let bag = game.get_bag(ADVENTURER_ID); - // assert(bag.item_1.id == 0, 'bag item1 should be empty'); - // assert(bag.item_2.id == 0, 'bag item2 should be empty'); - - // let adventurer = game.get_adventurer(ADVENTURER_ID); - // assert(adventurer.neck.id == 0, 'neck should be empty'); - - // // advance to next level - // game.explore(ADVENTURER_ID, true); - // game.attack(ADVENTURER_ID, true); - - // let updated_adventurer = game.get_adventurer(ADVENTURER_ID); - // let updated_bag = game.get_bag(ADVENTURER_ID); - - // // get items from market - // let mut market_item_ids = game.get_items_on_market(ADVENTURER_ID); - // let mut shopping_cart = ArrayTrait::::new(); - - // loop { - // match market_item_ids.pop_front() { - // Option::Some(item_id) => { - // let market_item = ImplLoot::get_item(item_id); - // if shopping_cart.len() < 2 - // && item_id != ItemId::Wand - // && item_id != updated_adventurer.weapon.id - // && item_id != updated_adventurer.chest.id - // && item_id != updated_adventurer.head.id - // && item_id != updated_adventurer.waist.id - // && item_id != updated_adventurer.foot.id - // && item_id != updated_adventurer.hand.id - // && item_id != updated_adventurer.ring.id - // && item_id != updated_bag.item_1.id - // && item_id != updated_bag.item_2.id - // && item_id != updated_bag.item_3.id - // && item_id != updated_bag.item_4.id - // && item_id != updated_bag.item_5.id - // && item_id != updated_bag.item_6.id - // && item_id != updated_bag.item_7.id - // && item_id != updated_bag.item_8.id - // && item_id != updated_bag.item_9.id - // && item_id != updated_bag.item_10.id - // && item_id != updated_bag.item_11.id { - // shopping_cart - // .append(ItemPurchase { item_id: market_item.id, equip: false }); - // } else if shopping_cart.len() == 2 { - // break; - // } - // }, - // Option::None => { break; }, - // } - // }; - - // assert(shopping_cart.len() == 2, 'did not purchase enough items'); - - // // purchase items - // let potions = 0; - // let stat_upgrades = Stats { - // strength: 0, dexterity: 0, vitality: 0, intelligence: 0, wisdom: 0, charisma: 1, luck: 0 - // }; - // game.upgrade(ADVENTURER_ID, potions, stat_upgrades, shopping_cart); - - // // verify meta data for necklace and bagged item are different - // let updated_adventurer = game.get_adventurer(ADVENTURER_ID); - // let updated_bag = game.get_bag(ADVENTURER_ID); - // updated_adventurer.neck.metadata.print(); - // updated_bag.item_1.metadata.print(); - // updated_bag.item_2.metadata.print(); - // assert( - // updated_bag.item_1.metadata != updated_bag.item_2.metadata, - // 'neck and item1 share metadata' - // ); - // } - fn already_owned(item_id: u8, adventurer: Adventurer, bag: Bag) -> bool { item_id == adventurer.weapon.id || item_id == adventurer.chest.id @@ -1637,539 +1457,6 @@ mod tests { || item_id == bag.item_11.id } - // To run this test we need to increase starting gold so we can buy max number of items - // We either need to use cheat codes to accomplish this or have the contract take in - // game settings in the constructor. Commenting this out for now so our CI doesn't run it - // #[test] - // #[available_gas(80000000000)] - // fn test_max_out_and_recycle_items() { - // // start game on level 2 so we have access to the market - // let mut game = new_adventurer_lvl2(1000, 1696201757, 0); - - // // get items from market - // let mut market_item_ids = game.get_items_on_market(ADVENTURER_ID); - - // let mut purchased_chest: u8 = 0; - // let mut purchased_head: u8 = 0; - // let mut purchased_waist: u8 = 0; - // let mut purchased_foot: u8 = 0; - // let mut purchased_hand: u8 = 0; - // let mut purchased_ring: u8 = 0; - // let mut purchased_necklace: u8 = 0; - // let mut shopping_cart = ArrayTrait::::new(); - - // let mut bagged_items: u8 = 0; - - // loop { - // match market_item_ids.pop_front() { - // Option::Some(item_id) => { - // let market_item = ImplLoot::get_item(item_id); - // // fill up all equipment slots - // if (market_item.slot == Slot::Chest(()) && purchased_chest == 0) { - // shopping_cart.append(ItemPurchase { item_id: market_item.id, equip: true }); - // purchased_chest = market_item.id; - // } else if (market_item.slot == Slot::Head(()) && purchased_head == 0) { - // shopping_cart.append(ItemPurchase { item_id: market_item.id, equip: true }); - // purchased_head = market_item.id; - // } else if (market_item.slot == Slot::Waist(()) && purchased_waist == 0) { - // shopping_cart.append(ItemPurchase { item_id: market_item.id, equip: true }); - // purchased_waist = market_item.id; - // } else if (market_item.slot == Slot::Foot(()) && purchased_foot == 0) { - // shopping_cart.append(ItemPurchase { item_id: market_item.id, equip: true }); - // purchased_foot = market_item.id; - // } else if (market_item.slot == Slot::Hand(()) && purchased_hand == 0) { - // shopping_cart.append(ItemPurchase { item_id: market_item.id, equip: true }); - // purchased_hand = market_item.id; - // } else if (market_item.slot == Slot::Ring(()) && purchased_ring == 0) { - // shopping_cart.append(ItemPurchase { item_id: market_item.id, equip: true }); - // purchased_ring = market_item.id; - // } else if (market_item.slot == Slot::Neck(()) && purchased_necklace == 0) { - // shopping_cart.append(ItemPurchase { item_id: market_item.id, equip: true }); - // purchased_necklace = market_item.id; - // } else if bagged_items < 11 && item_id != ItemId::Wand { - // shopping_cart - // .append(ItemPurchase { item_id: market_item.id, equip: false }); - // bagged_items += 1; - // } - // }, - // Option::None => { break; }, - // } - // }; - - // assert( - // purchased_chest != 0 - // && purchased_head != 0 - // && purchased_waist != 0 - // && purchased_foot != 0 - // && purchased_hand != 0 - // && purchased_ring != 0 - // && purchased_necklace != 0 - // && bagged_items == 11, - // 'did not purchase all items' - // ); - - // // buy items in shopping cart which will fully equip the adventurer - // // and fill their bag - // let potions = 0; - // let stat_upgrades = Stats { - // strength: 0, dexterity: 0, vitality: 0, intelligence: 0, wisdom: 0, charisma: 1, luck: 0 - // }; - // game.upgrade(ADVENTURER_ID, potions, stat_upgrades, shopping_cart); - - // // verify adventurer is fully equipped except for ring - // let updated_adventurer = game.get_adventurer(ADVENTURER_ID); - // assert(updated_adventurer.is_equipped(purchased_chest), 'chest not equipped'); - // assert(updated_adventurer.is_equipped(purchased_head), 'head not equipped'); - // assert(updated_adventurer.is_equipped(purchased_waist), 'waist not equipped'); - // assert(updated_adventurer.is_equipped(purchased_foot), 'foot not equipped'); - // assert(updated_adventurer.is_equipped(purchased_hand), 'hand not equipped'); - // assert(updated_adventurer.is_equipped(purchased_ring), 'ring not equipped'); - // assert(updated_adventurer.is_equipped(purchased_necklace), 'necklace not equipped'); - - // // verify bag is full - // let bag = game.get_bag(ADVENTURER_ID); - // assert(bag.item_1.id != 0, 'bag item1 is empty'); - // assert(bag.item_2.id != 0, 'bag item2 is empty'); - // assert(bag.item_3.id != 0, 'bag item3 is empty'); - // assert(bag.item_4.id != 0, 'bag item4 is empty'); - // assert(bag.item_5.id != 0, 'bag item5 is empty'); - // assert(bag.item_6.id != 0, 'bag item6 is empty'); - // assert(bag.item_7.id != 0, 'bag item7 is empty'); - // assert(bag.item_8.id != 0, 'bag item8 is empty'); - // assert(bag.item_9.id != 0, 'bag item9 is empty'); - // assert(bag.item_10.id != 0, 'bag item10 is empty'); - // assert(bag.item_11.id != 0, 'bag item11 is empty'); - - // // drop first two items in our bag - // game.drop(ADVENTURER_ID, array![bag.item_1.id, bag.item_2.id, updated_adventurer.neck.id]); - - // // get updated bag and verify item_1 is now 0 - // let bag = game.get_bag(ADVENTURER_ID); - // assert(bag.item_1.id == 0, 'bag item1 should be empty'); - // assert(bag.item_2.id == 0, 'bag item2 should be empty'); - - // let adventurer = game.get_adventurer(ADVENTURER_ID); - // assert(adventurer.neck.id == 0, 'neck should be empty'); - - // // advance to next level - // game.explore(ADVENTURER_ID, true); - // game.attack(ADVENTURER_ID, true); - - // let updated_adventurer = game.get_adventurer(ADVENTURER_ID); - // let updated_bag = game.get_bag(ADVENTURER_ID); - - // // get items from market - // let mut market_item_ids = game.get_items_on_market(ADVENTURER_ID); - // let mut shopping_cart = ArrayTrait::::new(); - - // loop { - // match market_item_ids.pop_front() { - // Option::Some(item_id) => { - // let market_item = ImplLoot::get_item(item_id); - // if shopping_cart.len() < 2 - // && !already_owned(item_id, updated_adventurer, updated_bag) { - // shopping_cart - // .append(ItemPurchase { item_id: market_item.id, equip: false }); - // } else if shopping_cart.len() == 2 { - // break; - // } - // }, - // Option::None => { break; }, - // } - // }; - - // assert(shopping_cart.len() == 2, 'did not purchase enough items'); - - // // purchase items - // let potions = 0; - // let stat_upgrades = Stats { - // strength: 0, dexterity: 0, vitality: 0, intelligence: 0, wisdom: 0, charisma: 1, luck: 0 - // }; - // game.upgrade(ADVENTURER_ID, potions, stat_upgrades, shopping_cart); - - // // verify meta data for necklace and bagged item are different - // let updated_bag = game.get_bag(ADVENTURER_ID); - // assert( - // updated_bag.item_1.metadata != updated_bag.item_2.metadata, - // 'neck and item1 share metadata' - // ); - // assert( - // all_items_have_unique_metadata(updated_adventurer, updated_bag), 'items share metadata' - // ); - - // game.explore(ADVENTURER_ID, true); - // game.attack(ADVENTURER_ID, true); - - // // purchase necklace - // let mut market_item_ids = game.get_items_on_market(ADVENTURER_ID); - // let mut shopping_cart = ArrayTrait::::new(); - // loop { - // match market_item_ids.pop_front() { - // Option::Some(item_id) => { - // let market_item = ImplLoot::get_item(item_id); - // if (market_item.slot == Slot::Neck(()) && purchased_necklace == 0) { - // shopping_cart.append(ItemPurchase { item_id: market_item.id, equip: true }); - // } - // }, - // Option::None => { break; }, - // } - // }; - // game.upgrade(ADVENTURER_ID, potions, stat_upgrades, shopping_cart); - - // // verify all meta data is still unique - // assert( - // all_items_have_unique_metadata(updated_adventurer, updated_bag), 'items share metadata' - // ); - // } - - fn all_items_have_unique_metadata(adventurer: Adventurer, bag: Bag) -> bool { - // @dev: don't judge me too harshly on this hacky implementation because AI bulk generated it in 10 seconds - // and ultimately a more elegant loop would only be minimally more efficient - adventurer.weapon.metadata != adventurer.chest.metadata - && adventurer.weapon.metadata != adventurer.head.metadata - && adventurer.weapon.metadata != adventurer.waist.metadata - && adventurer.weapon.metadata != adventurer.foot.metadata - && adventurer.weapon.metadata != adventurer.hand.metadata - && adventurer.weapon.metadata != adventurer.ring.metadata - && adventurer.weapon.metadata != adventurer.neck.metadata - && adventurer.weapon.metadata != bag.item_1.metadata - && adventurer.weapon.metadata != bag.item_2.metadata - && adventurer.weapon.metadata != bag.item_3.metadata - && adventurer.weapon.metadata != bag.item_4.metadata - && adventurer.weapon.metadata != bag.item_5.metadata - && adventurer.weapon.metadata != bag.item_6.metadata - && adventurer.weapon.metadata != bag.item_7.metadata - && adventurer.weapon.metadata != bag.item_8.metadata - && adventurer.weapon.metadata != bag.item_9.metadata - && adventurer.weapon.metadata != bag.item_10.metadata - && adventurer.weapon.metadata != bag.item_11.metadata - && adventurer.chest.metadata != adventurer.head.metadata - && adventurer.chest.metadata != adventurer.waist.metadata - && adventurer.chest.metadata != adventurer.foot.metadata - && adventurer.chest.metadata != adventurer.hand.metadata - && adventurer.chest.metadata != adventurer.ring.metadata - && adventurer.chest.metadata != adventurer.neck.metadata - && adventurer.chest.metadata != bag.item_1.metadata - && adventurer.chest.metadata != bag.item_2.metadata - && adventurer.chest.metadata != bag.item_3.metadata - && adventurer.chest.metadata != bag.item_4.metadata - && adventurer.chest.metadata != bag.item_5.metadata - && adventurer.chest.metadata != bag.item_6.metadata - && adventurer.chest.metadata != bag.item_7.metadata - && adventurer.chest.metadata != bag.item_8.metadata - && adventurer.chest.metadata != bag.item_9.metadata - && adventurer.chest.metadata != bag.item_10.metadata - && adventurer.chest.metadata != bag.item_11.metadata - && adventurer.head.metadata != adventurer.waist.metadata - && adventurer.head.metadata != adventurer.foot.metadata - && adventurer.head.metadata != adventurer.hand.metadata - && adventurer.head.metadata != adventurer.ring.metadata - && adventurer.head.metadata != adventurer.neck.metadata - && adventurer.head.metadata != bag.item_1.metadata - && adventurer.head.metadata != bag.item_2.metadata - && adventurer.head.metadata != bag.item_3.metadata - && adventurer.head.metadata != bag.item_4.metadata - && adventurer.head.metadata != bag.item_5.metadata - && adventurer.head.metadata != bag.item_6.metadata - && adventurer.head.metadata != bag.item_7.metadata - && adventurer.head.metadata != bag.item_8.metadata - && adventurer.head.metadata != bag.item_9.metadata - && adventurer.head.metadata != bag.item_10.metadata - && adventurer.head.metadata != bag.item_11.metadata - && adventurer.waist.metadata != adventurer.foot.metadata - && adventurer.waist.metadata != adventurer.hand.metadata - && adventurer.waist.metadata != adventurer.ring.metadata - && adventurer.waist.metadata != adventurer.neck.metadata - && adventurer.waist.metadata != bag.item_1.metadata - && adventurer.waist.metadata != bag.item_2.metadata - && adventurer.waist.metadata != bag.item_3.metadata - && adventurer.waist.metadata != bag.item_4.metadata - && adventurer.waist.metadata != bag.item_5.metadata - && adventurer.waist.metadata != bag.item_6.metadata - && adventurer.waist.metadata != bag.item_7.metadata - && adventurer.waist.metadata != bag.item_8.metadata - && adventurer.waist.metadata != bag.item_9.metadata - && adventurer.waist.metadata != bag.item_10.metadata - && adventurer.waist.metadata != bag.item_11.metadata - && adventurer.foot.metadata != adventurer.hand.metadata - && adventurer.foot.metadata != adventurer.ring.metadata - && adventurer.foot.metadata != adventurer.neck.metadata - && adventurer.foot.metadata != bag.item_1.metadata - && adventurer.foot.metadata != bag.item_2.metadata - && adventurer.foot.metadata != bag.item_3.metadata - && adventurer.foot.metadata != bag.item_4.metadata - && adventurer.foot.metadata != bag.item_5.metadata - && adventurer.foot.metadata != bag.item_6.metadata - && adventurer.foot.metadata != bag.item_7.metadata - && adventurer.foot.metadata != bag.item_8.metadata - && adventurer.foot.metadata != bag.item_9.metadata - && adventurer.foot.metadata != bag.item_10.metadata - && adventurer.foot.metadata != bag.item_11.metadata - && adventurer.hand.metadata != adventurer.ring.metadata - && adventurer.hand.metadata != adventurer.neck.metadata - && adventurer.hand.metadata != bag.item_1.metadata - && adventurer.hand.metadata != bag.item_2.metadata - && adventurer.hand.metadata != bag.item_3.metadata - && adventurer.hand.metadata != bag.item_4.metadata - && adventurer.hand.metadata != bag.item_5.metadata - && adventurer.hand.metadata != bag.item_6.metadata - && adventurer.hand.metadata != bag.item_7.metadata - && adventurer.hand.metadata != bag.item_8.metadata - && adventurer.hand.metadata != bag.item_9.metadata - && adventurer.hand.metadata != bag.item_10.metadata - && adventurer.hand.metadata != bag.item_11.metadata - && adventurer.ring.metadata != adventurer.neck.metadata - && adventurer.ring.metadata != bag.item_1.metadata - && adventurer.ring.metadata != bag.item_2.metadata - && adventurer.ring.metadata != bag.item_3.metadata - && adventurer.ring.metadata != bag.item_4.metadata - && adventurer.ring.metadata != bag.item_5.metadata - && adventurer.ring.metadata != bag.item_6.metadata - && adventurer.ring.metadata != bag.item_7.metadata - && adventurer.ring.metadata != bag.item_8.metadata - && adventurer.ring.metadata != bag.item_9.metadata - && adventurer.ring.metadata != bag.item_10.metadata - && adventurer.ring.metadata != bag.item_11.metadata - && adventurer.neck.metadata != bag.item_1.metadata - && adventurer.neck.metadata != bag.item_2.metadata - && adventurer.neck.metadata != bag.item_3.metadata - && adventurer.neck.metadata != bag.item_4.metadata - && adventurer.neck.metadata != bag.item_5.metadata - && adventurer.neck.metadata != bag.item_6.metadata - && adventurer.neck.metadata != bag.item_7.metadata - && adventurer.neck.metadata != bag.item_8.metadata - && adventurer.neck.metadata != bag.item_9.metadata - && adventurer.neck.metadata != bag.item_10.metadata - && adventurer.neck.metadata != bag.item_11.metadata - && bag.item_1.metadata != bag.item_2.metadata - && bag.item_1.metadata != bag.item_3.metadata - && bag.item_1.metadata != bag.item_4.metadata - && bag.item_1.metadata != bag.item_5.metadata - && bag.item_1.metadata != bag.item_6.metadata - && bag.item_1.metadata != bag.item_7.metadata - && bag.item_1.metadata != bag.item_8.metadata - && bag.item_1.metadata != bag.item_9.metadata - && bag.item_1.metadata != bag.item_10.metadata - && bag.item_1.metadata != bag.item_11.metadata - && bag.item_2.metadata != bag.item_3.metadata - && bag.item_2.metadata != bag.item_4.metadata - && bag.item_2.metadata != bag.item_5.metadata - && bag.item_2.metadata != bag.item_6.metadata - && bag.item_2.metadata != bag.item_7.metadata - && bag.item_2.metadata != bag.item_8.metadata - && bag.item_2.metadata != bag.item_9.metadata - && bag.item_2.metadata != bag.item_10.metadata - && bag.item_2.metadata != bag.item_11.metadata - && bag.item_3.metadata != bag.item_4.metadata - && bag.item_3.metadata != bag.item_5.metadata - && bag.item_3.metadata != bag.item_6.metadata - && bag.item_3.metadata != bag.item_7.metadata - && bag.item_3.metadata != bag.item_8.metadata - && bag.item_3.metadata != bag.item_9.metadata - && bag.item_3.metadata != bag.item_10.metadata - && bag.item_3.metadata != bag.item_11.metadata - && bag.item_4.metadata != bag.item_5.metadata - && bag.item_4.metadata != bag.item_6.metadata - && bag.item_4.metadata != bag.item_7.metadata - && bag.item_4.metadata != bag.item_8.metadata - && bag.item_4.metadata != bag.item_9.metadata - && bag.item_4.metadata != bag.item_10.metadata - && bag.item_4.metadata != bag.item_11.metadata - && bag.item_5.metadata != bag.item_6.metadata - && bag.item_5.metadata != bag.item_7.metadata - && bag.item_5.metadata != bag.item_8.metadata - && bag.item_5.metadata != bag.item_9.metadata - && bag.item_5.metadata != bag.item_10.metadata - && bag.item_5.metadata != bag.item_11.metadata - && bag.item_6.metadata != bag.item_7.metadata - && bag.item_6.metadata != bag.item_8.metadata - && bag.item_6.metadata != bag.item_9.metadata - && bag.item_6.metadata != bag.item_10.metadata - && bag.item_6.metadata != bag.item_11.metadata - && bag.item_7.metadata != bag.item_8.metadata - && bag.item_7.metadata != bag.item_9.metadata - && bag.item_7.metadata != bag.item_10.metadata - && bag.item_7.metadata != bag.item_11.metadata - && bag.item_8.metadata != bag.item_9.metadata - && bag.item_8.metadata != bag.item_10.metadata - && bag.item_8.metadata != bag.item_11.metadata - && bag.item_9.metadata != bag.item_10.metadata - && bag.item_9.metadata != bag.item_11.metadata - && bag.item_10.metadata != bag.item_11.metadata - } - - // To run this test we need to increase starting gold so we can buy max number of items - // We either need to use cheat codes to accomplish this or have the contract take in - // game settings in the constructor. Commenting this out for now so our CI doesn't run it - // #[test] - // #[available_gas(80000000000)] - // fn test_metadata_recycling() { - // // start game on level 2 so we have access to the market - // let mut game = new_adventurer_lvl2(1000, 1696201757, 0); - - // // get items from market - // let mut market_item_ids = game.get_items_on_market(ADVENTURER_ID); - - // let mut purchased_chest: u8 = 0; - // let mut purchased_head: u8 = 0; - // let mut purchased_waist: u8 = 0; - // let mut purchased_foot: u8 = 0; - // let mut purchased_hand: u8 = 0; - // let mut purchased_ring: u8 = 0; - // let mut shopping_cart = ArrayTrait::::new(); - - // let mut bagged_items: u8 = 0; - - // loop { - // match market_item_ids.pop_front() { - // Option::Some(item_id) => { - // let market_item = ImplLoot::get_item(item_id); - // // fill up all equipment slots - // if (market_item.slot == Slot::Chest(()) && purchased_chest == 0) { - // shopping_cart.append(ItemPurchase { item_id: market_item.id, equip: true }); - // purchased_chest = market_item.id; - // } else if (market_item.slot == Slot::Head(()) && purchased_head == 0) { - // shopping_cart.append(ItemPurchase { item_id: market_item.id, equip: true }); - // purchased_head = market_item.id; - // } else if (market_item.slot == Slot::Waist(()) && purchased_waist == 0) { - // shopping_cart.append(ItemPurchase { item_id: market_item.id, equip: true }); - // purchased_waist = market_item.id; - // } else if (market_item.slot == Slot::Foot(()) && purchased_foot == 0) { - // shopping_cart.append(ItemPurchase { item_id: market_item.id, equip: true }); - // purchased_foot = market_item.id; - // } else if (market_item.slot == Slot::Hand(()) && purchased_hand == 0) { - // shopping_cart.append(ItemPurchase { item_id: market_item.id, equip: true }); - // purchased_hand = market_item.id; - // } else if (market_item.slot == Slot::Ring(()) && purchased_ring == 0) { - // shopping_cart.append(ItemPurchase { item_id: market_item.id, equip: true }); - // purchased_ring = market_item.id; - // } else if bagged_items < 11 && item_id != ItemId::Wand { - // shopping_cart - // .append(ItemPurchase { item_id: market_item.id, equip: false }); - // bagged_items += 1; - // } - // }, - // Option::None => { break; }, - // } - // }; - - // assert( - // purchased_chest != 0 - // && purchased_head != 0 - // && purchased_waist != 0 - // && purchased_foot != 0 - // && purchased_hand != 0 - // && purchased_ring != 0 - // && bagged_items == 11, - // 'did not purchase all items' - // ); - - // // buy items in shopping cart which will fully equip the adventurer - // // and fill their bag - // let potions = 0; - // let stat_upgrades = Stats { - // strength: 0, dexterity: 0, vitality: 0, intelligence: 0, wisdom: 0, charisma: 1, luck: 0 - // }; - // game.upgrade(ADVENTURER_ID, potions, stat_upgrades, shopping_cart); - - // // verify adventurer is fully equipped except for necklace - // let adventurer = game.get_adventurer(ADVENTURER_ID); - // assert(adventurer.is_equipped(purchased_chest), 'chest not equipped'); - // assert(adventurer.is_equipped(purchased_head), 'head not equipped'); - // assert(adventurer.is_equipped(purchased_waist), 'waist not equipped'); - // assert(adventurer.is_equipped(purchased_foot), 'foot not equipped'); - // assert(adventurer.is_equipped(purchased_hand), 'hand not equipped'); - // assert(adventurer.is_equipped(purchased_ring), 'ring not equipped'); - // assert(adventurer.neck.id == 0, 'necklace should not be equipped'); - - // // verify bag is full - // let bag = game.get_bag(ADVENTURER_ID); - // assert(bag.item_1.id != 0, 'bag item1 is empty'); - // assert(bag.item_2.id != 0, 'bag item2 is empty'); - // assert(bag.item_3.id != 0, 'bag item3 is empty'); - // assert(bag.item_4.id != 0, 'bag item4 is empty'); - // assert(bag.item_5.id != 0, 'bag item5 is empty'); - // assert(bag.item_6.id != 0, 'bag item6 is empty'); - // assert(bag.item_7.id != 0, 'bag item7 is empty'); - // assert(bag.item_8.id != 0, 'bag item8 is empty'); - // assert(bag.item_9.id != 0, 'bag item9 is empty'); - // assert(bag.item_10.id != 0, 'bag item10 is empty'); - // assert(bag.item_11.id != 0, 'bag item11 is empty'); - - // // record metadata of item_1 and item_2 and then drop them from bag - // let item_1_meta = bag.item_1.metadata; - // let item_2_meta = bag.item_2.metadata; - // game.drop(ADVENTURER_ID, array![bag.item_1.id, bag.item_2.id]); - - // // verify items are dropped - // let bag = game.get_bag(ADVENTURER_ID); - // assert(bag.item_1.id == 0, 'bag item1 should be empty'); - // assert(bag.item_2.id == 0, 'bag item2 should be empty'); - // // but the metadata should be the same - // assert(item_1_meta == bag.item_1.metadata, 'item1 meta should be the same'); - // assert(item_2_meta == bag.item_2.metadata, 'item2 meta should be the same'); - - // // clear next level - // game.explore(ADVENTURER_ID, true); - // game.attack(ADVENTURER_ID, true); - - // // get updated adventurer and bag from contract - // let adventurer = game.get_adventurer(ADVENTURER_ID); - // let bag = game.get_bag(ADVENTURER_ID); - - // // get items from market - // let mut market_item_ids = game.get_items_on_market(ADVENTURER_ID); - // let mut shopping_cart = ArrayTrait::::new(); - - // loop { - // match market_item_ids.pop_front() { - // Option::Some(item_id) => { - // // shop for two items - // let market_item = ImplLoot::get_item(item_id); - // if shopping_cart.len() < 2 - // && item_id != ItemId::Wand - // && item_id != adventurer.weapon.id - // && item_id != adventurer.chest.id - // && item_id != adventurer.head.id - // && item_id != adventurer.waist.id - // && item_id != adventurer.foot.id - // && item_id != adventurer.hand.id - // && item_id != adventurer.ring.id - // && item_id != bag.item_1.id - // && item_id != bag.item_2.id - // && item_id != bag.item_3.id - // && item_id != bag.item_4.id - // && item_id != bag.item_5.id - // && item_id != bag.item_6.id - // && item_id != bag.item_7.id - // && item_id != bag.item_8.id - // && item_id != bag.item_9.id - // && item_id != bag.item_10.id - // && item_id != bag.item_11.id { - // shopping_cart - // .append(ItemPurchase { item_id: market_item.id, equip: false }); - // } else if shopping_cart.len() == 2 { - // break; - // } - // }, - // Option::None => { break; }, - // } - // }; - - // // verify shopping cart contains two items - // assert(shopping_cart.len() == 2, 'wrong number of items in cart'); - - // // purchase items - // game.upgrade(ADVENTURER_ID, potions, stat_upgrades, shopping_cart); - - // // get updated bag - // let updated_bag = game.get_bag(ADVENTURER_ID); - - // // verify contract reused metadata slots from dropped items - // assert(item_1_meta == updated_bag.item_1.metadata, 'item1 should use recycled meta'); - // assert(item_2_meta == updated_bag.item_2.metadata, 'item2 should use recycled meta'); - // } - #[test] #[available_gas(83000000)] fn test_drop_item() { diff --git a/contracts/loot/src/loot.cairo b/contracts/loot/src/loot.cairo index 94f258dc7..9c71a72fc 100644 --- a/contracts/loot/src/loot.cairo +++ b/contracts/loot/src/loot.cairo @@ -2,7 +2,7 @@ use core::{ serde::Serde, clone::Clone, option::OptionTrait, starknet::StorePacking, traits::{TryInto, Into} }; -use combat::{combat::ImplCombat, constants::CombatEnums::{Type, Tier, Slot}}; +use combat::{combat::{ImplCombat, SpecialPowers}, constants::CombatEnums::{Type, Tier, Slot}}; use super::{ constants::{ NamePrefixLength, ItemNameSuffix, ItemId, ItemNamePrefix, NameSuffixLength, @@ -65,29 +65,29 @@ impl ImplLoot of ILoot { // @param entropy The entropy. // @return The naming seed. #[inline(always)] - fn generate_naming_seed(item_id: u8, entropy: u128) -> u128 { + fn generate_naming_seed(item_id: u8, entropy: u64) -> u64 { let rnd = entropy % NUM_ITEMS.into(); rnd * ImplLoot::get_slot_length(ImplLoot::get_slot(item_id)).into() + ImplLoot::get_item_index(item_id).into() } - // generate_prefix1 returns the name prefix of an item (Agony, Apocalypse, Armageddon, etc) + // get_prefix1 returns the name prefix of an item (Agony, Apocalypse, Armageddon, etc) // @param self The item. // @param entropy The entropy. // @return The name prefix id. #[inline(always)] - fn generate_prefix1(item_id: u8, entropy: u128) -> u8 { + fn get_prefix1(item_id: u8, entropy: u64) -> u8 { (ImplLoot::generate_naming_seed(item_id, entropy) % NamePrefixLength.into() + 1) .try_into() .unwrap() } - // generate_prefix2 returns the name suffix of an item (Bane, Root, Bite, etc) + // get_prefix2 returns the name suffix of an item (Bane, Root, Bite, etc) // @param self The item. // @param entropy The entropy. // @return The name suffix id. #[inline(always)] - fn generate_prefix2(item_id: u8, entropy: u128) -> u8 { + fn get_prefix2(item_id: u8, entropy: u64) -> u8 { (ImplLoot::generate_naming_seed(item_id, entropy) % NameSuffixLength.into() + 1) .try_into() .unwrap() @@ -98,12 +98,33 @@ impl ImplLoot of ILoot { // @param entropy The entropy for randomness // @return u8 special1 for the item #[inline(always)] - fn get_special1(item_id: u8, entropy: u128) -> u8 { + fn get_suffix(item_id: u8, entropy: u64) -> u8 { (ImplLoot::generate_naming_seed(item_id, entropy) % ItemSuffixLength.into() + 1) .try_into() .unwrap() } + // @notice gets the specials of an item + // @param id the id of the item to get specials for + // @param greatness the greatness of the item + // @param start_entropy the entropy to use for randomness + // @return the specials of the item + fn get_specials(id: u8, greatness: u8, start_entropy: u64) -> SpecialPowers { + if greatness < 15 { + SpecialPowers { special1: 0, special2: 0, special3: 0, } + } else if greatness < 19 { + SpecialPowers { + special1: ImplLoot::get_suffix(id, start_entropy), special2: 0, special3: 0, + } + } else { + SpecialPowers { + special1: ImplLoot::get_suffix(id, start_entropy), + special2: ImplLoot::get_prefix1(id, start_entropy), + special3: ImplLoot::get_prefix2(id, start_entropy), + } + } + } + // @notice gets Loot item from item id // @param id the id of the item to get // @return the Loot item @@ -1032,82 +1053,82 @@ mod tests { #[test] #[available_gas(3975111110)] fn test_suffix_assignments() { - let mut i: u128 = 0; + let mut i: u64 = 0; loop { if i > ItemSuffixLength.into() { break (); } // verify Warhammers are part of set1 - let warhammer_suffix = ImplLoot::get_special1(ItemId::Warhammer, i); + let warhammer_suffix = ImplLoot::get_suffix(ItemId::Warhammer, i); assert(is_special1_set1(warhammer_suffix), 'invalid warhammer suffix'); // verify quarterstaffs are part of set2 - let quarterstaff_suffix = ImplLoot::get_special1(ItemId::Quarterstaff, i); + let quarterstaff_suffix = ImplLoot::get_suffix(ItemId::Quarterstaff, i); assert(is_special1_set2(quarterstaff_suffix), 'invalid quarterstaff suffix'); // verify mauls are part of set1 - let maul_suffix = ImplLoot::get_special1(ItemId::Maul, i); + let maul_suffix = ImplLoot::get_suffix(ItemId::Maul, i); assert(is_special1_set1(maul_suffix), 'invalid maul suffix'); // verify maces are part of set2 - let mace_suffix = ImplLoot::get_special1(ItemId::Mace, i); + let mace_suffix = ImplLoot::get_suffix(ItemId::Mace, i); assert(is_special1_set2(mace_suffix), 'invalid mace suffix'); // verify clubs are part of set2 - let club_suffix = ImplLoot::get_special1(ItemId::Club, i); + let club_suffix = ImplLoot::get_suffix(ItemId::Club, i); assert(is_special1_set1(club_suffix), 'invalid club suffix'); // verify katanas are part of set1 - let katana_suffix = ImplLoot::get_special1(ItemId::Katana, i); + let katana_suffix = ImplLoot::get_suffix(ItemId::Katana, i); assert(is_special1_set2(katana_suffix), 'invalid katana suffix'); // verify falchions are part of set2 - let falchion_suffix = ImplLoot::get_special1(ItemId::Falchion, i); + let falchion_suffix = ImplLoot::get_suffix(ItemId::Falchion, i); assert(is_special1_set1(falchion_suffix), 'invalid falchion suffix'); // verify scimitars are part of set1 - let scimitar_suffix = ImplLoot::get_special1(ItemId::Scimitar, i); + let scimitar_suffix = ImplLoot::get_suffix(ItemId::Scimitar, i); assert(is_special1_set2(scimitar_suffix), 'invalid scimitar suffix'); // verify long swords are part of set2 - let long_sword_suffix = ImplLoot::get_special1(ItemId::LongSword, i); + let long_sword_suffix = ImplLoot::get_suffix(ItemId::LongSword, i); assert(is_special1_set1(long_sword_suffix), 'invalid long sword suffix'); // verify short swords are part of set1 - let short_sword_suffix = ImplLoot::get_special1(ItemId::ShortSword, i); + let short_sword_suffix = ImplLoot::get_suffix(ItemId::ShortSword, i); assert(is_special1_set2(short_sword_suffix), 'invalid short sword suffix'); // verify ghost wands are part of set2 - let ghost_wand_suffix = ImplLoot::get_special1(ItemId::GhostWand, i); + let ghost_wand_suffix = ImplLoot::get_suffix(ItemId::GhostWand, i); assert(is_special1_set1(ghost_wand_suffix), 'invalid ghost wand suffix'); // verify grave wands are part of set1 - let grave_wand_suffix = ImplLoot::get_special1(ItemId::GraveWand, i); + let grave_wand_suffix = ImplLoot::get_suffix(ItemId::GraveWand, i); assert(is_special1_set2(grave_wand_suffix), 'invalid grave wand suffix'); // verify bone wands are part of set2 - let bone_wand_suffix = ImplLoot::get_special1(ItemId::BoneWand, i); + let bone_wand_suffix = ImplLoot::get_suffix(ItemId::BoneWand, i); assert(is_special1_set1(bone_wand_suffix), 'invalid bone wand suffix'); // verify wands are part of set1 - let wand_suffix = ImplLoot::get_special1(ItemId::Wand, i); + let wand_suffix = ImplLoot::get_suffix(ItemId::Wand, i); assert(is_special1_set2(wand_suffix), 'invalid wand suffix'); // verify grimoires are part of set2 - let grimoire_suffix = ImplLoot::get_special1(ItemId::Grimoire, i); + let grimoire_suffix = ImplLoot::get_suffix(ItemId::Grimoire, i); assert(is_special1_set1(grimoire_suffix), 'invalid grimoire suffix'); // verify chronicles are part of set1 - let chronicle_suffix = ImplLoot::get_special1(ItemId::Chronicle, i); + let chronicle_suffix = ImplLoot::get_suffix(ItemId::Chronicle, i); assert(is_special1_set2(chronicle_suffix), 'invalid chronicle suffix'); // verify tomes are part of set2 - let tome_suffix = ImplLoot::get_special1(ItemId::Tome, i); + let tome_suffix = ImplLoot::get_suffix(ItemId::Tome, i); assert(is_special1_set1(tome_suffix), 'invalid tome suffix'); // verify books are part of set1 - let book_suffix = ImplLoot::get_special1(ItemId::Book, i); + let book_suffix = ImplLoot::get_suffix(ItemId::Book, i); assert(is_special1_set2(book_suffix), 'invalid book suffix'); // increment counter @@ -1118,7 +1139,7 @@ mod tests { #[test] #[available_gas(2298200670)] fn test_prefix2_assignments() { - let mut i: u128 = 0; + let mut i: u64 = 0; loop { // test over entire entropy set which is size of name suffix list @@ -1132,109 +1153,108 @@ mod tests { // Warhammers are always 'X Bane' assert( - ImplLoot::generate_prefix2(ItemId::Warhammer, i) == ItemNameSuffix::Bane, + ImplLoot::get_prefix2(ItemId::Warhammer, i) == ItemNameSuffix::Bane, 'warhammer should be bane' ); // Quarterstaffs are always 'X Root' assert( - ImplLoot::generate_prefix2(ItemId::Quarterstaff, i) == ItemNameSuffix::Root, + ImplLoot::get_prefix2(ItemId::Quarterstaff, i) == ItemNameSuffix::Root, 'quarterstaff should be root' ); // Mauls are always 'X Bite' assert( - ImplLoot::generate_prefix2(ItemId::Maul, i) == ItemNameSuffix::Bite, + ImplLoot::get_prefix2(ItemId::Maul, i) == ItemNameSuffix::Bite, 'maul should be bite' ); // Maces are always 'X Song' assert( - ImplLoot::generate_prefix2(ItemId::Mace, i) == ItemNameSuffix::Song, + ImplLoot::get_prefix2(ItemId::Mace, i) == ItemNameSuffix::Song, 'mace should be song' ); // Clubs are always 'X Roar' assert( - ImplLoot::generate_prefix2(ItemId::Club, i) == ItemNameSuffix::Roar, + ImplLoot::get_prefix2(ItemId::Club, i) == ItemNameSuffix::Roar, 'club should be roar' ); // Katanas are always 'X Grasp' assert( - ImplLoot::generate_prefix2(ItemId::Katana, i) == ItemNameSuffix::Grasp, + ImplLoot::get_prefix2(ItemId::Katana, i) == ItemNameSuffix::Grasp, 'katana should be grasp' ); // Falchions are always 'X Instrument' assert( - ImplLoot::generate_prefix2(ItemId::Falchion, i) == ItemNameSuffix::Instrument, + ImplLoot::get_prefix2(ItemId::Falchion, i) == ItemNameSuffix::Instrument, 'falchion should be instrument' ); // Scimitars are always 'X Glow' assert( - ImplLoot::generate_prefix2(ItemId::Scimitar, i) == ItemNameSuffix::Glow, + ImplLoot::get_prefix2(ItemId::Scimitar, i) == ItemNameSuffix::Glow, 'scimitar should be glow' ); // Long Swords are always 'X Bender' assert( - ImplLoot::generate_prefix2(ItemId::LongSword, i) == ItemNameSuffix::Bender, + ImplLoot::get_prefix2(ItemId::LongSword, i) == ItemNameSuffix::Bender, 'long sword should be bender' ); // Short Swords are always 'X Shadow' assert( - ImplLoot::generate_prefix2(ItemId::ShortSword, i) == ItemNameSuffix::Shadow, + ImplLoot::get_prefix2(ItemId::ShortSword, i) == ItemNameSuffix::Shadow, 'short sword should be shadow' ); // Ghost Wands are always 'X Whisper' assert( - ImplLoot::generate_prefix2(ItemId::GhostWand, i) == ItemNameSuffix::Whisper, + ImplLoot::get_prefix2(ItemId::GhostWand, i) == ItemNameSuffix::Whisper, 'ghost wand should be whisper' ); // Grave Wands are always 'X Shout' assert( - ImplLoot::generate_prefix2(ItemId::GraveWand, i) == ItemNameSuffix::Shout, + ImplLoot::get_prefix2(ItemId::GraveWand, i) == ItemNameSuffix::Shout, 'grave wand should be shout' ); // Bone Wands are always 'X Growl' assert( - ImplLoot::generate_prefix2(ItemId::BoneWand, i) == ItemNameSuffix::Growl, + ImplLoot::get_prefix2(ItemId::BoneWand, i) == ItemNameSuffix::Growl, 'bone wand should be growl' ); // Wands are always 'X Tear' assert( - ImplLoot::generate_prefix2(ItemId::Wand, i) == ItemNameSuffix::Tear, + ImplLoot::get_prefix2(ItemId::Wand, i) == ItemNameSuffix::Tear, 'wand should be tear' ); // Grimoires are always 'X Peak' assert( - ImplLoot::generate_prefix2(ItemId::Grimoire, i) == ItemNameSuffix::Peak, + ImplLoot::get_prefix2(ItemId::Grimoire, i) == ItemNameSuffix::Peak, 'grimoire should be peak' ); // Chronicles are always 'X Form' assert( - ImplLoot::generate_prefix2(ItemId::Chronicle, i) == ItemNameSuffix::Form, + ImplLoot::get_prefix2(ItemId::Chronicle, i) == ItemNameSuffix::Form, 'chronicle should be form' ); // Tomes are always 'X Sun' assert( - ImplLoot::generate_prefix2(ItemId::Tome, i) == ItemNameSuffix::Sun, - 'tome should be sun' + ImplLoot::get_prefix2(ItemId::Tome, i) == ItemNameSuffix::Sun, 'tome should be sun' ); // Books are always 'X Moon' assert( - ImplLoot::generate_prefix2(ItemId::Book, i) == ItemNameSuffix::Moon, + ImplLoot::get_prefix2(ItemId::Book, i) == ItemNameSuffix::Moon, 'book should be moon' ); @@ -1242,19 +1262,19 @@ mod tests { // // Divine Robes are always {X Bane, X Song, X Instrument, X Shadow, X Growl, X Form} (set 1) assert( - is_special3_set1(ImplLoot::generate_prefix2(ItemId::DivineRobe, i)), + is_special3_set1(ImplLoot::get_prefix2(ItemId::DivineRobe, i)), 'invalid divine robe name suffix' ); // Chain Mail is always {X Root, X Roar, X Glow, X Whisper, X Tear, X Sun} (set 2) assert( - is_special3_set2(ImplLoot::generate_prefix2(ItemId::ChainMail, i)), + is_special3_set2(ImplLoot::get_prefix2(ItemId::ChainMail, i)), 'invalid chain mail name suffix' ); // Demon Husks are always {X Bite, X Grasp, X Bender, X Shout, X Peak, X Moon} (set 3) assert( - is_special3_set3(ImplLoot::generate_prefix2(ItemId::DemonHusk, i)), + is_special3_set3(ImplLoot::get_prefix2(ItemId::DemonHusk, i)), 'invalid demon husk name suffix' ); // @@ -1263,19 +1283,19 @@ mod tests { // // Ancient Helms use name suffix set 1 assert( - is_special3_set1(ImplLoot::generate_prefix2(ItemId::AncientHelm, i)), + is_special3_set1(ImplLoot::get_prefix2(ItemId::AncientHelm, i)), 'invalid war cap name suffix' ); // Crown uses name suffix set 2 assert( - is_special3_set2(ImplLoot::generate_prefix2(ItemId::Crown, i)), + is_special3_set2(ImplLoot::get_prefix2(ItemId::Crown, i)), 'invalid crown name suffix' ); // Divine Hood uses name suffix set 3 assert( - is_special3_set3(ImplLoot::generate_prefix2(ItemId::DivineHood, i)), + is_special3_set3(ImplLoot::get_prefix2(ItemId::DivineHood, i)), 'invalid divine hood name suffix' ); @@ -1284,19 +1304,19 @@ mod tests { // // Ornate Belt uses name suffix set 1 assert( - is_special3_set1(ImplLoot::generate_prefix2(ItemId::OrnateBelt, i)), + is_special3_set1(ImplLoot::get_prefix2(ItemId::OrnateBelt, i)), 'invalid ornate belt suffix' ); // Brightsilk Sash uses name suffix set 2 assert( - is_special3_set2(ImplLoot::generate_prefix2(ItemId::BrightsilkSash, i)), + is_special3_set2(ImplLoot::get_prefix2(ItemId::BrightsilkSash, i)), 'invalid brightsilk sash suffix' ); // Hard Leather Belt uses name set 3 assert( - is_special3_set3(ImplLoot::generate_prefix2(ItemId::HardLeatherBelt, i)), + is_special3_set3(ImplLoot::get_prefix2(ItemId::HardLeatherBelt, i)), 'wrong hard leather belt suffix' ); @@ -1305,19 +1325,19 @@ mod tests { // // Holy Graves uses name suffix set 1 assert( - is_special3_set1(ImplLoot::generate_prefix2(ItemId::HolyGreaves, i)), + is_special3_set1(ImplLoot::get_prefix2(ItemId::HolyGreaves, i)), 'invalid holy greaves suffix' ); // Heavy Boots use name suffix set 2 assert( - is_special3_set2(ImplLoot::generate_prefix2(ItemId::HeavyBoots, i)), + is_special3_set2(ImplLoot::get_prefix2(ItemId::HeavyBoots, i)), 'invalid heavy boots suffix' ); // Silk Slippers use name suffix set 3 assert( - is_special3_set3(ImplLoot::generate_prefix2(ItemId::SilkSlippers, i)), + is_special3_set3(ImplLoot::get_prefix2(ItemId::SilkSlippers, i)), 'invalid silk slippers suffix' ); @@ -1326,19 +1346,19 @@ mod tests { // // Holy Gauntlets use name suffix set 1 assert( - is_special3_set1(ImplLoot::generate_prefix2(ItemId::HolyGauntlets, i)), + is_special3_set1(ImplLoot::get_prefix2(ItemId::HolyGauntlets, i)), 'invalid holy gauntlets suffix' ); // Linen Gloves use name suffix set 2 assert( - is_special3_set2(ImplLoot::generate_prefix2(ItemId::LinenGloves, i)), + is_special3_set2(ImplLoot::get_prefix2(ItemId::LinenGloves, i)), 'invalid linen gloves suffix' ); // Hard Leather Gloves use name suffix set 3 assert( - is_special3_set3(ImplLoot::generate_prefix2(ItemId::HardLeatherGloves, i)), + is_special3_set3(ImplLoot::get_prefix2(ItemId::HardLeatherGloves, i)), 'invalid hard lthr gloves suffix' ); @@ -1347,19 +1367,19 @@ mod tests { // // Neckalce uses name suffix set 1 assert( - is_special3_set1(ImplLoot::generate_prefix2(ItemId::Necklace, i)), + is_special3_set1(ImplLoot::get_prefix2(ItemId::Necklace, i)), 'invalid Necklace name suffix' ); // Amulets use name suffix set 2 assert( - is_special3_set2(ImplLoot::generate_prefix2(ItemId::Amulet, i)), + is_special3_set2(ImplLoot::get_prefix2(ItemId::Amulet, i)), 'invalid amulet name suffix' ); // Pendants use name suffix set 3 assert( - is_special3_set3(ImplLoot::generate_prefix2(ItemId::Pendant, i)), + is_special3_set3(ImplLoot::get_prefix2(ItemId::Pendant, i)), 'invalid pendant name suffix' ); @@ -1381,7 +1401,7 @@ mod tests { #[test] #[available_gas(1655011840)] fn test_prefix1_assignment() { - let mut i: u128 = 0; + let mut i: u64 = 0; loop { if i > NamePrefixLength.into() { break (); @@ -1389,427 +1409,390 @@ mod tests { // verify warhammer uses set1 assert( - is_special2_set1(ImplLoot::generate_prefix1(ItemId::Warhammer, i)), + is_special2_set1(ImplLoot::get_prefix1(ItemId::Warhammer, i)), 'invalid warhammer prefix' ); // verify quarterstaff uses set2 assert( - is_special2_set2(ImplLoot::generate_prefix1(ItemId::Quarterstaff, i)), + is_special2_set2(ImplLoot::get_prefix1(ItemId::Quarterstaff, i)), 'invalid quarterstaff prefix' ); // verify maul uses set3 - assert( - is_special2_set3(ImplLoot::generate_prefix1(ItemId::Maul, i)), - 'invalid maul prefix' - ); + assert(is_special2_set3(ImplLoot::get_prefix1(ItemId::Maul, i)), 'invalid maul prefix'); // verify mace uses set1 - assert( - is_special2_set1(ImplLoot::generate_prefix1(ItemId::Mace, i)), - 'invalid mace prefix' - ); + assert(is_special2_set1(ImplLoot::get_prefix1(ItemId::Mace, i)), 'invalid mace prefix'); // verify club uses set2 - assert( - is_special2_set2(ImplLoot::generate_prefix1(ItemId::Club, i)), - 'invalid club prefix' - ); + assert(is_special2_set2(ImplLoot::get_prefix1(ItemId::Club, i)), 'invalid club prefix'); // verify katana uses set3 assert( - is_special2_set3(ImplLoot::generate_prefix1(ItemId::Katana, i)), - 'invalid katana prefix' + is_special2_set3(ImplLoot::get_prefix1(ItemId::Katana, i)), 'invalid katana prefix' ); // verify falchion uses set1 assert( - is_special2_set1(ImplLoot::generate_prefix1(ItemId::Falchion, i)), + is_special2_set1(ImplLoot::get_prefix1(ItemId::Falchion, i)), 'invalid falchion prefix' ); // verify scimitar uses set2 assert( - is_special2_set2(ImplLoot::generate_prefix1(ItemId::Scimitar, i)), + is_special2_set2(ImplLoot::get_prefix1(ItemId::Scimitar, i)), 'invalid scimitar prefix' ); // verify long sword uses set3 assert( - is_special2_set3(ImplLoot::generate_prefix1(ItemId::LongSword, i)), + is_special2_set3(ImplLoot::get_prefix1(ItemId::LongSword, i)), 'invalid long sword prefix' ); // verify short sword uses set1 assert( - is_special2_set1(ImplLoot::generate_prefix1(ItemId::ShortSword, i)), + is_special2_set1(ImplLoot::get_prefix1(ItemId::ShortSword, i)), 'invalid short sword prefix' ); // verify ghost wand uses set2 assert( - is_special2_set2(ImplLoot::generate_prefix1(ItemId::GhostWand, i)), + is_special2_set2(ImplLoot::get_prefix1(ItemId::GhostWand, i)), 'invalid ghost wand prefix' ); // verify grave wand uses set3 assert( - is_special2_set3(ImplLoot::generate_prefix1(ItemId::GraveWand, i)), + is_special2_set3(ImplLoot::get_prefix1(ItemId::GraveWand, i)), 'invalid grave wand prefix' ); // verify bone wand uses set1 assert( - is_special2_set1(ImplLoot::generate_prefix1(ItemId::BoneWand, i)), + is_special2_set1(ImplLoot::get_prefix1(ItemId::BoneWand, i)), 'invalid bone wand prefix' ); // verify wand uses set2 - assert( - is_special2_set2(ImplLoot::generate_prefix1(ItemId::Wand, i)), - 'invalid wand prefix' - ); + assert(is_special2_set2(ImplLoot::get_prefix1(ItemId::Wand, i)), 'invalid wand prefix'); // verify grimoire uses set3 assert( - is_special2_set3(ImplLoot::generate_prefix1(ItemId::Grimoire, i)), + is_special2_set3(ImplLoot::get_prefix1(ItemId::Grimoire, i)), 'invalid grimoire prefix' ); // verify chronicle uses set1 assert( - is_special2_set1(ImplLoot::generate_prefix1(ItemId::Chronicle, i)), + is_special2_set1(ImplLoot::get_prefix1(ItemId::Chronicle, i)), 'invalid chronicle prefix' ); // verify tome uses set2 - assert( - is_special2_set2(ImplLoot::generate_prefix1(ItemId::Tome, i)), - 'invalid tome prefix' - ); + assert(is_special2_set2(ImplLoot::get_prefix1(ItemId::Tome, i)), 'invalid tome prefix'); // verify book uses set3 - assert( - is_special2_set3(ImplLoot::generate_prefix1(ItemId::Book, i)), - 'invalid book prefix' - ); + assert(is_special2_set3(ImplLoot::get_prefix1(ItemId::Book, i)), 'invalid book prefix'); // verify divine robe uses set1 assert( - is_special2_set1(ImplLoot::generate_prefix1(ItemId::DivineRobe, i)), + is_special2_set1(ImplLoot::get_prefix1(ItemId::DivineRobe, i)), 'invalid divine robe prefix' ); // verify silk robe uses set2 assert( - is_special2_set2(ImplLoot::generate_prefix1(ItemId::SilkRobe, i)), + is_special2_set2(ImplLoot::get_prefix1(ItemId::SilkRobe, i)), 'invalid silk robe prefix' ); // verify linen robe uses set3 assert( - is_special2_set3(ImplLoot::generate_prefix1(ItemId::LinenRobe, i)), + is_special2_set3(ImplLoot::get_prefix1(ItemId::LinenRobe, i)), 'invalid linen robe prefix' ); // verify robe uses set1 - assert( - is_special2_set1(ImplLoot::generate_prefix1(ItemId::Robe, i)), - 'invalid robe prefix' - ); + assert(is_special2_set1(ImplLoot::get_prefix1(ItemId::Robe, i)), 'invalid robe prefix'); // verify shirt uses set2 assert( - is_special2_set2(ImplLoot::generate_prefix1(ItemId::Shirt, i)), - 'invalid shirt prefix' + is_special2_set2(ImplLoot::get_prefix1(ItemId::Shirt, i)), 'invalid shirt prefix' ); // verify demon husk uses set3 assert( - is_special2_set3(ImplLoot::generate_prefix1(ItemId::DemonHusk, i)), + is_special2_set3(ImplLoot::get_prefix1(ItemId::DemonHusk, i)), 'invalid demon husk prefix' ); // verify dragonskin armor uses set1 assert( - is_special2_set1(ImplLoot::generate_prefix1(ItemId::DragonskinArmor, i)), + is_special2_set1(ImplLoot::get_prefix1(ItemId::DragonskinArmor, i)), 'invalid dragonskin armor prefix' ); // verify studded leather armor uses set2 assert( - is_special2_set2(ImplLoot::generate_prefix1(ItemId::StuddedLeatherArmor, i)), + is_special2_set2(ImplLoot::get_prefix1(ItemId::StuddedLeatherArmor, i)), 'invalid studded leather prefix' ); // verify hard leather armor uses set3 assert( - is_special2_set3(ImplLoot::generate_prefix1(ItemId::HardLeatherArmor, i)), + is_special2_set3(ImplLoot::get_prefix1(ItemId::HardLeatherArmor, i)), 'invalid hard leather prefix' ); // verify leather armor uses set1 assert( - is_special2_set1(ImplLoot::generate_prefix1(ItemId::LeatherArmor, i)), + is_special2_set1(ImplLoot::get_prefix1(ItemId::LeatherArmor, i)), 'invalid leather armor prefix' ); // verify holy chestplate uses set2 assert( - is_special2_set2(ImplLoot::generate_prefix1(ItemId::HolyChestplate, i)), + is_special2_set2(ImplLoot::get_prefix1(ItemId::HolyChestplate, i)), 'invalid holy chestplate prefix' ); // verify ornate chestplate uses set3 assert( - is_special2_set3(ImplLoot::generate_prefix1(ItemId::OrnateChestplate, i)), + is_special2_set3(ImplLoot::get_prefix1(ItemId::OrnateChestplate, i)), 'invalid ornte chestplate prefix' ); // verify plate mail uses set1 assert( - is_special2_set1(ImplLoot::generate_prefix1(ItemId::PlateMail, i)), + is_special2_set1(ImplLoot::get_prefix1(ItemId::PlateMail, i)), 'invalid plate mail prefix' ); // verify chain mail uses set2 assert( - is_special2_set2(ImplLoot::generate_prefix1(ItemId::ChainMail, i)), + is_special2_set2(ImplLoot::get_prefix1(ItemId::ChainMail, i)), 'invalid chain mail prefix' ); // verify ring mail uses set3 assert( - is_special2_set3(ImplLoot::generate_prefix1(ItemId::RingMail, i)), + is_special2_set3(ImplLoot::get_prefix1(ItemId::RingMail, i)), 'invalid ring mail prefix' ); // assert ancient helm uses set1 assert( - is_special2_set1(ImplLoot::generate_prefix1(ItemId::AncientHelm, i)), + is_special2_set1(ImplLoot::get_prefix1(ItemId::AncientHelm, i)), 'invalid ancient helm prefix' ); // assert ornate helm uses set2 assert( - is_special2_set2(ImplLoot::generate_prefix1(ItemId::OrnateHelm, i)), + is_special2_set2(ImplLoot::get_prefix1(ItemId::OrnateHelm, i)), 'invalid ornate helm prefix' ); // assert great helm uses set3 assert( - is_special2_set3(ImplLoot::generate_prefix1(ItemId::GreatHelm, i)), + is_special2_set3(ImplLoot::get_prefix1(ItemId::GreatHelm, i)), 'invalid great helm prefix' ); // assert full helm uses set1 assert( - is_special2_set1(ImplLoot::generate_prefix1(ItemId::FullHelm, i)), + is_special2_set1(ImplLoot::get_prefix1(ItemId::FullHelm, i)), 'invalid full helm prefix' ); // assert helm uses set2 - assert( - is_special2_set2(ImplLoot::generate_prefix1(ItemId::Helm, i)), - 'invalid helm prefix' - ); + assert(is_special2_set2(ImplLoot::get_prefix1(ItemId::Helm, i)), 'invalid helm prefix'); // assert demon crown uses set3 assert( - is_special2_set3(ImplLoot::generate_prefix1(ItemId::DemonCrown, i)), + is_special2_set3(ImplLoot::get_prefix1(ItemId::DemonCrown, i)), 'invalid demon crown prefix' ); // assert dragons crown uses set1 assert( - is_special2_set1(ImplLoot::generate_prefix1(ItemId::DragonsCrown, i)), + is_special2_set1(ImplLoot::get_prefix1(ItemId::DragonsCrown, i)), 'invalid dragons crown prefix' ); // assert war cap uses set2 assert( - is_special2_set2(ImplLoot::generate_prefix1(ItemId::WarCap, i)), - 'invalid war cap prefix' + is_special2_set2(ImplLoot::get_prefix1(ItemId::WarCap, i)), 'invalid war cap prefix' ); // assert leather cap uses set3 assert( - is_special2_set3(ImplLoot::generate_prefix1(ItemId::LeatherCap, i)), + is_special2_set3(ImplLoot::get_prefix1(ItemId::LeatherCap, i)), 'invalid leather cap prefix' ); // assert cap uses set1 - assert( - is_special2_set1(ImplLoot::generate_prefix1(ItemId::Cap, i)), - 'invalid cap prefix' - ); + assert(is_special2_set1(ImplLoot::get_prefix1(ItemId::Cap, i)), 'invalid cap prefix'); // assert crown uses set2 assert( - is_special2_set2(ImplLoot::generate_prefix1(ItemId::Crown, i)), - 'invalid crown prefix' + is_special2_set2(ImplLoot::get_prefix1(ItemId::Crown, i)), 'invalid crown prefix' ); // assert divine hood uses set3 assert( - is_special2_set3(ImplLoot::generate_prefix1(ItemId::DivineHood, i)), + is_special2_set3(ImplLoot::get_prefix1(ItemId::DivineHood, i)), 'invalid divine hood prefix' ); // assert silk hood uses set1 assert( - is_special2_set1(ImplLoot::generate_prefix1(ItemId::SilkHood, i)), + is_special2_set1(ImplLoot::get_prefix1(ItemId::SilkHood, i)), 'invalid silk hood prefix' ); // assert linen hood uses set2 assert( - is_special2_set2(ImplLoot::generate_prefix1(ItemId::LinenHood, i)), + is_special2_set2(ImplLoot::get_prefix1(ItemId::LinenHood, i)), 'invalid linen hood prefix' ); // assert hood uses set3 - assert( - is_special2_set3(ImplLoot::generate_prefix1(ItemId::Hood, i)), - 'invalid hood prefix' - ); + assert(is_special2_set3(ImplLoot::get_prefix1(ItemId::Hood, i)), 'invalid hood prefix'); // assert ornate belt is set1 assert( - is_special2_set1(ImplLoot::generate_prefix1(ItemId::OrnateBelt, i)), + is_special2_set1(ImplLoot::get_prefix1(ItemId::OrnateBelt, i)), 'invalid ornate belt prefix' ); // assert war belt is set2 assert( - is_special2_set2(ImplLoot::generate_prefix1(ItemId::WarBelt, i)), + is_special2_set2(ImplLoot::get_prefix1(ItemId::WarBelt, i)), 'invalid war belt prefix' ); // assert plated belt is set3 assert( - is_special2_set3(ImplLoot::generate_prefix1(ItemId::PlatedBelt, i)), + is_special2_set3(ImplLoot::get_prefix1(ItemId::PlatedBelt, i)), 'invalid plated belt prefix' ); // assert mesh belt is set1 assert( - is_special2_set1(ImplLoot::generate_prefix1(ItemId::MeshBelt, i)), + is_special2_set1(ImplLoot::get_prefix1(ItemId::MeshBelt, i)), 'invalid mesh belt prefix' ); // assert heavy belt is set2 assert( - is_special2_set2(ImplLoot::generate_prefix1(ItemId::HeavyBelt, i)), + is_special2_set2(ImplLoot::get_prefix1(ItemId::HeavyBelt, i)), 'invalid heavy belt prefix' ); // assert demonhide belt is set3 assert( - is_special2_set3(ImplLoot::generate_prefix1(ItemId::DemonhideBelt, i)), + is_special2_set3(ImplLoot::get_prefix1(ItemId::DemonhideBelt, i)), 'invalid demonhide belt prefix' ); // assert dragonskin belt is set1 assert( - is_special2_set1(ImplLoot::generate_prefix1(ItemId::DragonskinBelt, i)), + is_special2_set1(ImplLoot::get_prefix1(ItemId::DragonskinBelt, i)), 'invalid dragonskin belt prefix' ); // assert studded leather belt is set2 assert( - is_special2_set2(ImplLoot::generate_prefix1(ItemId::StuddedLeatherBelt, i)), + is_special2_set2(ImplLoot::get_prefix1(ItemId::StuddedLeatherBelt, i)), 'invalid studded lthr blt prefix' ); // assert hard leather belt is set3 assert( - is_special2_set3(ImplLoot::generate_prefix1(ItemId::HardLeatherBelt, i)), + is_special2_set3(ImplLoot::get_prefix1(ItemId::HardLeatherBelt, i)), 'invalid hard leather blt prefix' ); // assert leather belt is set1 assert( - is_special2_set1(ImplLoot::generate_prefix1(ItemId::LeatherBelt, i)), + is_special2_set1(ImplLoot::get_prefix1(ItemId::LeatherBelt, i)), 'invalid leather belt prefix' ); // assert brightsilk sash is set2 assert( - is_special2_set2(ImplLoot::generate_prefix1(ItemId::BrightsilkSash, i)), + is_special2_set2(ImplLoot::get_prefix1(ItemId::BrightsilkSash, i)), 'invalid brightsilk sash prefix' ); // assert silk sash is set3 assert( - is_special2_set3(ImplLoot::generate_prefix1(ItemId::SilkSash, i)), + is_special2_set3(ImplLoot::get_prefix1(ItemId::SilkSash, i)), 'invalid silk sash prefix' ); // assert wool sash is set1 assert( - is_special2_set1(ImplLoot::generate_prefix1(ItemId::WoolSash, i)), + is_special2_set1(ImplLoot::get_prefix1(ItemId::WoolSash, i)), 'invalid wool sash prefix' ); // assert linen sash is set2 assert( - is_special2_set2(ImplLoot::generate_prefix1(ItemId::LinenSash, i)), + is_special2_set2(ImplLoot::get_prefix1(ItemId::LinenSash, i)), 'invalid linen sash prefix' ); // assert sash is set3 - assert( - is_special2_set3(ImplLoot::generate_prefix1(ItemId::Sash, i)), - 'invalid sash prefix' - ); + assert(is_special2_set3(ImplLoot::get_prefix1(ItemId::Sash, i)), 'invalid sash prefix'); // assert holy greaves is set1 assert( - is_special2_set1(ImplLoot::generate_prefix1(ItemId::HolyGreaves, i)), + is_special2_set1(ImplLoot::get_prefix1(ItemId::HolyGreaves, i)), 'invalid holy greaves prefix' ); // assert ornate greaves is set2 assert( - is_special2_set2(ImplLoot::generate_prefix1(ItemId::OrnateGreaves, i)), + is_special2_set2(ImplLoot::get_prefix1(ItemId::OrnateGreaves, i)), 'invalid ornate greaves prefix' ); // assert greaves is set3 assert( - is_special2_set3(ImplLoot::generate_prefix1(ItemId::Greaves, i)), + is_special2_set3(ImplLoot::get_prefix1(ItemId::Greaves, i)), 'invalid greaves prefix' ); // assert chain boots is set1 assert( - is_special2_set1(ImplLoot::generate_prefix1(ItemId::ChainBoots, i)), + is_special2_set1(ImplLoot::get_prefix1(ItemId::ChainBoots, i)), 'invalid chain boots prefix' ); // assert heavy boots is set2 assert( - is_special2_set2(ImplLoot::generate_prefix1(ItemId::HeavyBoots, i)), + is_special2_set2(ImplLoot::get_prefix1(ItemId::HeavyBoots, i)), 'invalid heavy boots prefix' ); // assert demonhide boots is set3 assert( - is_special2_set3(ImplLoot::generate_prefix1(ItemId::DemonhideBoots, i)), + is_special2_set3(ImplLoot::get_prefix1(ItemId::DemonhideBoots, i)), 'invalid demonhide boots prefix' ); // assert dragonskin boots is set1 assert( - is_special2_set1(ImplLoot::generate_prefix1(ItemId::DragonskinBoots, i)), + is_special2_set1(ImplLoot::get_prefix1(ItemId::DragonskinBoots, i)), 'invalid dragonskin boots prefix' ); // assert studded leather boots is set2 assert( - is_special2_set2(ImplLoot::generate_prefix1(ItemId::StuddedLeatherBoots, i)), + is_special2_set2(ImplLoot::get_prefix1(ItemId::StuddedLeatherBoots, i)), 'invalid stdded lthr boots prfix' );