use crate::static_data::AbilityIndex; use crate::static_data::LearnableMoves; use crate::static_data::Statistic; use crate::static_data::{Ability, StaticStatisticSet}; use crate::Random; use crate::StringKey; use hashbrown::HashSet; #[derive(Debug)] pub struct Form { name: StringKey, height: f32, weight: f32, base_experience: u32, types: Vec, base_stats: StaticStatisticSet, abilities: Vec, hidden_abilities: Vec, moves: LearnableMoves, flags: HashSet, } impl Form { pub fn new( name: &StringKey, height: f32, weight: f32, base_experience: u32, types: Vec, base_stats: StaticStatisticSet, abilities: Vec, hidden_abilities: Vec, moves: LearnableMoves, flags: HashSet, ) -> Form { Form { name: name.clone(), height, weight, base_experience, types, base_stats, abilities, hidden_abilities, moves, flags, } } pub fn name(&self) -> &StringKey { &self.name } pub fn height(&self) -> f32 { self.height } pub fn weight(&self) -> f32 { self.weight } pub fn base_experience(&self) -> u32 { self.base_experience } pub fn types(&self) -> &Vec { &self.types } pub fn base_stats(&self) -> &StaticStatisticSet { &self.base_stats } pub fn abilities(&self) -> &Vec { &self.abilities } pub fn hidden_abilities(&self) -> &Vec { &self.hidden_abilities } pub fn moves(&self) -> &LearnableMoves { &self.moves } pub fn flags(&self) -> &HashSet { &self.flags } pub fn get_type(&self, index: usize) -> u8 { self.types[index] } pub fn get_base_stat(&self, stat: Statistic) -> u16 { self.base_stats.get_stat(stat) } pub fn find_ability_index(&self, ability: &Ability) -> Option { for (index, a) in self.abilities.iter().enumerate() { if a == ability.name() { return Some(AbilityIndex { hidden: false, index: index as u8, }); } } for (index, a) in self.hidden_abilities.iter().enumerate() { if a == ability.name() { return Some(AbilityIndex { hidden: true, index: index as u8, }); } } None } pub fn get_ability(&self, index: AbilityIndex) -> &StringKey { if index.hidden { &self.hidden_abilities[index.index as usize] } else { &self.abilities[index.index as usize] } } pub fn get_random_ability(&self, rand: &mut Random) -> &StringKey { &self.abilities[rand.get_between_unsigned(0, self.abilities.len() as u32) as usize] } pub fn get_random_hidden_ability(&self, rand: &mut Random) -> &StringKey { &self.hidden_abilities[rand.get_between_unsigned(0, self.hidden_abilities.len() as u32) as usize] } pub fn has_flag(&self, key: &StringKey) -> bool { self.flags.contains(key) } }