diff --git a/contracts/adventurer/src/bag.cairo b/contracts/adventurer/src/bag.cairo index 8fb825ab6..f16b76563 100644 --- a/contracts/adventurer/src/bag.cairo +++ b/contracts/adventurer/src/bag.cairo @@ -136,7 +136,7 @@ impl ImplBag of IBag { // @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. 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); + item.set_metadata_id(adventurer, self, false); self.add_item(item); } diff --git a/contracts/adventurer/src/constants/adventurer_constants.cairo b/contracts/adventurer/src/constants/adventurer_constants.cairo index 45ef7e75d..289675fcc 100644 --- a/contracts/adventurer/src/constants/adventurer_constants.cairo +++ b/contracts/adventurer/src/constants/adventurer_constants.cairo @@ -2,7 +2,6 @@ const STARTING_GOLD: u16 = 25; const STARTING_HEALTH: u16 = 100; - // Adventurer Max Values const MAX_ADVENTURER_HEALTH: u16 = 511; // 9 bits const MAX_XP: u16 = 16383; // 14 bits diff --git a/contracts/adventurer/src/item_meta.cairo b/contracts/adventurer/src/item_meta.cairo index b4f5accd8..51b8d9739 100644 --- a/contracts/adventurer/src/item_meta.cairo +++ b/contracts/adventurer/src/item_meta.cairo @@ -1,5 +1,6 @@ use starknet::{StorePacking}; -use lootitems::constants::{ItemId, ItemSuffix}; +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} @@ -263,51 +264,81 @@ impl ImplItemSpecials of IItemSpecials { /// 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(adventurer: Adventurer, bag: Bag) -> u8 { - if (adventurer.weapon.id == 0 && adventurer.weapon.metadata != 0) { - adventurer.weapon.metadata - } else if (adventurer.head.id == 0 && adventurer.head.metadata != 0) { - adventurer.head.metadata - } else if (adventurer.chest.id == 0 && adventurer.chest.metadata != 0) { - adventurer.chest.metadata - } else if (adventurer.hand.id == 0 && adventurer.hand.metadata != 0) { - adventurer.hand.metadata - } else if (adventurer.foot.id == 0 && adventurer.foot.metadata != 0) { - adventurer.foot.metadata - } else if (adventurer.ring.id == 0 && adventurer.ring.metadata != 0) { - adventurer.ring.metadata - } else if (adventurer.neck.id == 0 && adventurer.neck.metadata != 0) { - adventurer.neck.metadata - } else if (adventurer.waist.id == 0 && adventurer.waist.metadata != 0) { - adventurer.waist.metadata - } else 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 + 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 { - 0 + // 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 + } } } @@ -406,8 +437,10 @@ impl ImplItemSpecials of IItemSpecials { /// @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) { - let reused_metadata = ImplItemSpecials::get_recycled_metadata(adventurer, bag); + 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 { @@ -514,7 +547,7 @@ mod tests { } #[test] - #[available_gas(4000000)] + #[available_gas(40000000)] fn test_set_metadata_id() { // start test with a new adventurer wielding a wand let mut adventurer = ImplAdventurer::new(ItemId::Wand); @@ -562,7 +595,7 @@ mod tests { 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); + katana.set_metadata_id(adventurer, bag, false); // toss starter wand in bag bag.add_item(starter_wand); @@ -580,82 +613,82 @@ mod tests { ); // proceed to buy armor for the adventurer, verifying meta data pointers for each item - demon_crown.set_metadata_id(adventurer, bag); + 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); + 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); + 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); + 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); + 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); + 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); + 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); + 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); + 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); + 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); + 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); + 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); + 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); + 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); + demonhide_boots.set_metadata_id(adventurer, bag, false); bag.add_item(demonhide_boots); assert( bag.item_11 == demonhide_boots && demonhide_boots.metadata == 17, @@ -689,7 +722,7 @@ mod tests { // 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); + demonhide_belt.set_metadata_id(adventurer, bag, false); bag.add_item(demonhide_belt); assert( bag.item_1 == demonhide_belt && demonhide_belt.metadata == 1, @@ -702,10 +735,10 @@ mod tests { 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); + 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); + 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'); @@ -714,13 +747,13 @@ mod tests { // necklace should pickup metadata 18 let mut necklace = ItemPrimitive { id: ItemId::Necklace, xp: 1, metadata: 0 }; - necklace.set_metadata_id(adventurer, bag); + 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); + 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' @@ -729,7 +762,7 @@ mod tests { // 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); + grimoire.set_metadata_id(adventurer, bag, true); adventurer.equip_item(grimoire); assert(adventurer.weapon == grimoire && grimoire.metadata == 2, 'wrong grimoire metadata'); } diff --git a/contracts/game/src/lib.cairo b/contracts/game/src/lib.cairo index 7fb6cac40..ffbb31f0d 100644 --- a/contracts/game/src/lib.cairo +++ b/contracts/game/src/lib.cairo @@ -2203,7 +2203,7 @@ 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); + new_item.set_metadata_id(adventurer, bag, true); unequipped_item_id = _equip_item(contract_state, ref adventurer, ref bag, adventurer_id, new_item); } else { diff --git a/contracts/game/src/tests/test_game.cairo b/contracts/game/src/tests/test_game.cairo index b3f7acd52..fb854448f 100644 --- a/contracts/game/src/tests/test_game.cairo +++ b/contracts/game/src/tests/test_game.cairo @@ -1,5 +1,6 @@ #[cfg(test)] mod tests { + use debug::PrintTrait; use arcade_account::{Account, TRANSACTION_VERSION}; use arcade_account::tests::utils::helper_contracts::{ ISimpleTestContractDispatcher, ISimpleTestContractDispatcherTrait, simple_test_contract, @@ -1662,17 +1663,13 @@ mod tests { // game settings in the constructor. Commenting this out for now so our CI doesn't run it // #[test] // #[available_gas(80000000000)] - // fn test_max_items() { + // fn test_metadata_unique() { // // start game on level 2 so we have access to the market - // let mut game = new_adventurer_lvl2(1000,1696201757); + // let mut game = new_adventurer_lvl2(1000, 1696201757, 0); - // // get items from market - // let mut market_items = @game.get_items_on_market(ADVENTURER_ID); - - // // get first item on the market - // let item_id = *market_items.at(0).item.id; + // // get items from market + // let mut market_item_ids = game.get_items_on_market(ADVENTURER_ID); - // let mut purchased_weapon: u8 = 0; // let mut purchased_chest: u8 = 0; // let mut purchased_head: u8 = 0; // let mut purchased_waist: u8 = 0; @@ -1682,108 +1679,718 @@ mod tests { // let mut purchased_necklace: u8 = 0; // let mut shopping_cart = ArrayTrait::::new(); - // let mut i: u32 = 0; + // let mut bagged_items: u8 = 0; + // loop { - // if i >= market_items.len() { - // break (); + // 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; }, // } - // let market_item = *market_items.at(i).item; - - // // if the item is a weapon and we haven't purchased a weapon yet - // // and the item is a tier 4 or 5 item - // // repeat this for everything - // if (market_item.slot == Slot::Weapon(()) - // && purchased_weapon == 0 - // && market_item.id != 12) { - // shopping_cart.append(ItemPurchase { item_id: market_item.id, equip: false }); - // purchased_weapon = market_item.id; - // } else 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; - // } - // i += 1; // }; // assert( - // purchased_weapon != 0 - // && purchased_chest != 0 + // purchased_chest != 0 // && purchased_head != 0 // && purchased_waist != 0 // && purchased_foot != 0 // && purchased_hand != 0 // && purchased_ring != 0 - // && purchased_necklace != 0, + // && purchased_necklace != 0 + // && bagged_items == 11, // 'did not purchase all items' // ); - // let mut i: u32 = 0; + // // 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 { - // if i >= market_items.len() { - // break (); - // } - // let market_item = *market_items.at(i).item; - - // if (market_item.id == purchased_weapon - // || market_item.id == purchased_chest - // || market_item.id == purchased_head - // || market_item.id == purchased_waist - // || market_item.id == purchased_foot - // || market_item.id == purchased_hand - // || market_item.id == purchased_ring - // || market_item.id == purchased_necklace - // || shopping_cart.len() == 19) { - // i += 1; - // continue; + // 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; }, // } + // }; - // shopping_cart.append(ItemPurchase { item_id: market_item.id, equip: false }); + // assert(shopping_cart.len() == 2, 'did not purchase enough items'); - // i += 1; + // // 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' + // ); + // } - // // We intentionally loaded our cart with 19 items which would be one more than max - // // when you add our starter weapon. We did this so we could pop one item off the cart - // // and into this overflow shopping cart which we'll use later - // let mut overflow_item = shopping_cart.pop_front().unwrap(); - // overflow_item.equip = true; - // let mut overflow_shopping_cart = ArrayTrait::::new(); - // overflow_shopping_cart.append(overflow_item); + fn already_owned(item_id: u8, adventurer: Adventurer, bag: Bag) -> bool { + 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 == adventurer.neck.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 + } - // // verify we have at least two items in shopping cart - // assert(shopping_cart.len() == 18, 'should be max items'); + // 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 - // game.buy_items(ADVENTURER_ID, shopping_cart.clone()); + // 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); - // // drop our weapon and attempt (should free up an item slow) - // let mut items_to_drop = ArrayTrait::::new(); - // items_to_drop.append(12); - // game.drop(ADVENTURER_ID, items_to_drop); + // // 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'); - // game.buy_items(ADVENTURER_ID, overflow_shopping_cart.clone()); + // // 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); - // // get updated adventurer and bag state + // // 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] diff --git a/contracts/market/src/constants.cairo b/contracts/market/src/constants.cairo index cc0b1090e..b4d95336b 100644 --- a/contracts/market/src/constants.cairo +++ b/contracts/market/src/constants.cairo @@ -1,4 +1,4 @@ -// number of items per level per survivor +// number of items available per stat upgrade const NUMBER_OF_ITEMS_PER_LEVEL: u8 = 21; // number of loot items