2020-11-04 02:01:12 +00:00
|
|
|
use crate::{combat, comp};
|
2020-07-06 14:23:08 +00:00
|
|
|
use serde::{Deserialize, Serialize};
|
2019-09-25 15:52:58 +00:00
|
|
|
|
|
|
|
/// An effect that may be applied to an entity
|
2020-10-27 21:27:19 +00:00
|
|
|
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
2019-09-25 15:52:58 +00:00
|
|
|
pub enum Effect {
|
2019-10-17 20:59:36 +00:00
|
|
|
Health(comp::HealthChange),
|
2020-12-06 02:29:46 +00:00
|
|
|
Poise(comp::PoiseChange),
|
2020-11-04 02:01:12 +00:00
|
|
|
Damage(combat::Damage),
|
2020-10-27 21:27:19 +00:00
|
|
|
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-09-25 15:52:58 +00:00
|
|
|
}
|
2019-10-09 19:28:05 +00:00
|
|
|
|
|
|
|
impl Effect {
|
|
|
|
pub fn info(&self) -> String {
|
|
|
|
match self {
|
2019-10-17 20:59:36 +00:00
|
|
|
Effect::Health(c) => format!("{:+} health", c.amount),
|
2020-12-06 02:29:46 +00:00
|
|
|
Effect::Poise(c) => format!("{:+} poise", c.amount),
|
2020-11-04 02:01:12 +00:00
|
|
|
Effect::Damage(d) => format!("{:+}", d.value),
|
2020-10-27 21:27:19 +00:00
|
|
|
Effect::Buff(e) => format!("{:?} buff", e),
|
2020-11-04 02:01:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn modify_strength(&mut self, modifier: f32) {
|
|
|
|
match self {
|
|
|
|
Effect::Health(change) => {
|
|
|
|
change.amount = (change.amount as f32 * modifier) as i32;
|
|
|
|
},
|
2020-12-05 18:23:45 +00:00
|
|
|
Effect::Poise(change) => {
|
2020-12-06 02:29:46 +00:00
|
|
|
change.amount = (change.amount as f32 * modifier) as i32;
|
2020-12-05 18:23:45 +00:00
|
|
|
},
|
2020-11-04 02:01:12 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|