diff --git a/contracts/adventurer/src/adventurer.cairo b/contracts/adventurer/src/adventurer.cairo index 1a36738cf..9f3c5d53f 100644 --- a/contracts/adventurer/src/adventurer.cairo +++ b/contracts/adventurer/src/adventurer.cairo @@ -21,7 +21,10 @@ use super::{ discovery_constants::DiscoveryEnums::{ExploreResult, DiscoveryType} } }; -use pack::{pack::{Packing, rshift_split}, constants::{MASK_16, pow, MASK_8, MASK_BOOL, mask}}; +use pack::{ + pack::{Packing, rshift_split}, constants, + constants::{MASK_16, pow, MASK_8, MASK_3, MASK_BOOL, mask, U128_MASK_8, u128_pow} +}; use lootitems::{ loot::{Loot, ILoot, ImplLoot}, constants::{ItemSuffix, ItemId, NamePrefixLength, NameSuffixLength} @@ -127,24 +130,20 @@ impl ImplAdventurer of IAdventurer { // @param starting_item: the id of the starting item // @param block_number: the block number of the block that the adventurer was created in // @return Adventurer: the new adventurer - fn new(starting_item: u8, block_number: u64, starting_stats: Stats) -> Adventurer { + fn new( + starting_item: u8, num_starting_stats: u8, block_number: u64, entropy: u128 + ) -> Adventurer { let current_block_modulo_512: u16 = (block_number % MAX_ADVENTURER_BLOCKS.into()) .try_into() .unwrap(); + let starting_stats = AdventurerUtils::generate_starting_stats(entropy, num_starting_stats); + let mut adventurer = Adventurer { last_action: current_block_modulo_512, health: STARTING_HEALTH, xp: 0, - stats: Stats { - strength: starting_stats.strength, - dexterity: starting_stats.dexterity, - vitality: starting_stats.vitality, - intelligence: starting_stats.intelligence, - wisdom: starting_stats.wisdom, - charisma: starting_stats.charisma, - luck: 0 - }, + stats: starting_stats, gold: STARTING_GOLD, weapon: ItemPrimitive { id: starting_item, xp: 0, metadata: 1, }, chest: ItemPrimitive { id: 0, xp: 0, metadata: 0, }, @@ -1471,13 +1470,9 @@ mod tests { use option::OptionTrait; use poseidon::poseidon_hash_span; use array::ArrayTrait; - use lootitems::{loot::{Loot, ILoot, ImplLoot}, constants::{ItemSuffix, ItemId}}; - use combat::{constants::CombatEnums::{Slot}}; - use beasts::{beast::{ImplBeast, Beast}, constants::BeastSettings}; - use survivor::{ adventurer::{IAdventurer, ImplAdventurer, Adventurer}, item_meta::{ItemSpecials, ItemSpecialsStorage, ImplItemSpecials}, adventurer_stats::Stats, @@ -1493,32 +1488,22 @@ mod tests { discovery_constants::DiscoveryEnums::{ExploreResult, DiscoveryType} } }; - use pack::{pack::{Packing, rshift_split}, constants::{MASK_16, pow, MASK_8, MASK_BOOL, mask}}; + use pack::{ + pack::{Packing, rshift_split}, constants, constants::{MASK_8, pow, MASK_3, MASK_BOOL, mask} + }; #[test] - #[available_gas(28690)] + #[available_gas(173744)] fn test_beast_gold_reward_multiplier_gas() { - let mut adventurer = ImplAdventurer::new( - 12, - 0, - Stats { - strength: 1, dexterity: 1, vitality: 1, intelligence: 1, wisdom: 1, charisma: 1, luck: 1 - } - ); + let mut adventurer = ImplAdventurer::new(12, 0, 0, 0,); let reward = adventurer.beast_gold_reward_multiplier(); } #[test] - #[available_gas(48970)] + #[available_gas(194024)] fn test_beast_gold_reward_multiplier() { - let mut adventurer = ImplAdventurer::new( - 12, - 0, - Stats { - strength: 1, dexterity: 1, vitality: 1, intelligence: 1, wisdom: 1, charisma: 1, luck: 1 - } - ); + let mut adventurer = ImplAdventurer::new(12, 0, 0, 0); assert(adventurer.beast_gold_reward_multiplier() == 1, 'no gold reward'); @@ -1538,28 +1523,16 @@ mod tests { } #[test] - #[available_gas(28690)] + #[available_gas(173744)] fn test_get_bonus_luck_gas() { - let adventurer = ImplAdventurer::new( - 12, - 0, - Stats { - strength: 0, dexterity: 0, vitality: 0, intelligence: 0, wisdom: 0, charisma: 0, luck: 0 } - ); - + let adventurer = ImplAdventurer::new(12, 0, 0, 0); let bonus_luck = adventurer.get_bonus_luck(); } #[test] - #[available_gas(48970)] + #[available_gas(194024)] fn test_get_bonus_luck() { - let mut adventurer = ImplAdventurer::new( - 12, - 0, - Stats { - strength: 0, dexterity: 0, vitality: 0, intelligence: 0, wisdom: 0, charisma: 0, luck: 0 - } - ); + let mut adventurer = ImplAdventurer::new(12, 0, 0, 0); assert(adventurer.get_bonus_luck() == 0, 'no bonus luck'); @@ -1579,28 +1552,16 @@ mod tests { } #[test] - #[available_gas(28690)] + #[available_gas(300884)] fn test_obstacle_gold_reward_multplier_gas() { - let mut adventurer = ImplAdventurer::new( - 12, - 0, - Stats { - strength: 1, dexterity: 1, vitality: 1, intelligence: 1, wisdom: 1, charisma: 1, luck: 1 - } - ); + let mut adventurer = ImplAdventurer::new(12, 6, 0, 0); let reward = adventurer.obstacle_gold_reward_multplier(); } #[test] - #[available_gas(2811390)] + #[available_gas(321164)] fn test_obstacle_gold_reward_multplier() { - let mut adventurer = ImplAdventurer::new( - 12, - 0, - Stats { - strength: 1, dexterity: 1, vitality: 1, intelligence: 1, wisdom: 1, charisma: 1, luck: 1 - } - ); + let mut adventurer = ImplAdventurer::new(12, 6, 0, 0); assert(adventurer.obstacle_gold_reward_multplier() == 0, 'no obstacle gold reward'); @@ -1620,28 +1581,16 @@ mod tests { } #[test] - #[available_gas(28690)] + #[available_gas(300884)] fn test_discovery_bonus_multplier_gas() { - let mut adventurer = ImplAdventurer::new( - 12, - 0, - Stats { - strength: 1, dexterity: 1, vitality: 1, intelligence: 1, wisdom: 1, charisma: 1, luck: 1 - } - ); + let mut adventurer = ImplAdventurer::new(12, 6, 0, 0); let discovery_bonus = adventurer.discovery_bonus_multplier(); } #[test] - #[available_gas(48970)] + #[available_gas(321164)] fn test_discovery_bonus_multplier() { - let mut adventurer = ImplAdventurer::new( - 12, - 0, - Stats { - strength: 1, dexterity: 1, vitality: 1, intelligence: 1, wisdom: 1, charisma: 1, luck: 1 - } - ); + let mut adventurer = ImplAdventurer::new(12, 6, 0, 0); assert(adventurer.discovery_bonus_multplier() == 1, 'start with 1x discovery bonus'); @@ -2165,15 +2114,9 @@ mod tests { } #[test] - #[available_gas(35590)] + #[available_gas(300884)] fn test_double_gold_from_beasts_unlocked_gas() { - let adventurer = ImplAdventurer::new( - 12, - 0, - Stats { - strength: 1, dexterity: 1, vitality: 1, intelligence: 1, wisdom: 1, charisma: 1, luck: 1 - } - ); + let adventurer = ImplAdventurer::new(12, 6, 0, 0); let bag = Bag { item_1: ItemPrimitive { id: ItemId::Katana, xp: 0, metadata: 9 }, item_2: ItemPrimitive { id: ItemId::Crown, xp: 0, metadata: 10 }, @@ -2193,15 +2136,9 @@ mod tests { } #[test] - #[available_gas(99050)] + #[available_gas(344144)] fn test_double_gold_from_beasts_unlocked() { - let mut adventurer = ImplAdventurer::new( - 12, - 0, - Stats { - strength: 1, dexterity: 1, vitality: 1, intelligence: 1, wisdom: 1, charisma: 1, luck: 1 - } - ); + let mut adventurer = ImplAdventurer::new(12, 6, 0, 0); let bag = Bag { item_1: ItemPrimitive { id: ItemId::Katana, xp: 0, metadata: 9 }, @@ -2268,29 +2205,17 @@ mod tests { } #[test] - #[available_gas(28690)] + #[available_gas(300884)] fn test_armor_bonus_multiplier_gas() { - let adventurer = ImplAdventurer::new( - 12, - 0, - Stats { - strength: 1, dexterity: 1, vitality: 1, intelligence: 1, wisdom: 1, charisma: 1, luck: 1 - } - ); + let adventurer = ImplAdventurer::new(12, 6, 0, 0); let armor_bonus = ImplAdventurer::armor_bonus_multiplier(adventurer); } #[test] - #[available_gas(41310)] + #[available_gas(313504)] fn test_armor_bonus_multiplier() { - let mut adventurer = ImplAdventurer::new( - 12, - 0, - Stats { - strength: 1, dexterity: 1, vitality: 1, intelligence: 1, wisdom: 1, charisma: 1, luck: 1 - } - ); + let mut adventurer = ImplAdventurer::new(12, 6, 0, 0); // verify no armor bonus multplier at start assert( @@ -2311,15 +2236,9 @@ mod tests { } #[test] - #[available_gas(29090)] + #[available_gas(301284)] fn test_critical_hit_bonus_multiplier_gas() { - let mut adventurer = ImplAdventurer::new( - 12, - 0, - Stats { - strength: 1, dexterity: 1, vitality: 1, intelligence: 1, wisdom: 1, charisma: 1, luck: 1 - } - ); + let mut adventurer = ImplAdventurer::new(12, 6, 0, 0); // equip a Platinum Ring ring with 400xp (greatness 20) adventurer.ring = ItemPrimitive { id: ItemId::PlatinumRing, xp: 400, metadata: 6 }; @@ -2327,15 +2246,9 @@ mod tests { } #[test] - #[available_gas(45410)] + #[available_gas(317604)] fn test_critical_hit_bonus_multiplier() { - let mut adventurer = ImplAdventurer::new( - 12, - 0, - Stats { - strength: 1, dexterity: 1, vitality: 1, intelligence: 1, wisdom: 1, charisma: 1, luck: 1 - } - ); + let mut adventurer = ImplAdventurer::new(12, 6, 0, 0); // verify starting state (no necklace) assert(adventurer.neck.id == 0, 'start without a neck'); @@ -2365,15 +2278,9 @@ mod tests { // gas baseline #[test] - #[available_gas(29090)] + #[available_gas(301284)] fn test_name_match_bonus_damage_multiplier_gas() { - let mut adventurer = ImplAdventurer::new( - 12, - 0, - Stats { - strength: 1, dexterity: 1, vitality: 1, intelligence: 1, wisdom: 1, charisma: 1, luck: 1 - } - ); + let mut adventurer = ImplAdventurer::new(12, 6, 0, 0); // equip a titanium ring with 400xp (greatness 20) adventurer.ring = ItemPrimitive { id: ItemId::TitaniumRing, xp: 400, metadata: 6 }; @@ -2381,15 +2288,9 @@ mod tests { } #[test] - #[available_gas(45410)] + #[available_gas(317604)] fn test_name_match_bonus_damage_multiplier() { - let mut adventurer = ImplAdventurer::new( - 12, - 0, - Stats { - strength: 1, dexterity: 1, vitality: 1, intelligence: 1, wisdom: 1, charisma: 1, luck: 1 - } - ); + let mut adventurer = ImplAdventurer::new(12, 6, 0, 0); // verify starting state (no necklace) assert(adventurer.neck.id == 0, 'start without a ring'); @@ -2445,15 +2346,9 @@ mod tests { #[test] - #[available_gas(170320)] + #[available_gas(275934)] fn test_get_beast_seed_gas() { - let mut adventurer = ImplAdventurer::new( - 12, - 0, - Stats { - strength: 0, dexterity: 0, vitality: 0, intelligence: 0, wisdom: 0, charisma: 0, luck: 0 - } - ); + let mut adventurer = ImplAdventurer::new(12, 0, 0, 0); let adventurer_entropy = 1; ImplAdventurer::get_beast_seed(adventurer, adventurer_entropy); adventurer.xp = 100; @@ -2463,13 +2358,7 @@ mod tests { #[test] #[available_gas(1064170)] fn test_get_beast() { - let mut adventurer = ImplAdventurer::new( - 12, - 0, - Stats { - strength: 0, dexterity: 0, vitality: 0, intelligence: 0, wisdom: 0, charisma: 0, luck: 0 - } - ); + let mut adventurer = ImplAdventurer::new(12, 0, 0, 0); let entropy = 1; // check new adventurer (level 1) gets a starter beast @@ -2621,15 +2510,9 @@ mod tests { } #[test] - #[available_gas(71630)] + #[available_gas(216684)] fn test_set_last_action() { - let mut adventurer = ImplAdventurer::new( - 12, - 0, - Stats { - strength: 0, dexterity: 0, vitality: 0, intelligence: 0, wisdom: 0, charisma: 0, luck: 0 - } - ); + let mut adventurer = ImplAdventurer::new(12, 0, 0, 0); adventurer.set_last_action(0); assert(adventurer.last_action == 0, 'last action should be 0'); adventurer.set_last_action(511); @@ -2643,15 +2526,9 @@ mod tests { } #[test] - #[available_gas(200000)] + #[available_gas(253944)] fn test_charisma_adjusted_item_price() { - let mut adventurer = ImplAdventurer::new( - 12, - 0, - Stats { - strength: 0, dexterity: 0, vitality: 0, intelligence: 0, wisdom: 0, charisma: 0, luck: 0 - } - ); + let mut adventurer = ImplAdventurer::new(12, 0, 0, 0); // zero case let item_price = adventurer.charisma_adjusted_item_price(0); @@ -2673,12 +2550,9 @@ mod tests { } #[test] - #[available_gas(290000)] + #[available_gas(288554)] fn test_charisma_adjusted_potion_price() { - let starting_stats = Stats { - strength: 0, dexterity: 0, vitality: 0, intelligence: 0, wisdom: 0, charisma: 0, luck: 0 - }; - let mut adventurer = ImplAdventurer::new(12, 0, starting_stats); + let mut adventurer = ImplAdventurer::new(12, 0, 0, 0); // default case (no charisma discount) let potion_price = adventurer.charisma_adjusted_potion_price(); @@ -2707,12 +2581,9 @@ mod tests { } #[test] - #[available_gas(150000)] + #[available_gas(241184)] fn test_get_idle_blocks() { - let starting_stats = Stats { - strength: 0, dexterity: 0, vitality: 0, intelligence: 0, wisdom: 0, charisma: 0, luck: 0 - }; - let mut adventurer = ImplAdventurer::new(12, 0, starting_stats); + let mut adventurer = ImplAdventurer::new(12, 0, 0, 0); adventurer.last_action = 1; // test with current block greater than last action @@ -2848,10 +2719,7 @@ mod tests { #[test] #[available_gas(2000000)] fn test_new_adventurer() { - let starting_stats = Stats { - strength: 0, dexterity: 0, vitality: 0, intelligence: 0, wisdom: 0, charisma: 0, luck: 0 - }; - let mut adventurer = ImplAdventurer::new(12, 0, starting_stats); + let mut adventurer = ImplAdventurer::new(12, 0, 0, 0); adventurer.pack(); assert(adventurer.health == STARTING_HEALTH, 'wrong starting health'); assert(adventurer.gold == STARTING_GOLD, 'wrong starting gold'); @@ -2859,12 +2727,9 @@ mod tests { } #[test] - #[available_gas(200000)] + #[available_gas(304164)] fn test_increase_health() { - let starting_stats = Stats { - strength: 0, dexterity: 0, vitality: 0, intelligence: 0, wisdom: 0, charisma: 0, luck: 0 - }; - let mut adventurer = ImplAdventurer::new(12, 0, starting_stats); + let mut adventurer = ImplAdventurer::new(12, 0, 0, 0); // test stock max health is 100 adventurer.increase_health(5); @@ -2891,12 +2756,9 @@ mod tests { } #[test] - #[available_gas(2600000)] + #[available_gas(2701164)] fn test_increase_gold() { - let starting_stats = Stats { - strength: 0, dexterity: 0, vitality: 0, intelligence: 0, wisdom: 0, charisma: 0, luck: 0 - }; - let mut adventurer = ImplAdventurer::new(12, 0, starting_stats); + let mut adventurer = ImplAdventurer::new(12, 0, 0, 0); // assert starting state assert(adventurer.gold == STARTING_GOLD, 'wrong advntr starting gold'); @@ -2920,12 +2782,9 @@ mod tests { } #[test] - #[available_gas(51310)] + #[available_gas(196364)] fn test_decrease_health() { - let starting_stats = Stats { - strength: 0, dexterity: 0, vitality: 0, intelligence: 0, wisdom: 0, charisma: 0, luck: 0 - }; - let mut adventurer = ImplAdventurer::new(12, 0, starting_stats); + let mut adventurer = ImplAdventurer::new(12, 0, 0, 0); let starting_health = adventurer.health; let deduct_amount = 5; @@ -2939,12 +2798,9 @@ mod tests { } #[test] - #[available_gas(53000)] + #[available_gas(196364)] fn test_deduct_gold() { - let starting_stats = Stats { - strength: 0, dexterity: 0, vitality: 0, intelligence: 0, wisdom: 0, charisma: 0, luck: 0 - }; - let mut adventurer = ImplAdventurer::new(12, 0, starting_stats); + let mut adventurer = ImplAdventurer::new(12, 0, 0, 0); let starting_gold = adventurer.gold; let deduct_amount = 5; @@ -2958,12 +2814,9 @@ mod tests { } #[test] - #[available_gas(250000)] + #[available_gas(337814)] fn test_increase_adventurer_xp() { - let starting_stats = Stats { - strength: 0, dexterity: 0, vitality: 0, intelligence: 0, wisdom: 0, charisma: 0, luck: 0 - }; - let mut adventurer = ImplAdventurer::new(12, 0, starting_stats); + let mut adventurer = ImplAdventurer::new(12, 0, 0, 0); // base case level increase let (previous_level, new_level) = adventurer.increase_adventurer_xp(4); assert(adventurer.xp == 4, 'xp should be 4'); @@ -2990,11 +2843,7 @@ mod tests { #[test] #[available_gas(3000000)] fn test_increase_stat_points_available() { - // get new adventurer - let starting_stats = Stats { - strength: 0, dexterity: 0, vitality: 0, intelligence: 0, wisdom: 0, charisma: 0, luck: 0 - }; - let mut adventurer = ImplAdventurer::new(12, 0, starting_stats); + let mut adventurer = ImplAdventurer::new(12, 0, 0, 0); let original_stat_points = adventurer.stat_points_available; // zero case @@ -3027,12 +2876,9 @@ mod tests { } #[test] - #[available_gas(90000)] + #[available_gas(182964)] fn test_increase_strength() { - let starting_stats = Stats { - strength: 0, dexterity: 0, vitality: 0, intelligence: 0, wisdom: 0, charisma: 0, luck: 0 - }; - let mut adventurer = ImplAdventurer::new(12, 0, starting_stats); + let mut adventurer = ImplAdventurer::new(12, 0, 0, 0); // basic case adventurer.stats.increase_strength(1); assert(adventurer.stats.strength == 1, 'strength should be 1'); @@ -3042,12 +2888,9 @@ mod tests { } #[test] - #[available_gas(90000)] + #[available_gas(182964)] fn test_increase_dexterity() { - let starting_stats = Stats { - strength: 0, dexterity: 0, vitality: 0, intelligence: 0, wisdom: 0, charisma: 0, luck: 0 - }; - let mut adventurer = ImplAdventurer::new(12, 0, starting_stats); + let mut adventurer = ImplAdventurer::new(12, 0, 0, 0); // basic case adventurer.stats.increase_dexterity(1); assert(adventurer.stats.dexterity == 1, 'dexterity should be 1'); @@ -3057,12 +2900,9 @@ mod tests { } #[test] - #[available_gas(90000)] + #[available_gas(182964)] fn test_increase_vitality() { - let starting_stats = Stats { - strength: 0, dexterity: 0, vitality: 0, intelligence: 0, wisdom: 0, charisma: 0, luck: 0 - }; - let mut adventurer = ImplAdventurer::new(12, 0, starting_stats); + let mut adventurer = ImplAdventurer::new(12, 0, 0, 0); // basic case adventurer.stats.increase_vitality(1); assert(adventurer.stats.vitality == 1, 'vitality should be 1'); @@ -3072,12 +2912,9 @@ mod tests { } #[test] - #[available_gas(90000)] + #[available_gas(182964)] fn test_increase_intelligence() { - let starting_stats = Stats { - strength: 0, dexterity: 0, vitality: 0, intelligence: 0, wisdom: 0, charisma: 0, luck: 0 - }; - let mut adventurer = ImplAdventurer::new(12, 0, starting_stats); + let mut adventurer = ImplAdventurer::new(12, 0, 0, 0); // basic case adventurer.stats.increase_intelligence(1); assert(adventurer.stats.intelligence == 1, 'intelligence should be 1'); @@ -3087,12 +2924,9 @@ mod tests { } #[test] - #[available_gas(90000)] + #[available_gas(182964)] fn test_increase_wisdom() { - let starting_stats = Stats { - strength: 0, dexterity: 0, vitality: 0, intelligence: 0, wisdom: 0, charisma: 0, luck: 0 - }; - let mut adventurer = ImplAdventurer::new(12, 0, starting_stats); + let mut adventurer = ImplAdventurer::new(12, 0, 0, 0); // basic case adventurer.stats.increase_wisdom(1); assert(adventurer.stats.wisdom == 1, 'wisdom should be 1'); @@ -3102,12 +2936,9 @@ mod tests { } #[test] - #[available_gas(90000)] + #[available_gas(182964)] fn test_increase_charisma() { - let starting_stats = Stats { - strength: 0, dexterity: 0, vitality: 0, intelligence: 0, wisdom: 0, charisma: 0, luck: 0 - }; - let mut adventurer = ImplAdventurer::new(12, 0, starting_stats); + let mut adventurer = ImplAdventurer::new(12, 0, 0, 0); // basic case adventurer.stats.increase_charisma(1); assert(adventurer.stats.charisma == 1, 'charisma should be 1'); @@ -3117,12 +2948,9 @@ mod tests { } #[test] - #[available_gas(90000)] + #[available_gas(191964)] fn test_decrease_strength() { - let starting_stats = Stats { - strength: 0, dexterity: 0, vitality: 0, intelligence: 0, wisdom: 0, charisma: 0, luck: 0 - }; - let mut adventurer = ImplAdventurer::new(12, 0, starting_stats); + let mut adventurer = ImplAdventurer::new(12, 0, 0, 0); // basic case adventurer.stats.increase_strength(2); adventurer.stats.decrease_strength(1); @@ -3134,12 +2962,9 @@ mod tests { } #[test] - #[available_gas(90000)] + #[available_gas(191964)] fn test_decrease_dexterity() { - let starting_stats = Stats { - strength: 0, dexterity: 0, vitality: 0, intelligence: 0, wisdom: 0, charisma: 0, luck: 0 - }; - let mut adventurer = ImplAdventurer::new(12, 0, starting_stats); + let mut adventurer = ImplAdventurer::new(12, 0, 0, 0); // basic case adventurer.stats.increase_dexterity(2); adventurer.stats.decrease_dexterity(1); @@ -3151,12 +2976,9 @@ mod tests { } #[test] - #[available_gas(90000)] + #[available_gas(191964)] fn test_decrease_vitality() { - let starting_stats = Stats { - strength: 0, dexterity: 0, vitality: 0, intelligence: 0, wisdom: 0, charisma: 0, luck: 0 - }; - let mut adventurer = ImplAdventurer::new(12, 0, starting_stats); + let mut adventurer = ImplAdventurer::new(12, 0, 0, 0); // basic case adventurer.stats.increase_vitality(2); adventurer.stats.decrease_vitality(1); @@ -3168,12 +2990,9 @@ mod tests { } #[test] - #[available_gas(90000)] + #[available_gas(191964)] fn test_decrease_intelligence() { - let starting_stats = Stats { - strength: 0, dexterity: 0, vitality: 0, intelligence: 0, wisdom: 0, charisma: 0, luck: 0 - }; - let mut adventurer = ImplAdventurer::new(12, 0, starting_stats); + let mut adventurer = ImplAdventurer::new(12, 0, 0, 0); // basic case adventurer.stats.increase_intelligence(2); adventurer.stats.decrease_intelligence(1); @@ -3185,25 +3004,16 @@ mod tests { } #[test] - #[available_gas(90300)] + #[available_gas(191964)] fn test_decrease_wisdom_gas() { - let mut adventurer = ImplAdventurer::new( - 12, - 0, - Stats { - strength: 0, dexterity: 0, vitality: 0, intelligence: 0, wisdom: 1, charisma: 0, luck: 0 - } - ); + let mut adventurer = ImplAdventurer::new(12, 0, 0, 0); adventurer.stats.decrease_wisdom(1); } #[test] - #[available_gas(90300)] + #[available_gas(191964)] fn test_decrease_wisdom() { - let starting_stats = Stats { - strength: 0, dexterity: 0, vitality: 0, intelligence: 0, wisdom: 0, charisma: 0, luck: 0 - }; - let mut adventurer = ImplAdventurer::new(12, 0, starting_stats); + let mut adventurer = ImplAdventurer::new(12, 0, 0, 0); // basic case adventurer.stats.increase_wisdom(2); adventurer.stats.decrease_wisdom(1); @@ -3215,12 +3025,9 @@ mod tests { } #[test] - #[available_gas(90000)] + #[available_gas(191964)] fn test_decrease_charisma() { - let starting_stats = Stats { - strength: 0, dexterity: 0, vitality: 0, intelligence: 0, wisdom: 0, charisma: 0, luck: 0 - }; - let mut adventurer = ImplAdventurer::new(12, 0, starting_stats); + let mut adventurer = ImplAdventurer::new(12, 0, 0, 0); // basic case adventurer.stats.increase_charisma(2); adventurer.stats.decrease_charisma(1); @@ -3241,7 +3048,7 @@ mod tests { // let starting_stats = Stats { // strength: 0, dexterity: 0, vitality: 0, intelligence: 0, wisdom: 0, charisma: 0, luck: 0 // }; - // let mut adventurer = ImplAdventurer::new(12, 0, starting_stats); + // let mut adventurer = ImplAdventurer::new(12, 0, 0, 0); // // create demon crown item // let item = ItemPrimitive { id: ItemId::DemonCrown, xp: 1, metadata: 0 }; // // try to equip it to adventurer as a weapon @@ -3253,12 +3060,9 @@ mod tests { // } #[test] - #[available_gas(90000)] + #[available_gas(171784)] fn test_equip_valid_weapon() { - let starting_stats = Stats { - strength: 0, dexterity: 0, vitality: 0, intelligence: 0, wisdom: 0, charisma: 0, luck: 0 - }; - let mut adventurer = ImplAdventurer::new(12, 0, starting_stats); + let mut adventurer = ImplAdventurer::new(12, 0, 0, 0); // Create Katana item let item = ItemPrimitive { id: ItemId::Katana, xp: 1, metadata: 0 }; @@ -3281,7 +3085,7 @@ mod tests { // let starting_stats = Stats { // strength: 0, dexterity: 0, vitality: 0, intelligence: 0, wisdom: 0, charisma: 0, luck: 0 // }; - // let mut adventurer = ImplAdventurer::new(12, 0, starting_stats); + // let mut adventurer = ImplAdventurer::new(12, 0, 0, 0); // // try to equip a Demon Crown as chest item // let item = ItemPrimitive { id: ItemId::DemonCrown, xp: 1, metadata: 0 }; // adventurer.equip_chest_armor(item); @@ -3292,12 +3096,9 @@ mod tests { // } #[test] - #[available_gas(90000)] + #[available_gas(171784)] fn test_equip_valid_chest() { - let starting_stats = Stats { - strength: 0, dexterity: 0, vitality: 0, intelligence: 0, wisdom: 0, charisma: 0, luck: 0 - }; - let mut adventurer = ImplAdventurer::new(12, 0, starting_stats); + let mut adventurer = ImplAdventurer::new(12, 0, 0, 0); // equip Divine Robe as chest item let item = ItemPrimitive { id: ItemId::DivineRobe, xp: 1, metadata: 0 }; adventurer.equip_chest_armor(item); @@ -3318,7 +3119,7 @@ mod tests { // let starting_stats = Stats { // strength: 0, dexterity: 0, vitality: 0, intelligence: 0, wisdom: 0, charisma: 0, luck: 0 // }; - // let mut adventurer = ImplAdventurer::new(12, 0, starting_stats); + // let mut adventurer = ImplAdventurer::new(12, 0, 0, 0); // // try to equip a Katana as head item // let item = ItemPrimitive { id: ItemId::Katana, xp: 1, metadata: 0 }; // adventurer.equip_head_armor(item); @@ -3326,12 +3127,9 @@ mod tests { // } #[test] - #[available_gas(90000)] + #[available_gas(171784)] fn test_equip_valid_head() { - let starting_stats = Stats { - strength: 0, dexterity: 0, vitality: 0, intelligence: 0, wisdom: 0, charisma: 0, luck: 0 - }; - let mut adventurer = ImplAdventurer::new(12, 0, starting_stats); + let mut adventurer = ImplAdventurer::new(12, 0, 0, 0); // equip Crown as head item let item = ItemPrimitive { id: ItemId::Crown, xp: 1, metadata: 0 }; adventurer.equip_head_armor(item); @@ -3351,7 +3149,7 @@ mod tests { // let starting_stats = Stats { // strength: 0, dexterity: 0, vitality: 0, intelligence: 0, wisdom: 0, charisma: 0, luck: 0 // }; - // let mut adventurer = ImplAdventurer::new(12, 0, starting_stats); + // let mut adventurer = ImplAdventurer::new(12, 0, 0, 0); // // try to equip a Demon Crown as waist item // let item = ItemPrimitive { id: ItemId::DemonCrown, xp: 1, metadata: 0 }; // adventurer.equip_waist_armor(item); @@ -3359,12 +3157,9 @@ mod tests { // } #[test] - #[available_gas(90000)] + #[available_gas(171784)] fn test_equip_valid_waist() { - let starting_stats = Stats { - strength: 0, dexterity: 0, vitality: 0, intelligence: 0, wisdom: 0, charisma: 0, luck: 0 - }; - let mut adventurer = ImplAdventurer::new(12, 0, starting_stats); + let mut adventurer = ImplAdventurer::new(12, 0, 0, 0); // equip Wool Sash as waist item let item = ItemPrimitive { id: ItemId::WoolSash, xp: 1, metadata: 0 }; @@ -3386,7 +3181,7 @@ mod tests { // let starting_stats = Stats { // strength: 0, dexterity: 0, vitality: 0, intelligence: 0, wisdom: 0, charisma: 0, luck: 0 // }; - // let mut adventurer = ImplAdventurer::new(12, 0, starting_stats); + // let mut adventurer = ImplAdventurer::new(12, 0, 0, 0); // // try to equip a Demon Crown as foot item // let item = ItemPrimitive { id: ItemId::DemonCrown, xp: 1, metadata: 0 }; // adventurer.equip_foot_armor(item); @@ -3394,12 +3189,9 @@ mod tests { // } #[test] - #[available_gas(90000)] + #[available_gas(171784)] fn test_equip_valid_foot() { - let starting_stats = Stats { - strength: 0, dexterity: 0, vitality: 0, intelligence: 0, wisdom: 0, charisma: 0, luck: 0 - }; - let mut adventurer = ImplAdventurer::new(12, 0, starting_stats); + let mut adventurer = ImplAdventurer::new(12, 0, 0, 0); // equip Silk Slippers as foot item let item = ItemPrimitive { id: ItemId::SilkSlippers, xp: 1, metadata: 0 }; @@ -3421,7 +3213,7 @@ mod tests { // let starting_stats = Stats { // strength: 0, dexterity: 0, vitality: 0, intelligence: 0, wisdom: 0, charisma: 0, luck: 0 // }; - // let mut adventurer = ImplAdventurer::new(12, 0, starting_stats); + // let mut adventurer = ImplAdventurer::new(12, 0, 0, 0); // // try to equip a Demon Crown as hand item // let item = ItemPrimitive { id: ItemId::DemonCrown, xp: 1, metadata: 0 }; @@ -3430,12 +3222,9 @@ mod tests { // } #[test] - #[available_gas(90000)] + #[available_gas(171784)] fn test_equip_valid_hand() { - let starting_stats = Stats { - strength: 0, dexterity: 0, vitality: 0, intelligence: 0, wisdom: 0, charisma: 0, luck: 0 - }; - let mut adventurer = ImplAdventurer::new(12, 0, starting_stats); + let mut adventurer = ImplAdventurer::new(12, 0, 0, 0); // equip Divine Gloves as hand item let item = ItemPrimitive { id: ItemId::DivineGloves, xp: 1, metadata: 0 }; @@ -3457,7 +3246,7 @@ mod tests { // let starting_stats = Stats { // strength: 0, dexterity: 0, vitality: 0, intelligence: 0, wisdom: 0, charisma: 0, luck: 0 // }; - // let mut adventurer = ImplAdventurer::new(12, 0, starting_stats); + // let mut adventurer = ImplAdventurer::new(12, 0, 0, 0); // // try to equip a Demon Crown as necklace // let item = ItemPrimitive { id: ItemId::DemonCrown, xp: 1, metadata: 0 }; @@ -3466,12 +3255,9 @@ mod tests { // } #[test] - #[available_gas(90000)] + #[available_gas(171784)] fn test_equip_valid_neck() { - let starting_stats = Stats { - strength: 0, dexterity: 0, vitality: 0, intelligence: 0, wisdom: 0, charisma: 0, luck: 0 - }; - let mut adventurer = ImplAdventurer::new(12, 0, starting_stats); + let mut adventurer = ImplAdventurer::new(12, 0, 0, 0); // equip Pendant as necklace let item = ItemPrimitive { id: ItemId::Pendant, xp: 1, metadata: 0 }; @@ -3493,7 +3279,7 @@ mod tests { // let starting_stats = Stats { // strength: 0, dexterity: 0, vitality: 0, intelligence: 0, wisdom: 0, charisma: 0, luck: 0 // }; - // let mut adventurer = ImplAdventurer::new(12, 0, starting_stats); + // let mut adventurer = ImplAdventurer::new(12, 0, 0, 0); // // try to equip a Demon Crown as ring // let item = ItemPrimitive { id: ItemId::DemonCrown, xp: 1, metadata: 0 }; @@ -3502,15 +3288,9 @@ mod tests { // } #[test] - #[available_gas(90000)] + #[available_gas(171784)] fn test_equip_valid_ring() { - let mut adventurer = ImplAdventurer::new( - 12, - 0, - Stats { - strength: 0, dexterity: 0, vitality: 0, intelligence: 0, wisdom: 0, charisma: 0, luck: 0 - } - ); + let mut adventurer = ImplAdventurer::new(12, 0, 0, 0); let item = ItemPrimitive { id: ItemId::PlatinumRing, xp: 1, metadata: 0 }; adventurer.equip_ring(item); assert(adventurer.ring.id == ItemId::PlatinumRing, 'did not equip ring'); @@ -3519,28 +3299,16 @@ mod tests { } #[test] - #[available_gas(51230)] + #[available_gas(196284)] fn test_increase_item_xp_at_slot_gas() { - let mut adventurer = ImplAdventurer::new( - 12, - 0, - Stats { - strength: 0, dexterity: 0, vitality: 0, intelligence: 0, wisdom: 0, charisma: 0, luck: 0 - } - ); + let mut adventurer = ImplAdventurer::new(12, 0, 0, 0); adventurer.increase_item_xp_at_slot(Slot::Weapon(()), 1); } #[test] - #[available_gas(237530)] + #[available_gas(382584)] fn test_increase_item_xp_at_slot() { - let mut adventurer = ImplAdventurer::new( - 12, - 0, - Stats { - strength: 0, dexterity: 0, vitality: 0, intelligence: 0, wisdom: 0, charisma: 0, luck: 0 - } - ); + let mut adventurer = ImplAdventurer::new(12, 0, 0, 0); // assert starting conditions assert(adventurer.weapon.xp == 0, 'weapon should start with 0xp'); @@ -3578,15 +3346,9 @@ mod tests { } #[test] - #[available_gas(52030)] + #[available_gas(197084)] fn test_increase_item_xp_at_slot_max() { - let mut adventurer = ImplAdventurer::new( - 12, - 0, - Stats { - strength: 0, dexterity: 0, vitality: 0, intelligence: 0, wisdom: 0, charisma: 0, luck: 0 - } - ); + let mut adventurer = ImplAdventurer::new(12, 0, 0, 0); assert(adventurer.weapon.xp == 0, 'weapon should start with 0xp'); adventurer.increase_item_xp_at_slot(Slot::Weapon(()), 65535); @@ -3594,15 +3356,9 @@ mod tests { } #[test] - #[available_gas(52030)] + #[available_gas(197084)] fn test_increase_item_xp_at_slot_zero() { - let mut adventurer = ImplAdventurer::new( - 12, - 0, - Stats { - strength: 0, dexterity: 0, vitality: 0, intelligence: 0, wisdom: 0, charisma: 0, luck: 0 - } - ); + let mut adventurer = ImplAdventurer::new(12, 0, 0, 0); assert(adventurer.weapon.xp == 0, 'weapon should start with 0xp'); adventurer.increase_item_xp_at_slot(Slot::Weapon(()), 0); @@ -3610,15 +3366,9 @@ mod tests { } #[test] - #[available_gas(303210)] + #[available_gas(448264)] fn test_get_equipped_items() { - let mut adventurer = ImplAdventurer::new( - ItemId::Wand, - 0, - Stats { - strength: 0, dexterity: 0, vitality: 0, intelligence: 0, wisdom: 0, charisma: 0, luck: 0 - } - ); + let mut adventurer = ImplAdventurer::new(ItemId::Wand, 0, 0, 0); let starting_equipment = adventurer.get_equipped_items(); assert(starting_equipment.len() == 1, 'adventurer starts with 1 item'); @@ -3733,14 +3483,9 @@ mod tests { } #[test] - #[available_gas(90000)] - #[test] - #[available_gas(60000)] + #[available_gas(184344)] fn test_set_beast_health() { - let starting_stats = Stats { - strength: 0, dexterity: 0, vitality: 0, intelligence: 0, wisdom: 0, charisma: 0, luck: 0 - }; - let mut adventurer = ImplAdventurer::new(12, 0, starting_stats); + let mut adventurer = ImplAdventurer::new(12, 0, 0, 0); // base case adventurer.set_beast_health(100); @@ -3754,12 +3499,9 @@ mod tests { } #[test] - #[available_gas(90000)] + #[available_gas(194364)] fn test_deduct_beast_health() { - let starting_stats = Stats { - strength: 0, dexterity: 0, vitality: 0, intelligence: 0, wisdom: 0, charisma: 0, luck: 0 - }; - let mut adventurer = ImplAdventurer::new(12, 0, starting_stats); + let mut adventurer = ImplAdventurer::new(12, 0, 0, 0); // stage beast with 100 adventurer.set_beast_health(100); @@ -3791,13 +3533,7 @@ mod tests { #[test] #[available_gas(300000)] fn test_get_item_at_slot() { - let mut adventurer = ImplAdventurer::new( - 12, - 0, - Stats { - strength: 0, dexterity: 0, vitality: 0, intelligence: 0, wisdom: 0, charisma: 0, luck: 0 - } - ); + let mut adventurer = ImplAdventurer::new(12, 0, 0, 0); // stage items let weapon = ItemPrimitive { id: ItemId::Katana, xp: 1, metadata: 1 }; @@ -3831,15 +3567,9 @@ mod tests { } #[test] - #[available_gas(340000)] + #[available_gas(352884)] fn test_is_slot_free() { - let mut adventurer = ImplAdventurer::new( - 12, - 0, - Stats { - strength: 0, dexterity: 0, vitality: 0, intelligence: 0, wisdom: 0, charisma: 0, luck: 0 - } - ); + let mut adventurer = ImplAdventurer::new(12, 0, 0, 0); // stage items let weapon = ItemPrimitive { id: ItemId::Katana, xp: 1, metadata: 1 }; @@ -3871,10 +3601,7 @@ mod tests { #[test] #[available_gas(600000)] fn test_get_level() { - let starting_stats = Stats { - strength: 0, dexterity: 0, vitality: 0, intelligence: 0, wisdom: 0, charisma: 0, luck: 0 - }; - let mut adventurer = ImplAdventurer::new(12, 0, starting_stats); + let mut adventurer = ImplAdventurer::new(12, 0, 0, 0); assert(adventurer.get_level() == 1, 'level should be 1'); adventurer.xp = 4; @@ -3896,12 +3623,9 @@ mod tests { } #[test] - #[available_gas(200000)] + #[available_gas(233824)] fn test_charisma_health_discount_overflow() { - let starting_stats = Stats { - strength: 0, dexterity: 0, vitality: 0, intelligence: 0, wisdom: 0, charisma: 0, luck: 0 - }; - let mut adventurer = ImplAdventurer::new(12, 0, starting_stats); + let mut adventurer = ImplAdventurer::new(12, 0, 0, 0); // max charisma adventurer.stats.charisma = 255; @@ -3917,12 +3641,9 @@ mod tests { } #[test] - #[available_gas(200000)] + #[available_gas(233824)] fn test_charisma_item_discount_overflow() { - let starting_stats = Stats { - strength: 0, dexterity: 0, vitality: 0, intelligence: 0, wisdom: 0, charisma: 0, luck: 0 - }; - let mut adventurer = ImplAdventurer::new(12, 0, starting_stats); + let mut adventurer = ImplAdventurer::new(12, 0, 0, 0); let item_price = 15; // no charisma case @@ -3946,13 +3667,9 @@ mod tests { } #[test] - #[available_gas(150000)] + #[available_gas(255224)] fn test_increase_xp() { - // initialize lvl 1 adventurer with no stat points available - let starting_stats = Stats { - strength: 0, dexterity: 0, vitality: 0, intelligence: 0, wisdom: 0, charisma: 0, luck: 0 - }; - let mut adventurer = ImplAdventurer::new(12, 0, starting_stats); + let mut adventurer = ImplAdventurer::new(12, 0, 0, 0); // increase adventurer xp by 3 which should level up the adventurer adventurer.increase_adventurer_xp(4); @@ -3964,12 +3681,9 @@ mod tests { } #[test] - #[available_gas(148630)] + #[available_gas(293684)] fn test_apply_suffix_boost() { - let starting_stats = Stats { - strength: 0, dexterity: 0, vitality: 0, intelligence: 0, wisdom: 0, charisma: 0, luck: 0 - }; - let mut adventurer = ImplAdventurer::new(12, 0, starting_stats); + let mut adventurer = ImplAdventurer::new(12, 0, 0, 0); adventurer.stats.apply_suffix_boost(ItemSuffix::of_Power); assert(adventurer.stats.strength == 3, 'strength should be 3'); @@ -4015,10 +3729,7 @@ mod tests { #[test] #[available_gas(1900000)] fn test_remove_suffix_boost() { - let starting_stats = Stats { - strength: 0, dexterity: 0, vitality: 0, intelligence: 0, wisdom: 0, charisma: 0, luck: 0 - }; - let mut adventurer = ImplAdventurer::new(12, 0, starting_stats); + let mut adventurer = ImplAdventurer::new(12, 0, 0, 0); // verify starting state assert(adventurer.stats.strength == 0, 'strength should be 0'); @@ -4041,7 +3752,13 @@ mod tests { health: 100, xp: 1, stats: Stats { - strength: 0, dexterity: 0, vitality: 0, intelligence: 0, wisdom: 0, charisma: 0, luck: 0 + strength: 0, + dexterity: 0, + vitality: 0, + intelligence: 0, + wisdom: 0, + charisma: 0, + luck: 0 }, gold: 40, weapon: ItemPrimitive { id: 1, xp: 225, metadata: 1, }, @@ -4119,15 +3836,9 @@ mod tests { // test base case #[test] - #[available_gas(62270)] + #[available_gas(207324)] fn test_apply_stat_boosts() { - let mut adventurer = ImplAdventurer::new( - 12, - 0, - Stats { - strength: 0, dexterity: 0, vitality: 0, intelligence: 0, wisdom: 0, charisma: 0, luck: 0 - } - ); + let mut adventurer = ImplAdventurer::new(12, 0, 0, 0); let boost_stats = Stats { strength: 5, dexterity: 1, vitality: 5, intelligence: 1, wisdom: 1, charisma: 2, luck: 1 @@ -4145,15 +3856,9 @@ mod tests { // test zero case #[test] - #[available_gas(62270)] + #[available_gas(207324)] fn test_apply_stat_boosts_zero() { - let mut adventurer = ImplAdventurer::new( - 12, - 0, - Stats { - strength: 0, dexterity: 0, vitality: 0, intelligence: 0, wisdom: 0, charisma: 0, luck: 0 - } - ); + let mut adventurer = ImplAdventurer::new(12, 0, 0, 0); let boost_stats = Stats { strength: 0, dexterity: 0, vitality: 0, intelligence: 0, wisdom: 0, charisma: 0, luck: 0 @@ -4170,15 +3875,9 @@ mod tests { // test max value case #[test] - #[available_gas(62270)] + #[available_gas(207324)] fn test_apply_stat_boosts_max() { - let mut adventurer = ImplAdventurer::new( - 12, - 0, - Stats { - strength: 0, dexterity: 0, vitality: 0, intelligence: 0, wisdom: 0, charisma: 0, luck: 0 - } - ); + let mut adventurer = ImplAdventurer::new(12, 0, 0, 0); let boost_stats = Stats { strength: 255, dexterity: 255, @@ -4202,16 +3901,41 @@ mod tests { #[test] #[available_gas(53430)] fn test_remove_stat_boosts() { - let mut adventurer = ImplAdventurer::new( - 12, - 0, - Stats { - strength: 5, dexterity: 4, vitality: 3, intelligence: 2, wisdom: 1, charisma: 0, luck: 0 - } - ); + let mut adventurer = Adventurer { + last_action: 511, + health: 100, + xp: 1, + stats: Stats { + strength: 5, + dexterity: 4, + vitality: 3, + intelligence: 2, + wisdom: 1, + charisma: 0, + 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, }, + beast_health: 20, + stat_points_available: 0, + mutated: false, + }; let boost_stats = Stats { - strength: 5, dexterity: 4, vitality: 3, intelligence: 2, wisdom: 1, charisma: 20, luck: 1 + strength: 5, + dexterity: 4, + vitality: 3, + intelligence: 2, + wisdom: 1, + charisma: 20, + luck: 1 }; adventurer.remove_stat_boosts(boost_stats); @@ -4227,13 +3951,32 @@ mod tests { #[test] #[available_gas(53430)] fn test_remove_stat_boosts_zero() { - let mut adventurer = ImplAdventurer::new( - 12, - 0, - Stats { - strength: 5, dexterity: 4, vitality: 3, intelligence: 2, wisdom: 1, charisma: 0, luck: 1 - } - ); + let mut adventurer = Adventurer { + last_action: 511, + health: 100, + xp: 1, + stats: Stats { + strength: 5, + dexterity: 4, + vitality: 3, + intelligence: 2, + wisdom: 1, + charisma: 0, + 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, }, + beast_health: 20, + stat_points_available: 0, + mutated: false, + }; let boost_stats = Stats { strength: 0, dexterity: 0, vitality: 0, intelligence: 0, wisdom: 0, charisma: 0, luck: 0 @@ -4252,13 +3995,32 @@ mod tests { #[test] #[available_gas(53430)] fn test_remove_stat_boosts_max() { - let mut adventurer = ImplAdventurer::new( - 12, - 0, - Stats { - strength: 5, dexterity: 4, vitality: 3, intelligence: 2, wisdom: 1, charisma: 0, luck: 0 - } - ); + let mut adventurer = Adventurer { + last_action: 511, + health: 100, + xp: 1, + stats: Stats { + strength: 5, + dexterity: 4, + vitality: 3, + intelligence: 2, + wisdom: 1, + charisma: 0, + 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, }, + beast_health: 20, + stat_points_available: 0, + mutated: false, + }; let boost_stats = Stats { strength: 255, @@ -4282,10 +4044,7 @@ mod tests { #[test] #[available_gas(390000)] fn test_discover_treasure() { - let starting_stats = Stats { - strength: 0, dexterity: 0, vitality: 0, intelligence: 0, wisdom: 0, charisma: 0, luck: 0 - }; - let mut adventurer = ImplAdventurer::new(12, 0, starting_stats); + let mut adventurer = ImplAdventurer::new(12, 0, 0, 0); // give vitality so we can discover health adventurer.stats.vitality = 1; @@ -4303,29 +4062,17 @@ mod tests { } #[test] - #[available_gas(161530)] + #[available_gas(242984)] fn test_calculate_luck_gas_no_luck() { - let mut adventurer = ImplAdventurer::new( - 12, - 0, - Stats { - strength: 0, dexterity: 0, vitality: 0, intelligence: 0, wisdom: 0, charisma: 0, luck: 0 - } - ); + let mut adventurer = ImplAdventurer::new(12, 0, 0, 0); let bag = ImplBag::new(); assert(adventurer.calculate_luck(bag) == 2, 'start with 2 luck'); } #[test] - #[available_gas(161530)] + #[available_gas(246784)] fn test_calculate_luck_gas_with_luck() { - let mut adventurer = ImplAdventurer::new( - 12, - 0, - Stats { - strength: 0, dexterity: 0, vitality: 0, intelligence: 0, wisdom: 0, charisma: 0, luck: 0 - } - ); + let mut adventurer = ImplAdventurer::new(12, 0, 0, 0); let bag = ImplBag::new(); let neck = ItemPrimitive { id: ItemId::Amulet, xp: 1, metadata: 7 }; @@ -4336,15 +4083,9 @@ mod tests { } #[test] - #[available_gas(983740)] + #[available_gas(685924)] fn test_calculate_luck() { - let mut adventurer = ImplAdventurer::new( - 12, - 0, - Stats { - strength: 0, dexterity: 0, vitality: 0, intelligence: 0, wisdom: 0, charisma: 0, luck: 0 - } - ); + let mut adventurer = ImplAdventurer::new(12, 0, 0, 0); let bag = ImplBag::new(); assert(adventurer.calculate_luck(bag) == 2, 'start with 2 luck'); @@ -4378,15 +4119,9 @@ mod tests { } #[test] - #[available_gas(45000)] + #[available_gas(177584)] fn test_in_battle() { - let mut adventurer = ImplAdventurer::new( - 12, - 0, - Stats { - strength: 0, dexterity: 0, vitality: 0, intelligence: 0, wisdom: 0, charisma: 0, luck: 0 - } - ); + let mut adventurer = ImplAdventurer::new(12, 0, 0, 0); assert(adventurer.in_battle() == true, 'new advntr start in battle'); adventurer.beast_health = 0; @@ -4400,10 +4135,7 @@ mod tests { #[test] #[available_gas(550000)] fn test_equip_item() { - let starting_stats = Stats { - strength: 0, dexterity: 0, vitality: 0, intelligence: 0, wisdom: 0, charisma: 0, luck: 0 - }; - let mut adventurer = ImplAdventurer::new(12, 0, starting_stats); + let mut adventurer = ImplAdventurer::new(12, 0, 0, 0); // assert starting conditions assert(adventurer.weapon.id == 12, 'weapon should be 12'); @@ -4448,12 +4180,9 @@ mod tests { #[test] #[available_gas(1000000)] fn test_is_equipped() { + let mut adventurer = ImplAdventurer::new(12, 0, 0, 0); let wand = ItemPrimitive { id: ItemId::Wand, xp: 1, metadata: 1 }; let demon_crown = ItemPrimitive { id: ItemId::DemonCrown, xp: 1, metadata: 2 }; - let starting_stats = Stats { - strength: 0, dexterity: 0, vitality: 0, intelligence: 0, wisdom: 0, charisma: 0, luck: 0 - }; - let mut adventurer = ImplAdventurer::new(12, 0, starting_stats); // assert starting state assert(adventurer.weapon.id == wand.id, 'weapon should be wand'); @@ -4587,13 +4316,9 @@ mod tests { #[test] #[should_panic(expected: ('item is not equipped',))] - #[available_gas(50000)] + #[available_gas(172784)] fn test_drop_item_not_equipped() { - // instantiate adventurer - let starting_stats = Stats { - strength: 0, dexterity: 0, vitality: 0, intelligence: 0, wisdom: 0, charisma: 0, luck: 0 - }; - let mut adventurer = ImplAdventurer::new(12, 0, starting_stats); + let mut adventurer = ImplAdventurer::new(12, 0, 0, 0); // try to drop an item that isn't equipped // this should panic with 'item is not equipped' // the test is annotated to expect this panic @@ -4601,12 +4326,9 @@ mod tests { } #[test] - #[available_gas(700000)] + #[available_gas(507684)] fn test_drop_item() { - let starting_stats = Stats { - strength: 0, dexterity: 0, vitality: 0, intelligence: 0, wisdom: 0, charisma: 0, luck: 0 - }; - let mut adventurer = ImplAdventurer::new(12, 0, starting_stats); + let mut adventurer = ImplAdventurer::new(12, 0, 0, 0); // assert starting conditions assert(adventurer.weapon.id == ItemId::Wand, 'weapon should be wand'); @@ -4688,15 +4410,9 @@ mod tests { } #[test] - #[available_gas(274270)] + #[available_gas(419324)] fn test_is_ambush() { - let mut adventurer = ImplAdventurer::new( - 12, - 0, - Stats { - strength: 0, dexterity: 0, vitality: 0, intelligence: 0, wisdom: 0, charisma: 0, luck: 0 - } - ); + let mut adventurer = ImplAdventurer::new(12, 0, 0, 0); // without any wisdom, should get ambushed by all entropy assert(adventurer.is_ambushed(1), 'no wisdom should get ambushed'); diff --git a/contracts/adventurer/src/adventurer_utils.cairo b/contracts/adventurer/src/adventurer_utils.cairo index 59e731683..bbeef0ffa 100644 --- a/contracts/adventurer/src/adventurer_utils.cairo +++ b/contracts/adventurer/src/adventurer_utils.cairo @@ -23,7 +23,10 @@ use lootitems::constants::{ } }; use combat::constants::CombatEnums::{Type, Tier, Slot}; -use pack::pack::{rshift_split}; +use pack::{ + pack::{rshift_split}, + constants::{MASK_16, pow, MASK_8, MASK_3, MASK_BOOL, mask, U128_MASK_8, u128_pow} +}; #[generate_trait] impl AdventurerUtils of IAdventurerUtils { @@ -216,6 +219,72 @@ impl AdventurerUtils of IAdventurerUtils { let (d, r) = rshift_split(felt_to_split.into(), U128_MAX.into()); (r.try_into().unwrap(), d.try_into().unwrap()) } + + fn generate_starting_stats(entropy: u128, starting_stat_count: u8) -> Stats { + let mut starting_stats = Stats { + strength: 0, + dexterity: 0, + vitality: 0, + charisma: 0, + intelligence: 0, + wisdom: 0, + luck: 0, + }; + + let random_outcomes = AdventurerUtils::u128_to_u8_array(entropy); + + // TODO: Use conditional compilation to only run this check in debug mode as not to waste gas in production + assert(starting_stat_count.into() < random_outcomes.len(), 'stat count out of bounds'); + + let mut i = 0; + loop { + if i == starting_stat_count.into() { + break; + } + let random_u8 = *random_outcomes.at(i); + let random_stat_index = random_u8 % 6; + if random_stat_index == 0 { + starting_stats.strength += 1; + } else if random_stat_index == 1 { + starting_stats.dexterity += 1; + } else if random_stat_index == 2 { + starting_stats.vitality += 1; + } else if random_stat_index == 3 { + starting_stats.charisma += 1; + } else if random_stat_index == 4 { + starting_stats.intelligence += 1; + } else if random_stat_index == 5 { + starting_stats.wisdom += 1; + } else { + panic_with_felt252('stat out of range'); + } + + i += 1; + }; + + starting_stats + } + + fn u128_to_u8_array(value: u128) -> Array { + let mut result = ArrayTrait::::new(); + result.append((value & U128_MASK_8).try_into().unwrap()); + result.append(((value / u128_pow::_8) & U128_MASK_8).try_into().unwrap()); + result.append(((value / u128_pow::_16) & U128_MASK_8).try_into().unwrap()); + result.append(((value / u128_pow::_24) & U128_MASK_8).try_into().unwrap()); + result.append(((value / u128_pow::_32) & U128_MASK_8).try_into().unwrap()); + result.append(((value / u128_pow::_40) & U128_MASK_8).try_into().unwrap()); + result.append(((value / u128_pow::_48) & U128_MASK_8).try_into().unwrap()); + result.append(((value / u128_pow::_56) & U128_MASK_8).try_into().unwrap()); + result.append(((value / u128_pow::_64) & U128_MASK_8).try_into().unwrap()); + result.append(((value / u128_pow::_72) & U128_MASK_8).try_into().unwrap()); + result.append(((value / u128_pow::_80) & U128_MASK_8).try_into().unwrap()); + result.append(((value / u128_pow::_88) & U128_MASK_8).try_into().unwrap()); + result.append(((value / u128_pow::_96) & U128_MASK_8).try_into().unwrap()); + result.append(((value / u128_pow::_104) & U128_MASK_8).try_into().unwrap()); + result.append(((value / u128_pow::_112) & U128_MASK_8).try_into().unwrap()); + result.append(((value / u128_pow::_120) & U128_MASK_8).try_into().unwrap()); + result + } } // --------------------------- @@ -223,6 +292,7 @@ impl AdventurerUtils of IAdventurerUtils { // --------------------------- #[cfg(test)] mod tests { + use poseidon::poseidon_hash_span; use survivor::{ constants::{ adventurer_constants::{ @@ -235,13 +305,167 @@ mod tests { adventurer_utils::AdventurerUtils }; use combat::constants::CombatEnums::{Type, Tier, Slot}; + #[test] + #[available_gas(166544)] + fn test_generate_starting_stats_gas() { + AdventurerUtils::generate_starting_stats(0, 1); + } + #[test] - #[available_gas(150000)] - fn test_is_health_full() { - let starting_stats = Stats { - strength: 0, dexterity: 0, vitality: 0, intelligence: 0, wisdom: 0, charisma: 0, luck: 0 + #[available_gas(166544)] + #[should_panic(expected: ('stat count out of bounds',))] + fn test_generate_starting_stats_fail_out_of_bounds() { + AdventurerUtils::generate_starting_stats(0, 20); + } + + #[test] + #[available_gas(1924040)] + fn test_generate_starting_stats() { + let starting_stat_count = 9; + + // zero case + let entropy = 0; + let stats = AdventurerUtils::generate_starting_stats(entropy, starting_stat_count); + let stat_count = stats.strength + + stats.dexterity + + stats.vitality + + stats.intelligence + + stats.wisdom + + stats.charisma; + assert(stat_count == starting_stat_count, 'wrong stat total'); + assert(stats.strength == 9, 'strength should be 9'); + assert(stats.dexterity == 0, 'dexterity should be 0'); + assert(stats.vitality == 0, 'vitality should be 0'); + assert(stats.intelligence == 0, 'intelligence should be 0'); + assert(stats.wisdom == 0, 'wisdom should be 0'); + assert(stats.charisma == 0, 'charisma should be 0'); + + // max u128 case + let entropy = 0xffffffffffffffffffffffffffffffff; + let stats = AdventurerUtils::generate_starting_stats(entropy, starting_stat_count); + let stat_count = stats.strength + + stats.dexterity + + stats.vitality + + stats.intelligence + + stats.wisdom + + stats.charisma; + assert(stat_count == starting_stat_count, 'wrong stat total'); + assert(stats.strength == 0, 'strength should be 0'); + assert(stats.dexterity == 0, 'dexterity should be 0'); + assert(stats.vitality == 0, 'vitality should be 0'); + assert(stats.intelligence == 0, 'intelligence should be 0'); + assert(stats.wisdom == 0, 'wisdom should be 0'); + assert(stats.charisma == 9, 'charisma should be 9'); + + let mut hash_span = ArrayTrait::new(); + hash_span.append(241); + hash_span.append(14212); + let poseidon = poseidon_hash_span(hash_span.span()); + let (rnd1, rnd2) = AdventurerUtils::split_hash(poseidon); + let stats = AdventurerUtils::generate_starting_stats(rnd1, starting_stat_count); + let stat_count = stats.strength + + stats.dexterity + + stats.vitality + + stats.intelligence + + stats.wisdom + + stats.charisma; + assert(stat_count == starting_stat_count, 'wrong stat total'); + assert(stats.strength == 1, 'strength should be 1'); + assert(stats.dexterity == 1, 'dexterity should be 1'); + assert(stats.vitality == 2, 'vitality should be 2'); + assert(stats.intelligence == 1, 'intelligence should be 1'); + assert(stats.wisdom == 4, 'wisdom should be 4'); + assert(stats.charisma == 0, 'charisma should be 0'); + + let stats = AdventurerUtils::generate_starting_stats(rnd2, starting_stat_count); + let stat_count = stats.strength + + stats.dexterity + + stats.vitality + + stats.intelligence + + stats.wisdom + + stats.charisma; + assert(stat_count == starting_stat_count, 'wrong stat total'); + assert(stats.strength == 0, 'strength should be 0'); + assert(stats.dexterity == 1, 'dexterity should be 1'); + assert(stats.vitality == 3, 'vitality should be 3'); + assert(stats.intelligence == 4, 'intelligence should be 4'); + assert(stats.wisdom == 1, 'wisdom should be 1'); + assert(stats.charisma == 0, 'charisma should be 0'); + + let stats = AdventurerUtils::generate_starting_stats(rnd2, starting_stat_count + 5); + let stat_count = stats.strength + + stats.dexterity + + stats.vitality + + stats.intelligence + + stats.wisdom + + stats.charisma; + assert(stat_count == starting_stat_count + 5, 'wrong stat total'); + assert(stats.strength == 0, 'strength should be 0'); + assert(stats.dexterity == 3, 'dexterity should be 3'); + assert(stats.vitality == 4, 'vitality should be 4'); + assert(stats.intelligence == 5, 'intelligence should be 5'); + assert(stats.wisdom == 1, 'wisdom should be 1'); + assert(stats.charisma == 1, 'charisma should be 1'); + } + + #[test] + #[available_gas(1448412)] + fn test_u128_to_u8_array() { + // zero case + let value = 0; + let values = AdventurerUtils::u128_to_u8_array(value); + let mut i = 0; + loop { + if i == values.len() { + break; + } + + let value = *values.at(i); + assert(value == 0, 'all values should be 0'); + i += 1; }; - let mut adventurer = ImplAdventurer::new(12, 0, starting_stats); + + // max u128 case + let value = 0xffffffffffffffffffffffffffffffff; + let values = AdventurerUtils::u128_to_u8_array(value); + let mut i = 0; + loop { + if i == values.len() { + break; + } + + let value = *values.at(i); + assert(value == 255, 'all values should be 1'); + i += 1; + }; + + // random case + let value = + 0b00000110110100110000110010010111000001000110111100110010001111010010000001111110000110100111101100010101000000001111111101100101; + + let values = AdventurerUtils::u128_to_u8_array(value); + assert(*values.at(15) == 6, 'rand15 should be 6'); + assert(*values.at(14) == 211, 'rand14 should be 211'); + assert(*values.at(13) == 12, 'rand13 should be 12'); + assert(*values.at(12) == 151, 'rand12 should be 151'); + assert(*values.at(11) == 4, 'rand11 should be 4'); + assert(*values.at(10) == 111, 'rand10 should be 111'); + assert(*values.at(9) == 50, 'rand9 should be 50'); + assert(*values.at(8) == 61, 'rand8 should be 61'); + assert(*values.at(7) == 32, 'rand7 should be 32'); + assert(*values.at(6) == 126, 'rand6 should be 126'); + assert(*values.at(5) == 26, 'rand5 should be 26'); + assert(*values.at(4) == 123, 'rand4 should be 123'); + assert(*values.at(3) == 21, 'rand3 should be 21'); + assert(*values.at(2) == 0, 'rand2 should be 0'); + assert(*values.at(1) == 255, 'rand1 should be 255'); + assert(*values.at(0) == 101, 'rand0 should be 101'); + } + + #[test] + #[available_gas(259044)] + fn test_is_health_full() { + let mut adventurer = ImplAdventurer::new(12, 0, 0, 0); // adventurers should start with full health assert( @@ -273,12 +497,9 @@ mod tests { } #[test] - #[available_gas(200000)] + #[available_gas(204804)] fn test_get_max_health() { - let starting_stats = Stats { - strength: 0, dexterity: 0, vitality: 0, intelligence: 0, wisdom: 0, charisma: 0, luck: 0 - }; - let mut adventurer = ImplAdventurer::new(12, 0, starting_stats); + let mut adventurer = ImplAdventurer::new(12, 0, 0, 0); // assert starting state assert( diff --git a/contracts/adventurer/src/constants/adventurer_constants.cairo b/contracts/adventurer/src/constants/adventurer_constants.cairo index 916098fcb..def037ca6 100644 --- a/contracts/adventurer/src/constants/adventurer_constants.cairo +++ b/contracts/adventurer/src/constants/adventurer_constants.cairo @@ -87,3 +87,9 @@ mod ClassStatBoosts { const U128_MAX: u128 = 340282366920938463463374607431768211455; const MAX_U128_PRIME: u128 = 340282366920938463463374607431768211383; + +const TWO_POW_8: u128 = 0x100; +const TWO_POW_40: u128 = 0x10000000000; + +const MASK_8: u128 = 0xff; +const MASK_32: u128 = 0xffffffff; \ No newline at end of file diff --git a/contracts/adventurer/src/exploration.cairo b/contracts/adventurer/src/exploration.cairo index 61b69ddd8..6c1d59db3 100644 --- a/contracts/adventurer/src/exploration.cairo +++ b/contracts/adventurer/src/exploration.cairo @@ -3,9 +3,7 @@ use core::traits::{Into, TryInto}; use survivor::{ adventurer::{Adventurer, ImplAdventurer, ItemPrimitive}, - constants::discovery_constants::{ - DiscoveryEnums::DiscoveryType, DiscoveryEnums::ExploreResult - } + constants::discovery_constants::{DiscoveryEnums::DiscoveryType, DiscoveryEnums::ExploreResult} }; use lootitems::constants::ItemId; @@ -73,29 +71,17 @@ mod tests { use lootitems::constants::ItemId; #[test] - #[available_gas(55960)] + #[available_gas(328154)] fn test_get_gold_discovery_gas() { - let adventurer = ImplAdventurer::new( - 12, - 0, - Stats { - strength: 1, dexterity: 1, vitality: 1, intelligence: 1, wisdom: 1, charisma: 1, luck: 1 - } - ); + let adventurer = ImplAdventurer::new(12, 6, 0, 0); let entropy = 0; ExploreUtils::get_gold_discovery(adventurer, entropy); } #[test] - #[available_gas(56460)] + #[available_gas(328654)] fn test_get_gold_discovery() { - let mut adventurer = ImplAdventurer::new( - 12, - 0, - Stats { - strength: 1, dexterity: 1, vitality: 1, intelligence: 1, wisdom: 1, charisma: 1, luck: 1 - } - ); + let mut adventurer = ImplAdventurer::new(12, 6, 0, 0); // base discovery for level 1 adventurer with 0 entropy should be 1 let entropy = 0; @@ -104,29 +90,17 @@ mod tests { } #[test] - #[available_gas(55960)] + #[available_gas(328154)] fn test_get_health_discovery_gas() { - let adventurer = ImplAdventurer::new( - 12, - 0, - Stats { - strength: 1, dexterity: 1, vitality: 1, intelligence: 1, wisdom: 1, charisma: 1, luck: 1 - } - ); + let adventurer = ImplAdventurer::new(12, 6, 0, 0); let entropy = 12345; ExploreUtils::get_health_discovery(adventurer, entropy); } #[test] - #[available_gas(56460)] + #[available_gas(328654)] fn test_get_health_discovery() { - let mut adventurer = ImplAdventurer::new( - 12, - 0, - Stats { - strength: 1, dexterity: 1, vitality: 1, intelligence: 1, wisdom: 1, charisma: 1, luck: 1 - } - ); + let mut adventurer = ImplAdventurer::new(12, 6, 0, 0); // base discovery for level 1 adventurer with 0 entropy should be 1 let entropy = 0; diff --git a/contracts/adventurer/src/item_meta.cairo b/contracts/adventurer/src/item_meta.cairo index ede31f585..87028a39a 100644 --- a/contracts/adventurer/src/item_meta.cairo +++ b/contracts/adventurer/src/item_meta.cairo @@ -476,8 +476,8 @@ mod tests { use pack::pack::{Packing}; use lootitems::constants::{ItemId}; use survivor::{ - adventurer::{ImplAdventurer}, item_primitive::ItemPrimitive, - adventurer_stats::Stats, bag::{Bag, IBag}, + adventurer::{ImplAdventurer}, item_primitive::ItemPrimitive, adventurer_stats::Stats, + bag::{Bag, IBag}, item_meta::{ ImplItemSpecials, ItemSpecialsStorage, ItemSpecials, MAX_SPECIAL1, MAX_SPECIAL2, MAX_SPECIAL3, STORAGE @@ -539,13 +539,7 @@ mod tests { #[available_gas(4000000)] fn test_set_metadata_id() { // start test with a new adventurer wielding a wand - let mut adventurer = ImplAdventurer::new( - 12, - 1, - Stats { - strength: 1, dexterity: 1, vitality: 1, intelligence: 1, wisdom: 1, charisma: 1, luck: 1 - } - ); + let mut adventurer = ImplAdventurer::new(12, 6, 1, 0); // assert adventurer starter weapon has meta data id 1 assert(adventurer.weapon.metadata == 1, 'advntr wpn meta data shld be 1'); diff --git a/contracts/game/src/game/constants.cairo b/contracts/game/src/game/constants.cairo index 67f41394b..aa366df91 100644 --- a/contracts/game/src/game/constants.cairo +++ b/contracts/game/src/game/constants.cairo @@ -20,7 +20,7 @@ mod messages { const ITEM_ALREADY_OWNED: felt252 = 'Item already owned'; const ADVENTURER_DOESNT_OWN_ITEM: felt252 = 'Adventurer doesnt own item'; const ZERO_DEXTERITY: felt252 = 'Cant flee, no dexterity'; - const WRONG_STARTING_STATS: felt252 = 'Wrong starting stat count'; + const WRONG_NUM_STARTING_STATS: felt252 = 'Wrong starting stat count'; const MUST_USE_ALL_STATS: felt252 = 'Must use all stats'; const NO_ITEMS: felt252 = 'Must provide item ids'; const NON_ZERO_STARTING_LUCK: felt252 = 'Luck must be zero'; @@ -29,7 +29,7 @@ mod messages { // TODO: Update for mainnet const BLOCKS_IN_A_WEEK: u64 = 1000; const COST_TO_PLAY: u8 = 25; -const STARTING_STATS: u8 = 6; +const NUM_STARTING_STATS: u8 = 9; const IDLE_DEATH_PENALTY_BLOCKS: u8 = 12; const MIN_BLOCKS_FOR_GAME_ENTROPY_CHANGE: u8 = 25; diff --git a/contracts/game/src/game/interfaces.cairo b/contracts/game/src/game/interfaces.cairo index 69eec119d..b30779352 100644 --- a/contracts/game/src/game/interfaces.cairo +++ b/contracts/game/src/game/interfaces.cairo @@ -12,10 +12,9 @@ trait IGame { // actions --------------------------------------------------- fn start( ref self: TContractState, - interface_id: ContractAddress, + client_reward_address: ContractAddress, starting_weapon: u8, - adventurer_meta: AdventurerMetadata, - starting_stats: Stats + adventurer_meta: AdventurerMetadata ); fn explore(ref self: TContractState, adventurer_id: u256, till_beast: bool); fn attack(ref self: TContractState, adventurer_id: u256, to_the_death: bool); @@ -113,7 +112,7 @@ trait IGame { // contract details fn get_dao_address(self: @TContractState) -> ContractAddress; fn get_lords_address(self: @TContractState) -> ContractAddress; - fn get_entropy(self: @TContractState) -> u64; + fn get_entropy(self: @TContractState) -> u64; // checks ---------------------------------------------------- fn owner_of(self: @TContractState, adventurer_id: u256) -> ContractAddress; diff --git a/contracts/game/src/lib.cairo b/contracts/game/src/lib.cairo index 59a5de79f..f9f477cc6 100644 --- a/contracts/game/src/lib.cairo +++ b/contracts/game/src/lib.cairo @@ -35,7 +35,7 @@ mod Game { constants::{ messages, Week, REWARD_DISTRIBUTIONS_PHASE1, REWARD_DISTRIBUTIONS_PHASE2, REWARD_DISTRIBUTIONS_PHASE3, BLOCKS_IN_A_WEEK, COST_TO_PLAY, U64_MAX, U128_MAX, - STARTER_BEAST_ATTACK_DAMAGE, STARTING_STATS, IDLE_DEATH_PENALTY_BLOCKS, + STARTER_BEAST_ATTACK_DAMAGE, NUM_STARTING_STATS, IDLE_DEATH_PENALTY_BLOCKS, MIN_BLOCKS_FOR_GAME_ENTROPY_CHANGE } }; @@ -150,22 +150,18 @@ mod Game { //@dev Ensures that the chosen starting weapon and stats are valid before beginning the adventure. fn start( ref self: ContractState, - interface_id: ContractAddress, + client_reward_address: ContractAddress, starting_weapon: u8, adventurer_meta: AdventurerMetadata, - starting_stats: Stats, ) { _assert_valid_starter_weapon(starting_weapon); - _assert_starting_stats(starting_stats); let caller = get_caller_address(); let block_number = starknet::get_block_info().unbox().block_number; - _start( - ref self, block_number, caller, starting_weapon, adventurer_meta, starting_stats - ); + _start(ref self, block_number, caller, starting_weapon, adventurer_meta); - _payout(ref self, caller, block_number, interface_id); + _payout(ref self, caller, block_number, client_reward_address); } //@notice Sends an adventurer to explore. @@ -1061,21 +1057,18 @@ mod Game { block_number: u64, caller: ContractAddress, starting_weapon: u8, - adventurer_meta: AdventurerMetadata, - starting_stats: Stats, + adventurer_meta: AdventurerMetadata ) { // increment adventurer id (first adventurer is id 1) let adventurer_id = self._counter.read() + 1; - // generate a new adventurer using the provided started weapon and current block number - let mut new_adventurer: Adventurer = ImplAdventurer::new( - starting_weapon, block_number, starting_stats - ); - let adventurer_entropy = AdventurerUtils::generate_adventurer_entropy( block_number, adventurer_id ); + // generate a new adventurer using the provided started weapon and current block number + let mut new_adventurer: Adventurer = ImplAdventurer::new(starting_weapon, NUM_STARTING_STATS, block_number, adventurer_entropy); + // set entropy on adventurer metadata let adventurer_meta = AdventurerMetadata { name: adventurer_meta.name, @@ -2167,7 +2160,7 @@ mod Game { + starting_stats.intelligence + starting_stats.wisdom + starting_stats.charisma; - assert(total_stats == STARTING_STATS, messages::WRONG_STARTING_STATS); + assert(total_stats == NUM_STARTING_STATS, messages::WRONG_NUM_STARTING_STATS); _assert_zero_luck(starting_stats); } diff --git a/contracts/game/src/tests/test_game.cairo b/contracts/game/src/tests/test_game.cairo index 3067e2822..7f4894098 100644 --- a/contracts/game/src/tests/test_game.cairo +++ b/contracts/game/src/tests/test_game.cairo @@ -102,18 +102,10 @@ mod tests { name: 'loothero'.try_into().unwrap(), home_realm: 1, class: 1, entropy: 1 }; - let starting_stats = Stats { - strength: 0, dexterity: 2, vitality: 0, intelligence: 2, wisdom: 2, charisma: 0, luck: 0 - }; - - game.start(INTERFACE_ID(), ItemId::Wand, adventurer_meta, starting_stats); + game.start(INTERFACE_ID(), ItemId::Wand, adventurer_meta); let original_adventurer = game.get_adventurer(ADVENTURER_ID); assert(original_adventurer.xp == 0, 'wrong starting xp'); - assert( - original_adventurer.health == STARTING_HEALTH - STARTER_BEAST_ATTACK_DAMAGE, - 'wrong starting health' - ); assert(original_adventurer.weapon.id == ItemId::Wand, 'wrong starting weapon'); assert( original_adventurer.beast_health == BeastSettings::STARTER_BEAST_HEALTH, @@ -128,18 +120,10 @@ mod tests { name: 'Loaf'.try_into().unwrap(), home_realm: 1, class: 1, entropy: 1 }; - let starting_stats = Stats { - strength: 0, dexterity: 2, vitality: 0, intelligence: 2, wisdom: 2, charisma: 0, luck: 0 - }; - - game.start(INTERFACE_ID(), ItemId::Wand, adventurer_meta, starting_stats); + game.start(INTERFACE_ID(), ItemId::Wand, adventurer_meta); let original_adventurer = game.get_adventurer(ADVENTURER_ID); assert(original_adventurer.xp == 0, 'wrong starting xp'); - assert( - original_adventurer.health == STARTING_HEALTH - STARTER_BEAST_ATTACK_DAMAGE, - 'wrong starting health' - ); assert(original_adventurer.weapon.id == ItemId::Wand, 'wrong starting weapon'); assert( original_adventurer.beast_health == BeastSettings::STARTER_BEAST_HEALTH, @@ -151,9 +135,6 @@ mod tests { fn new_adventurer_max_charisma() -> IGameDispatcher { let mut game = setup(1000); - let starting_stats = Stats { - strength: 0, dexterity: 0, vitality: 0, intelligence: 0, wisdom: 0, charisma: 6, luck: 0 - }; game .start( @@ -161,8 +142,7 @@ mod tests { ItemId::Wand, AdventurerMetadata { name: 'loothero'.try_into().unwrap(), home_realm: 1, class: 1, entropy: 1 - }, - starting_stats + } ); game @@ -1295,7 +1275,7 @@ mod tests { } #[test] - #[available_gas(141535180)] + #[available_gas(142346872)] fn test_multi_slay_adventurers() { let STARTING_BLOCK_NUMBER = 512; diff --git a/contracts/pack/src/constants.cairo b/contracts/pack/src/constants.cairo index 5393de29c..5e09a4aa7 100644 --- a/contracts/pack/src/constants.cairo +++ b/contracts/pack/src/constants.cairo @@ -130,11 +130,32 @@ mod mask { } const MASK_63: u256 = 0x7FFFFFFFFFFFFFFF; +const MASK_3: u256 = 0b111; const MASK_6: u256 = 0x3F; const MASK_8: u256 = 0xFF; // Mask for 8-bit values: id, prefix1, prefix2, suffix +const U128_MASK_8: u128 = 0xFF; + const MASK_16: u256 = 0xFFFF; // Mask for 16-bit values: xp const MASK_BOOL: u256 = 0x1; // Mask for boolean values: isEquipped +mod u128_pow { + const _8: u128 = 0x100; + const _16: u128 = 0x10000; + const _24: u128 = 0x1000000; + const _32: u128 = 0x100000000; + const _40: u128 = 0x10000000000; + const _48: u128 = 0x1000000000000; + const _56: u128 = 0x100000000000000; + const _64: u128 = 0x10000000000000000; + const _72: u128 = 0x1000000000000000000; + const _80: u128 = 0x100000000000000000000; + const _88: u128 = 0x10000000000000000000000; + const _96: u128 = 0x1000000000000000000000000; + const _104: u128 = 0x100000000000000000000000000; + const _112: u128 = 0x10000000000000000000000000000; + const _120: u128 = 0x1000000000000000000000000000000; +} + mod pow { const TWO_POW_1: u256 = 0x2; // 2^1 const TWO_POW_2: u256 = 0x4; // 2^2