Initial commit, implements most of the static_data side.
This commit is contained in:
89
src/static_data/species_data/form.rs
Normal file
89
src/static_data/species_data/form.rs
Normal file
@@ -0,0 +1,89 @@
|
||||
use self::super::learnable_moves::LearnableMoves;
|
||||
use crate::static_data::species_data::ability_index::AbilityIndex;
|
||||
use crate::static_data::statistic_set::StatisticSet;
|
||||
use crate::static_data::statistics::Statistic;
|
||||
use crate::utils::random::Random;
|
||||
use derive_getters::Getters;
|
||||
use std::collections::HashSet;
|
||||
|
||||
#[derive(Getters, Debug)]
|
||||
pub struct Form<'a> {
|
||||
name: String,
|
||||
height: f32,
|
||||
weight: f32,
|
||||
base_experience: u32,
|
||||
types: Vec<u8>,
|
||||
base_stats: StatisticSet<u16>,
|
||||
abilities: Vec<String>,
|
||||
hidden_abilities: Vec<String>,
|
||||
moves: LearnableMoves<'a>,
|
||||
flags: HashSet<String>,
|
||||
}
|
||||
|
||||
impl<'a> Form<'a> {
|
||||
pub fn new(
|
||||
name: &str,
|
||||
height: f32,
|
||||
weight: f32,
|
||||
base_experience: u32,
|
||||
types: Vec<u8>,
|
||||
base_stats: StatisticSet<u16>,
|
||||
abilities: Vec<String>,
|
||||
hidden_abilities: Vec<String>,
|
||||
moves: LearnableMoves<'a>,
|
||||
flags: HashSet<String>,
|
||||
) -> Form<'a> {
|
||||
Form {
|
||||
name: name.to_string(),
|
||||
height,
|
||||
weight,
|
||||
base_experience,
|
||||
types,
|
||||
base_stats,
|
||||
abilities,
|
||||
hidden_abilities,
|
||||
moves,
|
||||
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: &str) -> Option<AbilityIndex> {
|
||||
for (index, a) in self.abilities.iter().enumerate() {
|
||||
if a == ability {
|
||||
return Some(AbilityIndex {
|
||||
hidden: false,
|
||||
index: index as u8,
|
||||
});
|
||||
}
|
||||
}
|
||||
for (index, a) in self.hidden_abilities.iter().enumerate() {
|
||||
if a == ability {
|
||||
return Some(AbilityIndex {
|
||||
hidden: true,
|
||||
index: index as u8,
|
||||
});
|
||||
}
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
pub fn get_random_ability(&self, rand: &mut Random) -> &String {
|
||||
&self.abilities[rand.get_between_unsigned(0, self.abilities.len() as u32) as usize]
|
||||
}
|
||||
pub fn get_random_hidden_ability(&self, rand: &mut Random) -> &String {
|
||||
&self.hidden_abilities
|
||||
[rand.get_between_unsigned(0, self.hidden_abilities.len() as u32) as usize]
|
||||
}
|
||||
|
||||
pub fn has_flag(&self, key: &str) -> bool {
|
||||
self.flags.contains(key)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user