58 lines
2.8 KiB
Rust
58 lines
2.8 KiB
Rust
use crate::dynamic_data::Pokemon;
|
|
use crate::static_data::{EvolutionMethod, TimeOfDay};
|
|
|
|
/// A library for handling the checking of evolution requirements.
|
|
pub trait EvolutionLibrary {
|
|
/// Checks if the given Pokemon fulfills the given evolution conditions.
|
|
fn pokemon_fulfills_evolution_conditions(&self, pokemon: &Pokemon, method: &EvolutionMethod) -> bool;
|
|
}
|
|
|
|
/// A standard implementation of the Evolution Library.
|
|
pub struct EvolutionLibraryImpl;
|
|
|
|
impl EvolutionLibrary for EvolutionLibraryImpl {
|
|
fn pokemon_fulfills_evolution_conditions(&self, pokemon: &Pokemon, method: &EvolutionMethod) -> bool {
|
|
match method {
|
|
EvolutionMethod::Level { level } => pokemon.level() >= *level,
|
|
EvolutionMethod::LevelGender { level, gender } => pokemon.level() >= *level && pokemon.gender() == *gender,
|
|
EvolutionMethod::Item { .. } => false,
|
|
EvolutionMethod::ItemGender { .. } => false,
|
|
EvolutionMethod::HoldItem { item } => pokemon.has_held_item(item),
|
|
EvolutionMethod::DayHoldItem { item } => {
|
|
let time_of_day = pokemon.library().misc_library().time_of_day();
|
|
pokemon.has_held_item(item) && time_of_day == TimeOfDay::Morning || time_of_day == TimeOfDay::Day
|
|
}
|
|
EvolutionMethod::NightHoldItem { item } => {
|
|
let time_of_day = pokemon.library().misc_library().time_of_day();
|
|
pokemon.has_held_item(item) && time_of_day == TimeOfDay::Evening || time_of_day == TimeOfDay::Night
|
|
}
|
|
EvolutionMethod::HasMove { move_name } => pokemon
|
|
.learned_moves()
|
|
.read()
|
|
.iter()
|
|
.any(|learned_move| learned_move.as_ref().is_some_and(|v| v.move_data().name() == move_name)),
|
|
EvolutionMethod::Happiness { happiness } => pokemon.happiness() >= *happiness,
|
|
EvolutionMethod::HappinessDay { happiness } => {
|
|
let time_of_day = pokemon.library().misc_library().time_of_day();
|
|
pokemon.happiness() >= *happiness && time_of_day == TimeOfDay::Morning || time_of_day == TimeOfDay::Day
|
|
}
|
|
EvolutionMethod::HappinessNight { happiness } => {
|
|
let time_of_day = pokemon.library().misc_library().time_of_day();
|
|
pokemon.happiness() >= *happiness && time_of_day == TimeOfDay::Evening
|
|
|| time_of_day == TimeOfDay::Night
|
|
}
|
|
EvolutionMethod::Trade => false,
|
|
EvolutionMethod::TradeSpecies { .. } => false,
|
|
EvolutionMethod::TradeItem { .. } => false,
|
|
EvolutionMethod::Location { .. } => {
|
|
// TODO: Implement this.
|
|
false
|
|
}
|
|
EvolutionMethod::Custom { .. } => {
|
|
// TODO: Implement this.
|
|
false
|
|
}
|
|
}
|
|
}
|
|
}
|