Skip to content

Commit

Permalink
add select deck
Browse files Browse the repository at this point in the history
  • Loading branch information
dpinones committed Oct 30, 2024
1 parent b6bfefd commit da6bb8d
Show file tree
Hide file tree
Showing 9 changed files with 296 additions and 92 deletions.
43 changes: 36 additions & 7 deletions manifests/dev/deployment/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -1256,8 +1256,8 @@
{
"kind": "DojoContract",
"address": "0x6a41badee85305fa1aac33488860360c66b60d7f3b204d6e2cd84071dc3c394",
"class_hash": "0x6ad9936a7fc685dfcae8a15c782d32db93b55c2296c8406652e982418f7caed",
"original_class_hash": "0x6ad9936a7fc685dfcae8a15c782d32db93b55c2296c8406652e982418f7caed",
"class_hash": "0x58feb428c2692bda09414a95336a6f566852ff95338fe1760f21f53e520eba0",
"original_class_hash": "0x58feb428c2692bda09414a95336a6f566852ff95338fe1760f21f53e520eba0",
"base_class_hash": "0x2427dd10a58850ac9a5ca6ce04b7771b05330fd18f2e481831ad903b969e6b2",
"abi": [
{
Expand Down Expand Up @@ -1466,6 +1466,22 @@
],
"state_mutability": "external"
},
{
"type": "function",
"name": "select_deck",
"inputs": [
{
"name": "game_id",
"type": "core::integer::u32"
},
{
"name": "deck_id",
"type": "core::integer::u8"
}
],
"outputs": [],
"state_mutability": "external"
},
{
"type": "function",
"name": "play",
Expand Down Expand Up @@ -1649,6 +1665,7 @@
"init_calldata": [],
"tag": "jokers_of_neon-game_system",
"systems": [
"select_deck",
"play",
"discard",
"discard_effect_card",
Expand Down Expand Up @@ -1983,8 +2000,8 @@
{
"kind": "DojoContract",
"address": "0x75602558fd679c49be1a6ccb73e3d6d842f0558e1f41c4013ce109d05a5790f",
"class_hash": "0x3dd4a1244136cde97126bb75b820cc0f134fb8af5f4916c030f12bac06e3dec",
"original_class_hash": "0x3dd4a1244136cde97126bb75b820cc0f134fb8af5f4916c030f12bac06e3dec",
"class_hash": "0xe1327a50fe39d93f025e0a84e7ce9ccd46c1acd1f575c50acd881e3d4e23b7",
"original_class_hash": "0xe1327a50fe39d93f025e0a84e7ce9ccd46c1acd1f575c50acd881e3d4e23b7",
"base_class_hash": "0x2427dd10a58850ac9a5ca6ce04b7771b05330fd18f2e481831ad903b969e6b2",
"abi": [
{
Expand Down Expand Up @@ -8374,8 +8391,8 @@
"key": false
}
],
"class_hash": "0x62a66a5fb4ec621dba3f4179c6e338a380a8a95797ac4e4e3c8060f5e8c94f4",
"original_class_hash": "0x62a66a5fb4ec621dba3f4179c6e338a380a8a95797ac4e4e3c8060f5e8c94f4",
"class_hash": "0xd231a89d484f9ce343542808702a69ff45ecd316470ea746e8de8e889d6f8",
"original_class_hash": "0xd231a89d484f9ce343542808702a69ff45ecd316470ea746e8de8e889d6f8",
"abi": [
{
"type": "impl",
Expand Down Expand Up @@ -8749,13 +8766,25 @@
"name": "jokers_of_neon::models::status::game::game::GameState",
"variants": [
{
"name": "IN_GAME",
"name": "SELECT_DECK",
"type": "()"
},
{
"name": "SELECT_SPECIAL_CARDS",
"type": "()"
},
{
"name": "SELECT_MODIFIER_CARDS",
"type": "()"
},
{
"name": "AT_SHOP",
"type": "()"
},
{
"name": "IN_GAME",
"type": "()"
},
{
"name": "FINISHED",
"type": "()"
Expand Down
13 changes: 7 additions & 6 deletions manifests/dev/deployment/manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,16 @@ manifest_name = "dojo-base"
[[contracts]]
kind = "DojoContract"
address = "0x6a41badee85305fa1aac33488860360c66b60d7f3b204d6e2cd84071dc3c394"
class_hash = "0x6ad9936a7fc685dfcae8a15c782d32db93b55c2296c8406652e982418f7caed"
original_class_hash = "0x6ad9936a7fc685dfcae8a15c782d32db93b55c2296c8406652e982418f7caed"
class_hash = "0x58feb428c2692bda09414a95336a6f566852ff95338fe1760f21f53e520eba0"
original_class_hash = "0x58feb428c2692bda09414a95336a6f566852ff95338fe1760f21f53e520eba0"
base_class_hash = "0x2427dd10a58850ac9a5ca6ce04b7771b05330fd18f2e481831ad903b969e6b2"
abi = "manifests/dev/deployment/abis/contracts/jokers_of_neon-game_system-7a205bbc.json"
reads = []
writes = ["ns:jokers_of_neon"]
init_calldata = []
tag = "jokers_of_neon-game_system"
systems = [
"select_deck",
"play",
"discard",
"discard_effect_card",
Expand All @@ -57,8 +58,8 @@ manifest_name = "jokers_of_neon-poker_hand_system-25bae3ed"
[[contracts]]
kind = "DojoContract"
address = "0x75602558fd679c49be1a6ccb73e3d6d842f0558e1f41c4013ce109d05a5790f"
class_hash = "0x3dd4a1244136cde97126bb75b820cc0f134fb8af5f4916c030f12bac06e3dec"
original_class_hash = "0x3dd4a1244136cde97126bb75b820cc0f134fb8af5f4916c030f12bac06e3dec"
class_hash = "0xe1327a50fe39d93f025e0a84e7ce9ccd46c1acd1f575c50acd881e3d4e23b7"
original_class_hash = "0xe1327a50fe39d93f025e0a84e7ce9ccd46c1acd1f575c50acd881e3d4e23b7"
base_class_hash = "0x2427dd10a58850ac9a5ca6ce04b7771b05330fd18f2e481831ad903b969e6b2"
abi = "manifests/dev/deployment/abis/contracts/jokers_of_neon-rage_system-601fc835.json"
reads = []
Expand Down Expand Up @@ -497,8 +498,8 @@ key = false

[[models]]
kind = "DojoModel"
class_hash = "0x62a66a5fb4ec621dba3f4179c6e338a380a8a95797ac4e4e3c8060f5e8c94f4"
original_class_hash = "0x62a66a5fb4ec621dba3f4179c6e338a380a8a95797ac4e4e3c8060f5e8c94f4"
class_hash = "0xd231a89d484f9ce343542808702a69ff45ecd316470ea746e8de8e889d6f8"
original_class_hash = "0xd231a89d484f9ce343542808702a69ff45ecd316470ea746e8de8e889d6f8"
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 Down
61 changes: 61 additions & 0 deletions src/constants/card.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ const JOKER_CARD: u32 = 52;
const NEON_JOKER_CARD: u32 = 53;
const INVALID_CARD: u32 = 9999;

const SCRIBE_DECK: u8 = 0;
const WARRIOR_DECK: u8 = 1;
const WIZARD_DECK: u8 = 2;

// TRADITIONALS
fn TWO_CLUBS() -> Card {
Card { id: TWO_CLUBS_ID, suit: Suit::Clubs, value: Value::Two, points: 2, multi_add: 0 }
Expand Down Expand Up @@ -218,3 +222,60 @@ fn KING_SPADES() -> Card {
fn ACE_SPADES() -> Card {
Card { id: ACE_SPADES_ID, suit: Suit::Spades, value: Value::Ace, points: 11, multi_add: 0 }
}

fn traditional_cards_all() -> Array<u32> {
array![
TWO_CLUBS_ID,
THREE_CLUBS_ID,
FOUR_CLUBS_ID,
FIVE_CLUBS_ID,
SIX_CLUBS_ID,
SEVEN_CLUBS_ID,
EIGHT_CLUBS_ID,
NINE_CLUBS_ID,
TEN_CLUBS_ID,
JACK_CLUBS_ID,
QUEEN_CLUBS_ID,
KING_CLUBS_ID,
ACE_CLUBS_ID,
TWO_DIAMONDS_ID,
THREE_DIAMONDS_ID,
FOUR_DIAMONDS_ID,
FIVE_DIAMONDS_ID,
SIX_DIAMONDS_ID,
SEVEN_DIAMONDS_ID,
EIGHT_DIAMONDS_ID,
NINE_DIAMONDS_ID,
TEN_DIAMONDS_ID,
JACK_DIAMONDS_ID,
QUEEN_DIAMONDS_ID,
KING_DIAMONDS_ID,
ACE_DIAMONDS_ID,
TWO_HEARTS_ID,
THREE_HEARTS_ID,
FOUR_HEARTS_ID,
FIVE_HEARTS_ID,
SIX_HEARTS_ID,
SEVEN_HEARTS_ID,
EIGHT_HEARTS_ID,
NINE_HEARTS_ID,
TEN_HEARTS_ID,
JACK_HEARTS_ID,
QUEEN_HEARTS_ID,
KING_HEARTS_ID,
ACE_HEARTS_ID,
TWO_SPADES_ID,
THREE_SPADES_ID,
FOUR_SPADES_ID,
FIVE_SPADES_ID,
SIX_SPADES_ID,
SEVEN_SPADES_ID,
EIGHT_SPADES_ID,
NINE_SPADES_ID,
TEN_SPADES_ID,
JACK_SPADES_ID,
QUEEN_SPADES_ID,
KING_SPADES_ID,
ACE_SPADES_ID
]
}
1 change: 1 addition & 0 deletions src/lib.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ mod tests {
mod test_game_discard_effect_card;
mod test_game_discard_special_card;
mod test_game_play;
mod test_game_select_deck;
mod utils;
}

Expand Down
95 changes: 33 additions & 62 deletions src/models/data/game_deck.cairo
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
use dojo::world::{IWorld, IWorldDispatcher, IWorldDispatcherTrait};
use jokers_of_neon::constants::card::INVALID_CARD;
use jokers_of_neon::constants::card::{
ACE_CLUBS_ID, ACE_DIAMONDS_ID, ACE_HEARTS_ID, ACE_SPADES_ID, JOKER_CARD, INVALID_CARD, SCRIBE_DECK, WARRIOR_DECK,
traditional_cards_all
};
use jokers_of_neon::constants::modifiers::{POINTS_MODIFIER_4_ID, MULTI_MODIFIER_4_ID};
use jokers_of_neon::store::{Store, StoreTrait};

#[derive(Copy, Drop, IntrospectPacked, Serde)]
#[dojo::model]
Expand All @@ -22,67 +27,33 @@ struct DeckCard {

#[generate_trait]
impl GameDeckImpl of IGameDeck {
fn init(world: IWorldDispatcher, game_id: u32) {
set!(
world,
(
GameDeck { game_id, len: 54, round_len: 54 },
DeckCard { game_id, index: 0, card_id: 0 },
DeckCard { game_id, index: 1, card_id: 1 },
DeckCard { game_id, index: 2, card_id: 2 },
DeckCard { game_id, index: 3, card_id: 3 },
DeckCard { game_id, index: 4, card_id: 4 },
DeckCard { game_id, index: 5, card_id: 5 },
DeckCard { game_id, index: 6, card_id: 6 },
DeckCard { game_id, index: 7, card_id: 7 },
DeckCard { game_id, index: 8, card_id: 8 },
DeckCard { game_id, index: 9, card_id: 9 },
DeckCard { game_id, index: 10, card_id: 10 },
DeckCard { game_id, index: 11, card_id: 11 },
DeckCard { game_id, index: 12, card_id: 12 },
DeckCard { game_id, index: 13, card_id: 13 },
DeckCard { game_id, index: 14, card_id: 14 },
DeckCard { game_id, index: 15, card_id: 15 },
DeckCard { game_id, index: 16, card_id: 16 },
DeckCard { game_id, index: 17, card_id: 17 },
DeckCard { game_id, index: 18, card_id: 18 },
DeckCard { game_id, index: 19, card_id: 19 },
DeckCard { game_id, index: 20, card_id: 20 },
DeckCard { game_id, index: 21, card_id: 21 },
DeckCard { game_id, index: 22, card_id: 22 },
DeckCard { game_id, index: 23, card_id: 23 },
DeckCard { game_id, index: 24, card_id: 24 },
DeckCard { game_id, index: 25, card_id: 25 },
DeckCard { game_id, index: 26, card_id: 26 },
DeckCard { game_id, index: 27, card_id: 27 },
DeckCard { game_id, index: 28, card_id: 28 },
DeckCard { game_id, index: 29, card_id: 29 },
DeckCard { game_id, index: 30, card_id: 30 },
DeckCard { game_id, index: 31, card_id: 31 },
DeckCard { game_id, index: 32, card_id: 32 },
DeckCard { game_id, index: 33, card_id: 33 },
DeckCard { game_id, index: 34, card_id: 34 },
DeckCard { game_id, index: 35, card_id: 35 },
DeckCard { game_id, index: 36, card_id: 36 },
DeckCard { game_id, index: 37, card_id: 37 },
DeckCard { game_id, index: 38, card_id: 38 },
DeckCard { game_id, index: 39, card_id: 39 },
DeckCard { game_id, index: 40, card_id: 40 },
DeckCard { game_id, index: 41, card_id: 41 },
DeckCard { game_id, index: 42, card_id: 42 },
DeckCard { game_id, index: 43, card_id: 43 },
DeckCard { game_id, index: 44, card_id: 44 },
DeckCard { game_id, index: 45, card_id: 45 },
DeckCard { game_id, index: 46, card_id: 46 },
DeckCard { game_id, index: 47, card_id: 47 },
DeckCard { game_id, index: 48, card_id: 48 },
DeckCard { game_id, index: 49, card_id: 49 },
DeckCard { game_id, index: 50, card_id: 50 },
DeckCard { game_id, index: 51, card_id: 51 },
DeckCard { game_id, index: 52, card_id: 52 },
DeckCard { game_id, index: 53, card_id: 52 },
)
);
fn init(ref store: Store, game_id: u32, deck_id: u8) {

// Traditional Deck
let mut cards = traditional_cards_all();
cards.append(JOKER_CARD);
cards.append(JOKER_CARD);

if deck_id == SCRIBE_DECK {
cards.append(JOKER_CARD);
cards.append(JOKER_CARD);
cards.append(JOKER_CARD);
cards.append(JOKER_CARD);
} else if deck_id == WARRIOR_DECK {
cards.append(JOKER_CARD);
cards.append(POINTS_MODIFIER_4_ID);
cards.append(POINTS_MODIFIER_4_ID);
cards.append(MULTI_MODIFIER_4_ID);
cards.append(MULTI_MODIFIER_4_ID);
} else { // WIZARD_DECK
cards.append(JOKER_CARD);
cards.append(JOKER_CARD);
cards.append(ACE_CLUBS_ID);
cards.append(ACE_DIAMONDS_ID);
cards.append(ACE_HEARTS_ID);
cards.append(ACE_SPADES_ID);
}
store.create_deck(game_id, cards);
}

fn add(ref self: GameDeck, world: IWorldDispatcher, card_id: u32) {
Expand Down
5 changes: 4 additions & 1 deletion src/models/status/game/game.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ use starknet::ContractAddress;

#[derive(Serde, Copy, Drop, IntrospectPacked, PartialEq)]
enum GameState {
IN_GAME,
SELECT_DECK,
SELECT_SPECIAL_CARDS,
SELECT_MODIFIER_CARDS,
AT_SHOP,
IN_GAME,
FINISHED,
OPEN_BLISTER_PACK
}
Expand Down
14 changes: 14 additions & 0 deletions src/store.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ use jokers_of_neon::models::data::blister_pack::BlisterPack;
use jokers_of_neon::models::data::card::{Card, Suit, Value, SuitEnumerableImpl, ValueEnumerableImpl,};
use jokers_of_neon::models::data::effect_card::{EffectCard, Effect};
use jokers_of_neon::models::data::events::{PokerHandEvent, CreateGameEvent, CardScoreEvent};
use jokers_of_neon::models::data::game_deck::{DeckCard, GameDeck};
use jokers_of_neon::models::data::poker_hand::{LevelPokerHand, PokerHand};

use jokers_of_neon::models::status::game::game::{Game, CurrentSpecialCards};
Expand Down Expand Up @@ -364,6 +365,19 @@ impl StoreImpl of StoreTrait {
fn set_blister_pack_result(ref self: Store, blister_pack_result: BlisterPackResult) {
set!(self.world, (blister_pack_result));
}

fn create_deck(ref self: Store, game_id: u32, cards: Array<u32>) {
set!(self.world, (GameDeck { game_id, len: cards.len(), round_len: cards.len() }));

let mut idx = 0;
loop {
if idx == cards.len() {
break;
}
set!(self.world, (DeckCard { game_id, index: idx, card_id: *cards[idx] }));
idx += 1;
}
}
}

fn get_traditional_card(id: u32) -> Card {
Expand Down
Loading

0 comments on commit da6bb8d

Please sign in to comment.