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),
|
2019-09-25 15:52:58 +00:00
|
|
|
Xp(i64),
|
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),
|
2019-10-09 19:28:05 +00:00
|
|
|
Effect::Xp(n) => format!("{:+} exp", n),
|
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;
|
|
|
|
},
|
|
|
|
Effect::Xp(amount) => {
|
|
|
|
*amount = (*amount as f32 * modifier) as i64;
|
|
|
|
},
|
|
|
|
Effect::Damage(damage) => {
|
|
|
|
damage.interpolate_damage(modifier, 0.0);
|
|
|
|
},
|
2020-10-27 21:27:19 +00:00
|
|
|
_ => {},
|
2019-10-09 19:28:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|