From db2be0e7bb2f99ce665a581dc2fe7b25e79a30b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Damian=20Pi=C3=B1ones?= Date: Thu, 31 Oct 2024 13:12:00 -0300 Subject: [PATCH] update beast system --- src/systems/beast_system.cairo | 14 ++++++++++++++ src/systems/game_system.cairo | 21 ++++++++++++++------- src/utils/level.cairo | 22 ++++++++++------------ 3 files changed, 38 insertions(+), 19 deletions(-) diff --git a/src/systems/beast_system.cairo b/src/systems/beast_system.cairo index d99239c..66bd1cd 100644 --- a/src/systems/beast_system.cairo +++ b/src/systems/beast_system.cairo @@ -141,6 +141,7 @@ mod beast_system { assert(game.owner.is_non_zero(), errors::GAME_NOT_FOUND); assert(game.owner == get_caller_address(), errors::CALLER_NOT_OWNER); assert(game.state == GameState::IN_GAME, errors::GAME_NOT_IN_GAME); + assert(game.substate == GameSubState::BEAST, errors::GAME_NOT_IN_BEAST); let mut cards = array![]; let mut idx = 0; @@ -182,10 +183,23 @@ mod beast_system { game.state = GameState::FINISHED; store.set_game(game); } + + if player_beast.energy.is_zero() { + let mut beast = BeastStore::get(world, game.id); + println!("energia en zero - me ataca la bestia"); + self._attack_beast(world, ref store, ref game, ref player_beast, ref beast, ref game_mode_beast); + } } + fn end_turn(ref world: IWorldDispatcher, game_id: u32) { let mut store: Store = StoreTrait::new(world); let mut game = store.get_game(game_id); + + assert(game.owner.is_non_zero(), errors::GAME_NOT_FOUND); + assert(game.owner == get_caller_address(), errors::CALLER_NOT_OWNER); + assert(game.state == GameState::IN_GAME, errors::GAME_NOT_IN_GAME); + assert(game.substate == GameSubState::BEAST, errors::GAME_NOT_IN_BEAST); + let mut beast = BeastStore::get(world, game.id); let mut game_mode_beast = GameModeBeastStore::get(world, game.id); let mut player_beast = PlayerBeastStore::get(world, game.id); diff --git a/src/systems/game_system.cairo b/src/systems/game_system.cairo index f782418..92edcc1 100644 --- a/src/systems/game_system.cairo +++ b/src/systems/game_system.cairo @@ -59,8 +59,8 @@ mod game_system { use jokers_of_neon::models::status::shop::shop::{BlisterPackResult}; use jokers_of_neon::store::{Store, StoreTrait}; - use jokers_of_neon::systems::rage_system::{IRageSystemDispatcher, IRageSystemDispatcherTrait}; use jokers_of_neon::systems::beast_system::{IBeastSystemDispatcher, IBeastSystemDispatcherTrait}; + use jokers_of_neon::systems::rage_system::{IRageSystemDispatcher, IRageSystemDispatcherTrait}; use jokers_of_neon::utils::calculate_hand::calculate_hand; use jokers_of_neon::utils::constants::{ RAGE_CARD_DIMINISHED_HOLD, RAGE_CARD_SILENT_JOKERS, RAGE_CARD_SILENT_HEARTS, RAGE_CARD_SILENT_CLUBS, @@ -190,11 +190,13 @@ mod game_system { assert(game.owner.is_non_zero(), errors::GAME_NOT_FOUND); if game.substate == GameSubState::BEAST { - let (_, beast_system_address) = match world.resource(selector_from_tag!("jokers_of_neon-beast_system")) { + let (_, beast_system_address) = + match world.resource(selector_from_tag!("jokers_of_neon-beast_system")) { Contract((class_hash, contract_address)) => Option::Some((class_hash, contract_address)), _ => Option::None }.unwrap(); - IBeastSystemDispatcher { contract_address: beast_system_address.try_into().unwrap() }.play(game_id, cards_index, modifiers_index); + IBeastSystemDispatcher { contract_address: beast_system_address.try_into().unwrap() } + .play(game_id, cards_index, modifiers_index); } } @@ -202,13 +204,16 @@ mod game_system { let mut store: Store = StoreTrait::new(world); let game = store.get_game(game_id); + assert(game.owner.is_non_zero(), errors::GAME_NOT_FOUND); if game.substate == GameSubState::BEAST { - let (_, beast_system_address) = match world.resource(selector_from_tag!("jokers_of_neon-beast_system")) { + let (_, beast_system_address) = + match world.resource(selector_from_tag!("jokers_of_neon-beast_system")) { Contract((class_hash, contract_address)) => Option::Some((class_hash, contract_address)), _ => Option::None }.unwrap(); - IBeastSystemDispatcher { contract_address: beast_system_address.try_into().unwrap() }.discard(game_id, cards_index, modifiers_index); + IBeastSystemDispatcher { contract_address: beast_system_address.try_into().unwrap() } + .discard(game_id, cards_index, modifiers_index); } } @@ -216,9 +221,11 @@ mod game_system { let mut store: Store = StoreTrait::new(world); let game = store.get_game(game_id); - + assert(game.owner.is_non_zero(), errors::GAME_NOT_FOUND); + if game.substate == GameSubState::BEAST { - let (_, beast_system_address) = match world.resource(selector_from_tag!("jokers_of_neon-beast_system")) { + let (_, beast_system_address) = + match world.resource(selector_from_tag!("jokers_of_neon-beast_system")) { Contract((class_hash, contract_address)) => Option::Some((class_hash, contract_address)), _ => Option::None }.unwrap(); diff --git a/src/utils/level.cairo b/src/utils/level.cairo index 4965d2a..987497f 100644 --- a/src/utils/level.cairo +++ b/src/utils/level.cairo @@ -1,25 +1,23 @@ use dojo::world::{IWorld, IWorldDispatcher, IWorldDispatcherTrait}; +use jokers_of_neon::models::data::game_deck::{GameDeckImpl, GameDeck, GameDeckStore}; +use jokers_of_neon::models::game_mode::beast::{ + GameModeBeast, GameModeBeastStore, Beast, BeastStore, PlayerBeast, PlayerBeastStore +}; use jokers_of_neon::models::status::game::game::{Game, GameState, GameSubState}; -use jokers_of_neon::store::{Store, StoreTrait}; -use jokers_of_neon::utils::random::{Random, RandomImpl, RandomTrait}; use jokers_of_neon::models::status::game::rage::{RageRound, RageRoundStore}; -use jokers_of_neon::utils::rage::is_rage_card_active; +use jokers_of_neon::models::status::round::current_hand_card::{CurrentHandCard, CurrentHandCardTrait}; +use jokers_of_neon::store::{Store, StoreTrait}; use jokers_of_neon::utils::constants::{ RAGE_CARD_DIMINISHED_HOLD, RAGE_CARD_SILENT_JOKERS, RAGE_CARD_SILENT_HEARTS, RAGE_CARD_SILENT_CLUBS, RAGE_CARD_SILENT_DIAMONDS, RAGE_CARD_SILENT_SPADES, RAGE_CARD_ZERO_WASTE, is_neon_card, is_modifier_card }; -use jokers_of_neon::models::game_mode::beast::{ - GameModeBeast, GameModeBeastStore, Beast, BeastStore, PlayerBeast, PlayerBeastStore -}; -use jokers_of_neon::models::data::game_deck::{GameDeckImpl, GameDeck, GameDeckStore}; -use jokers_of_neon::models::status::round::current_hand_card::{CurrentHandCard, CurrentHandCardTrait}; +use jokers_of_neon::utils::rage::is_rage_card_active; +use jokers_of_neon::utils::random::{Random, RandomImpl, RandomTrait}; fn create_level(world: IWorldDispatcher, ref store: Store, game: Game) { - if true { - create_beast_level(world, ref store, game); + create_beast_level(world, ref store, game); } - } fn create_beast_level(world: IWorldDispatcher, ref store: Store, game: Game) { @@ -34,7 +32,7 @@ fn create_beast_level(world: IWorldDispatcher, ref store: Store, game: Game) { } store.set_game(game); - let game_mode_beast = GameModeBeast { game_id: game.id, cost_discard: 2, cost_play: 1, energy_max_player: 3 }; + let game_mode_beast = GameModeBeast { game_id: game.id, cost_discard: 1, cost_play: 2, energy_max_player: 3 }; GameModeBeastStore::set(@game_mode_beast, world); let beast = Beast { game_id: game.id, tier: 5, level: 5, health: 300, attack: 15 };