mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Moved duration to inside BuffId enum to future-proof for when buffs are persisted.
This commit is contained in:
parent
1a1ceb54bc
commit
0df061a38e
@ -16,12 +16,18 @@ use std::time::Duration;
|
||||
#[derive(Clone, Copy, PartialEq, Debug, Serialize, Deserialize)]
|
||||
pub enum BuffId {
|
||||
/// Restores health/time for some period
|
||||
Regeneration { strength: f32 },
|
||||
Regeneration {
|
||||
strength: f32,
|
||||
duration: Option<Duration>,
|
||||
},
|
||||
/// Lowers health over time for some duration
|
||||
Bleeding { strength: f32 },
|
||||
Bleeding {
|
||||
strength: f32,
|
||||
duration: Option<Duration>,
|
||||
},
|
||||
/// Prefixes an entity's name with "Cursed"
|
||||
/// Currently placeholder buff to show other stuff is possible
|
||||
Cursed,
|
||||
Cursed { duration: Option<Duration> },
|
||||
}
|
||||
|
||||
/// De/buff category ID.
|
||||
@ -143,30 +149,34 @@ impl Buffs {
|
||||
}
|
||||
|
||||
impl Buff {
|
||||
pub fn new(
|
||||
id: BuffId,
|
||||
time: Option<Duration>,
|
||||
cat_ids: Vec<BuffCategoryId>,
|
||||
source: BuffSource,
|
||||
) -> Self {
|
||||
let effects = match id {
|
||||
BuffId::Bleeding { strength } => vec![
|
||||
BuffEffect::HealthChangeOverTime {
|
||||
rate: -strength,
|
||||
pub fn new(id: BuffId, cat_ids: Vec<BuffCategoryId>, source: BuffSource) -> Self {
|
||||
let (effects, time) = match id {
|
||||
BuffId::Bleeding { strength, duration } => (
|
||||
vec![
|
||||
BuffEffect::HealthChangeOverTime {
|
||||
rate: -strength,
|
||||
accumulated: 0.0,
|
||||
},
|
||||
// This effect is for testing purposes
|
||||
BuffEffect::NameChange {
|
||||
prefix: String::from("Injured "),
|
||||
},
|
||||
],
|
||||
duration,
|
||||
),
|
||||
BuffId::Regeneration { strength, duration } => (
|
||||
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::Cursed => vec![BuffEffect::NameChange {
|
||||
prefix: String::from("Cursed "),
|
||||
}],
|
||||
}],
|
||||
duration,
|
||||
),
|
||||
BuffId::Cursed { duration } => (
|
||||
vec![BuffEffect::NameChange {
|
||||
prefix: String::from("Cursed "),
|
||||
}],
|
||||
duration,
|
||||
),
|
||||
};
|
||||
Buff {
|
||||
id,
|
||||
|
@ -157,8 +157,8 @@ impl<'a> System<'a> for Sys {
|
||||
buff_change: buff::BuffChange::Add(buff::Buff::new(
|
||||
buff::BuffId::Bleeding {
|
||||
strength: -damage.healthchange,
|
||||
duration: Some(Duration::from_millis(10000)),
|
||||
},
|
||||
Some(Duration::from_millis(10000)),
|
||||
vec![buff::BuffCategoryId::Physical],
|
||||
buff::BuffSource::Character { by: *uid },
|
||||
)),
|
||||
|
@ -862,9 +862,11 @@ fn determine_replace_active_buff(active_buff: buff::Buff, new_buff: buff::Buff)
|
||||
match new_buff.id {
|
||||
BuffId::Bleeding {
|
||||
strength: new_strength,
|
||||
duration: _,
|
||||
} => {
|
||||
if let BuffId::Bleeding {
|
||||
strength: active_strength,
|
||||
duration: _,
|
||||
} = active_buff.id
|
||||
{
|
||||
new_strength > active_strength
|
||||
@ -874,9 +876,11 @@ fn determine_replace_active_buff(active_buff: buff::Buff, new_buff: buff::Buff)
|
||||
},
|
||||
BuffId::Regeneration {
|
||||
strength: new_strength,
|
||||
duration: _,
|
||||
} => {
|
||||
if let BuffId::Regeneration {
|
||||
strength: active_strength,
|
||||
duration: _,
|
||||
} = active_buff.id
|
||||
{
|
||||
new_strength > active_strength
|
||||
@ -884,7 +888,7 @@ fn determine_replace_active_buff(active_buff: buff::Buff, new_buff: buff::Buff)
|
||||
false
|
||||
}
|
||||
},
|
||||
BuffId::Cursed => false,
|
||||
BuffId::Cursed { duration: _ } => false,
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user