From 986c82723cf9a4adada02287309999f4ebbf94e3 Mon Sep 17 00:00:00 2001 From: troido Date: Tue, 3 Mar 2020 18:06:02 +0100 Subject: randomise attack damage --- src/components/messages.rs | 25 ++++++++++++++++--------- src/components/mod.rs | 7 ++++--- 2 files changed, 20 insertions(+), 12 deletions(-) (limited to 'src/components') diff --git a/src/components/messages.rs b/src/components/messages.rs index a2ecd2f..ae615f1 100644 --- a/src/components/messages.rs +++ b/src/components/messages.rs @@ -32,21 +32,28 @@ impl Inbox { } } -#[derive(Debug, Clone)] -pub struct AttackMessage { - pub damage: i64, - pub attacker: Option + +#[derive(Debug, Clone, PartialEq, Eq)] +pub enum AttackType { + Attack(i64), + Heal(i64) } -impl AttackMessage { - pub fn new(damage: i64) -> Self { - Self { - damage, - attacker: None +impl AttackType { + pub fn is_hostile(&self) -> bool { + match self { + Self::Attack(_) => true, + Self::Heal(_) => false } } } +#[derive(Debug, Clone)] +pub struct AttackMessage { + pub attacker: Option, + pub typ: AttackType +} + impl Message for AttackMessage {} pub type AttackInbox = Inbox; diff --git a/src/components/mod.rs b/src/components/mod.rs index 96261c7..202caf2 100644 --- a/src/components/mod.rs +++ b/src/components/mod.rs @@ -5,7 +5,8 @@ pub mod messages; pub use item::Item; pub use messages::{ AttackMessage, - AttackInbox + AttackInbox, + AttackType }; use specs::{ @@ -140,13 +141,13 @@ pub struct Dead; #[derive(Component, Debug, Clone)] #[storage(HashMapStorage)] pub struct Trap { - pub attack: AttackMessage + pub attack: AttackType } #[derive(Component, Debug, Clone)] #[storage(HashMapStorage)] pub struct Fighter { - pub attack: AttackMessage, + pub attack: AttackType, pub cooldown: i64, pub range: i64 } -- cgit