···11//! Contains a modifier that can be applied to [`Stat`](crate::Stat).
2233+use std::fmt::{Display, Formatter};
34use std::ops::{AddAssign, DivAssign, MulAssign, SubAssign};
4556/// Modifier values that can be [applied](super::Stat::apply) to a [`Stat`](super::Stat).
···3940 Self {
4041 multiplier,
4142 ..Self::default()
4343+ }
4444+ }
4545+4646+ /// Returns a new modifier scaled by a fraction.
4747+ ///
4848+ /// When the scale is zero, the bonus will be zero while the multiplier will be one.
4949+ pub fn scaled(&self, fraction: f32) -> Self {
5050+ Self {
5151+ bonus: (self.bonus as f32 * fraction) as i32,
5252+ multiplier: (1.0 - fraction) * 1.0 + fraction * self.multiplier,
4253 }
4354 }
4455}
···7990 self.multiplier /= rhs;
8091 }
8192}
9393+9494+impl Display for Modifier {
9595+ fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
9696+ if let Some(precision) = f.precision() {
9797+ write!(f, "(+{}) x {:.*}", self.bonus, precision, self.multiplier)
9898+ } else {
9999+ write!(f, "(+{}) x {}", self.bonus, self.multiplier)
100100+ }
101101+ }
102102+}
+18-1
immediate_stats/src/stat.rs
···2233use crate::StatContainer;
44use crate::modifier::Modifier;
55+use std::fmt::{Display, Formatter};
56use std::ops::{AddAssign, DivAssign, MulAssign, SubAssign};
6778/// A stat that [resets][reset] to a base value every iteration.
···7980 self.multiplier *= modifier.multiplier;
8081 }
81828282- /// Scales and applies the [`Modifier`] values to the bonus and multiplier.
8383+ /// [Scales](Modifier::scaled) and applies the [`Modifier`] values to the bonus and multiplier.
8484+ ///
8585+ /// When the scale is zero, the bonus will be zero while the multiplier will be one.
8386 ///
8487 /// This adds the bonuses, and multiplies the multipliers.
8588 pub fn apply_scaled(&mut self, modifier: Modifier, fraction: f32) {
···133136 self.multiplier /= rhs;
134137 }
135138}
139139+140140+impl Display for Stat {
141141+ fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
142142+ if let Some(precision) = f.precision() {
143143+ write!(
144144+ f,
145145+ "({} + {}) x {:.*}",
146146+ self.base, self.bonus, precision, self.multiplier
147147+ )
148148+ } else {
149149+ write!(f, "({} + {}) x {}", self.base, self.bonus, self.multiplier)
150150+ }
151151+ }
152152+}