2022-06-11 18:51:37 +00:00
|
|
|
use crate::static_data::Ability;
|
|
|
|
use crate::static_data::AbilityIndex;
|
|
|
|
use crate::static_data::LearnableMoves;
|
|
|
|
use crate::static_data::Statistic;
|
|
|
|
use crate::static_data::StatisticSet;
|
|
|
|
use crate::Random;
|
2022-06-11 15:22:46 +00:00
|
|
|
use crate::StringKey;
|
2022-06-06 11:54:59 +00:00
|
|
|
use hashbrown::HashSet;
|
2022-06-11 15:22:46 +00:00
|
|
|
use std::ops::Deref;
|
2021-01-30 21:29:59 +00:00
|
|
|
|
2022-06-06 12:43:41 +00:00
|
|
|
#[derive(Debug)]
|
2021-01-30 21:29:59 +00:00
|
|
|
pub struct Form<'a> {
|
2022-06-11 15:22:46 +00:00
|
|
|
name: StringKey,
|
2021-01-30 21:29:59 +00:00
|
|
|
height: f32,
|
|
|
|
weight: f32,
|
|
|
|
base_experience: u32,
|
|
|
|
types: Vec<u8>,
|
|
|
|
base_stats: StatisticSet<u16>,
|
2022-06-11 15:22:46 +00:00
|
|
|
abilities: Vec<&'a Ability>,
|
|
|
|
hidden_abilities: Vec<&'a Ability>,
|
2021-01-30 21:29:59 +00:00
|
|
|
moves: LearnableMoves<'a>,
|
2022-06-11 15:22:46 +00:00
|
|
|
flags: HashSet<StringKey>,
|
2021-01-30 21:29:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a> Form<'a> {
|
|
|
|
pub fn new(
|
2022-06-11 15:22:46 +00:00
|
|
|
name: &StringKey,
|
2021-01-30 21:29:59 +00:00
|
|
|
height: f32,
|
|
|
|
weight: f32,
|
|
|
|
base_experience: u32,
|
|
|
|
types: Vec<u8>,
|
|
|
|
base_stats: StatisticSet<u16>,
|
2022-06-11 15:22:46 +00:00
|
|
|
abilities: Vec<&'a Ability>,
|
|
|
|
hidden_abilities: Vec<&'a Ability>,
|
2021-01-30 21:29:59 +00:00
|
|
|
moves: LearnableMoves<'a>,
|
2022-06-11 15:22:46 +00:00
|
|
|
flags: HashSet<StringKey>,
|
2021-01-30 21:29:59 +00:00
|
|
|
) -> Form<'a> {
|
|
|
|
Form {
|
2022-06-11 15:22:46 +00:00
|
|
|
name: name.clone(),
|
2021-01-30 21:29:59 +00:00
|
|
|
height,
|
|
|
|
weight,
|
|
|
|
base_experience,
|
|
|
|
types,
|
|
|
|
base_stats,
|
|
|
|
abilities,
|
|
|
|
hidden_abilities,
|
|
|
|
moves,
|
|
|
|
flags,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-06-11 15:22:46 +00:00
|
|
|
pub fn name(&self) -> &StringKey {
|
2022-06-06 12:43:41 +00:00
|
|
|
&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<u8> {
|
|
|
|
&self.types
|
|
|
|
}
|
|
|
|
pub fn base_stats(&self) -> StatisticSet<u16> {
|
|
|
|
self.base_stats
|
|
|
|
}
|
2022-06-11 15:22:46 +00:00
|
|
|
pub fn abilities(&self) -> &Vec<&'a Ability> {
|
2022-06-06 12:43:41 +00:00
|
|
|
&self.abilities
|
|
|
|
}
|
2022-06-11 15:22:46 +00:00
|
|
|
pub fn hidden_abilities(&self) -> &Vec<&'a Ability> {
|
2022-06-06 12:43:41 +00:00
|
|
|
&self.hidden_abilities
|
|
|
|
}
|
|
|
|
pub fn moves(&self) -> &LearnableMoves<'a> {
|
|
|
|
&self.moves
|
|
|
|
}
|
2022-06-11 15:22:46 +00:00
|
|
|
pub fn flags(&self) -> &HashSet<StringKey> {
|
2022-06-06 12:43:41 +00:00
|
|
|
&self.flags
|
|
|
|
}
|
|
|
|
|
2021-01-30 21:29:59 +00:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
|
2022-06-11 15:22:46 +00:00
|
|
|
pub fn find_ability_index(&self, ability: &Ability) -> Option<AbilityIndex> {
|
2021-01-30 21:29:59 +00:00
|
|
|
for (index, a) in self.abilities.iter().enumerate() {
|
2022-06-11 15:22:46 +00:00
|
|
|
if std::ptr::eq(a.deref(), ability as *const Ability) {
|
2021-01-30 21:29:59 +00:00
|
|
|
return Some(AbilityIndex {
|
|
|
|
hidden: false,
|
|
|
|
index: index as u8,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
for (index, a) in self.hidden_abilities.iter().enumerate() {
|
2022-06-11 15:22:46 +00:00
|
|
|
if std::ptr::eq(a.deref(), ability as *const Ability) {
|
2021-01-30 21:29:59 +00:00
|
|
|
return Some(AbilityIndex {
|
|
|
|
hidden: true,
|
|
|
|
index: index as u8,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
None
|
|
|
|
}
|
|
|
|
|
2022-06-11 15:22:46 +00:00
|
|
|
pub fn get_ability(&self, index: AbilityIndex) -> &Ability {
|
|
|
|
if index.hidden {
|
|
|
|
self.hidden_abilities[index.index as usize]
|
|
|
|
} else {
|
|
|
|
self.abilities[index.index as usize]
|
|
|
|
}
|
2021-01-30 21:29:59 +00:00
|
|
|
}
|
2022-06-11 15:22:46 +00:00
|
|
|
|
|
|
|
pub fn get_random_ability(&self, rand: &mut Random) -> &Ability {
|
|
|
|
self.abilities[rand.get_between_unsigned(0, self.abilities.len() as u32) as usize]
|
|
|
|
}
|
|
|
|
pub fn get_random_hidden_ability(&self, rand: &mut Random) -> &Ability {
|
|
|
|
self.hidden_abilities
|
2021-01-30 21:29:59 +00:00
|
|
|
[rand.get_between_unsigned(0, self.hidden_abilities.len() as u32) as usize]
|
|
|
|
}
|
|
|
|
|
2022-06-11 15:22:46 +00:00
|
|
|
pub fn has_flag(&self, key: &StringKey) -> bool {
|
2021-01-30 21:29:59 +00:00
|
|
|
self.flags.contains(key)
|
|
|
|
}
|
|
|
|
}
|