Skip to content

Commit

Permalink
update beast system
Browse files Browse the repository at this point in the history
  • Loading branch information
dpinones committed Oct 31, 2024
1 parent 3d61227 commit db2be0e
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 19 deletions.
14 changes: 14 additions & 0 deletions src/systems/beast_system.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
21 changes: 14 additions & 7 deletions src/systems/game_system.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -190,35 +190,42 @@ 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);
}
}

fn discard(ref world: IWorldDispatcher, game_id: u32, cards_index: Array<u32>, modifiers_index: Array<u32>) {
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);
}
}

fn end_turn(ref world: IWorldDispatcher, game_id: u32) {
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();
Expand Down
22 changes: 10 additions & 12 deletions src/utils/level.cairo
Original file line number Diff line number Diff line change
@@ -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) {
Expand All @@ -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 };
Expand Down

0 comments on commit db2be0e

Please sign in to comment.