Skip to content

Commit

Permalink
add player data to game
Browse files Browse the repository at this point in the history
  • Loading branch information
dubzn committed Nov 2, 2024
1 parent 9125c47 commit d1ff145
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 8 deletions.
12 changes: 8 additions & 4 deletions src/models/status/game/game.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,21 @@ struct Game {
owner: ContractAddress,
player_name: felt252,
player_hp: u32,
player_score: u32,
player_level: u32,
obstacles_cleared: u32,
beasts_defeated: u32,
current_player_hp: u32,
max_hands: u8,
max_discard: u8,
max_jokers: u8,
player_score: u32,
level: u32,
len_hand: u32,
len_max_current_special_cards: u32,
len_current_special_cards: u32,
current_jokers: u8,
state: GameState,
substate: GameSubState,
cash: u32
}

#[derive(Copy, Drop, IntrospectPacked, Serde)]
Expand All @@ -62,19 +64,21 @@ impl DefaultGame of Default<Game> {
owner: Zeroable::zero(),
player_name: Zeroable::zero(),
player_hp: 500,
player_score: 0,
obstacles_cleared: 0,
beasts_defeated: 0,
player_level: 1,
current_player_hp: 500,
max_hands: 5,
max_discard: 5,
max_jokers: 5,
player_score: 0,
level: 1,
len_hand: 8,
len_max_current_special_cards: 5,
len_current_special_cards: 0,
current_jokers: 0,
state: GameState::IN_GAME,
substate: GameSubState::CREATE_LEVEL,
cash: 0
}
}
}
9 changes: 6 additions & 3 deletions src/models/status/round/beast.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,18 @@ impl BeastImpl of BeastTrait {
player_beast.energy -= game_mode_beast.cost_play;
PlayerBeastStore::set(@player_beast, world);


if beast.current_health.is_zero() {
let play_win_game_event = PlayWinGameEvent {
player: get_caller_address(), game_id, level: game.level, player_score: 0
};
emit!(world, (play_win_game_event));
game.state = GameState::IN_GAME;
game.player_score += (beast.tier).into() * 500 + (beast.level).into() * 100;
game.beasts_defeated += 1;
game.player_level += 1;
game.player_hp += 10;
game.current_player_hp += 10;

game.substate = GameSubState::CREATE_REWARD;
game.player_score += 1;

if is_rage_card_active(@rage_round, RAGE_CARD_DIMINISHED_HOLD) {
// return the cards to the deck
Expand Down
3 changes: 3 additions & 0 deletions src/models/status/round/challenge.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ impl ChallengeImpl of ChallengeTrait {
if Self::is_completed(world, game_id) {
emit!(world, ChallengeCompleted { player: game.owner, player_name: game.player_name, game_id });
game.substate = GameSubState::CREATE_REWARD;
game.player_score += challenge.active_ids.len() * 100;
game.obstacles_cleared += 1;

GameStore::set(@game, world);
} else {
challenge_player.plays -= 1;
Expand Down
4 changes: 3 additions & 1 deletion src/systems/game_system.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,10 @@ mod game_system {
owner: player_id,
player_name,
player_hp: 500, // TODO: Obtain HP from adventurer
player_level: 1,
current_player_hp: 500,
obstacles_cleared: 0,
beasts_defeated: 0,
max_hands: 5,
max_discard: 5,
max_jokers: 5,
Expand All @@ -114,7 +117,6 @@ mod game_system {
current_jokers: 0,
state: GameState::IN_GAME,
substate: GameSubState::DRAFT_DECK,
cash: 0
};
store.set_game(game);
emit!(world, (game));
Expand Down

0 comments on commit d1ff145

Please sign in to comment.