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

JON-477: Move HP to game entity #7

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
1 change: 0 additions & 1 deletion src/models/data/beast.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,5 @@ struct Beast {
struct PlayerBeast {
#[key]
game_id: u32,
health: u32,
energy: u8
}
2 changes: 2 additions & 0 deletions src/models/status/game/game.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ struct Game {
id: u32,
owner: ContractAddress,
player_name: felt252,
player_hp: u32,
max_hands: u8,
max_discard: u8,
max_jokers: u8,
Expand Down Expand Up @@ -58,6 +59,7 @@ impl DefaultGame of Default<Game> {
id: 1,
owner: Zeroable::zero(),
player_name: Zeroable::zero(),
player_hp: 500,
max_hands: 5,
max_discard: 5,
max_jokers: 5,
Expand Down
12 changes: 6 additions & 6 deletions src/models/status/round/beast.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use jokers_of_neon::models::data::beast::{
};
use jokers_of_neon::models::data::events::{PlayWinGameEvent, PlayGameOverEvent};
use jokers_of_neon::models::data::game_deck::{GameDeckImpl, GameDeck, GameDeckStore};
use jokers_of_neon::models::status::game::game::{Game, GameState, GameSubState};
use jokers_of_neon::models::status::game::game::{Game, GameStore, GameState, GameSubState};
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::store::{Store, StoreTrait};
Expand Down Expand Up @@ -52,7 +52,7 @@ impl BeastImpl of BeastTrait {
let beast = Beast { game_id, tier: 5, level: 5, health: 300, attack: 15 };
BeastStore::set(@beast, world);

let player_beast = PlayerBeast { game_id, health: 100, energy: game_mode_beast.energy_max_player };
let player_beast = PlayerBeast { game_id, energy: game_mode_beast.energy_max_player };
PlayerBeastStore::set(@player_beast, world);

let mut game_deck = GameDeckStore::get(world, game_id);
Expand Down Expand Up @@ -241,20 +241,20 @@ fn _attack_beast(
ref beast: Beast,
ref game_mode_beast: GameModeBeast
) {
player_beast.health = if beast.attack > player_beast.health {
game.player_hp = if beast.attack > game.player_hp {
0
} else {
player_beast.health - beast.attack
game.player_hp - beast.attack
};

if player_beast.health.is_zero() {
if game.player_hp.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;
store.set_game(game);
} else {
// reset energy
player_beast.energy = game_mode_beast.energy_max_player;
}
store.set_game(game);
PlayerBeastStore::set(@player_beast, world);
}
1 change: 1 addition & 0 deletions src/systems/game_system.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ mod game_system {
id: game_id,
owner: player_id,
player_name,
player_hp: 500, // TODO: Obtain HP from adventurer
max_hands: 5,
max_discard: 5,
max_jokers: 5,
Expand Down
Loading