Skip to content

Commit

Permalink
fix discard modifier (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
dpinones authored Nov 2, 2024
1 parent fb2c351 commit 23ba3b2
Showing 1 changed file with 32 additions and 10 deletions.
42 changes: 32 additions & 10 deletions src/models/status/round/challenge.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -89,25 +89,47 @@ impl ChallengeImpl of ChallengeTrait {
GameStore::set(@game, world);
} else {
challenge_player.plays -= 1;
emit!(world, (challenge_player));
ChallengePlayerStore::set(@challenge_player, world);
if challenge_player.plays.is_zero() {
let play_game_over_event = PlayGameOverEvent { player: get_caller_address(), game_id: game.id };
emit!(world, (play_game_over_event));
game.state = GameState::FINISHED;
GameStore::set(@game, world);
return;
}
emit!(world, (challenge_player));
ChallengePlayerStore::set(@challenge_player, world);
}

CurrentHandCardTrait::refresh(world, game_id, cards_index);
let mut cards = array![];
let mut idx = 0;
loop {
if idx == cards_index.len() {
break;
}
cards.append(*cards_index.at(idx));
idx += 1;
};

let game_deck = GameDeckStore::get(world, game_id);
if game_deck.round_len.is_zero() && _player_has_empty_hand(ref store, @game) {
let play_game_over_event = PlayGameOverEvent { player: get_caller_address(), game_id: game.id };
emit!(world, (play_game_over_event));
game.state = GameState::FINISHED;
GameStore::set(@game, world);
idx = 0;
loop {
if idx == modifiers_index.len() {
break;
}
let card_index = *modifiers_index.at(idx);
if card_index != 100 {
cards.append(card_index);
}
idx += 1;
};

CurrentHandCardTrait::refresh(world, game_id, cards);

let game_deck = GameDeckStore::get(world, game_id);
if game_deck.round_len.is_zero() && _player_has_empty_hand(ref store, @game) {
let play_game_over_event = PlayGameOverEvent { player: get_caller_address(), game_id: game.id };
emit!(world, (play_game_over_event));
game.state = GameState::FINISHED;
GameStore::set(@game, world);
}
}
}

Expand Down

0 comments on commit 23ba3b2

Please sign in to comment.