144 lines
4.2 KiB
Rust
144 lines
4.2 KiB
Rust
|
use crate::defines::{LevelInt, MAX_MOVES};
|
||
|
use crate::dynamic_data::libraries::dynamic_library::DynamicLibrary;
|
||
|
use crate::dynamic_data::models::battle::Battle;
|
||
|
use crate::dynamic_data::models::battle_side::BattleSide;
|
||
|
use crate::dynamic_data::models::learned_move::LearnedMove;
|
||
|
use crate::dynamic_data::script_handling::script::Script;
|
||
|
use crate::dynamic_data::script_handling::script_set::ScriptSet;
|
||
|
use crate::static_data::items::item::Item;
|
||
|
use crate::static_data::species_data::ability_index::AbilityIndex;
|
||
|
use crate::static_data::species_data::form::Form;
|
||
|
use crate::static_data::species_data::gender::Gender;
|
||
|
use crate::static_data::species_data::species::Species;
|
||
|
use crate::static_data::statistic_set::StatisticSet;
|
||
|
use crate::static_data::statistics::Statistic;
|
||
|
use derive_getters::Getters;
|
||
|
use std::collections::HashSet;
|
||
|
|
||
|
#[derive(Getters)]
|
||
|
pub struct PokemonBattleData<'a> {
|
||
|
battle: &'a Battle,
|
||
|
battle_side: &'a BattleSide,
|
||
|
on_battle_field: bool,
|
||
|
seen_opponents: HashSet<Pokemon<'a>>,
|
||
|
}
|
||
|
|
||
|
#[derive(Getters)]
|
||
|
pub struct Pokemon<'a> {
|
||
|
library: &'a DynamicLibrary<'a>,
|
||
|
species: &'a Species<'a>,
|
||
|
form: &'a Form<'a>,
|
||
|
|
||
|
display_species: Option<&'a Species<'a>>,
|
||
|
display_form: Option<&'a Form<'a>>,
|
||
|
|
||
|
level: LevelInt,
|
||
|
experience: u32,
|
||
|
unique_identifier: u32,
|
||
|
gender: Gender,
|
||
|
coloring: u8,
|
||
|
held_item: Option<&'a Item>,
|
||
|
health: u32,
|
||
|
|
||
|
stat_boost: StatisticSet<i8>,
|
||
|
flat_stats: StatisticSet<u16>,
|
||
|
boosted_stats: StatisticSet<u16>,
|
||
|
|
||
|
nickname: Option<String>,
|
||
|
|
||
|
ability_index: AbilityIndex,
|
||
|
is_ability_overridden: bool,
|
||
|
overridden_ability_name: String,
|
||
|
|
||
|
battle_data: Option<PokemonBattleData<'a>>,
|
||
|
|
||
|
moves: [Option<LearnedMove>; MAX_MOVES],
|
||
|
allowed_experience: bool,
|
||
|
|
||
|
types: Vec<u8>,
|
||
|
|
||
|
ability_script: Option<Box<dyn Script>>,
|
||
|
status_script: Option<Box<dyn Script>>,
|
||
|
volatile: ScriptSet,
|
||
|
}
|
||
|
|
||
|
impl<'a> Pokemon<'a> {
|
||
|
pub fn new(
|
||
|
library: &'a DynamicLibrary,
|
||
|
species: &'a Species,
|
||
|
form: &'a Form,
|
||
|
ability: AbilityIndex,
|
||
|
level: LevelInt,
|
||
|
unique_identifier: u32,
|
||
|
gender: Gender,
|
||
|
coloring: u8,
|
||
|
) -> Pokemon<'a> {
|
||
|
// Calculate experience from the level for the specified growth rate.
|
||
|
let experience = library
|
||
|
.static_data()
|
||
|
.growth_rates()
|
||
|
.calculate_experience(species.growth_rate(), level);
|
||
|
let health = form.get_base_stat(Statistic::HP) as u32;
|
||
|
Pokemon {
|
||
|
library,
|
||
|
species,
|
||
|
form,
|
||
|
display_species: None,
|
||
|
display_form: None,
|
||
|
level,
|
||
|
experience,
|
||
|
unique_identifier,
|
||
|
gender,
|
||
|
coloring,
|
||
|
held_item: None,
|
||
|
health,
|
||
|
stat_boost: Default::default(),
|
||
|
flat_stats: *form.base_stats(),
|
||
|
boosted_stats: *form.base_stats(),
|
||
|
nickname: None,
|
||
|
ability_index: ability,
|
||
|
is_ability_overridden: false,
|
||
|
overridden_ability_name: "".to_string(),
|
||
|
battle_data: None,
|
||
|
moves: [None, None, None, None],
|
||
|
allowed_experience: false,
|
||
|
types: form.types().to_vec(),
|
||
|
ability_script: None,
|
||
|
status_script: None,
|
||
|
volatile: ScriptSet {},
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
#[cfg(test)]
|
||
|
pub mod test {
|
||
|
use crate::dynamic_data::libraries::dynamic_library;
|
||
|
use crate::dynamic_data::models::pokemon::Pokemon;
|
||
|
use crate::static_data::libraries::data_library::DataLibrary;
|
||
|
use crate::static_data::species_data::ability_index::AbilityIndex;
|
||
|
use crate::static_data::species_data::gender::Gender;
|
||
|
|
||
|
#[test]
|
||
|
fn construct_pokemon() {
|
||
|
let lib = dynamic_library::test::build();
|
||
|
let species = lib.static_data().species().get("foo").unwrap();
|
||
|
let form = species.get_form("default").unwrap();
|
||
|
|
||
|
let pokemon = Pokemon::new(
|
||
|
&lib,
|
||
|
species,
|
||
|
form,
|
||
|
AbilityIndex {
|
||
|
hidden: false,
|
||
|
index: 0,
|
||
|
},
|
||
|
10,
|
||
|
0,
|
||
|
Gender::Male,
|
||
|
0,
|
||
|
);
|
||
|
assert_eq!(pokemon.species.name(), "foo");
|
||
|
assert_eq!(pokemon.form.name(), "default");
|
||
|
}
|
||
|
}
|