Damage and poise reduction stats now track split modifiers

This commit is contained in:
Sam 2024-05-27 22:06:12 -04:00
parent 9264c10289
commit 8b24ca68a8
5 changed files with 38 additions and 10 deletions

View File

@ -1224,7 +1224,7 @@ impl Damage {
}; };
let stats_dr = if let Some(stats) = stats { let stats_dr = if let Some(stats) = stats {
stats.damage_reduction stats.damage_reduction.modifier()
} else { } else {
0.0 0.0
}; };

View File

@ -275,7 +275,7 @@ impl Poise {
if resistant { 0.5 } else { 0.0 } if resistant { 0.5 } else { 0.0 }
}; };
let from_stats = if let Some(stats) = stats { let from_stats = if let Some(stats) = stats {
stats.poise_reduction stats.poise_reduction.modifier()
} else { } else {
0.0 0.0
}; };

View File

@ -28,6 +28,25 @@ impl Default for StatsModifier {
} }
} }
#[derive(Debug, Clone, Copy, Deserialize, Serialize)]
pub struct StatsSplit {
pub pos_mod: f32,
pub neg_mod: f32,
}
impl Default for StatsSplit {
fn default() -> Self {
Self {
pos_mod: 0.0,
neg_mod: 0.0,
}
}
}
impl StatsSplit {
pub fn modifier(&self) -> f32 { self.pos_mod + self.neg_mod }
}
impl StatsModifier { impl StatsModifier {
pub fn compute_maximum(&self, base_value: f32) -> f32 { pub fn compute_maximum(&self, base_value: f32) -> f32 {
base_value * self.mult_mod + self.add_mod base_value * self.mult_mod + self.add_mod
@ -53,9 +72,11 @@ impl Error for StatChangeError {}
pub struct Stats { pub struct Stats {
pub name: String, pub name: String,
pub original_body: Body, pub original_body: Body,
pub damage_reduction: f32, pub damage_reduction: StatsSplit,
pub poise_reduction: f32, pub poise_reduction: StatsSplit,
pub heal_multiplier: f32, pub heal_multiplier: f32,
// Note: This is used to counteract agility as a "potion sickness" right now, and otherwise
// does not impact movement speed
pub move_speed_multiplier: f32, pub move_speed_multiplier: f32,
pub max_health_modifiers: StatsModifier, pub max_health_modifiers: StatsModifier,
pub move_speed_modifier: f32, pub move_speed_modifier: f32,
@ -87,8 +108,8 @@ impl Stats {
Self { Self {
name, name,
original_body: body, original_body: body,
damage_reduction: 0.0, damage_reduction: StatsSplit::default(),
poise_reduction: 0.0, poise_reduction: StatsSplit::default(),
heal_multiplier: 1.0, heal_multiplier: 1.0,
move_speed_multiplier: 1.0, move_speed_multiplier: 1.0,
max_health_modifiers: StatsModifier::default(), max_health_modifiers: StatsModifier::default(),

View File

@ -702,7 +702,11 @@ fn execute_effect(
}, },
}, },
BuffEffect::DamageReduction(dr) => { BuffEffect::DamageReduction(dr) => {
stat.damage_reduction = 1.0 - ((1.0 - stat.damage_reduction) * (1.0 - *dr)); if *dr > 0.0 {
stat.damage_reduction.pos_mod = stat.damage_reduction.pos_mod.max(*dr);
} else {
stat.damage_reduction.neg_mod += dr;
}
}, },
BuffEffect::MaxHealthChangeOverTime { BuffEffect::MaxHealthChangeOverTime {
rate, rate,
@ -761,9 +765,12 @@ fn execute_effect(
BuffEffect::GroundFriction(gf) => { BuffEffect::GroundFriction(gf) => {
stat.friction_modifier *= *gf; stat.friction_modifier *= *gf;
}, },
#[allow(clippy::manual_clamp)]
BuffEffect::PoiseReduction(pr) => { BuffEffect::PoiseReduction(pr) => {
stat.poise_reduction = stat.poise_reduction.max(*pr).min(1.0); if *pr > 0.0 {
stat.damage_reduction.pos_mod = stat.damage_reduction.pos_mod.max(*pr);
} else {
stat.damage_reduction.neg_mod += pr;
}
}, },
BuffEffect::HealReduction(red) => { BuffEffect::HealReduction(red) => {
stat.heal_multiplier *= 1.0 - *red; stat.heal_multiplier *= 1.0 - *red;

View File

@ -620,7 +620,7 @@ fn selected_entity_window(
.striped(true) .striped(true)
.show(ui, |ui| { .show(ui, |ui| {
two_col_row(ui, "Name", stats.name.to_string()); two_col_row(ui, "Name", stats.name.to_string());
two_col_row(ui, "Damage Reduction", format!("{:.1}", stats.damage_reduction)); two_col_row(ui, "Damage Reduction", format!("{:.1}", stats.damage_reduction.modifier()));
two_col_row(ui, "Multiplicative Max Health Modifier", format!("{:.1}", stats.max_health_modifiers.mult_mod)); two_col_row(ui, "Multiplicative Max Health Modifier", format!("{:.1}", stats.max_health_modifiers.mult_mod));
two_col_row(ui, "Move Speed Modifier", format!("{:.1}", stats.move_speed_modifier)); two_col_row(ui, "Move Speed Modifier", format!("{:.1}", stats.move_speed_modifier));
}); });