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

JON-465: Rewards + refactor Game substates #18

Merged
merged 4 commits into from
Nov 2, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
3,385 changes: 2,365 additions & 1,020 deletions manifests/dev/deployment/manifest.json

Large diffs are not rendered by default.

113 changes: 95 additions & 18 deletions manifests/dev/deployment/manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ manifest_name = "dojo-base"
[[contracts]]
kind = "DojoContract"
address = "0x6a41badee85305fa1aac33488860360c66b60d7f3b204d6e2cd84071dc3c394"
class_hash = "0x2251dab55d7d4473ca9badd43dee9aa8cc3664a1afbab3a29284b251805fa49"
original_class_hash = "0x2251dab55d7d4473ca9badd43dee9aa8cc3664a1afbab3a29284b251805fa49"
class_hash = "0x352fd9eeb1842a703803b0b06071e21caf0e093be86e0bdeb3b7bad13f11be5"
original_class_hash = "0x352fd9eeb1842a703803b0b06071e21caf0e093be86e0bdeb3b7bad13f11be5"
base_class_hash = "0x2427dd10a58850ac9a5ca6ce04b7771b05330fd18f2e481831ad903b969e6b2"
abi = "manifests/dev/deployment/abis/contracts/jokers_of_neon-game_system-7a205bbc.json"
reads = []
Expand Down Expand Up @@ -62,8 +62,8 @@ manifest_name = "jokers_of_neon-poker_hand_system-25bae3ed"
[[contracts]]
kind = "DojoContract"
address = "0x75602558fd679c49be1a6ccb73e3d6d842f0558e1f41c4013ce109d05a5790f"
class_hash = "0x4d335ac492b01d48fc5431dc87810c59111033fb62eaefd438ab41b6cdb3c06"
original_class_hash = "0x4d335ac492b01d48fc5431dc87810c59111033fb62eaefd438ab41b6cdb3c06"
class_hash = "0x5f1bddfab781d4c4b67d7814361d1a38549f876f4e2574a576903291c3f536d"
original_class_hash = "0x5f1bddfab781d4c4b67d7814361d1a38549f876f4e2574a576903291c3f536d"
base_class_hash = "0x2427dd10a58850ac9a5ca6ce04b7771b05330fd18f2e481831ad903b969e6b2"
abi = "manifests/dev/deployment/abis/contracts/jokers_of_neon-rage_system-601fc835.json"
reads = []
Expand All @@ -75,8 +75,8 @@ manifest_name = "jokers_of_neon-rage_system-601fc835"

[[models]]
kind = "DojoModel"
class_hash = "0x5a1c6141a6afc7ffaff55d76c948b77992e8cd89ca6c50b21ac617a9889dcd0"
original_class_hash = "0x5a1c6141a6afc7ffaff55d76c948b77992e8cd89ca6c50b21ac617a9889dcd0"
class_hash = "0x138b1cf753d19f46b39fc7eebc67b9cdea0ce30ef41c961bf150392837796bf"
original_class_hash = "0x138b1cf753d19f46b39fc7eebc67b9cdea0ce30ef41c961bf150392837796bf"
abi = "manifests/dev/deployment/abis/models/jokers_of_neon-Beast-35a29cda.json"
tag = "jokers_of_neon-Beast"
qualified_path = "jokers_of_neon::models::data::beast::beast"
Expand All @@ -87,6 +87,11 @@ name = "game_id"
type = "u32"
key = true

[[models.members]]
name = "beast_id"
type = "u32"
key = false

[[models.members]]
name = "tier"
type = "u8"
Expand All @@ -102,6 +107,35 @@ name = "health"
type = "u32"
key = false

[[models.members]]
name = "current_health"
type = "u32"
key = false

[[models.members]]
name = "attack"
type = "u32"
key = false

[[models.members]]
name = "type_beast"
type = "TypeBeast"
key = false

