From 66c9af1302dc8ea58056a91abe40fc611821f975 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dami=C3=A1n=20Pi=C3=B1ones?= <30808181+dpinones@users.noreply.github.com> Date: Thu, 7 Nov 2024 12:23:47 -0300 Subject: [PATCH] event beast mintable (#37) --- src/interfaces/erc721.cairo | 1 + src/models/data/events.cairo | 24 ++++++++++++++++++++++++ src/models/status/round/beast.cairo | 25 ++++++++++++++++++++++++- 3 files changed, 49 insertions(+), 1 deletion(-) diff --git a/src/interfaces/erc721.cairo b/src/interfaces/erc721.cairo index b95bcae..a7249c1 100644 --- a/src/interfaces/erc721.cairo +++ b/src/interfaces/erc721.cairo @@ -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; } diff --git a/src/models/data/events.cairo b/src/models/data/events.cairo index 444dd5c..057bacf 100644 --- a/src/models/data/events.cairo +++ b/src/models/data/events.cairo @@ -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 +} diff --git a/src/models/status/round/beast.cairo b/src/models/status/round/beast.cairo index c0917c2..892eac1 100644 --- a/src/models/status/round/beast.cairo +++ b/src/models/status/round/beast.cairo @@ -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}; @@ -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() + })); } } } @@ -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