From ef49413e904a9eea078d1c94a678e03b6648e267 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Santiago=20Galv=C3=A1n=20=28Dub=29?= Date: Fri, 1 Nov 2024 03:19:31 +0100 Subject: [PATCH] refactor health (#7) --- src/models/data/beast.cairo | 1 - src/models/status/game/game.cairo | 2 ++ src/models/status/round/beast.cairo | 12 ++++++------ src/systems/game_system.cairo | 1 + 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/src/models/data/beast.cairo b/src/models/data/beast.cairo index 9c8c6fa..692087c 100644 --- a/src/models/data/beast.cairo +++ b/src/models/data/beast.cairo @@ -25,6 +25,5 @@ struct Beast { struct PlayerBeast { #[key] game_id: u32, - health: u32, energy: u8 } diff --git a/src/models/status/game/game.cairo b/src/models/status/game/game.cairo index 3e82a62..0f1846e 100644 --- a/src/models/status/game/game.cairo +++ b/src/models/status/game/game.cairo @@ -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, @@ -58,6 +59,7 @@ impl DefaultGame of Default { id: 1, owner: Zeroable::zero(), player_name: Zeroable::zero(), + player_hp: 500, max_hands: 5, max_discard: 5, max_jokers: 5, diff --git a/src/models/status/round/beast.cairo b/src/models/status/round/beast.cairo index 17c06ab..0d88cea 100644 --- a/src/models/status/round/beast.cairo +++ b/src/models/status/round/beast.cairo @@ -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}; @@ -53,7 +53,7 @@ impl BeastImpl of BeastTrait { BeastStore::set(@beast, world); emit!(world, (beast)); - 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); @@ -242,20 +242,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); } diff --git a/src/systems/game_system.cairo b/src/systems/game_system.cairo index 2cc3416..4f91924 100644 --- a/src/systems/game_system.cairo +++ b/src/systems/game_system.cairo @@ -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,