diff --git a/src/config.cairo b/src/config.cairo index fbdd5e4..ceef26b 100644 --- a/src/config.cairo +++ b/src/config.cairo @@ -5,12 +5,14 @@ use starknet::{ContractAddress}; trait IConfig { fn init_role(self: @TContractState); fn init_skill(self: @TContractState); + fn init_config(self: @TContractState); + fn init_global(self: @TContractState); } // dojo decorator #[dojo::contract] mod config { - use mississippi_mini::models::{Role, Skill}; + use mississippi_mini::models::{Role, Skill, Global}; use mississippi_mini::constants; use super::IConfig; @@ -65,6 +67,15 @@ mod config { }; set!(world, (addSpeedSkill)); } + + fn init_config(self: @ContractState) { + + } + + fn init_global(self: @ContractState) { + let world = self.world_dispatcher.read(); + set!(world, (Global{id:constants::GlOBAL_CONFIG_KEY, battleId:0})); + } } } \ No newline at end of file diff --git a/src/constants.cairo b/src/constants.cairo index ca3de98..e8cc586 100644 --- a/src/constants.cairo +++ b/src/constants.cairo @@ -6,3 +6,6 @@ const ROLE_KNIGHT: u32 = 1; const SKILL_COMBO_ATTACK: u32 = 0; const SKILL_ADD_HP: u32 = 1; const SKILL_ADD_SPEED: u32 = 2; + +// Global Config Key +const GlOBAL_CONFIG_KEY: u32 = 100; diff --git a/src/game.cairo b/src/game.cairo index e01a440..b71ad69 100644 --- a/src/game.cairo +++ b/src/game.cairo @@ -14,7 +14,7 @@ trait IGame { #[dojo::contract] mod game { use starknet::{ContractAddress, get_caller_address}; - use mississippi_mini::models::{Player, BattleInfo, BattleResult, Skill, Role}; + use mississippi_mini::models::{Player, BattleInfo, BattleResult, Skill, Role, Global}; use mississippi_mini::utils::next_position; use mississippi_mini::constants; // use mississippi_mini::utils::battle_property_settting; @@ -77,7 +77,12 @@ mod game { // retrive player let world = self.world_dispatcher.read(); let player = get_caller_address(); - let battleId = 1; + + + let mut globalParams = get!(world, constants::GlOBAL_CONFIG_KEY, (Global)); + globalParams.battleId = globalParams.battleId + 1; + let battleId = globalParams.battleId; + set!(world, (globalParams)); // check target exist @@ -161,6 +166,7 @@ mod game { battleId : attacker.battleId, winner : winner, }; + set!(world, (battleResult)); emit!(world, Win { battleId: attacker.battleId, winner: winner}); } @@ -246,6 +252,10 @@ mod tests { let x = 5; x.print(); + let battleReuslt = get!(world, 1, (BattleResult)); + battleReuslt.print(); + let battleInfo = get!(world, (1, false), (BattleInfo)); + diff --git a/src/models.cairo b/src/models.cairo index 239d735..c4ff708 100644 --- a/src/models.cairo +++ b/src/models.cairo @@ -41,6 +41,16 @@ struct Config { battleId : u32, } +#[derive(Model, Copy, Drop, Print, Serde)] +struct Global { + #[key] // primary key + id: u32, + battleId : u32, +} + + + + #[derive(Model, Copy, Drop, Print, Serde)] struct BattleInfo { #[key] // primary key