-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[feat] Create an evolution PoC model
- Loading branch information
1 parent
d088b3b
commit b1f5765
Showing
3 changed files
with
54 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
dojo 1.0.0-alpha.5 | ||
scarb 2.7.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'), | ||
} | ||
} | ||
} |