2021-11-13 20:46:45 +00:00
|
|
|
use crate::DamageSource;
|
2022-01-15 16:58:28 +00:00
|
|
|
#[cfg(not(target_arch = "wasm32"))]
|
|
|
|
use crate::{comp, consts::HP_PER_LEVEL};
|
2021-11-13 20:46:45 +00:00
|
|
|
use hashbrown::HashMap;
|
2020-10-31 22:34:08 +00:00
|
|
|
use serde::{Deserialize, Serialize};
|
2021-11-13 20:46:45 +00:00
|
|
|
use std::convert::TryFrom;
|
2021-02-17 13:03:20 +00:00
|
|
|
|
2021-11-13 20:46:45 +00:00
|
|
|
use crate::{combat::DamageContributor, resources::Time};
|
2021-02-17 13:03:20 +00:00
|
|
|
#[cfg(not(target_arch = "wasm32"))]
|
2021-01-07 20:25:12 +00:00
|
|
|
use specs::{Component, DerefFlaggedStorage};
|
2021-09-14 02:16:01 +00:00
|
|
|
use std::ops::Mul;
|
2020-10-31 22:34:08 +00:00
|
|
|
|
|
|
|
/// Specifies what and how much changed current health
|
2021-09-09 04:07:17 +00:00
|
|
|
#[derive(Clone, Copy, Debug, Serialize, Deserialize, PartialEq)]
|
2020-10-31 22:34:08 +00:00
|
|
|
pub struct HealthChange {
|
2021-11-13 20:46:45 +00:00
|
|
|
/// The amount of the health change, negative is damage, positive is healing
|
2021-09-09 04:07:17 +00:00
|
|
|
pub amount: f32,
|
2022-01-13 03:18:26 +00:00
|
|
|
/// The individual or group who caused the health change (None if the
|
2021-11-13 20:46:45 +00:00
|
|
|
/// damage wasn't caused by an entity)
|
|
|
|
pub by: Option<DamageContributor>,
|
|
|
|
/// The category of action that resulted in the health change
|
2021-09-09 04:07:17 +00:00
|
|
|
pub cause: Option<DamageSource>,
|
2021-11-13 20:46:45 +00:00
|
|
|
/// The time that the health change occurred at
|
|
|
|
pub time: Time,
|
2022-05-17 19:30:51 +00:00
|
|
|
/// A boolean that tells you if the change was a crit
|
|
|
|
pub crit: bool,
|
2022-05-02 19:10:55 +00:00
|
|
|
/// A random ID, used to group up health changes from the same attack
|
2022-01-26 10:16:45 +00:00
|
|
|
pub instance: u64,
|
2020-10-31 22:34:08 +00:00
|
|
|
}
|
|
|
|
|
2021-09-09 04:07:17 +00:00
|
|
|
impl HealthChange {
|
2021-11-13 20:46:45 +00:00
|
|
|
pub fn damage_by(&self) -> Option<DamageContributor> {
|
|
|
|
self.cause.is_some().then_some(self.by).flatten()
|
|
|
|
}
|
2020-10-31 22:34:08 +00:00
|
|
|
}
|
|
|
|
|
2021-11-13 20:46:45 +00:00
|
|
|
#[derive(Clone, Debug, Serialize, Deserialize)]
|
2021-09-09 04:07:17 +00:00
|
|
|
/// Health is represented by u32s within the module, but treated as a float by
|
|
|
|
/// the rest of the game.
|
|
|
|
// As a general rule, all input and output values to public functions should be
|
|
|
|
// floats rather than integers.
|
2020-10-31 22:34:08 +00:00
|
|
|
pub struct Health {
|
2021-09-09 04:07:17 +00:00
|
|
|
// Current and base_max are scaled by 256 within this module compared to what is visible to
|
2021-09-10 19:20:14 +00:00
|
|
|
// outside this module. The scaling is done to allow health to function as a fixed point while
|
|
|
|
// still having the advantages of being an integer. The scaling of 256 was chosen so that max
|
|
|
|
// health could be u16::MAX - 1, and then the scaled health could fit inside an f32 with no
|
|
|
|
// precision loss
|
2021-09-23 11:36:03 +00:00
|
|
|
/// Current health is how much health the entity currently has. Current
|
|
|
|
/// health *must* be lower than or equal to maximum health.
|
2020-10-31 22:34:08 +00:00
|
|
|
current: u32,
|
2021-09-10 19:20:14 +00:00
|
|
|
/// Base max is the amount of health the entity has without considering
|
|
|
|
/// temporary modifiers such as buffs
|
2021-03-20 17:29:57 +00:00
|
|
|
base_max: u32,
|
2021-09-10 19:20:14 +00:00
|
|
|
/// Maximum is the amount of health the entity has after temporary modifiers
|
|
|
|
/// are considered
|
2020-10-31 22:34:08 +00:00
|
|
|
maximum: u32,
|
2021-11-13 20:46:45 +00:00
|
|
|
/// The last change to health
|
|
|
|
pub last_change: HealthChange,
|
2020-10-31 22:34:08 +00:00
|
|
|
pub is_dead: bool,
|
2021-11-13 20:46:45 +00:00
|
|
|
|
|
|
|
/// Keeps track of damage per DamageContributor and the last time they
|
|
|
|
/// caused damage, used for EXP sharing
|
|
|
|
#[serde(skip)]
|
|
|
|
damage_contributors: HashMap<DamageContributor, (u64, Time)>,
|
2020-10-31 22:34:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Health {
|
2021-09-10 19:20:14 +00:00
|
|
|
/// Used when comparisons to health are needed outside this module.
|
|
|
|
// This value is chosen as anything smaller than this is more precise than our
|
|
|
|
// units of health.
|
|
|
|
pub const HEALTH_EPSILON: f32 = 0.5 / Self::MAX_SCALED_HEALTH as f32;
|
|
|
|
/// Maximum value allowed for health before scaling
|
|
|
|
const MAX_HEALTH: u16 = u16::MAX - 1;
|
2021-09-09 04:07:17 +00:00
|
|
|
/// The maximum value allowed for current and maximum health
|
2021-09-10 19:20:14 +00:00
|
|
|
/// Maximum value is (u16:MAX - 1) * 256, which only requires 24 bits. This
|
2021-09-09 04:07:17 +00:00
|
|
|
/// can fit into an f32 with no loss to precision
|
2021-09-10 19:20:14 +00:00
|
|
|
// Cast to u32 done as u32::from cannot be called inside constant
|
|
|
|
const MAX_SCALED_HEALTH: u32 = Self::MAX_HEALTH as u32 * Self::SCALING_FACTOR_INT;
|
2021-09-09 04:07:17 +00:00
|
|
|
/// The amount health is scaled by within this module
|
|
|
|
const SCALING_FACTOR_FLOAT: f32 = 256.;
|
2021-09-10 19:20:14 +00:00
|
|
|
const SCALING_FACTOR_INT: u32 = Self::SCALING_FACTOR_FLOAT as u32;
|
2021-09-09 04:07:17 +00:00
|
|
|
|
|
|
|
/// Returns the current value of health casted to a float
|
|
|
|
pub fn current(&self) -> f32 { self.current as f32 / Self::SCALING_FACTOR_FLOAT }
|
2020-10-31 22:34:08 +00:00
|
|
|
|
2021-09-09 04:07:17 +00:00
|
|
|
/// Returns the base maximum value of health casted to a float
|
|
|
|
pub fn base_max(&self) -> f32 { self.base_max as f32 / Self::SCALING_FACTOR_FLOAT }
|
2020-10-31 22:34:08 +00:00
|
|
|
|
2021-09-09 04:07:17 +00:00
|
|
|
/// Returns the maximum value of health casted to a float
|
|
|
|
pub fn maximum(&self) -> f32 { self.maximum as f32 / Self::SCALING_FACTOR_FLOAT }
|
|
|
|
|
|
|
|
/// Returns the fraction of health an entity has remaining
|
|
|
|
pub fn fraction(&self) -> f32 { self.current() / self.maximum().max(1.0) }
|
|
|
|
|
2022-01-18 05:17:20 +00:00
|
|
|
/// Calculates a new maximum value and returns it if the value differs from
|
|
|
|
/// the current maximum.
|
|
|
|
///
|
|
|
|
/// Note: The returned value uses an internal format so don't expect it to
|
|
|
|
/// be useful for anything other than a parameter to
|
|
|
|
/// [`Self::update_maximum`].
|
|
|
|
pub fn needs_maximum_update(&self, modifiers: comp::stats::StatsModifier) -> Option<u32> {
|
2021-09-09 04:07:17 +00:00
|
|
|
let maximum = modifiers
|
2021-09-14 02:16:01 +00:00
|
|
|
.compute_maximum(self.base_max())
|
|
|
|
.mul(Self::SCALING_FACTOR_FLOAT)
|
2021-09-10 19:20:14 +00:00
|
|
|
// NaN does not need to be handled here as rust will automatically change to 0 when casting to u32
|
|
|
|
.clamp(0.0, Self::MAX_SCALED_HEALTH as f32) as u32;
|
2022-01-18 05:17:20 +00:00
|
|
|
|
2022-09-08 19:51:02 +00:00
|
|
|
(maximum != self.maximum).then_some(maximum)
|
2022-01-18 05:17:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Updates the maximum value for health.
|
|
|
|
///
|
|
|
|
/// Note: The accepted `u32` value is in the internal format of this type.
|
|
|
|
/// So attempting to pass values that weren't returned from
|
|
|
|
/// [`Self::needs_maximum_update`] can produce strange or unexpected
|
|
|
|
/// results.
|
2022-01-18 05:52:31 +00:00
|
|
|
pub fn update_internal_integer_maximum(&mut self, maximum: u32) {
|
2021-09-09 04:07:17 +00:00
|
|
|
self.maximum = maximum;
|
2021-09-23 11:36:03 +00:00
|
|
|
// Clamp the current health to enforce the current <= maximum invariant.
|
2021-09-14 02:16:01 +00:00
|
|
|
self.current = self.current.min(self.maximum);
|
2020-10-31 22:34:08 +00:00
|
|
|
}
|
|
|
|
|
2021-09-09 04:07:17 +00:00
|
|
|
#[cfg(not(target_arch = "wasm32"))]
|
|
|
|
pub fn new(body: comp::Body, level: u16) -> Self {
|
2021-09-10 19:20:14 +00:00
|
|
|
let health = u32::from(
|
|
|
|
body.base_health()
|
2022-01-15 16:58:28 +00:00
|
|
|
.saturating_add(HP_PER_LEVEL.saturating_mul(level)),
|
2021-09-10 19:20:14 +00:00
|
|
|
) * Self::SCALING_FACTOR_INT;
|
2020-10-31 22:34:08 +00:00
|
|
|
Health {
|
2021-09-09 04:07:17 +00:00
|
|
|
current: health,
|
|
|
|
base_max: health,
|
|
|
|
maximum: health,
|
2021-11-13 20:46:45 +00:00
|
|
|
last_change: HealthChange {
|
2021-09-09 04:07:17 +00:00
|
|
|
amount: 0.0,
|
|
|
|
by: None,
|
|
|
|
cause: None,
|
2022-05-17 19:30:51 +00:00
|
|
|
crit: false,
|
2021-11-13 20:46:45 +00:00
|
|
|
time: Time(0.0),
|
2022-01-26 10:16:45 +00:00
|
|
|
instance: rand::random(),
|
2021-11-13 20:46:45 +00:00
|
|
|
},
|
2020-10-31 22:34:08 +00:00
|
|
|
is_dead: false,
|
2021-11-13 20:46:45 +00:00
|
|
|
damage_contributors: HashMap::new(),
|
2020-10-31 22:34:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-09 04:07:17 +00:00
|
|
|
// TODO: Delete this once stat points will be a thing
|
2021-02-17 13:03:20 +00:00
|
|
|
#[cfg(not(target_arch = "wasm32"))]
|
2021-09-09 04:07:17 +00:00
|
|
|
pub fn update_max_hp(&mut self, body: comp::Body, level: u16) {
|
|
|
|
let old_max = self.base_max;
|
2021-09-10 19:20:14 +00:00
|
|
|
self.base_max = u32::from(
|
|
|
|
body.base_health()
|
2022-01-15 16:58:28 +00:00
|
|
|
.saturating_add(HP_PER_LEVEL.saturating_mul(level)),
|
2021-09-10 19:20:14 +00:00
|
|
|
) * Self::SCALING_FACTOR_INT;
|
2021-09-09 04:07:17 +00:00
|
|
|
self.current = (self.current + self.base_max - old_max).min(self.maximum);
|
2020-10-31 22:34:08 +00:00
|
|
|
}
|
|
|
|
|
2021-02-17 13:03:20 +00:00
|
|
|
#[cfg(not(target_arch = "wasm32"))]
|
2022-06-14 21:11:58 +00:00
|
|
|
/// Returns a boolean if the delta was not zero.
|
2022-01-25 12:29:14 +00:00
|
|
|
pub fn change_by(&mut self, change: HealthChange) -> bool {
|
2021-11-13 20:46:45 +00:00
|
|
|
let prev_health = i64::from(self.current);
|
2021-09-10 19:20:14 +00:00
|
|
|
self.current = (((self.current() + change.amount).clamp(0.0, f32::from(Self::MAX_HEALTH))
|
2021-09-14 02:16:01 +00:00
|
|
|
* Self::SCALING_FACTOR_FLOAT) as u32)
|
2021-09-09 04:07:17 +00:00
|
|
|
.min(self.maximum);
|
2021-11-13 20:46:45 +00:00
|
|
|
let delta = i64::from(self.current) - prev_health;
|
|
|
|
|
|
|
|
self.last_change = change;
|
|
|
|
|
|
|
|
// If damage is applied by an entity, update the damage contributors
|
|
|
|
if delta < 0 {
|
|
|
|
if let Some(attacker) = change.by {
|
|
|
|
let entry = self
|
|
|
|
.damage_contributors
|
|
|
|
.entry(attacker)
|
|
|
|
.or_insert((0, change.time));
|
2022-09-08 19:51:02 +00:00
|
|
|
entry.0 += u64::try_from(-delta).unwrap_or(0);
|
|
|
|
entry.1 = change.time
|
2021-11-13 20:46:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Prune any damage contributors who haven't contributed damage for over the
|
|
|
|
// threshold - this enforces a maximum period that an entity will receive EXP
|
|
|
|
// for a kill after they last damaged the killed entity.
|
|
|
|
const DAMAGE_CONTRIB_PRUNE_SECS: f64 = 600.0;
|
|
|
|
self.damage_contributors.retain(|_, (_, last_damage_time)| {
|
|
|
|
(change.time.0 - last_damage_time.0) < DAMAGE_CONTRIB_PRUNE_SECS
|
|
|
|
});
|
|
|
|
}
|
2022-06-14 21:11:58 +00:00
|
|
|
delta != 0
|
2021-11-13 20:46:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn damage_contributions(&self) -> impl Iterator<Item = (&DamageContributor, &u64)> {
|
|
|
|
self.damage_contributors
|
|
|
|
.iter()
|
|
|
|
.map(|(damage_contrib, (damage, _))| (damage_contrib, damage))
|
2020-10-31 22:34:08 +00:00
|
|
|
}
|
|
|
|
|
2021-09-09 04:07:17 +00:00
|
|
|
pub fn should_die(&self) -> bool { self.current == 0 }
|
2021-03-20 17:29:57 +00:00
|
|
|
|
2022-08-20 21:10:29 +00:00
|
|
|
pub fn kill(&mut self) { self.current = 0; }
|
2020-10-31 22:34:08 +00:00
|
|
|
|
2021-02-17 13:03:20 +00:00
|
|
|
#[cfg(not(target_arch = "wasm32"))]
|
2020-10-31 22:34:08 +00:00
|
|
|
pub fn revive(&mut self) {
|
2021-09-09 04:07:17 +00:00
|
|
|
self.current = self.maximum;
|
2020-10-31 22:34:08 +00:00
|
|
|
self.is_dead = false;
|
|
|
|
}
|
2021-09-12 16:23:53 +00:00
|
|
|
|
2021-11-13 20:46:45 +00:00
|
|
|
#[cfg(test)]
|
2021-09-12 16:23:53 +00:00
|
|
|
pub fn empty() -> Self {
|
|
|
|
Health {
|
|
|
|
current: 0,
|
|
|
|
base_max: 0,
|
|
|
|
maximum: 0,
|
2021-11-13 20:46:45 +00:00
|
|
|
last_change: HealthChange {
|
2021-09-12 16:23:53 +00:00
|
|
|
amount: 0.0,
|
|
|
|
by: None,
|
|
|
|
cause: None,
|
2022-05-17 19:30:51 +00:00
|
|
|
crit: false,
|
2021-11-13 20:46:45 +00:00
|
|
|
time: Time(0.0),
|
2022-01-26 10:16:45 +00:00
|
|
|
instance: rand::random(),
|
2021-11-13 20:46:45 +00:00
|
|
|
},
|
2021-09-12 16:23:53 +00:00
|
|
|
is_dead: false,
|
2021-11-13 20:46:45 +00:00
|
|
|
damage_contributors: HashMap::new(),
|
2021-09-12 16:23:53 +00:00
|
|
|
}
|
|
|
|
}
|
StaminaPlus buff, modifying stamina via buffs
trying to fix this, coming back to this later
please remember to change potion back future self!
this ALMOST works. maybe MR ready, kinda jank tho
so close, and yet so far...
IT WORKS IT WORKS IT WORKS IT WORKS IT WORKS IT WO
did the same with health, ill fix this garbage l8r
think we're basically done here
whoops forgot to change the food back
fixing and cleaning up part 1
fixed everything part 2 now with buff images
ran clippy + fmt, fixed items that i modified
bracket bulldozing, boldly
hopefully this should be good?
need to rebase real quick
please let me be done
StaminaPlus buff, modifying stamina via buffs
trying to fix this, coming back to this later
please remember to change potion back future self!
this ALMOST works. maybe MR ready, kinda jank tho
so close, and yet so far...
IT WORKS IT WORKS IT WORKS IT WORKS IT WORKS IT WO
did the same with health, ill fix this garbage l8r
think we're basically done here
whoops forgot to change the food back
fixing and cleaning up part 1
fixed everything part 2 now with buff images
ran clippy + fmt, fixed items that i modified
hopefully this should be good?
cargo clippy fmt stuff
deleted an extraneous file?? how did that even...?
2021-01-26 22:47:55 +00:00
|
|
|
}
|
2021-02-17 13:03:20 +00:00
|
|
|
|
|
|
|
#[cfg(not(target_arch = "wasm32"))]
|
2020-10-31 22:34:08 +00:00
|
|
|
impl Component for Health {
|
2022-08-08 04:38:20 +00:00
|
|
|
type Storage = DerefFlaggedStorage<Self, specs::VecStorage<Self>>;
|
2020-10-31 22:34:08 +00:00
|
|
|
}
|
2021-11-13 20:46:45 +00:00
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
|
|
|
use crate::{
|
|
|
|
combat::DamageContributor,
|
|
|
|
comp::{Health, HealthChange},
|
|
|
|
resources::Time,
|
|
|
|
uid::Uid,
|
|
|
|
};
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_change_by_negative_health_change_adds_to_damage_contributors() {
|
|
|
|
let mut health = Health::empty();
|
|
|
|
health.current = 100 * Health::SCALING_FACTOR_INT;
|
|
|
|
health.maximum = health.current;
|
|
|
|
|
|
|
|
let damage_contrib = DamageContributor::Solo(Uid(0));
|
|
|
|
let health_change = HealthChange {
|
|
|
|
amount: -5.0,
|
|
|
|
time: Time(123.0),
|
|
|
|
by: Some(damage_contrib),
|
|
|
|
cause: None,
|
2022-05-17 19:30:51 +00:00
|
|
|
crit: false,
|
2022-01-26 10:16:45 +00:00
|
|
|
instance: rand::random(),
|
2021-11-13 20:46:45 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
health.change_by(health_change);
|
|
|
|
|
|
|
|
let (damage, time) = health.damage_contributors.get(&damage_contrib).unwrap();
|
|
|
|
|
|
|
|
assert_eq!(
|
|
|
|
health_change.amount.abs() as u64 * Health::SCALING_FACTOR_INT as u64,
|
|
|
|
*damage
|
|
|
|
);
|
|
|
|
assert_eq!(health_change.time, *time);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_change_by_positive_health_change_does_not_add_damage_contributor() {
|
|
|
|
let mut health = Health::empty();
|
|
|
|
health.maximum = 100 * Health::SCALING_FACTOR_INT;
|
|
|
|
health.current = (health.maximum as f32 * 0.5) as u32;
|
|
|
|
|
|
|
|
let damage_contrib = DamageContributor::Solo(Uid(0));
|
|
|
|
let health_change = HealthChange {
|
|
|
|
amount: 20.0,
|
|
|
|
time: Time(123.0),
|
|
|
|
by: Some(damage_contrib),
|
|
|
|
cause: None,
|
2022-05-17 19:30:51 +00:00
|
|
|
crit: false,
|
2022-01-26 10:16:45 +00:00
|
|
|
instance: rand::random(),
|
2021-11-13 20:46:45 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
health.change_by(health_change);
|
|
|
|
|
|
|
|
assert!(health.damage_contributors.is_empty());
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_change_by_multiple_damage_from_same_damage_contributor() {
|
|
|
|
let mut health = Health::empty();
|
|
|
|
health.current = 100 * Health::SCALING_FACTOR_INT;
|
|
|
|
health.maximum = health.current;
|
|
|
|
|
|
|
|
let damage_contrib = DamageContributor::Solo(Uid(0));
|
|
|
|
let health_change = HealthChange {
|
|
|
|
amount: -5.0,
|
|
|
|
time: Time(123.0),
|
|
|
|
by: Some(damage_contrib),
|
|
|
|
cause: None,
|
2022-05-17 19:30:51 +00:00
|
|
|
crit: false,
|
2022-01-26 10:16:45 +00:00
|
|
|
instance: rand::random(),
|
2021-11-13 20:46:45 +00:00
|
|
|
};
|
|
|
|
health.change_by(health_change);
|
|
|
|
health.change_by(health_change);
|
|
|
|
|
|
|
|
let (damage, _) = health.damage_contributors.get(&damage_contrib).unwrap();
|
|
|
|
|
|
|
|
assert_eq!(
|
|
|
|
(health_change.amount.abs() * 2.0) as u64 * Health::SCALING_FACTOR_INT as u64,
|
|
|
|
*damage
|
|
|
|
);
|
|
|
|
assert_eq!(1, health.damage_contributors.len());
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn test_change_by_damage_contributor_pruning() {
|
|
|
|
let mut health = Health::empty();
|
|
|
|
health.current = 100 * Health::SCALING_FACTOR_INT;
|
|
|
|
health.maximum = health.current;
|
|
|
|
|
|
|
|
let damage_contrib1 = DamageContributor::Solo(Uid(0));
|
|
|
|
let health_change = HealthChange {
|
|
|
|
amount: -5.0,
|
|
|
|
time: Time(10.0),
|
|
|
|
by: Some(damage_contrib1),
|
|
|
|
cause: None,
|
2022-05-17 19:30:51 +00:00
|
|
|
crit: false,
|
2022-01-26 10:16:45 +00:00
|
|
|
instance: rand::random(),
|
2021-11-13 20:46:45 +00:00
|
|
|
};
|
|
|
|
health.change_by(health_change);
|
|
|
|
|
|
|
|
let damage_contrib2 = DamageContributor::Solo(Uid(1));
|
|
|
|
let health_change = HealthChange {
|
|
|
|
amount: -5.0,
|
|
|
|
time: Time(100.0),
|
|
|
|
by: Some(damage_contrib2),
|
|
|
|
cause: None,
|
2022-05-17 19:30:51 +00:00
|
|
|
crit: false,
|
2022-01-26 10:16:45 +00:00
|
|
|
instance: rand::random(),
|
2021-11-13 20:46:45 +00:00
|
|
|
};
|
|
|
|
health.change_by(health_change);
|
|
|
|
|
|
|
|
assert!(health.damage_contributors.contains_key(&damage_contrib1));
|
|
|
|
assert!(health.damage_contributors.contains_key(&damage_contrib2));
|
|
|
|
|
|
|
|
// Apply damage 610 seconds after the damage from damage_contrib1 - this should
|
|
|
|
// result in the damage from damage_contrib1 being pruned.
|
|
|
|
let health_change = HealthChange {
|
|
|
|
amount: -5.0,
|
|
|
|
time: Time(620.0),
|
|
|
|
by: Some(damage_contrib2),
|
|
|
|
cause: None,
|
2022-05-17 19:30:51 +00:00
|
|
|
crit: false,
|
2022-01-26 10:16:45 +00:00
|
|
|
instance: rand::random(),
|
2021-11-13 20:46:45 +00:00
|
|
|
};
|
|
|
|
health.change_by(health_change);
|
|
|
|
|
|
|
|
assert!(!health.damage_contributors.contains_key(&damage_contrib1));
|
|
|
|
assert!(health.damage_contributors.contains_key(&damage_contrib2));
|
|
|
|
}
|
|
|
|
}
|