Merge branch 'sam/buff-split-stats' into 'master'

Damage and poise reduction stats now track split modifiers

See merge request veloren/veloren!4484
This commit is contained in:
Samuel Keiffer 2024-05-29 15:52:55 +00:00
commit c065b689ac
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 {
stats.damage_reduction
stats.damage_reduction.modifier()
} else {
0.0
};

View File

@ -275,7 +275,7 @@ impl Poise {
if resistant { 0.5 } else { 0.0 }
};
let from_stats = if let Some(stats) = stats {
stats.poise_reduction
stats.poise_reduction.modifier()
} else {
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 {
pub fn compute_maximum(&self, base_value: f32) -> f32 {
base_value * self.mult_mod + self.add_mod
@ -53,9 +72,11 @@ impl Error for StatChangeError {}
pub struct Stats {
pub name: String,
pub original_body: Body,
pub damage_reduction: f32,
pub poise_reduction: f32,
pub damage_reduction: StatsSplit,
pub poise_reduction: StatsSplit,
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 max_health_modifiers: StatsModifier,
pub move_speed_modifier: f32,
@ -88,8 +109,8 @@ impl Stats {
Self {
name,
original_body: body,
damage_reduction: 0.0,
poise_reduction: 0.0,
damage_reduction: StatsSplit::default(),
poise_reduction: StatsSplit::default(),
heal_multiplier: 1.0,
move_speed_multiplier: 1.0,
max_health_modifiers: StatsModifier::default(),

View File

@ -702,7 +702,11 @@ fn execute_effect(
},
},
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 {
rate,
@ -761,9 +765,12 @@ fn execute_effect(
BuffEffect::GroundFriction(gf) => {
stat.friction_modifier *= *gf;
},
#[allow(clippy::manual_clamp)]
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) => {
stat.heal_multiplier *= 1.0 - *red;

View File

@ -620,7 +620,7 @@ fn selected_entity_window(
.striped(true)
.show(ui, |ui| {
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, "Move Speed Modifier", format!("{:.1}", stats.move_speed_modifier));
});