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-11-04 02:01:12 +00:00
|
|
|
#[derive(Copy, 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),
|
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),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
},
|
2019-10-09 19:28:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|