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

fix discard modifier #19

Merged
merged 1 commit into from
Nov 2, 2024
Merged
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
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
Loading