From d98fcd27779653f063655b86e115b75ce1ccd5fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Santiago=20Galv=C3=A1n=20=28Dub=29?= Date: Wed, 6 Nov 2024 15:47:36 +0100 Subject: [PATCH] implement dynamic rewards (#33) --- src/models/data/reward.cairo | 16 ++++++++++++++++ src/models/status/round/beast.cairo | 4 ++++ src/models/status/round/challenge.cairo | 5 +++-- src/store.cairo | 3 ++- 4 files changed, 25 insertions(+), 3 deletions(-) diff --git a/src/models/data/reward.cairo b/src/models/data/reward.cairo index 550db51..254f7a8 100644 --- a/src/models/data/reward.cairo +++ b/src/models/data/reward.cairo @@ -1,6 +1,8 @@ +use dojo::world::{IWorld, IWorldDispatcher, IWorldDispatcherTrait}; use jokers_of_neon::constants::reward::{REWARD_HP_POTION, REWARD_BLISTER_PACK, REWARD_SPECIAL_CARDS}; #[derive(Copy, Drop, Serde)] +#[dojo::event] #[dojo::model] struct Reward { #[key] @@ -15,6 +17,20 @@ enum RewardType { SPECIAL_CARDS, NONE } +#[generate_trait] +impl RewardImpl of RewardTrait { + fn challenge(world: IWorldDispatcher, game_id: u32) { + let reward = Reward { game_id, rewards_ids: array![REWARD_HP_POTION, REWARD_BLISTER_PACK].span() }; + RewardStore::set(@reward, world); + emit!(world, (reward)) + } + + fn beast(world: IWorldDispatcher, game_id: u32) { + let reward = Reward { game_id, rewards_ids: array![REWARD_HP_POTION, REWARD_SPECIAL_CARDS].span() }; + RewardStore::set(@reward, world); + emit!(world, (reward)) + } +} impl u32IntoRewardType of Into { fn into(self: u32) -> RewardType { diff --git a/src/models/status/round/beast.cairo b/src/models/status/round/beast.cairo index e8b4b48..cbd4ee1 100644 --- a/src/models/status/round/beast.cairo +++ b/src/models/status/round/beast.cairo @@ -3,11 +3,13 @@ use dojo::world::Resource::Contract; 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::models::data::beast::{ GameModeBeast, GameModeBeastStore, Beast, BeastStore, PlayerBeast, PlayerBeastStore, TypeBeast, BeastStats }; use jokers_of_neon::models::data::events::{PlayWinGameEvent, PlayGameOverEvent, BeastAttack, PlayerAttack}; use jokers_of_neon::models::data::game_deck::{GameDeckImpl, GameDeck, GameDeckStore}; +use jokers_of_neon::models::data::reward::RewardTrait; use jokers_of_neon::models::status::game::game::{Game, GameStore, GameState, GameSubState}; use jokers_of_neon::models::status::game::rage::{RageRound, RageRoundStore}; use jokers_of_neon::models::status::round::current_hand_card::{CurrentHandCard, CurrentHandCardTrait}; @@ -19,6 +21,7 @@ use jokers_of_neon::utils::constants::{ 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; use jokers_of_neon::utils::rage::is_rage_card_active; @@ -104,6 +107,7 @@ impl BeastImpl of BeastTrait { game.current_player_hp += 10; game.substate = GameSubState::CREATE_REWARD; + RewardTrait::beast(world, game_id); if is_mainnet(get_tx_info().unbox().chain_id) { diff --git a/src/models/status/round/challenge.cairo b/src/models/status/round/challenge.cairo index 6d0636f..607c7d2 100644 --- a/src/models/status/round/challenge.cairo +++ b/src/models/status/round/challenge.cairo @@ -21,7 +21,7 @@ use jokers_of_neon::{ ChallengeCompleted, ItemChallengeCompleted, PlayGameOverEvent, ModifierCardSuitEvent, SpecialModifierSuitEvent, ObstacleAttack }, - poker_hand::PokerHand + poker_hand::PokerHand, reward::RewardTrait }, status::{ game::game::{Game, GameState, GameSubState, GameStore}, @@ -85,9 +85,10 @@ impl ChallengeImpl of ChallengeTrait { if Self::is_completed(world, game_id) { emit!(world, ChallengeCompleted { player: game.owner, player_name: game.player_name, game_id }); - game.substate = GameSubState::CREATE_REWARD; game.player_score += challenge.active_ids.len() * 100; game.obstacles_cleared += 1; + game.substate = GameSubState::CREATE_REWARD; + RewardTrait::challenge(world, game_id); GameStore::set(@game, world); } else { diff --git a/src/store.cairo b/src/store.cairo index 191d00b..4458dc6 100644 --- a/src/store.cairo +++ b/src/store.cairo @@ -57,7 +57,8 @@ use jokers_of_neon::constants::packs::{ EMPTY_BLISTER_PACK, BASIC_BLISTER_PACK_ID, ADVANCED_BLISTER_PACK_ID, JOKER_BLISTER_PACK_ID, SPECIALS_BLISTER_PACK_ID, MODIFIER_BLISTER_PACK_ID, FIGURES_BLISTER_PACK_ID, DECEITFUL_JOKER_BLISTER_PACK_ID, LOVERS_BLISTER_PACK_ID, SPECIAL_BET_BLISTER_PACK_ID, SPECIAL_CARDS_PACK_ID, SPECIAL_CARDS_PACK, - MODIFIER_CARDS_PACK_ID, MODIFIER_CARDS_PACK, REWARD_CARDS_PACK_ID, REWARD_PACK, REWARD_SPECIAL_CARDS_PACK_ID, REWARD_SPECIAL_CARDS_PACK + MODIFIER_CARDS_PACK_ID, MODIFIER_CARDS_PACK, REWARD_CARDS_PACK_ID, REWARD_PACK, REWARD_SPECIAL_CARDS_PACK_ID, + REWARD_SPECIAL_CARDS_PACK }; use jokers_of_neon::constants::playhand::{ ROYAL_FLUSH, STRAIGHT_FLUSH, FIVE_OF_A_KIND, FOUR_OF_A_KIND, FULL_HOUSE, FLUSH, STRAIGHT, THREE_OF_A_KIND, TWO_PAIR,