diff options
| author | troido <troido@protonmail.com> | 2020-03-03 18:06:02 +0100 |
|---|---|---|
| committer | troido <troido@protonmail.com> | 2020-03-03 18:06:02 +0100 |
| commit | 986c82723cf9a4adada02287309999f4ebbf94e3 (patch) | |
| tree | acc26dfd3cb604c959d16f4291db2f6f21d242f9 /src/systems | |
| parent | 9954b5cbaab27aaffcafa8723dcd5d1c99fa811f (diff) | |
randomise attack damage
Diffstat (limited to 'src/systems')
| -rw-r--r-- | src/systems/attacking.rs | 20 | ||||
| -rw-r--r-- | src/systems/fight.rs | 5 | ||||
| -rw-r--r-- | src/systems/trapping.rs | 4 | ||||
| -rw-r--r-- | src/systems/useitem.rs | 5 |
4 files changed, 22 insertions, 12 deletions
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); diff --git a/src/systems/fight.rs b/src/systems/fight.rs index 88305e2..00aeb3e 100644 --- a/src/systems/fight.rs +++ b/src/systems/fight.rs @@ -13,6 +13,7 @@ use crate::components::{ Controller, Position, AttackInbox, + AttackMessage, Fighter, Health, ControlCooldown, @@ -63,9 +64,7 @@ impl <'a> System<'a> for Fight { _ => {} } if let Some(ent) = target { - let mut attack = fighter.attack.clone(); - attack.attacker = Some(entity); - AttackInbox::add_message(&mut attacked, ent, attack); + AttackInbox::add_message(&mut attacked, ent, AttackMessage{typ: fighter.attack.clone(), attacker: Some(entity)}); cooldowns.insert(entity, ControlCooldown{amount: fighter.cooldown}).unwrap(); if let Some(autofighter) = autofighters.get_mut(entity){ autofighter.target = Some(ent); diff --git a/src/systems/trapping.rs b/src/systems/trapping.rs index 55b8bde..35c66d0 100644 --- a/src/systems/trapping.rs +++ b/src/systems/trapping.rs @@ -9,7 +9,7 @@ use specs::{ }; use crate::{ - components::{Health, AttackInbox, Moved, Entered, Trap, Position}, + components::{Health, AttackInbox, AttackMessage, Moved, Entered, Trap, Position}, resources::Ground }; @@ -31,7 +31,7 @@ impl <'a> System<'a> for Trapping { for (entity, _entered, trap, position) in (&entities, &entereds, &traps, &positions).join() { for ent in ground.cells.get(&position.pos).unwrap(){ if ent != &entity && moves.contains(*ent) && healths.contains(*ent) { - AttackInbox::add_message(&mut victims, *ent, trap.attack.clone()); + AttackInbox::add_message(&mut victims, *ent, AttackMessage{typ: trap.attack.clone(), attacker: Some(entity)}); } } } diff --git a/src/systems/useitem.rs b/src/systems/useitem.rs index 1a50865..ab147b7 100644 --- a/src/systems/useitem.rs +++ b/src/systems/useitem.rs @@ -15,7 +15,8 @@ use crate::{ Position, Inventory, AttackInbox, - AttackMessage + AttackMessage, + AttackType }, resources::{NewEntities}, components::item::ItemAction::{None, Build, Eat}, @@ -45,7 +46,7 @@ impl <'a> System<'a> for Use { inventory.items.remove(*rank); } Eat(health_diff) => { - AttackInbox::add_message(&mut attacked, ent, AttackMessage::new(-*health_diff)); + AttackInbox::add_message(&mut attacked, ent, AttackMessage{typ: AttackType::Heal(*health_diff), attacker: Option::None}); inventory.items.remove(*rank); } None => {} |