[[models]]
kind = "DojoModel"
class_hash = "0x5af087ffc9c3c2437a78b8884eb1bd53eaeb3207a4a68c35fc0c8c4744d12ef"
original_class_hash = "0x5af087ffc9c3c2437a78b8884eb1bd53eaeb3207a4a68c35fc0c8c4744d12ef"
abi = "manifests/dev/deployment/abis/models/jokers_of_neon-BeastAttack-46464e29.json"
tag = "jokers_of_neon-BeastAttack"
qualified_path = "jokers_of_neon::models::data::events::beast_attack"
manifest_name = "jokers_of_neon-BeastAttack-46464e29"

[[models.members]]
name = "player"
type = "ContractAddress"
key = true

[[models.members]]
name = "attack"
type = "u32"
Expand Down Expand Up @@ -371,8 +405,8 @@ key = false

[[models]]
kind = "DojoModel"
class_hash = "0x366273a4ee649b33c07c7584bba0132ac37cc86f52ba525e4ced46a49b960f4"
original_class_hash = "0x366273a4ee649b33c07c7584bba0132ac37cc86f52ba525e4ced46a49b960f4"
class_hash = "0x100656d30bb4f9835d1f7c5f04cbffa556d5b6cec46818209426c90fd1ad41d"
original_class_hash = "0x100656d30bb4f9835d1f7c5f04cbffa556d5b6cec46818209426c90fd1ad41d"
abi = "manifests/dev/deployment/abis/models/jokers_of_neon-Challenge-61873cc7.json"
tag = "jokers_of_neon-Challenge"
qualified_path = "jokers_of_neon::models::data::challenge::challenge"
Expand All @@ -385,7 +419,7 @@ key = true

[[models.members]]
name = "active_ids"
type = "Span<u32>"
type = "Span<(u32, bool)>"
key = false

[[models]]
Expand Down Expand Up @@ -603,8 +637,8 @@ key = false

[[models]]
kind = "DojoModel"
class_hash = "0x2a0bf5c76a2a51057fa8cd30b669b8b2e9ac982f6a7c0d2aac0caf2e8b385a1"
original_class_hash = "0x2a0bf5c76a2a51057fa8cd30b669b8b2e9ac982f6a7c0d2aac0caf2e8b385a1"
class_hash = "0x3ffc052edb32b194e03a69e0b624c9ee4d508d4ce3de3de43a0f5503832b6c2"
original_class_hash = "0x3ffc052edb32b194e03a69e0b624c9ee4d508d4ce3de3de43a0f5503832b6c2"
abi = "manifests/dev/deployment/abis/models/jokers_of_neon-Game-162de85b.json"
tag = "jokers_of_neon-Game"
qualified_path = "jokers_of_neon::models::status::game::game::game"
Expand All @@ -625,6 +659,16 @@ name = "player_name"
type = "felt252"
key = false

[[models.members]]
name = "player_hp"
type = "u32"
key = false

[[models.members]]
name = "current_player_hp"
type = "u32"
key = false

[[models.members]]
name = "max_hands"
type = "u8"
Expand Down Expand Up @@ -738,6 +782,25 @@ name = "energy_max_player"
type = "u8"
key = false

[[models]]
kind = "DojoModel"
class_hash = "0x40f2a16a814460d5105e655f240e0ef22171fdbb3f04fdf727511d5703316e2"
original_class_hash = "0x40f2a16a814460d5105e655f240e0ef22171fdbb3f04fdf727511d5703316e2"
abi = "manifests/dev/deployment/abis/models/jokers_of_neon-ItemChallengeCompleted-2cb0f253.json"
tag = "jokers_of_neon-ItemChallengeCompleted"
qualified_path = "jokers_of_neon::models::data::events::item_challenge_completed"
manifest_name = "jokers_of_neon-ItemChallengeCompleted-2cb0f253"

[[models.members]]
name = "game_id"
type = "u32"
key = true

[[models.members]]
name = "challenge_id"
type = "u32"
key = false

[[models]]
kind = "DojoModel"
class_hash = "0x2cdd0f8efcd582eb49fd33a9bc2c466d96bda4d2b7739b48258842fdb18984d"
Expand Down Expand Up @@ -909,8 +972,27 @@ key = false

