Skip to content

Commit

Permalink
JON-466: loot survivor beast (#15)
Browse files Browse the repository at this point in the history
* wip loot survivor beast

* update beast_id
  • Loading branch information
dpinones authored Nov 1, 2024
1 parent 3f6506f commit e40a4e3
Show file tree
Hide file tree
Showing 4 changed files with 197 additions and 5 deletions.
159 changes: 159 additions & 0 deletions src/constants/beast.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,159 @@
const AMMIT_BEAST_ID: u32 = 1;
const ANANSI_BEAST_ID: u32 = 2;
const BALROG_BEAST_ID: u32 = 3;
const BANSHEE_BEAST_ID: u32 = 4;
const BASILISK_BEAST_ID: u32 = 5;
const BEAR_BEAST_ID: u32 = 6;
const BEHEMOTH_BEAST_ID: u32 = 7;
const BERSERKER_BEAST_ID: u32 = 8;
const BIGFOOT_BEAST_ID: u32 = 9;
const CHIMERA_BEAST_ID: u32 = 10;
const CHUPACABRA_BEAST_ID: u32 = 11;
const COLOSSUS_BEAST_ID: u32 = 12;
const CYCLOPS_BEAST_ID: u32 = 13;
const DIREWOLF_BEAST_ID: u32 = 14;
const DRAGON_BEAST_ID: u32 = 15;
const DRAUGR_BEAST_ID: u32 = 16;
const ENT_BEAST_ID: u32 = 17;
const ETTIN_BEAST_ID: u32 = 18;
const FAIRY_BEAST_ID: u32 = 19;
const FENRIR_BEAST_ID: u32 = 20;
const GHOUL_BEAST_ID: u32 = 21;
const GIANT_BEAST_ID: u32 = 22;
const GNOME_BEAST_ID: u32 = 23;
const GOBLIN_BEAST_ID: u32 = 24;
const GOLEM_BEAST_ID: u32 = 25;
const GORGON_BEAST_ID: u32 = 26;
const GRIFFIN_BEAST_ID: u32 = 27;
const HARPY_BEAST_ID: u32 = 28;
const HIPPOGRIFF_BEAST_ID: u32 = 29;
const HYDRA_BEAST_ID: u32 = 30;
const JAGUAR_BEAST_ID: u32 = 31;
const JIANGSHI_BEAST_ID: u32 = 32;
const JOTUNN_BEAST_ID: u32 = 33;
const JUGGERNAUT_BEAST_ID: u32 = 34;
const KAPPA_BEAST_ID: u32 = 35;
const KELPIE_BEAST_ID: u32 = 36;
const KITSUNE_BEAST_ID: u32 = 37;
const KRAKEN_BEAST_ID: u32 = 38;
const LEPRECHAUN_BEAST_ID: u32 = 39;
const LEVIATHAN_BEAST_ID: u32 = 40;
const LICH_BEAST_ID: u32 = 41;
const MANTICORE_BEAST_ID: u32 = 42;
const MANTIS_BEAST_ID: u32 = 43;
const MINOTAUR_BEAST_ID: u32 = 44;
const NEMEANLION_BEAST_ID: u32 = 45;
const NEPHILIM_BEAST_ID: u32 = 46;
const NUE_BEAST_ID: u32 = 47;
const OGRE_BEAST_ID: u32 = 48;
const ONI_BEAST_ID: u32 = 49;
const ORC_BEAST_ID: u32 = 50;
const PEGASUS_BEAST_ID: u32 = 51;
const PHOENIX_BEAST_ID: u32 = 52;
const PIXIE_BEAST_ID: u32 = 53;
const QILIN_BEAST_ID: u32 = 54;
const RAKSHASA_BEAST_ID: u32 = 55;
const RAT_BEAST_ID: u32 = 56;
const ROC_BEAST_ID: u32 = 57;
const SATORI_BEAST_ID: u32 = 58;
const SKELETON_BEAST_ID: u32 = 59;
const SKINWALKER_BEAST_ID: u32 = 60;
const SPIDER_BEAST_ID: u32 = 61;
const SPRITE_BEAST_ID: u32 = 62;
const TARRASQUE_BEAST_ID: u32 = 63;
const TITAN_BEAST_ID: u32 = 64;
const TROLL_BEAST_ID: u32 = 65;
const TYPHON_BEAST_ID: u32 = 66;
const VAMPIRE_BEAST_ID: u32 = 67;
const WARLOCK_BEAST_ID: u32 = 68;
const WENDIGO_BEAST_ID: u32 = 69;
const WERETIGER_BEAST_ID: u32 = 70;
const WEREWOLF_BEAST_ID: u32 = 71;
const WOLF_BEAST_ID: u32 = 72;
const WRAITH_BEAST_ID: u32 = 73;
const WYVERN_BEAST_ID: u32 = 74;
const YETI_BEAST_ID: u32 = 75;

fn all_beast() -> Array<u32> {
array![
AMMIT_BEAST_ID,
ANANSI_BEAST_ID,
BALROG_BEAST_ID,
BANSHEE_BEAST_ID,
BASILISK_BEAST_ID,
BEAR_BEAST_ID,
BEHEMOTH_BEAST_ID,
BERSERKER_BEAST_ID,
BIGFOOT_BEAST_ID,
CHIMERA_BEAST_ID,
CHUPACABRA_BEAST_ID,
COLOSSUS_BEAST_ID,
CYCLOPS_BEAST_ID,
DIREWOLF_BEAST_ID,
DRAGON_BEAST_ID,
DRAUGR_BEAST_ID,
ENT_BEAST_ID,
ETTIN_BEAST_ID,
FAIRY_BEAST_ID,
FENRIR_BEAST_ID,
GHOUL_BEAST_ID,
GIANT_BEAST_ID,
GNOME_BEAST_ID,
GOBLIN_BEAST_ID,
GOLEM_BEAST_ID,
GORGON_BEAST_ID,
GRIFFIN_BEAST_ID,
HARPY_BEAST_ID,
HIPPOGRIFF_BEAST_ID,
HYDRA_BEAST_ID,
JAGUAR_BEAST_ID,
JIANGSHI_BEAST_ID,
JOTUNN_BEAST_ID,
JUGGERNAUT_BEAST_ID,
KAPPA_BEAST_ID,
KELPIE_BEAST_ID,
KITSUNE_BEAST_ID,
KRAKEN_BEAST_ID,
LEPRECHAUN_BEAST_ID,
LEVIATHAN_BEAST_ID,
LICH_BEAST_ID,
MANTICORE_BEAST_ID,
MANTIS_BEAST_ID,
MINOTAUR_BEAST_ID,
NEMEANLION_BEAST_ID,
NEPHILIM_BEAST_ID,
NUE_BEAST_ID,
OGRE_BEAST_ID,
ONI_BEAST_ID,
ORC_BEAST_ID,
PEGASUS_BEAST_ID,
PHOENIX_BEAST_ID,
PIXIE_BEAST_ID,
QILIN_BEAST_ID,
RAKSHASA_BEAST_ID,
RAT_BEAST_ID,
ROC_BEAST_ID,
SATORI_BEAST_ID,
SKELETON_BEAST_ID,
SKINWALKER_BEAST_ID,
SPIDER_BEAST_ID,
SPRITE_BEAST_ID,
TARRASQUE_BEAST_ID,
TITAN_BEAST_ID,
TROLL_BEAST_ID,
TYPHON_BEAST_ID,
VAMPIRE_BEAST_ID,
WARLOCK_BEAST_ID,
WENDIGO_BEAST_ID,
WERETIGER_BEAST_ID,
WEREWOLF_BEAST_ID,
WOLF_BEAST_ID,
WRAITH_BEAST_ID,
WYVERN_BEAST_ID,
YETI_BEAST_ID
]
}

fn is_loot_survivor_beast(beast_id: u32) -> bool {
beast_id <= YETI_BEAST_ID
}
1 change: 1 addition & 0 deletions src/lib.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ mod store;
mod traits;

mod constants {
mod beast;
mod card;
mod challenge;
mod effect;
Expand Down
9 changes: 8 additions & 1 deletion src/models/data/beast.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ struct GameModeBeast {
energy_max_player: u8
}

#[derive(Serde, Copy, Drop, IntrospectPacked, PartialEq)]
enum TypeBeast {
LOOT_SURVIVOR,
JOKERS_OF_NEON
}

#[derive(Copy, Drop, IntrospectPacked, Serde)]
#[dojo::event]
#[dojo::model]
Expand All @@ -19,7 +25,8 @@ struct Beast {
level: u8,
health: u32,
current_health: u32,
attack: u32
attack: u32,
type_beast: TypeBeast
}

#[derive(Copy, Drop, IntrospectPacked, Serde)]
Expand Down
33 changes: 29 additions & 4 deletions src/models/status/round/beast.cairo
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
use core::nullable::NullableTrait;
use dojo::world::Resource::Contract;
use dojo::world::{IWorldDispatcher, IWorldDispatcherTrait};
use jokers_of_neon::constants::beast::{all_beast, is_loot_survivor_beast};
use jokers_of_neon::constants::card::INVALID_CARD;
use jokers_of_neon::models::data::beast::{
GameModeBeast, GameModeBeastStore, Beast, BeastStore, PlayerBeast, PlayerBeastStore
GameModeBeast, GameModeBeastStore, Beast, BeastStore, PlayerBeast, PlayerBeastStore, TypeBeast
};
use jokers_of_neon::models::data::events::{PlayWinGameEvent, PlayGameOverEvent, BeastAttack, PlayerAttack};
use jokers_of_neon::models::data::game_deck::{GameDeckImpl, GameDeck, GameDeckStore};
Expand All @@ -16,6 +17,7 @@ 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::utils::random::{Random, RandomImpl, RandomTrait};
use jokers_of_neon::utils::game::play;
use jokers_of_neon::utils::level::create_level;
use jokers_of_neon::utils::rage::is_rage_card_active;
Expand Down Expand Up @@ -50,9 +52,7 @@ impl BeastImpl of BeastTrait {
let game_mode_beast = GameModeBeast { game_id, cost_discard: 1, cost_play: 2, energy_max_player: 3 };
GameModeBeastStore::set(@game_mode_beast, world);

let beast = Beast { game_id, beast_id: 1, tier: 5, level: 5, health: 300, current_health: 300, attack: 15 };
BeastStore::set(@beast, world);
emit!(world, (beast));
_create_beast(world, game_id, game.level.try_into().unwrap());

let player_beast = PlayerBeast { game_id, energy: game_mode_beast.energy_max_player };
PlayerBeastStore::set(@player_beast, world);
Expand Down Expand Up @@ -267,3 +267,28 @@ fn _attack_beast(
store.set_game(game);
PlayerBeastStore::set(@player_beast, world);
}

fn _create_beast(world: IWorldDispatcher, game_id: u32, level: u8) {
let mut randomizer = RandomImpl::new(world);
let beast_id = randomizer.between::<u32>(0, all_beast().len() - 1);
let (tier, health, attack) = _generate_stats(level);
let type_beast = if is_loot_survivor_beast(beast_id) {
TypeBeast::LOOT_SURVIVOR
} else {
TypeBeast::JOKERS_OF_NEON
};
let beast = Beast { game_id, beast_id, tier, level, health, current_health: health, attack, type_beast };
BeastStore::set(@beast, world);
emit!(world, (beast));
}

fn _generate_stats(level: u8) -> (u8, u32, u32) { // tier, health, attack
match level {
0 => (0, 0, 0),
1 => (1, 300, 15),
2 => (1, 600, 25),
3 => (1, 900, 35),
4 => (1, 1200, 45),
_ => (2, 2000, 50),
}
}

0 comments on commit e40a4e3

Please sign in to comment.