Addressed comments.

This commit is contained in:
Sam 2020-10-26 20:17:46 -05:00
parent e8f6338eb0
commit 6559df459e
3 changed files with 12 additions and 10 deletions

View File

@ -5,16 +5,14 @@ use specs_idvs::IdvStorage;
use std::{cmp::Ordering, collections::HashMap, time::Duration};
/// De/buff Kind.
/// This is used to determine what effects a buff will have, as well as
/// determine the strength and duration of the buff effects using the internal
/// values
/// This is used to determine what effects a buff will have
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug, Serialize, Deserialize)]
pub enum BuffKind {
/// Restores health/time for some period
Regeneration,
/// Lowers health over time for some duration
Bleeding,
/// Prefixes an entity's name with "Cursed"
/// Lower a creature's max health
/// Currently placeholder buff to show other stuff is possible
Cursed,
}
@ -151,7 +149,9 @@ impl Buff {
impl PartialOrd for Buff {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
if self.data.strength > other.data.strength {
if self == other {
Some(Ordering::Equal)
} else if self.data.strength > other.data.strength {
Some(Ordering::Greater)
} else if self.data.strength < other.data.strength {
Some(Ordering::Less)
@ -159,8 +159,6 @@ impl PartialOrd for Buff {
Some(Ordering::Greater)
} else if compare_duration(other.time, self.time) {
Some(Ordering::Less)
} else if self == other {
Some(Ordering::Equal)
} else {
None
}
@ -173,7 +171,7 @@ fn compare_duration(a: Option<Duration>, b: Option<Duration>) -> bool {
impl PartialEq for Buff {
fn eq(&self, other: &Self) -> bool {
self.data.strength == other.data.strength || self.time == other.time
self.data.strength == other.data.strength && self.time == other.time
}
}
@ -236,7 +234,6 @@ impl Buffs {
}
self.kinds.remove(&kind);
}
self.sort_kind(kind);
}
pub fn force_insert(&mut self, id: BuffId, buff: Buff) -> BuffId {

View File

@ -70,7 +70,9 @@ impl Health {
self.last_change = (0.0, change);
}
// This is private because max hp is based on the level
// This function changes the modified max health value, not the base health
// value. The modified health value takes into account buffs and other temporary
// changes to max health.
pub fn set_maximum(&mut self, amount: u32) {
self.maximum = amount;
self.current = self.current.min(self.maximum);

View File

@ -30,6 +30,7 @@ impl<'a> System<'a> for Sys {
let mut server_emitter = server_bus.emitter();
// Set to false to avoid spamming server
buffs.set_event_emission(false);
stats.set_event_emission(false);
for (entity, buff_comp, uid, stat) in (&entities, &mut buffs, &uids, &mut stats).join() {
let mut expired_buffs = Vec::<BuffId>::new();
for (id, buff) in buff_comp.buffs.iter_mut() {
@ -138,6 +139,8 @@ impl<'a> System<'a> for Sys {
});
}
}
// Turned back to true
buffs.set_event_emission(true);
stats.set_event_emission(true);
}
}