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

Challenge - Add substate transition #11

Merged
merged 1 commit into from
Nov 1, 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
14 changes: 11 additions & 3 deletions src/models/status/round/challenge.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ mod errors {
const SUBSTATE_NOT_OBSTACLE: felt252 = 'Substate not OBSTACLE';
const USE_INVALID_CARD: felt252 = 'Use an invalid card';
const ARRAY_REPEATED_ELEMENTS: felt252 = 'Array has repeated elements';
const OUT_OF_PLAYS: felt252 = 'Out of plays';
const OUT_OF_DISCARDS: felt252 = 'Out of discards';
}

#[generate_trait]
Expand All @@ -52,6 +54,9 @@ impl ChallengeImpl of ChallengeTrait {
assert(game.state == GameState::IN_GAME, errors::STATE_NOT_IN_GAME);
assert(game.substate == GameSubState::OBSTACLE, errors::SUBSTATE_NOT_OBSTACLE);

let mut challenge_player = ChallengePlayerStore::get(world, game_id);
assert(challenge_player.plays > 0, errors::OUT_OF_PLAYS);

let mut store = StoreTrait::new(world);
let mut current_special_cards_index = _current_special_cards(ref store, @game);
let (mut cards, _, _) = _get_cards(
Expand All @@ -65,9 +70,10 @@ impl ChallengeImpl of ChallengeTrait {
ChallengeStore::set(@challenge, world);

if Self::is_completed(@world, game_id) {
emit!(world, ChallengeCompleted { player: game.owner, player_name: game.player_name, game_id })
emit!(world, ChallengeCompleted { player: game.owner, player_name: game.player_name, game_id });
game.substate = GameSubState::CREATE_LEVEL;
GameStore::set(@game, world);
} else {
let mut challenge_player = ChallengePlayerStore::get(world, game_id);
challenge_player.plays -= 1;
ChallengePlayerStore::set(@challenge_player, world);
}
Expand All @@ -88,6 +94,9 @@ impl ChallengeImpl of ChallengeTrait {
assert(game.state == GameState::IN_GAME, errors::STATE_NOT_IN_GAME);
assert(game.substate == GameSubState::OBSTACLE, errors::SUBSTATE_NOT_OBSTACLE);

let mut challenge_player = ChallengePlayerStore::get(world, game_id);
assert(challenge_player.discards > 0, errors::OUT_OF_DISCARDS);

let mut store = StoreTrait::new(world);
let mut cards = array![];
let mut idx = 0;
Expand Down Expand Up @@ -115,7 +124,6 @@ impl ChallengeImpl of ChallengeTrait {
};
CurrentHandCardTrait::refresh(world, game_id, cards);

let mut challenge_player = ChallengePlayerStore::get(world, game_id);
challenge_player.discards -= 1;
ChallengePlayerStore::set(@challenge_player, world);

Expand Down
10 changes: 2 additions & 8 deletions src/tests/test_game_play_beast.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,7 @@ mod test_play_beast_special_cards {

// Mock hand
let hand_cards_ids = array![
SIX_CLUBS_ID,
QUEEN_CLUBS_ID,
FOUR_CLUBS_ID,
JACK_HEARTS_ID,
KING_DIAMONDS_ID,
MULTI_MODIFIER_1_ID
SIX_CLUBS_ID, QUEEN_CLUBS_ID, FOUR_CLUBS_ID, JACK_HEARTS_ID, KING_DIAMONDS_ID, MULTI_MODIFIER_1_ID
];
mock_current_hand_cards_ids(ref store, game.id, hand_cards_ids);

Expand Down Expand Up @@ -318,8 +313,7 @@ mod test_play_beast_modifier_cards {
KING_SPADES_ID, TWO_SPADES_ID, TWO_DIAMONDS_ID, TWO_CLUBS_ID, FOUR_DIAMONDS_ID, FOUR_HEARTS_ID
};
use jokers_of_neon::constants::modifiers::{
MULTI_MODIFIER_1_ID, POINTS_MODIFIER_4_ID, MULTI_MODIFIER_4_ID, POINTS_MODIFIER_2_ID,
MULTI_MODIFIER_3_ID,
MULTI_MODIFIER_1_ID, POINTS_MODIFIER_4_ID, MULTI_MODIFIER_4_ID, POINTS_MODIFIER_2_ID, MULTI_MODIFIER_3_ID,
};
use jokers_of_neon::models::data::beast::{
GameModeBeast, GameModeBeastStore, Beast, BeastStore, PlayerBeast, PlayerBeastStore
Expand Down
Loading