diff --git a/src/interfaces/erc721.cairo b/src/interfaces/erc721.cairo index 8657c81..b95bcae 100644 --- a/src/interfaces/erc721.cairo +++ b/src/interfaces/erc721.cairo @@ -1,12 +1,10 @@ use dojo::world::{IWorldDispatcher, IWorldDispatcherTrait}; -use starknet::ContractAddress; use jokers_of_neon::models::data::beast::BeastStats; +use starknet::ContractAddress; #[dojo::interface] trait IERC721System { fn owner_of(world: @IWorldDispatcher, token_id: u256) -> ContractAddress; - fn safe_mint( - ref world: IWorldDispatcher, recipient: ContractAddress, beast_stats: BeastStats - ); + fn safe_mint(ref world: IWorldDispatcher, recipient: ContractAddress, beast_stats: BeastStats); fn get_owner(world: @IWorldDispatcher, beast_stats: BeastStats) -> ContractAddress; } diff --git a/src/models/status/round/beast.cairo b/src/models/status/round/beast.cairo index cbd4ee1..c0917c2 100644 --- a/src/models/status/round/beast.cairo +++ b/src/models/status/round/beast.cairo @@ -4,6 +4,7 @@ use dojo::world::{IWorldDispatcher, IWorldDispatcherTrait}; use jokers_of_neon::constants::beast::{all_beast, beast_loot_survivor, is_loot_survivor_beast}; use jokers_of_neon::constants::card::INVALID_CARD; use jokers_of_neon::constants::reward::{REWARD_HP_POTION, REWARD_SPECIAL_CARDS}; +use jokers_of_neon::interfaces::erc721::{IERC721SystemDispatcher, IERC721SystemDispatcherTrait}; use jokers_of_neon::models::data::beast::{ GameModeBeast, GameModeBeastStore, Beast, BeastStore, PlayerBeast, PlayerBeastStore, TypeBeast, BeastStats }; @@ -15,12 +16,11 @@ use jokers_of_neon::models::status::game::rage::{RageRound, RageRoundStore}; use jokers_of_neon::models::status::round::current_hand_card::{CurrentHandCard, CurrentHandCardTrait}; use jokers_of_neon::store::{Store, StoreTrait}; use jokers_of_neon::systems::rage_system::{IRageSystemDispatcher, IRageSystemDispatcherTrait}; -use jokers_of_neon::interfaces::erc721::{IERC721SystemDispatcher, IERC721SystemDispatcherTrait}; +use jokers_of_neon::utils::adventurer::{is_mainnet, NFT_ADDRESS_MAINNET}; use jokers_of_neon::utils::constants::{ RAGE_CARD_DIMINISHED_HOLD, RAGE_CARD_SILENT_JOKERS, RAGE_CARD_SILENT_HEARTS, RAGE_CARD_SILENT_CLUBS, RAGE_CARD_SILENT_DIAMONDS, RAGE_CARD_SILENT_SPADES, RAGE_CARD_ZERO_WASTE, is_neon_card, is_modifier_card }; -use jokers_of_neon::utils::adventurer::{is_mainnet, NFT_ADDRESS_MAINNET}; use jokers_of_neon::utils::game::play; use jokers_of_neon::utils::level::create_level; @@ -109,13 +109,10 @@ impl BeastImpl of BeastTrait { game.substate = GameSubState::CREATE_REWARD; RewardTrait::beast(world, game_id); - if is_mainnet(get_tx_info().unbox().chain_id) { if !is_loot_survivor_beast(beast.beast_id) { let beast_stats = BeastStats { - tier: beast.tier, - level: beast.level, - beast_id: beast.beast_id.try_into().unwrap() + tier: beast.tier, level: beast.level, beast_id: beast.beast_id.try_into().unwrap() }; let erc721_dispatcher = IERC721SystemDispatcher { contract_address: NFT_ADDRESS_MAINNET() }; let owner = erc721_dispatcher.get_owner(beast_stats); @@ -288,7 +285,7 @@ fn _create_beast(world: IWorldDispatcher, game_id: u32, level: u8) { } else { *all_beast()[randomizer.between::(0, all_beast().len() - 1)] }; - let (tier, health, attack) = _generate_stats(level, beast_id); + let (tier, health, attack) = _generate_stats(level, beast_id, ref randomizer); let type_beast = if is_loot_survivor_beast(beast_id) { TypeBeast::LOOT_SURVIVOR } else { @@ -300,18 +297,19 @@ fn _create_beast(world: IWorldDispatcher, game_id: u32, level: u8) { } // tier, health, attack -fn _generate_stats(level: u8, beast_id: u32) -> (u8, u32, u32) { +fn _generate_stats(level: u8, beast_id: u32, ref randomizer: Random) -> (u8, u32, u32) { + let random_tier = _obtain_random_tier(ref randomizer); let mut stats = (0, 0, 0); if level <= 4 { - stats = (5, _calculate_beast_hp(level), 10); + stats = (random_tier, _calculate_beast_hp(level), 10); } else if level <= 8 { - stats = (4, _calculate_beast_hp(level), 20); + stats = (random_tier, _calculate_beast_hp(level), 20); } else if level <= 12 { - stats = (3, _calculate_beast_hp(level), 30); + stats = (random_tier, _calculate_beast_hp(level), 30); } else if level <= 16 { - stats = (2, _calculate_beast_hp(level), 40); + stats = (random_tier, _calculate_beast_hp(level), 40); } else { - stats = (1, _calculate_beast_hp(level), 50); + stats = (random_tier, _calculate_beast_hp(level), 50); } if beast_id >= 101 && beast_id <= 108 { @@ -322,6 +320,26 @@ fn _generate_stats(level: u8, beast_id: u32) -> (u8, u32, u32) { } } +// Tier 1: 00 - 40 +// Tier 2: 41 - 70 +// Tier 3: 71 - 85 +// Tier 4: 86 - 95 +// Tier 5: 96 - 100 +fn _obtain_random_tier(ref randomizer: Random) -> u8 { + let random = randomizer.between::(1, 100); + if random <= 40 { + 5 + } else if random <= 70 { + 4 + } else if random <= 85 { + 3 + } else if random <= 95 { + 2 + } else { + 1 + } +} + fn _calculate_beast_hp(level: u8) -> u32 { if level <= 2 { 300 * level.into() diff --git a/src/systems/game_system.cairo b/src/systems/game_system.cairo index bdc7645..1140dd1 100644 --- a/src/systems/game_system.cairo +++ b/src/systems/game_system.cairo @@ -426,10 +426,7 @@ mod game_system { let mut game = GameStore::get(world, game_id); assert(game.owner.is_non_zero(), errors::GAME_NOT_FOUND); assert(game.owner == get_caller_address(), errors::CALLER_NOT_OWNER); - assert( - game.substate == GameSubState::UNPASSED_OBSTACLE, - errors::WRONG_SUBSTATE_UNPASSED_OBSTABLE - ); + assert(game.substate == GameSubState::UNPASSED_OBSTACLE, errors::WRONG_SUBSTATE_UNPASSED_OBSTABLE); let mut store = StoreTrait::new(world); game.substate = GameSubState::CREATE_LEVEL; store.set_game(game);