Skip to content

Commit

Permalink
[feat] Create an evolution PoC model
Browse files Browse the repository at this point in the history
  • Loading branch information
jsanchez556 committed Nov 25, 2024
1 parent d088b3b commit b1f5765
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .tool-versions
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
dojo 1.0.0-alpha.5
scarb 2.7.0
1 change: 1 addition & 0 deletions src/lib.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ mod models {
mod achievement_rarity;
mod achievement_type;
mod achievements;
mod evolution;
}

mod tests {
Expand Down
51 changes: 51 additions & 0 deletions src/models/evolution.cairo
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
use core::{
result::Result
};

#[derive(Drop, Copy, Serde)]
#[dojo::model]
struct Evolution {
#[key]
pub base_beast_id: u32,
pub evolved_beast_id: u32,
pub level_requirement: u32,
pub required_battles: u32,
pub required_item: Option<u32>
}

mod rules {
/// Minimum rules for beast evolution

/// The ID assigned to the evolved beast form
const EVOLVED_BEAST_ID: u32 = 2;
/// Minimum level required before evolution is possible
const LEVEL_REQUIREMENT: u32 = 10;
/// Minimum number of battles required before evolution
const REQUIRED_BATTLES: u32 = 5;
/// Item ID required for evolution (special evolution stone)
const REQUIRED_ITEM: u32 = 1001;

}

#[generate_trait]
impl EvolutionImpl of EvolutionTrait {
fn can_evolve(self: Evolution) -> bool {
let is_valid_item: bool = match self.required_item {
Option::Some(val) => val == rules::REQUIRED_ITEM,
Option::None => true,
};

is_valid_item &&
self.level_requirement > rules::LEVEL_REQUIREMENT &&
self.required_battles > rules::REQUIRED_BATTLES
}

fn evolve(self: Evolution) -> Result<u32, felt252> {
assert(self.base_beast_id != 0, 'Invalid base beast');

match self.can_evolve() {
true => Result::Ok(rules::EVOLVED_BEAST_ID),
false => Result::Err('Evolution requirements not met'),
}
}
}

0 comments on commit b1f5765

Please sign in to comment.