Skip to content

Commit

Permalink
add select special and modifier cards
Browse files Browse the repository at this point in the history
  • Loading branch information
dpinones committed Oct 30, 2024
1 parent da6bb8d commit e8e1014
Show file tree
Hide file tree
Showing 14 changed files with 449 additions and 17 deletions.
38 changes: 36 additions & 2 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": "0x58feb428c2692bda09414a95336a6f566852ff95338fe1760f21f53e520eba0",
"original_class_hash": "0x58feb428c2692bda09414a95336a6f566852ff95338fe1760f21f53e520eba0",
"class_hash": "0x5f74e789806e15032b0e17a3d05f4f70f03b1bba1f6522bdf755235ac6286af",
"original_class_hash": "0x5f74e789806e15032b0e17a3d05f4f70f03b1bba1f6522bdf755235ac6286af",
"base_class_hash": "0x2427dd10a58850ac9a5ca6ce04b7771b05330fd18f2e481831ad903b969e6b2",
"abi": [
{
Expand Down Expand Up @@ -1482,6 +1482,38 @@
"outputs": [],
"state_mutability": "external"
},
{
"type": "function",
"name": "select_special_cards",
"inputs": [
{
"name": "game_id",
"type": "core::integer::u32"
},
{
"name": "cards_index",
"type": "core::array::Array::<core::integer::u32>"
}
],
"outputs": [],
"state_mutability": "external"
},
{
"type": "function",
"name": "select_modifier_cards",
"inputs": [
{
"name": "game_id",
"type": "core::integer::u32"
},
{
"name": "cards_index",
"type": "core::array::Array::<core::integer::u32>"
}
],
"outputs": [],
"state_mutability": "external"
},
{
"type": "function",
"name": "play",
Expand Down Expand Up @@ -1666,6 +1698,8 @@
"tag": "jokers_of_neon-game_system",
"systems": [
"select_deck",
"select_special_cards",
"select_modifier_cards",
"play",
"discard",
"discard_effect_card",
Expand Down
6 changes: 4 additions & 2 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 = "0x58feb428c2692bda09414a95336a6f566852ff95338fe1760f21f53e520eba0"
original_class_hash = "0x58feb428c2692bda09414a95336a6f566852ff95338fe1760f21f53e520eba0"
class_hash = "0x5f74e789806e15032b0e17a3d05f4f70f03b1bba1f6522bdf755235ac6286af"
original_class_hash = "0x5f74e789806e15032b0e17a3d05f4f70f03b1bba1f6522bdf755235ac6286af"
base_class_hash = "0x2427dd10a58850ac9a5ca6ce04b7771b05330fd18f2e481831ad903b969e6b2"
abi = "manifests/dev/deployment/abis/contracts/jokers_of_neon-game_system-7a205bbc.json"
reads = []
Expand All @@ -34,6 +34,8 @@ init_calldata = []
tag = "jokers_of_neon-game_system"
systems = [
"select_deck",
"select_special_cards",
"select_modifier_cards",
"play",
"discard",
"discard_effect_card",
Expand Down
41 changes: 40 additions & 1 deletion src/constants/packs.cairo
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
use jokers_of_neon::constants::card::{JOKER_CARD, NEON_JOKER_CARD};
use jokers_of_neon::constants::modifiers::{modifiers_ids_all, SUIT_HEARTS_MODIFIER_ID};
use jokers_of_neon::constants::specials::{specials_ids_all, SPECIAL_ALL_CARDS_TO_HEARTS_ID};
use jokers_of_neon::constants::specials::{
specials_ids_all, SPECIAL_ALL_CARDS_TO_HEARTS_ID, common_specials_ids, uncommon_specials_ids, rare_specials_ids,
epic_specials_ids, legendary_specials_ids
};
use jokers_of_neon::models::data::blister_pack::BlisterPack;
use jokers_of_neon::models::data::card::{Card, CardTrait, Suit, Value, ValueEnumerableImpl};
use jokers_of_neon::utils::constants::{jokers_all, common_cards_all};
Expand All @@ -14,8 +17,12 @@ const FIGURES_BLISTER_PACK_ID: u32 = 6;
const DECEITFUL_JOKER_BLISTER_PACK_ID: u32 = 7;
const LOVERS_BLISTER_PACK_ID: u32 = 8;
const SPECIAL_BET_BLISTER_PACK_ID: u32 = 9;

const EMPTY_PACK_ID: u32 = 999;

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

fn blister_packs_ids_all() -> Array<u32> {
array![
BASIC_BLISTER_PACK_ID,
Expand Down Expand Up @@ -207,3 +214,35 @@ fn EMPTY_BLISTER_PACK() -> BlisterPack {
id: EMPTY_PACK_ID, cost: 0, name: '', probability: 0, size: 0, cards: array![].span(), probs: array![].span(),
}
}

fn SPECIAL_CARDS_PACK() -> BlisterPack {
BlisterPack {
id: SPECIAL_CARDS_PACK_ID,
cost: 0,
name: 'special_cards_pack',
probability: 100,
size: 5,
cards: array![
array![].span(),
legendary_specials_ids().span(),
epic_specials_ids().span(),
rare_specials_ids().span(),
uncommon_specials_ids().span(),
common_specials_ids().span()
]
.span(),
probs: array![100, 5, 10, 15, 25, 45].span(),
}
}

fn MODIFIER_CARDS_PACK() -> BlisterPack {
BlisterPack {
id: MODIFIER_CARDS_PACK_ID,
cost: 0,
name: 'modifier_cards_pack',
probability: 100,
size: 5,
cards: array![array![].span(), modifiers_ids_all().span()].span(),
probs: array![100, 100].span(),
}
}
35 changes: 35 additions & 0 deletions src/constants/specials.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -275,3 +275,38 @@ fn specials_ids_all() -> Array<u32> {
SPECIAL_LUCKY_HAND_ID,
]
}

fn common_specials_ids() -> Array<u32> {
array![
SPECIAL_MULTI_FOR_HEART_ID,
SPECIAL_MULTI_FOR_CLUB_ID,
SPECIAL_MULTI_FOR_DIAMOND_ID,
SPECIAL_MULTI_FOR_SPADE_ID,
SPECIAL_INCREASE_LEVEL_PAIR_ID,
SPECIAL_INCREASE_LEVEL_DOUBLE_PAIR_ID,
SPECIAL_LUCKY_HAND_ID,
]
}

fn uncommon_specials_ids() -> Array<u32> {
array![
SPECIAL_INCREASE_LEVEL_STRAIGHT_ID,
SPECIAL_INCREASE_LEVEL_FLUSH_ID,
SPECIAL_STRAIGHT_WITH_FOUR_CARDS_ID,
SPECIAL_FLUSH_WITH_FOUR_CARDS_ID,
SPECIAL_MULTI_ACES_ID,
SPECIAL_NEON_BONUS_ID
]
}

fn rare_specials_ids() -> Array<u32> {
array![SPECIAL_HAND_THIEF_ID, SPECIAL_LUCKY_SEVEN_ID, SPECIAL_POINTS_FOR_FIGURES_ID, SPECIAL_ALL_CARDS_TO_HEARTS_ID]
}

fn epic_specials_ids() -> Array<u32> {
array![SPECIAL_EXTRA_HELP_ID, SPECIAL_JOKER_BOOSTER_ID, SPECIAL_DEADLINE_ID]
}

fn legendary_specials_ids() -> Array<u32> {
array![SPECIAL_INITIAL_ADVANTAGE_ID, SPECIAL_MODIFIER_BOOSTER_ID]
}
3 changes: 3 additions & 0 deletions src/lib.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,15 @@ mod tests {
mod test_game_discard_special_card;
mod test_game_play;
mod test_game_select_deck;
mod test_game_select_modifier_cards;
mod test_game_select_special_cards;
mod utils;
}

mod utils {
mod calculate_hand;
mod constants;
mod packs;
mod rage;
mod random;
mod round;
Expand Down
3 changes: 1 addition & 2 deletions src/models/data/game_deck.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,11 @@ struct DeckCard {
#[generate_trait]
impl GameDeckImpl of IGameDeck {
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);
Expand Down
2 changes: 1 addition & 1 deletion src/models/status/game/game.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ impl DefaultGame of Default<Game> {
player_score: 0,
level: 1,
len_hand: 8,
len_max_current_special_cards: 1,
len_max_current_special_cards: 5,
len_current_special_cards: 0,
current_jokers: 0,
state: GameState::IN_GAME,
Expand Down
7 changes: 6 additions & 1 deletion src/store.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ use jokers_of_neon::constants::packs::{
FIGURES_BLISTER_PACK, DECEITFUL_JOKER_BLISTER_PACK, LOVERS_BLISTER_PACK, SPECIAL_BET_BLISTER_PACK,
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,
LOVERS_BLISTER_PACK_ID, SPECIAL_BET_BLISTER_PACK_ID, SPECIAL_CARDS_PACK_ID, SPECIAL_CARDS_PACK,
MODIFIER_CARDS_PACK_ID, MODIFIER_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 Expand Up @@ -345,6 +346,10 @@ impl StoreImpl of StoreTrait {
LOVERS_BLISTER_PACK()
} else if id == SPECIAL_BET_BLISTER_PACK_ID {
SPECIAL_BET_BLISTER_PACK()
} else if id == SPECIAL_CARDS_PACK_ID {
SPECIAL_CARDS_PACK()
} else if id == MODIFIER_CARDS_PACK_ID {
MODIFIER_CARDS_PACK()
} else {
EMPTY_BLISTER_PACK()
}
Expand Down
64 changes: 63 additions & 1 deletion src/systems/game_system.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ use jokers_of_neon::models::data::poker_hand::PokerHand;
trait IGameSystem {
fn create_game(ref world: IWorldDispatcher, player_name: felt252) -> u32;
fn select_deck(ref world: IWorldDispatcher, game_id: u32, deck_id: u8);
fn select_special_cards(ref world: IWorldDispatcher, game_id: u32, cards_index: Array<u32>);
fn select_modifier_cards(ref world: IWorldDispatcher, game_id: u32, cards_index: Array<u32>);
fn play(ref world: IWorldDispatcher, game_id: u32, cards_index: Array<u32>, modifiers_index: Array<u32>);
fn discard(ref world: IWorldDispatcher, game_id: u32, cards_index: Array<u32>, modifiers_index: Array<u32>);
fn check_hand(
Expand All @@ -25,6 +27,7 @@ mod errors {
const GAME_NOT_IN_GAME: felt252 = 'Game: is not IN_GAME';
const GAME_NOT_SELECT_SPECIAL_CARDS: felt252 = 'Game:is not SELECT_SPECIAL_CARD';
const GAME_NOT_SELECT_DECK: felt252 = 'Game:is not SELECT_DECK';
const GAME_NOT_SELECT_MODIFIER_CARDS: felt252 = 'Game:is not SELCT_MODIFIER_CARD';
const USE_INVALID_CARD: felt252 = 'Game: use an invalid card';
const INVALID_DECK_ID: felt252 = 'Game: use an invalid deck';
}
Expand All @@ -34,6 +37,7 @@ mod game_system {
use core::nullable::NullableTrait;
use dojo::world::Resource::Contract;
use jokers_of_neon::constants::card::{JOKER_CARD, NEON_JOKER_CARD, INVALID_CARD};
use jokers_of_neon::constants::packs::{SPECIAL_CARDS_PACK_ID, MODIFIER_CARDS_PACK_ID};
use jokers_of_neon::constants::specials::{
SPECIAL_MULTI_FOR_HEART_ID, SPECIAL_MULTI_FOR_CLUB_ID, SPECIAL_MULTI_FOR_DIAMOND_ID, SPECIAL_MULTI_FOR_SPADE_ID,
SPECIAL_INCREASE_LEVEL_PAIR_ID, SPECIAL_INCREASE_LEVEL_DOUBLE_PAIR_ID, SPECIAL_INCREASE_LEVEL_STRAIGHT_ID,
Expand All @@ -56,6 +60,7 @@ mod game_system {
use jokers_of_neon::models::status::game::rage::{RageRound, RageRoundStore};
use jokers_of_neon::models::status::round::current_hand_card::{CurrentHandCard, CurrentHandCardTrait};
use jokers_of_neon::models::status::round::round::Round;
use jokers_of_neon::models::status::shop::shop::{BlisterPackResult};

use jokers_of_neon::store::{Store, StoreTrait};
use jokers_of_neon::systems::rage_system::{IRageSystemDispatcher, IRageSystemDispatcherTrait};
Expand All @@ -64,6 +69,7 @@ mod game_system {
RAGE_CARD_DIMINISHED_HOLD, RAGE_CARD_SILENT_JOKERS, RAGE_CARD_SILENT_HEARTS, RAGE_CARD_SILENT_CLUBS,
RAGE_CARD_SILENT_DIAMONDS, RAGE_CARD_SILENT_SPADES, RAGE_CARD_ZERO_WASTE, is_neon_card, is_modifier_card
};
use jokers_of_neon::utils::packs::{open_blister_pack, select_cards_from_blister};
use jokers_of_neon::utils::rage::is_rage_card_active;
use jokers_of_neon::utils::round::create_round;
use starknet::{ContractAddress, get_caller_address, ClassHash};
Expand All @@ -89,7 +95,7 @@ mod game_system {
player_score: 0,
level: 1,
len_hand: 8,
len_max_current_special_cards: 1,
len_max_current_special_cards: 5,
len_current_special_cards: 0,
current_jokers: 0,
state: GameState::SELECT_DECK,
Expand Down Expand Up @@ -118,10 +124,66 @@ mod game_system {
assert(deck_id < 3, errors::INVALID_DECK_ID);

GameDeckImpl::init(ref store, game_id, deck_id);
game.state = GameState::SELECT_SPECIAL_CARDS;
store.set_game(game);

let cards = open_blister_pack(world, ref store, game, SPECIAL_CARDS_PACK_ID);
store.set_blister_pack_result(BlisterPackResult { game_id, cards_picked: false, cards });
}

fn select_special_cards(ref world: IWorldDispatcher, game_id: u32, cards_index: Array<u32>) {
let mut store: Store = StoreTrait::new(world);

let mut game = store.get_game(game_id);
// Check that the game exists (if the game has no owner means it does not exists)
assert(game.owner.is_non_zero(), errors::GAME_NOT_FOUND);

// Check that the owner of the game is the caller
assert(game.owner == get_caller_address(), errors::CALLER_NOT_OWNER);

// Check that the status of the game
assert(game.state == GameState::SELECT_SPECIAL_CARDS, errors::GAME_NOT_SELECT_SPECIAL_CARDS);

let mut blister_pack_result = store.get_blister_pack_result(game.id);
assert(cards_index.len() <= 2, errors::INVALID_CARD_INDEX_LEN);

select_cards_from_blister(world, ref game, blister_pack_result.cards, cards_index);

blister_pack_result.cards_picked = true;
store.set_blister_pack_result(blister_pack_result);

let cards = open_blister_pack(world, ref store, game, MODIFIER_CARDS_PACK_ID);
store.set_blister_pack_result(BlisterPackResult { game_id, cards_picked: false, cards });

game.state = GameState::SELECT_MODIFIER_CARDS;
store.set_game(game);
}

fn select_modifier_cards(ref world: IWorldDispatcher, game_id: u32, cards_index: Array<u32>) {
let mut store: Store = StoreTrait::new(world);

let mut game = store.get_game(game_id);
// Check that the game exists (if the game has no owner means it does not exists)
assert(game.owner.is_non_zero(), errors::GAME_NOT_FOUND);

// Check that the owner of the game is the caller
assert(game.owner == get_caller_address(), errors::CALLER_NOT_OWNER);

// Check that the status of the game
assert(game.state == GameState::SELECT_MODIFIER_CARDS, errors::GAME_NOT_SELECT_MODIFIER_CARDS);

let mut blister_pack_result = store.get_blister_pack_result(game.id);
assert(cards_index.len() <= 5, errors::INVALID_CARD_INDEX_LEN);

select_cards_from_blister(world, ref game, blister_pack_result.cards, cards_index);

blister_pack_result.cards_picked = true;
store.set_blister_pack_result(blister_pack_result);

// game.state = GameState::; / TODO:
store.set_game(game);
}

fn play(ref world: IWorldDispatcher, game_id: u32, cards_index: Array<u32>, modifiers_index: Array<u32>) {
let mut store: Store = StoreTrait::new(world);

Expand Down
12 changes: 5 additions & 7 deletions src/tests/test_game_select_deck.cairo
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
mod test_select_deck {
use dojo::world::{IWorldDispatcher, IWorldDispatcherTrait};
use jokers_of_neon::models::status::game::game::{Game, GameState};
use jokers_of_neon::models::data::game_deck::{GameDeck, GameDeckStore, DeckCard, DeckCardStore};
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, WIZARD_DECK,
traditional_cards_all
ACE_CLUBS_ID, ACE_DIAMONDS_ID, ACE_HEARTS_ID, ACE_SPADES_ID, JOKER_CARD, INVALID_CARD, SCRIBE_DECK,
WARRIOR_DECK, WIZARD_DECK, traditional_cards_all
};
use jokers_of_neon::constants::modifiers::{POINTS_MODIFIER_4_ID, MULTI_MODIFIER_4_ID};
use jokers_of_neon::models::data::game_deck::{GameDeck, GameDeckStore, DeckCard, DeckCardStore};
use jokers_of_neon::models::status::game::game::{Game, GameState};
use jokers_of_neon::store::{Store, StoreTrait};
use jokers_of_neon::systems::game_system::{game_system, IGameSystemDispatcher, IGameSystemDispatcherTrait};
use jokers_of_neon::tests::setup::{
setup, setup::OWNER, setup::IDojoInitDispatcher, setup::IDojoInitDispatcherTrait
};
use jokers_of_neon::tests::utils::{
mock_game
};
use jokers_of_neon::tests::utils::{mock_game};
use starknet::testing::set_contract_address;

fn PLAYER() -> starknet::ContractAddress {
Expand Down
Loading

0 comments on commit e8e1014

Please sign in to comment.