veloren/common/src/effect.rs

57 lines
1.6 KiB
Rust
Raw Normal View History

use crate::{combat, comp};
use serde::{Deserialize, Serialize};
/// An effect that may be applied to an entity
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub enum Effect {
Health(comp::HealthChange),
2020-12-16 23:30:33 +00:00
PoiseChange(comp::PoiseChange),
Damage(combat::Damage),
Buff(BuffEffect),
}
/// A buff that may be applied to an entity
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct BuffEffect {
pub kind: comp::BuffKind,
pub data: comp::BuffData,
pub cat_ids: Vec<comp::BuffCategory>,
}
2019-10-09 19:28:05 +00:00
impl Effect {
pub fn info(&self) -> String {
match self {
Effect::Health(c) => format!("{:+} health", c.amount),
2020-12-16 23:30:33 +00:00
Effect::PoiseChange(c) => format!("{:+} poise", c.amount),
Effect::Damage(d) => format!("{:+}", d.value),
Effect::Buff(e) => format!("{:?} buff", e),
}
}
pub fn is_harm(&self) -> bool {
match self {
Effect::Health(c) => c.amount < 0.0,
Effect::PoiseChange(c) => c.amount < 0,
Effect::Damage(_) => true,
Effect::Buff(e) => !e.kind.is_buff(),
}
}
pub fn modify_strength(&mut self, modifier: f32) {
match self {
Effect::Health(change) => {
change.amount *= modifier;
},
2020-12-16 23:30:33 +00:00
Effect::PoiseChange(change) => {
2020-12-06 02:29:46 +00:00
change.amount = (change.amount as f32 * modifier) as i32;
},
Effect::Damage(damage) => {
damage.interpolate_damage(modifier, 0.0);
},
2020-11-05 14:54:17 +00:00
Effect::Buff(effect) => {
effect.data.strength *= modifier;
},
2019-10-09 19:28:05 +00:00
}
}
}