use std::collections::HashMap; use std::any::Any; use specs::{ Component, DenseVecStorage, Entity, WriteStorage }; use super::equipment::Stat; pub trait Message: Send + Sync + Any {} #[derive(Debug, Clone, Default)] pub struct Inbox { pub messages: Vec } impl Component for Inbox { type Storage = DenseVecStorage; } impl Inbox { pub fn add_message(messages: &mut WriteStorage, ent: Entity, message: M){ messages .entry(ent) .unwrap() .or_insert_with(|| Self{messages: Vec::new()}) .messages .push(message); } } #[derive(Debug, Clone, PartialEq, Eq)] pub enum AttackType { Attack(i64), Heal(i64) } impl AttackType { pub fn is_hostile(&self) -> bool { match self { Self::Attack(_) => true, Self::Heal(_) => false } } pub fn apply_bonuses(self, bonuses: &HashMap) -> AttackType { match self { Self::Attack(strength) => Self::Attack(strength + *bonuses.get(&Stat::Strength).unwrap_or(&0)), Self::Heal(_) => self } } } #[derive(Debug, Clone)] pub struct AttackMessage { pub attacker: Option, pub typ: AttackType } impl Message for AttackMessage {} pub type AttackInbox = Inbox; #[derive(Debug, Clone, Copy, PartialEq, Eq)] pub enum Trigger { Loot, Die, Remove } impl Trigger { pub fn from_str(txt: &str) -> Option { Some(match txt { "loot" => Self::Loot, "die" => Self::Die, "remove" => Self::Remove, _ => {return None} }) } } impl Message for Trigger {} pub type TriggerBox = Inbox;