Skip to content

Commit

Permalink
add player_system (#36)
Browse files Browse the repository at this point in the history
* add `get_player_current_hand()`

* add overlays

* add extra functions

* add extra functions
  • Loading branch information
dubzn authored Nov 7, 2024
1 parent e9b95d1 commit d87aaef
Show file tree
Hide file tree
Showing 7 changed files with 132 additions and 0 deletions.
4 changes: 4 additions & 0 deletions overlays/dev/player_system.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
tag = "jokers_of_neon-player_system"
writes = [
"ns:jokers_of_neon"
]
4 changes: 4 additions & 0 deletions overlays/prod/player_system.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
tag = "jokers_of_neon-player_system"
writes = [
"ns:jokers_of_neon"
]
4 changes: 4 additions & 0 deletions overlays/sepolia/player_system.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
tag = "jokers_of_neon-player_system"
writes = [
"ns:jokers_of_neon"
]
4 changes: 4 additions & 0 deletions overlays/testing/player_system.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
tag = "jokers_of_neon-player_system"
writes = [
"ns:jokers_of_neon"
]
1 change: 1 addition & 0 deletions src/lib.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ mod models {

mod systems {
mod game_system;
mod player_system;
mod poker_hand_system;
mod rage_system;
}
Expand Down
1 change: 1 addition & 0 deletions src/models/data/reward.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ enum RewardType {
SPECIAL_CARDS,
NONE
}

#[generate_trait]
impl RewardImpl of RewardTrait {
fn challenge(world: IWorldDispatcher, game_id: u32) {
Expand Down
114 changes: 114 additions & 0 deletions src/systems/player_system.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
use jokers_of_neon::{
models::{
data::{
adventurer::AdventurerConsumed, beast::{GameModeBeast, Beast, PlayerBeast},
challenge::{Challenge, ChallengePlayer}, reward::Reward,
},
status::{
game::game::{Game, CurrentSpecialCards}, shop::shop::BlisterPackResult,
round::current_hand_card::CurrentHandCard
}
}
};

#[dojo::interface]
trait IPlayerSystem {
fn get_game(world: @IWorldDispatcher, game_id: u32) -> Game;
fn get_adventurer(world: @IWorldDispatcher, adventurer_id: u32) -> AdventurerConsumed;
fn get_player_current_hand(world: @IWorldDispatcher, game_id: u32) -> Array<CurrentHandCard>;
fn get_game_mode_beast(world: @IWorldDispatcher, game_id: u32) -> GameModeBeast;
fn get_beast(world: @IWorldDispatcher, game_id: u32) -> Beast;
fn get_player_beast(world: @IWorldDispatcher, game_id: u32) -> PlayerBeast;
fn get_challenge(world: @IWorldDispatcher, game_id: u32) -> Challenge;
fn get_challenge_player(world: @IWorldDispatcher, game_id: u32) -> ChallengePlayer;
fn get_reward(world: @IWorldDispatcher, game_id: u32) -> Reward;
fn get_blister_pack_result(world: @IWorldDispatcher, game_id: u32) -> BlisterPackResult;
fn get_current_special_cards(world: @IWorldDispatcher, game_id: u32) -> Array<CurrentSpecialCards>;
}

#[dojo::contract]
mod player_system {
use jokers_of_neon::{
models::{
data::{
adventurer::{AdventurerConsumed, AdventurerConsumedStore},
beast::{Beast, BeastStore, GameModeBeast, GameModeBeastStore, PlayerBeast, PlayerBeastStore},
challenge::{Challenge, ChallengeStore, ChallengePlayer, ChallengePlayerStore},
reward::{Reward, RewardStore},
},
status::{
game::game::{Game, GameStore, CurrentSpecialCards, CurrentSpecialCardsStore}, shop::shop::{BlisterPackResult, BlisterPackResultStore},
round::current_hand_card::{CurrentHandCard, CurrentHandCardStore}
}
}
};

#[abi(embed_v0)]
impl PokerHandSystem of super::IPlayerSystem<ContractState> {
fn get_game(world: @IWorldDispatcher, game_id: u32) -> Game {
GameStore::get(world, game_id)
}

fn get_adventurer(world: @IWorldDispatcher, adventurer_id: u32) -> AdventurerConsumed {
AdventurerConsumedStore::get(world, adventurer_id)
}

fn get_player_current_hand(world: @IWorldDispatcher, game_id: u32) -> Array<CurrentHandCard> {
let mut current_hand = array![];
let game = GameStore::get(world, game_id);

let mut i = 0;
loop {
if i == game.len_hand {
break;
}
current_hand.append(CurrentHandCardStore::get(world, game_id, i));
i += 1;
};
current_hand
}

fn get_beast(world: @IWorldDispatcher, game_id: u32) -> Beast {
BeastStore::get(world, game_id)
}

fn get_player_beast(world: @IWorldDispatcher, game_id: u32) -> PlayerBeast {
PlayerBeastStore::get(world, game_id)
}

fn get_game_mode_beast(world: @IWorldDispatcher, game_id: u32) -> GameModeBeast {
GameModeBeastStore::get(world, game_id)
}

fn get_challenge(world: @IWorldDispatcher, game_id: u32) -> Challenge {
ChallengeStore::get(world, game_id)
}

fn get_challenge_player(world: @IWorldDispatcher, game_id: u32) -> ChallengePlayer {
ChallengePlayerStore::get(world, game_id)
}

fn get_reward(world: @IWorldDispatcher, game_id: u32) -> Reward {
RewardStore::get(world, game_id)
}

fn get_blister_pack_result(world: @IWorldDispatcher, game_id: u32) -> BlisterPackResult {
BlisterPackResultStore::get(world, game_id)
}

fn get_current_special_cards(world: @IWorldDispatcher, game_id: u32) -> Array<CurrentSpecialCards> {
let mut special_cards = array![];
let game = GameStore::get(world, game_id);

let mut i = 0;
loop {
if i == game.len_current_special_cards {
break;
}
special_cards.append(CurrentSpecialCardsStore::get(world, game_id, i));
i += 1;
};
special_cards
}
}
}

0 comments on commit d87aaef

Please sign in to comment.