[[models]]
kind = "DojoModel"
class_hash = "0x72bab25593e59ba01387711eaa353d06fd59c06a93e1b5dcff3c30245d6c640"
original_class_hash = "0x72bab25593e59ba01387711eaa353d06fd59c06a93e1b5dcff3c30245d6c640"
class_hash = "0x148cef5976cbfa98709e064fce8879c0f48cc22bab54cd29df7bdd6a9cb3e0"
original_class_hash = "0x148cef5976cbfa98709e064fce8879c0f48cc22bab54cd29df7bdd6a9cb3e0"
abi = "manifests/dev/deployment/abis/models/jokers_of_neon-PlayerAttack-3b7323b8.json"
tag = "jokers_of_neon-PlayerAttack"
qualified_path = "jokers_of_neon::models::data::events::player_attack"
manifest_name = "jokers_of_neon-PlayerAttack-3b7323b8"

[[models.members]]
name = "player"
type = "ContractAddress"
key = true

[[models.members]]
name = "attack"
type = "u32"
key = false

[[models]]
kind = "DojoModel"
class_hash = "0x789bb9f5c507a42d96c6d34cf48fa3ecff060db297695716c62b3f8129bcf49"
original_class_hash = "0x789bb9f5c507a42d96c6d34cf48fa3ecff060db297695716c62b3f8129bcf49"
abi = "manifests/dev/deployment/abis/models/jokers_of_neon-PlayerBeast-22d6f7af.json"
tag = "jokers_of_neon-PlayerBeast"
qualified_path = "jokers_of_neon::models::data::beast::player_beast"
Expand All @@ -921,11 +1003,6 @@ name = "game_id"
type = "u32"
key = true

[[models.members]]
name = "health"
type = "u32"
key = false

[[models.members]]
name = "energy"
type = "u8"
Expand Down
13 changes: 13 additions & 0 deletions src/constants/packs.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const EMPTY_PACK_ID: u32 = 999;

const SPECIAL_CARDS_PACK_ID: u32 = 20;
const MODIFIER_CARDS_PACK_ID: u32 = 21;
const REWARD_CARDS_PACK_ID: u32 = 22;

