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),
|
2021-09-25 18:07:47 +00:00
|
|
|
Poise(f32),
|
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),
|
2021-09-25 18:07:47 +00:00
|
|
|
Effect::Poise(p) => format!("{:+} poise", p),
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-26 13:52:43 +00:00
|
|
|
pub fn is_harm(&self) -> bool {
|
|
|
|
match self {
|
2021-09-09 04:07:17 +00:00
|
|
|
Effect::Health(c) => c.amount < 0.0,
|
2021-09-25 18:07:47 +00:00
|
|
|
Effect::Poise(p) => *p < 0.0,
|
2021-07-26 13:52:43 +00:00
|
|
|
Effect::Damage(_) => true,
|
|
|
|
Effect::Buff(e) => !e.kind.is_buff(),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-04 02:01:12 +00:00
|
|
|
pub fn modify_strength(&mut self, modifier: f32) {
|
|
|
|
match self {
|
|
|
|
Effect::Health(change) => {
|
2021-09-09 04:07:17 +00:00
|
|
|
change.amount *= modifier;
|
2020-11-04 02:01:12 +00:00
|
|
|
},
|
2021-09-25 18:07:47 +00:00
|
|
|
Effect::Poise(poise) => {
|
|
|
|
*poise *= modifier;
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|