Skip to content

Commit

Permalink
event beast mintable
Browse files Browse the repository at this point in the history
  • Loading branch information
dpinones committed Nov 7, 2024
1 parent d87aaef commit dc5332c
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/interfaces/erc721.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ trait IERC721System {
fn owner_of(world: @IWorldDispatcher, token_id: u256) -> ContractAddress;
fn safe_mint(ref world: IWorldDispatcher, recipient: ContractAddress, beast_stats: BeastStats);
fn get_owner(world: @IWorldDispatcher, beast_stats: BeastStats) -> ContractAddress;
fn total_supply(world: @IWorldDispatcher) -> u256;
}
24 changes: 24 additions & 0 deletions src/models/data/events.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -300,3 +300,27 @@ struct ObstacleAttack {
player: ContractAddress,
attack: u32
}

#[derive(Copy, Drop, Serde)]
#[dojo::event]
#[dojo::model]
struct BeastIsMintable {
#[key]
player: ContractAddress,
tier: u8,
level: u8,
beast_id: u8,
is_mintable: bool
}

#[derive(Copy, Drop, Serde)]
#[dojo::event]
#[dojo::model]
struct BeastNFT {
#[key]
player: ContractAddress,
tier: u8,
level: u8,
beast_id: u8,
token_id: u32
}
25 changes: 24 additions & 1 deletion src/models/status/round/beast.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use jokers_of_neon::interfaces::erc721::{IERC721SystemDispatcher, IERC721SystemD
use jokers_of_neon::models::data::beast::{
GameModeBeast, GameModeBeastStore, Beast, BeastStore, PlayerBeast, PlayerBeastStore, TypeBeast, BeastStats
};
use jokers_of_neon::models::data::events::{PlayWinGameEvent, PlayGameOverEvent, BeastAttack, PlayerAttack};
use jokers_of_neon::models::data::events::{PlayWinGameEvent, PlayGameOverEvent, BeastAttack, PlayerAttack, BeastIsMintable, BeastNFT};
use jokers_of_neon::models::data::game_deck::{GameDeckImpl, GameDeck, GameDeckStore};
use jokers_of_neon::models::data::reward::RewardTrait;
use jokers_of_neon::models::status::game::game::{Game, GameStore, GameState, GameSubState};
Expand Down Expand Up @@ -118,6 +118,15 @@ impl BeastImpl of BeastTrait {
let owner = erc721_dispatcher.get_owner(beast_stats);
if owner.is_zero() {
erc721_dispatcher.safe_mint(get_caller_address(), beast_stats);

let token_id = erc721_dispatcher.total_supply();
emit!(world, (BeastNFT {
player: get_caller_address(),
tier: beast.tier,
level: beast.level,
beast_id: beast.beast_id.try_into().unwrap(),
token_id: token_id.try_into().unwrap()
}));
}
}
}
Expand Down Expand Up @@ -294,6 +303,20 @@ fn _create_beast(world: IWorldDispatcher, game_id: u32, level: u8) {
let beast = Beast { game_id, beast_id, tier, level, health, current_health: health, attack, type_beast };
BeastStore::set(@beast, world);
emit!(world, (beast));

let beast_stats = BeastStats {
tier: beast.tier, level: beast.level, beast_id: beast.beast_id.try_into().unwrap()
};
let erc721_dispatcher = IERC721SystemDispatcher { contract_address: NFT_ADDRESS_MAINNET() };
let owner = erc721_dispatcher.get_owner(beast_stats);
emit!(world, (BeastIsMintable {
player: get_caller_address(),
tier: beast.tier,
level: beast.level,
beast_id: beast.beast_id.try_into().unwrap(),
is_mintable: owner.is_zero()
}
));
}

// tier, health, attack
Expand Down

0 comments on commit dc5332c

Please sign in to comment.