fn blister_packs_ids_all() -> Array<u32> {
array![
Expand Down Expand Up @@ -245,3 +246,15 @@ fn MODIFIER_CARDS_PACK() -> BlisterPack {
probs: array![100, 100].span(),
}
}

fn REWARD_PACK() -> BlisterPack {
BlisterPack {
id: REWARD_CARDS_PACK_ID,
cost: 0,
name: 'reward_cards_pack',
probability: 100,
size: 5,
cards: array![array![].span(), array![JOKER_CARD].span(), modifiers_ids_all().span()].span(),
probs: array![100, 20, 80].span(),
}
}
3 changes: 3 additions & 0 deletions src/constants/reward.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const REWARD_HP_POTION: u32 = 1;
const REWARD_BLISTER_PACK: u32 = 2;
const REWARD_SPECIAL_CARDS: u32 = 3;
2 changes: 2 additions & 0 deletions src/lib.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ mod constants {
mod modifiers;
mod packs;
mod playhand;
mod reward;
mod specials;
mod two_pow;
}
Expand All @@ -25,6 +26,7 @@ mod models {
mod game_deck;
mod last_beast_level;
mod poker_hand;
mod reward;
}
mod status {
mod game {
Expand Down
11 changes: 11 additions & 0 deletions src/models/data/events.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -281,3 +281,14 @@ struct PlayerAttack {
player: ContractAddress,
attack: u32
}

#[derive(Copy, Drop, Serde)]
#[dojo::event]
#[dojo::model]
struct PlayerHealed {
#[key]
game_id: u32,
potion_heal: u32,
current_hp: u32,
}

31 changes: 31 additions & 0 deletions src/models/data/reward.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
use jokers_of_neon::constants::reward::{REWARD_HP_POTION, REWARD_BLISTER_PACK, REWARD_SPECIAL_CARDS};

#[derive(Copy, Drop, Serde)]
#[dojo::model]
struct Reward {
#[key]
game_id: u32,
rewards_ids: Span<u32>
}

#[derive(Serde, Copy, Drop, IntrospectPacked, PartialEq)]
enum RewardType {
HP_POTION,
BLISTER_PACK,
SPECIAL_CARDS,
NONE
}

impl u32IntoRewardType of Into<u32, RewardType> {
fn into(self: u32) -> RewardType {
if self == REWARD_HP_POTION {
RewardType::HP_POTION
} else if self == REWARD_BLISTER_PACK {
RewardType::BLISTER_PACK
} else if self == REWARD_SPECIAL_CARDS {
RewardType::SPECIAL_CARDS
} else {
RewardType::NONE
}
}
}
15 changes: 8 additions & 7 deletions src/models/status/game/game.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,20 @@ use starknet::ContractAddress;
#[derive(Serde, Copy, Drop, IntrospectPacked, PartialEq)]
enum GameSubState {
BEAST,
OBSTACLE,
CREATE_LEVEL,
OBSTACLE
CREATE_REWARD,
REWARD_SPECIALS,
REWARD_CARDS_PACK,
DRAFT_MODIFIERS,
DRAFT_SPECIALS,
DRAFT_DECK
}

#[derive(Serde, Copy, Drop, IntrospectPacked, PartialEq)]
enum GameState {
SELECT_DECK,
SELECT_SPECIAL_CARDS,
SELECT_MODIFIER_CARDS,
AT_SHOP,
IN_GAME,
FINISHED,
OPEN_BLISTER_PACK
FINISHED
}

#[derive(Copy, Drop, IntrospectPacked, Serde)]
Expand Down
4 changes: 2 additions & 2 deletions src/models/status/round/beast.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ impl BeastImpl of BeastTrait {
};
emit!(world, (play_win_game_event));
game.state = GameState::IN_GAME;
game.substate = GameSubState::CREATE_LEVEL;
game.substate = GameSubState::CREATE_REWARD;
game.player_score += 1;

if is_rage_card_active(@rage_round, RAGE_CARD_DIMINISHED_HOLD) {
Expand All @@ -111,7 +111,7 @@ impl BeastImpl of BeastTrait {
_ => Option::None
}.unwrap();
IRageSystemDispatcher { contract_address: rage_system_address.try_into().unwrap() }.calculate(game.id);
// create_level(world, ref store, game); TODO:
// create_level(world, ref store, game); TODO:
} else if player_beast.energy.is_zero() {
_attack_beast(world, ref store, ref game, ref player_beast, ref beast, ref game_mode_beast);
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/models/status/round/challenge.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ 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_LEVEL;
game.substate = GameSubState::CREATE_REWARD;
GameStore::set(@game, world);
} else {
challenge_player.plays -= 1;
Expand Down
4 changes: 0 additions & 4 deletions src/models/status/round/level.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,23 @@ impl LevelImpl of LevelTrait {
let mut last_active_level = LastBeastLevelStore::get(world, game_id);

if game.level <= level_config.min_round_level_before_activate.into() {
println!("dale 1");
return GameSubState::OBSTACLE;
}

if last_active_level.level != 0 && game.level
- last_active_level.level.into() <= level_config.level_cooldown.try_into().unwrap() {
println!("dale 2");
return GameSubState::OBSTACLE;
}

let mut randomizer = RandomImpl::new(world);
let random = randomizer.between::<u16>(0, 100);
if random <= last_active_level.current_probability {
println!("dale 3");
last_active_level.level = game.level.try_into().unwrap();
last_active_level.current_probability = level_config.initial_probability;
LastBeastLevelStore::set(@last_active_level, world);

GameSubState::BEAST
} else {
println!("dale 4");
if last_active_level.current_probability + level_config.increment_by_round <= 100 {
last_active_level.current_probability = last_active_level.current_probability
+ level_config.increment_by_round;
Expand Down
Loading