Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add dynamic rewards #33

Merged
merged 2 commits into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions src/models/data/reward.cairo
Original file line number Diff line number Diff line change
@@ -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]
Expand All @@ -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<u32, RewardType> {
fn into(self: u32) -> RewardType {
Expand Down
4 changes: 4 additions & 0 deletions src/models/status/round/beast.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand All @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down
5 changes: 3 additions & 2 deletions src/models/status/round/challenge.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down Expand Up @@ -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 {
Expand Down
3 changes: 2 additions & 1 deletion src/store.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Loading