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 0154a39 commit 33cfe60
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 9 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
25 changes: 16 additions & 9 deletions src/models/evolution.cairo
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,17 @@ struct Evolution {
}

mod rules {
// Minimum rule to envolve
const ENVOLVED_BEAST_ID: u32 = 2;
/// 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]
Expand All @@ -29,16 +35,17 @@ impl EvolutionImpl of EvolutionTrait {
Option::None => true,
};

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

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

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

0 comments on commit 33cfe60

Please sign in to comment.