diff --git a/backend/dojo_examples/combat_game/src/constants.cairo b/backend/dojo_examples/combat_game/src/constants.cairo index c883285..3f836a6 100644 --- a/backend/dojo_examples/combat_game/src/constants.cairo +++ b/backend/dojo_examples/combat_game/src/constants.cairo @@ -25,3 +25,5 @@ pub const NOT_VERY_EFFECTIVE: u8 = 50; pub const FAVORED_ATTACK_MULTIPLIER: u8 = 120; pub const NORMAL_ATTACK_MULTIPLIER: u8 = 100; +// Base battle experience +pub const BASE_BATTLE_EXPERIENCE: u16 = 10; diff --git a/backend/dojo_examples/combat_game/src/lib.cairo b/backend/dojo_examples/combat_game/src/lib.cairo index f8c5ff4..1eb0142 100644 --- a/backend/dojo_examples/combat_game/src/lib.cairo +++ b/backend/dojo_examples/combat_game/src/lib.cairo @@ -31,6 +31,7 @@ mod types { mod helpers { pub mod pseudo_random; pub mod timestamp; + pub mod experience_utils; } pub mod utils { diff --git a/backend/dojo_examples/combat_game/src/store.cairo b/backend/dojo_examples/combat_game/src/store.cairo index 406504a..dfdd3d4 100644 --- a/backend/dojo_examples/combat_game/src/store.cairo +++ b/backend/dojo_examples/combat_game/src/store.cairo @@ -1,7 +1,7 @@ use dojo::{model::ModelStorage, world::WorldStorage}; use core::num::traits::zero::Zero; use combat_game::{ - constants::SECONDS_PER_DAY, + constants::{BASE_BATTLE_EXPERIENCE, SECONDS_PER_DAY}, models::{ player::Player, beast::{Beast, BeastTrait}, skill, skill::{Skill, SkillTrait}, beast_skill::BeastSkill, beast_stats::{BeastStats, BeastStatsActionTrait}, @@ -11,6 +11,7 @@ use combat_game::{ beast_type::BeastType, skill::SkillType, status_condition::StatusCondition, battle_status::BattleStatus, }, + helpers::experience_utils::ExperienceCalculatorImpl, }; use starknet::ContractAddress; @@ -314,17 +315,14 @@ pub impl StoreImpl of StoreTrait { beast.experience += exp_amount; // Check if level up is needed - // TODO: ExperienceCalculatorTrait is not implemented - // let exp_needed = ExperienceTrrait::calculate_exp_needed_for_level(beast.level); - let exp_needed = 10; + let exp_needed = ExperienceCalculatorImpl::calculate_exp_needed_for_level(beast.level); let level_up_occurred = beast.experience >= exp_needed; if level_up_occurred { // Calculate remaining exp - // TODO: ExperienceCalculatorTrait is not implemented - // beast.experience); - // beast.experience = ExperienceTrrait::remaining_exp_after_level_up(beast.level, - beast.experience = 5; + beast.experience = ExperienceCalculatorImpl::remaining_exp_after_level_up( + beast.level, beast.experience, + ); beast.level += 1; // Update beast stats @@ -410,8 +408,8 @@ pub impl StoreImpl of StoreTrait { // Update player stats self.update_player_battle_result(won: true); - // TODO: Define base experience for winning a game - self.award_battle_experience(attacker_beast_id, 1); + // Award experience for winning a game + self.award_battle_experience(attacker_beast_id, BASE_BATTLE_EXPERIENCE); } // Save changes