2022-08-20 11:17:20 +00:00
|
|
|
use std::sync::Arc;
|
|
|
|
|
2022-06-16 15:59:33 +00:00
|
|
|
use crate::defines::LevelInt;
|
2022-06-17 17:53:33 +00:00
|
|
|
use crate::dynamic_data::models::learned_move::MoveLearnMethod;
|
2022-06-16 15:59:33 +00:00
|
|
|
use crate::dynamic_data::models::pokemon::Pokemon;
|
2022-06-19 19:34:08 +00:00
|
|
|
use crate::dynamic_data::DynamicLibrary;
|
2022-06-16 15:59:33 +00:00
|
|
|
use crate::static_data::{AbilityIndex, DataLibrary, Gender};
|
2022-07-01 15:07:22 +00:00
|
|
|
use crate::{Random, StringKey};
|
2022-06-16 15:59:33 +00:00
|
|
|
|
2022-07-01 15:07:22 +00:00
|
|
|
/// This allows for the easy chain building of a Pokemon.
|
2022-08-20 11:17:20 +00:00
|
|
|
pub struct PokemonBuilder {
|
2022-07-01 15:07:22 +00:00
|
|
|
/// The library of the Pokemon.
|
2022-08-20 11:17:20 +00:00
|
|
|
library: Arc<DynamicLibrary>,
|
2022-07-01 15:07:22 +00:00
|
|
|
/// The name of the species of the Pokemon.
|
2022-06-16 15:59:33 +00:00
|
|
|
species: StringKey,
|
2022-07-01 15:07:22 +00:00
|
|
|
/// The level of the Pokemon.
|
2022-06-16 15:59:33 +00:00
|
|
|
level: LevelInt,
|
2022-07-01 15:07:22 +00:00
|
|
|
/// The moves the Pokemon will know.
|
2022-06-17 17:53:33 +00:00
|
|
|
learned_moves: Vec<StringKey>,
|
2022-07-01 15:07:22 +00:00
|
|
|
/// A random seed used for any randomization done.
|
|
|
|
random_seed: Option<u128>,
|
2022-06-16 15:59:33 +00:00
|
|
|
}
|
|
|
|
|
2022-08-20 11:17:20 +00:00
|
|
|
impl PokemonBuilder {
|
2022-07-01 15:07:22 +00:00
|
|
|
/// Creates a new PokemonBuilder with a library, species, and level.
|
2022-08-20 11:17:20 +00:00
|
|
|
pub fn new(library: Arc<DynamicLibrary>, species: StringKey, level: LevelInt) -> Self {
|
2022-06-16 15:59:33 +00:00
|
|
|
Self {
|
|
|
|
library,
|
|
|
|
species,
|
|
|
|
level,
|
2022-06-17 17:53:33 +00:00
|
|
|
learned_moves: vec![],
|
2022-07-01 15:07:22 +00:00
|
|
|
random_seed: None,
|
2022-06-16 15:59:33 +00:00
|
|
|
}
|
|
|
|
}
|
2022-07-01 15:07:22 +00:00
|
|
|
/// Makes the Pokemon learn a move.
|
2022-06-17 17:53:33 +00:00
|
|
|
pub fn learn_move(mut self, learned_move: StringKey) -> Self {
|
|
|
|
self.learned_moves.push(learned_move);
|
|
|
|
self
|
|
|
|
}
|
2022-06-16 15:59:33 +00:00
|
|
|
|
2022-07-01 15:07:22 +00:00
|
|
|
/// Finally turn the builder into an actual Pokemon.
|
2022-08-20 11:17:20 +00:00
|
|
|
pub fn build(self) -> Pokemon {
|
2022-07-01 15:07:22 +00:00
|
|
|
let mut random = if let Some(seed) = self.random_seed {
|
|
|
|
Random::new(seed)
|
|
|
|
} else {
|
|
|
|
Random::default()
|
|
|
|
};
|
|
|
|
|
2022-08-20 11:17:20 +00:00
|
|
|
let species = self.library.static_data().species().get(&self.species).unwrap().clone();
|
|
|
|
let form = species.get_default_form().clone();
|
2022-06-18 13:52:39 +00:00
|
|
|
let p = Pokemon::new(
|
2022-06-16 15:59:33 +00:00
|
|
|
self.library,
|
|
|
|
species,
|
2022-08-20 11:17:20 +00:00
|
|
|
&form,
|
2022-06-16 15:59:33 +00:00
|
|
|
AbilityIndex {
|
|
|
|
hidden: false,
|
|
|
|
index: 0,
|
|
|
|
},
|
|
|
|
self.level,
|
2022-07-01 15:07:22 +00:00
|
|
|
random.get_unsigned(),
|
2022-06-16 15:59:33 +00:00
|
|
|
Gender::Male,
|
|
|
|
0,
|
2022-06-17 17:53:33 +00:00
|
|
|
&"hardy".into(),
|
|
|
|
);
|
|
|
|
for learned_move in self.learned_moves {
|
|
|
|
p.learn_move(&learned_move, MoveLearnMethod::Unknown);
|
|
|
|
}
|
|
|
|
|
|
|
|
p
|
2022-06-16 15:59:33 +00:00
|
|
|
}
|
|
|
|
}
|