diff --git a/common/src/comp/buff.rs b/common/src/comp/buff.rs index b36535a39d..8aa6abe5a9 100644 --- a/common/src/comp/buff.rs +++ b/common/src/comp/buff.rs @@ -16,13 +16,15 @@ use std::time::Duration; #[derive(Clone, PartialEq, Debug, Serialize, Deserialize)] pub enum BuffId { /// Restores health/time for some period - Regeneration, - /// Lowers health/time for some period, but faster - Poison, + /// Has fields: strength (f32) + Regeneration(f32), /// Lowers health over time for some duration - Bleeding, - /// Changes entity name as to "Cursed {}" - Cursed, + /// Has fields: strength (f32) + Bleeding(f32), + /// Adds a prefix to the entity name + /// Currently placeholder buff to show other stuff is possible + /// Has fields: prefix (String) + Prefix(String), } /// De/buff category ID. @@ -131,6 +133,40 @@ impl Buffs { pub fn has_buff_id(&self, id: &BuffId) -> bool { self.buffs.iter().any(|buff| buff.id == *id) } } +impl Buff { + pub fn new(id: BuffId, time: Option, cat_ids: Vec) -> Self { + let effects = match id { + BuffId::Bleeding(strength) => vec![ + BuffEffect::HealthChangeOverTime { + rate: -strength, + accumulated: 0.0, + }, + // This effect is for testing purposes + BuffEffect::NameChange { + prefix: String::from("Injured "), + }, + ], + BuffId::Regeneration(strength) => vec![BuffEffect::HealthChangeOverTime { + rate: strength, + accumulated: 0.0, + }], + BuffId::Prefix(ref prefix) => { + let mut prefix = prefix.clone(); + prefix.push(' '); + vec![BuffEffect::NameChange { + prefix, + }] + }, + }; + Buff { + id: id.clone(), + cat_ids, + time, + effects, + } + } +} + impl Component for Buffs { type Storage = FlaggedStorage>; } diff --git a/common/src/sys/buff.rs b/common/src/sys/buff.rs index 98b5c8e8b6..78ecaff28d 100644 --- a/common/src/sys/buff.rs +++ b/common/src/sys/buff.rs @@ -28,7 +28,7 @@ impl<'a> System<'a> for Sys { let mut server_emitter = server_bus.emitter(); for (entity, uid, mut buffs) in (&entities, &uids, &mut buffs.restrict_mut()).join() { let buff_comp = buffs.get_mut_unchecked(); - let mut buff_indices_for_removal = Vec::new(); + let mut buff_indices_for_removal = Vec::::new(); // Tick all de/buffs on a Buffs component. for i in 0..buff_comp.buffs.len() { // First, tick the buff and subtract delta from it @@ -81,17 +81,6 @@ impl<'a> System<'a> for Sys { uid: *uid, buff_change: BuffChange::RemoveByIndex(buff_indices_for_removal), }); - // Remove buffs that have expired. - // Since buffs are added into this vec as it iterates up through the - // list, it will be in order of increasing values. - // Therefore to avoid removing the incorrect buff, - // removal will start from the greatest index - // value, which is the last in this vec. - /*while !buff_indices_for_removal.is_empty() { - if let Some(i) = buff_indices_for_removal.pop() { - buff_comp.buffs.remove(i); - } - }*/ } } } diff --git a/common/src/sys/combat.rs b/common/src/sys/combat.rs index cd7e1d0602..b9a9bc8e99 100644 --- a/common/src/sys/combat.rs +++ b/common/src/sys/combat.rs @@ -154,20 +154,11 @@ impl<'a> System<'a> for Sys { // Test for server event of buff, remove before merging server_emitter.emit(ServerEvent::Buff { uid: *uid_b, - buff_change: buff::BuffChange::Add(buff::Buff { - id: buff::BuffId::Bleeding, - cat_ids: vec![buff::BuffCategoryId::Physical], - time: Some(Duration::from_millis(2000)), - effects: vec![ - buff::BuffEffect::HealthChangeOverTime { - rate: 10.0, - accumulated: 0.0, - }, - buff::BuffEffect::NameChange { - prefix: String::from("Injured "), - }, - ], - }), + buff_change: buff::BuffChange::Add(buff::Buff::new( + buff::BuffId::Bleeding(50.0), + Some(Duration::from_millis(5000)), + vec![buff::BuffCategoryId::Physical], + )), }); attack.hit_count += 1; }