mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Added builder function for buffs
This commit is contained in:
parent
b8690473e4
commit
19c7ed7885
@ -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<Duration>, cat_ids: Vec<BuffCategoryId>) -> 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<Self, IdvStorage<Self>>;
|
||||
}
|
||||
|
@ -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::<usize>::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);
|
||||
}
|
||||
}*/
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user