use crate::shared::stats::*; use crate::shared::*; #[derive(Clone, Copy, PartialEq, Debug, Serialize, Deserialize)] pub enum Damage { Magical(f32), Physical(f32), True(f32), } impl Damage { pub fn apply(self, stats: Stats) -> f32 { match self { Damage::Magical(magical_damage) => { magical_damage * damage_multiplier(stats.magic_resist) } Damage::Physical(physical_damage) => physical_damage * damage_multiplier(stats.armor), Damage::True(true_damage) => true_damage, } } pub fn scale(self, factor: f32) -> Self { match self { Damage::Magical(magical_damage) => Damage::Magical(magical_damage * factor), Damage::Physical(physical_damage) => Damage::Physical(physical_damage * factor), Damage::True(true_damage) => Damage::True(true_damage * factor), } } } fn damage_multiplier(resistance: f32) -> f32 { if resistance >= 0. { 100. / (100. + resistance) } else { 2. - 100. / (100. - resistance) } }