72 lines
2.1 KiB
Rust
Executable File
72 lines
2.1 KiB
Rust
Executable File
use std::sync::Arc;
|
|
|
|
use crate::defines::LevelInt;
|
|
use crate::dynamic_data::models::learned_move::MoveLearnMethod;
|
|
use crate::dynamic_data::models::pokemon::Pokemon;
|
|
use crate::dynamic_data::DynamicLibrary;
|
|
use crate::static_data::{AbilityIndex, DataLibrary, Gender};
|
|
use crate::{Random, StringKey};
|
|
|
|
/// This allows for the easy chain building of a Pokemon.
|
|
pub struct PokemonBuilder {
|
|
/// The library of the Pokemon.
|
|
library: Arc<DynamicLibrary>,
|
|
/// The name of the species of the Pokemon.
|
|
species: StringKey,
|
|
/// The level of the Pokemon.
|
|
level: LevelInt,
|
|
/// The moves the Pokemon will know.
|
|
learned_moves: Vec<StringKey>,
|
|
/// A random seed used for any randomization done.
|
|
random_seed: Option<u128>,
|
|
}
|
|
|
|
impl PokemonBuilder {
|
|
/// Creates a new PokemonBuilder with a library, species, and level.
|
|
pub fn new(library: Arc<DynamicLibrary>, species: StringKey, level: LevelInt) -> Self {
|
|
Self {
|
|
library,
|
|
species,
|
|
level,
|
|
learned_moves: vec![],
|
|
random_seed: None,
|
|
}
|
|
}
|
|
/// Makes the Pokemon learn a move.
|
|
pub fn learn_move(mut self, learned_move: StringKey) -> Self {
|
|
self.learned_moves.push(learned_move);
|
|
self
|
|
}
|
|
|
|
/// Finally turn the builder into an actual Pokemon.
|
|
pub fn build(self) -> Pokemon {
|
|
let mut random = if let Some(seed) = self.random_seed {
|
|
Random::new(seed)
|
|
} else {
|
|
Random::default()
|
|
};
|
|
|
|
let species = self.library.static_data().species().get(&self.species).unwrap().clone();
|
|
let form = species.get_default_form().clone();
|
|
let p = Pokemon::new(
|
|
self.library,
|
|
species,
|
|
&form,
|
|
AbilityIndex {
|
|
hidden: false,
|
|
index: 0,
|
|
},
|
|
self.level,
|
|
random.get_unsigned(),
|
|
Gender::Male,
|
|
0,
|
|
&"hardy".into(),
|
|
);
|
|
for learned_move in self.learned_moves {
|
|
p.learn_move(&learned_move, MoveLearnMethod::Unknown);
|
|
}
|
|
|
|
p
|
|
}
|
|
}
|