Further massive amounts of work

This commit is contained in:
2022-06-06 13:54:59 +02:00
parent df662ce6b5
commit ce33ec0649
33 changed files with 848 additions and 80 deletions

View File

@@ -1,3 +1,80 @@
pub trait BattleStatCalculator {
//fn is_critical(attack: &ExecutingMove, target: &Pokemon, hit: u8);
use crate::dynamic_data::models::pokemon::Pokemon;
use crate::static_data::statistic_set::StatisticSet;
use crate::static_data::statistics::Statistic;
#[derive(Debug)]
pub struct BattleStatCalculator {}
impl BattleStatCalculator {
pub fn calculate_flat_stats(&self, pokemon: &Pokemon) -> StatisticSet<u32> {
StatisticSet::<u32>::new(
self.calculate_health_stat(pokemon),
self.calculate_other_stat(pokemon, Statistic::Attack),
self.calculate_other_stat(pokemon, Statistic::Defense),
self.calculate_other_stat(pokemon, Statistic::SpecialAttack),
self.calculate_other_stat(pokemon, Statistic::SpecialDefense),
self.calculate_other_stat(pokemon, Statistic::Speed),
)
}
pub fn calculate_flat_stat(&self, pokemon: &Pokemon, stat: Statistic) -> u32 {
if stat == Statistic::HP {
self.calculate_health_stat(pokemon)
} else {
self.calculate_other_stat(pokemon, stat)
}
}
pub fn calculate_boosted_stats(&self, pokemon: &Pokemon) -> StatisticSet<u32> {
StatisticSet::<u32>::new(
self.calculate_boosted_stat(pokemon, Statistic::HP),
self.calculate_boosted_stat(pokemon, Statistic::Attack),
self.calculate_boosted_stat(pokemon, Statistic::Defense),
self.calculate_boosted_stat(pokemon, Statistic::SpecialAttack),
self.calculate_boosted_stat(pokemon, Statistic::SpecialDefense),
self.calculate_boosted_stat(pokemon, Statistic::Speed),
)
}
pub fn calculate_boosted_stat(&self, pokemon: &Pokemon, stat: Statistic) -> u32 {
(self.calculate_flat_stat(pokemon, stat) as f32
* self.get_stat_boost_modifier(pokemon, stat)) as u32
}
fn calculate_health_stat(&self, pokemon: &Pokemon) -> u32 {
let base = pokemon.form().get_base_stat(Statistic::HP) as u32;
let iv = *pokemon.individual_values().hp() as u32;
let ev = *pokemon.effort_values().hp() as u32;
let level = *pokemon.level() as u32;
(((2 * base + iv + (ev / 4)) * level) / 100) + level + 10
}
fn calculate_other_stat(&self, pokemon: &Pokemon, stat: Statistic) -> u32 {
let base = pokemon.form().get_base_stat(stat) as u32;
let iv = pokemon.individual_values().get_stat(stat) as u32;
let ev = pokemon.effort_values().get_stat(stat) as u32;
let level = *pokemon.level() as u32;
let unmodified = (((2 * base + iv + (ev / 4)) * level) / 100) + 5;
return (unmodified as f32 * pokemon.nature().get_stat_modifier(stat)) as u32;
}
fn get_stat_boost_modifier(&self, pokemon: &Pokemon, stat: Statistic) -> f32 {
let boost = pokemon.stat_boost().get_stat(stat);
match boost {
-6 => 2.0 / 8.0,
-5 => 2.0 / 7.0,
-4 => 2.0 / 6.0,
-3 => 2.0 / 5.0,
-2 => 2.0 / 4.0,
-1 => 2.0 / 3.0,
0 => 1.0,
1 => 3.0 / 2.0,
2 => 4.0 / 2.0,
3 => 5.0 / 2.0,
4 => 6.0 / 2.0,
5 => 7.0 / 2.0,
6 => 8.0 / 2.0,
_ => panic!("Stat boost was out of expected range of -6 to 6"),
}
}
}

View File

@@ -1,19 +1,42 @@
use crate::dynamic_data::libraries::battle_stat_calculator::BattleStatCalculator;
use crate::dynamic_data::libraries::script_resolver::ScriptCategory;
use crate::dynamic_data::script_handling::script::Script;
use crate::static_data::libraries::static_data::StaticData;
use derive_getters::Getters;
use crate::PkmnResult;
#[derive(Getters, Debug)]
#[derive(Debug)]
pub struct DynamicLibrary<'a> {
static_data: StaticData<'a>,
stat_calculator: BattleStatCalculator,
}
impl<'a> DynamicLibrary<'a> {
pub fn static_data(&self) -> &StaticData<'a> {
&self.static_data
}
pub fn stat_calculator(&self) -> &BattleStatCalculator {
&self.stat_calculator
}
pub fn load_script(
&self,
_category: ScriptCategory,
_key: &str,
) -> PkmnResult<Box<dyn Script>> {
todo!()
}
}
#[cfg(test)]
pub mod test {
use crate::dynamic_data::libraries::battle_stat_calculator::BattleStatCalculator;
use crate::dynamic_data::libraries::dynamic_library::DynamicLibrary;
use crate::static_data::libraries::static_data;
pub fn build<'a>() -> DynamicLibrary<'a> {
DynamicLibrary {
static_data: static_data::test::build(),
stat_calculator: BattleStatCalculator {},
}
}
}

View File

@@ -1,2 +1,3 @@
pub mod battle_stat_calculator;
pub mod dynamic_library;
pub mod script_resolver;

View File

@@ -0,0 +1,12 @@
pub trait ScriptResolver {}
#[derive(Debug, Clone)]
pub enum ScriptCategory {
Move,
Ability,
Status,
Pokemon,
Battle,
Side,
ItemBattleTrigger,
}