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/systems/attacking.rs | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'src/systems/attacking.rs') diff --git a/src/systems/attacking.rs b/src/systems/attacking.rs index 9d10fee..4318695 100644 --- a/src/systems/attacking.rs +++ b/src/systems/attacking.rs @@ -1,4 +1,6 @@ + +use rand::Rng; use specs::{ ReadStorage, WriteStorage, @@ -9,7 +11,7 @@ use specs::{ }; use crate::{ - components::{Health, AttackInbox, Dead, Position, Autofight}, + components::{Health, AttackInbox, AttackType, Dead, Position, Autofight}, resources::NewEntities, Template, util @@ -31,7 +33,7 @@ impl <'a> System<'a> for Attacking { for (entity, attacked, autofighter) in (&entities, &attackeds, &mut autofighters).join() { for attack in &attacked.messages { - if attack.damage > 0 { + if attack.typ.is_hostile() { if let Some(attacker) = attack.attacker { if healths.contains(attacker) && attacker != entity { autofighter.target = Some(attacker); @@ -43,9 +45,17 @@ impl <'a> System<'a> for Attacking { for (ent, health, attacked) in (&entities, &mut healths, &mut attackeds).join() { let mut wounded = false; for attack in attacked.messages.drain(..) { - health.health -= attack.damage; - if attack.damage > 0 { - wounded = true; + match attack.typ { + AttackType::Attack(strength) => { + let damage = rand::thread_rng().gen_range(0, strength+1); + health.health -= damage; + if damage > 0 { + wounded = true; + } + } + AttackType::Heal(healthdiff) => { + health.health += healthdiff; + } } } health.health = util::clamp(health.health, 0, health.maxhealth); -- cgit