diff options
| author | troido <troido@protonmail.com> | 2020-03-01 22:28:02 +0100 |
|---|---|---|
| committer | troido <troido@protonmail.com> | 2020-03-01 22:28:02 +0100 |
| commit | 6a7a74e6878ff04e61e6ef21a922e314b9bab271 (patch) | |
| tree | b26015955f50856052153019969f7bee8d1cfbd3 /src/systems | |
| parent | c846e929a88837094d7a5383a306df1fec56c333 (diff) | |
use generics for message components
Diffstat (limited to 'src/systems')
| -rw-r--r-- | src/systems/attacking.rs | 12 | ||||
| -rw-r--r-- | src/systems/fight.rs | 6 | ||||
| -rw-r--r-- | src/systems/trapping.rs | 6 | ||||
| -rw-r--r-- | src/systems/useitem.rs | 8 |
4 files changed, 16 insertions, 16 deletions
diff --git a/src/systems/attacking.rs b/src/systems/attacking.rs index 4b47f11..d28e301 100644 --- a/src/systems/attacking.rs +++ b/src/systems/attacking.rs @@ -9,7 +9,7 @@ use specs::{ }; use crate::{ - components::{Health, Attacked, Dying, Removed, Position}, + components::{Health, AttackInbox, Dying, Removed, Position}, resources::NewEntities, Template, util @@ -20,17 +20,17 @@ pub struct Attacking; impl <'a> System<'a> for Attacking { type SystemData = ( Entities<'a>, - WriteStorage<'a, Attacked>, + WriteStorage<'a, AttackInbox>, WriteStorage<'a, Health>, WriteStorage<'a, Dying>, WriteStorage<'a, Removed>, ReadStorage<'a, Position>, Write<'a, NewEntities> ); - fn run(&mut self, (entities, mut victims, mut healths, mut deads, mut removals, positions, mut new): Self::SystemData) { - for (ent, health, attacked) in (&entities, &mut healths, &mut victims).join() { + fn run(&mut self, (entities, mut attackeds, mut healths, mut deads, mut removals, positions, mut new): Self::SystemData) { + for (ent, health, attacked) in (&entities, &mut healths, &mut attackeds).join() { let mut wounded = false; - for attack in attacked.attacks.drain(..) { + for attack in attacked.messages.drain(..) { health.health -= attack.damage; if attack.damage > 0 { wounded = true; @@ -47,7 +47,7 @@ impl <'a> System<'a> for Attacking { } } } - victims.clear(); + attackeds.clear(); } } diff --git a/src/systems/fight.rs b/src/systems/fight.rs index 547f5fa..42a7543 100644 --- a/src/systems/fight.rs +++ b/src/systems/fight.rs @@ -12,7 +12,7 @@ use specs::{ use crate::components::{ Controller, Position, - Attacked, + AttackInbox, Fighter, Health, ControlCooldown @@ -30,7 +30,7 @@ impl <'a> System<'a> for Fight { ReadStorage<'a, Controller>, WriteStorage<'a, Position>, Read<'a, Ground>, - WriteStorage<'a, Attacked>, + WriteStorage<'a, AttackInbox>, ReadStorage<'a, Fighter>, ReadStorage<'a, Health>, WriteStorage<'a, ControlCooldown> @@ -43,7 +43,7 @@ impl <'a> System<'a> for Fight { for direction in directions { for ent in ground.cells.get(&(position.pos + direction.to_position())).unwrap_or(&HashSet::new()) { if healths.contains(*ent) && *ent != entity { - Attacked::add_attack(&mut attacked, *ent, fighter.attack.clone()); + AttackInbox::add_message(&mut attacked, *ent, fighter.attack.clone()); cooldowns.insert(entity, ControlCooldown{amount: fighter.cooldown}).unwrap(); break; } diff --git a/src/systems/trapping.rs b/src/systems/trapping.rs index d6902a8..55b8bde 100644 --- a/src/systems/trapping.rs +++ b/src/systems/trapping.rs @@ -9,7 +9,7 @@ use specs::{ }; use crate::{ - components::{Health, Attacked, Moved, Entered, Trap, Position}, + components::{Health, AttackInbox, Moved, Entered, Trap, Position}, resources::Ground }; @@ -18,7 +18,7 @@ pub struct Trapping; impl <'a> System<'a> for Trapping { type SystemData = ( Entities<'a>, - WriteStorage<'a, Attacked>, + WriteStorage<'a, AttackInbox>, ReadStorage<'a, Health>, ReadStorage<'a, Moved>, ReadStorage<'a, Entered>, @@ -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) { - Attacked::add_attack(&mut victims, *ent, trap.attack.clone()); + AttackInbox::add_message(&mut victims, *ent, trap.attack.clone()); } } } diff --git a/src/systems/useitem.rs b/src/systems/useitem.rs index 183bd79..1a50865 100644 --- a/src/systems/useitem.rs +++ b/src/systems/useitem.rs @@ -14,12 +14,12 @@ use crate::{ Controller, Position, Inventory, - Attacked + AttackInbox, + AttackMessage }, resources::{NewEntities}, components::item::ItemAction::{None, Build, Eat}, controls::Control, - attack::Attack }; @@ -31,7 +31,7 @@ impl <'a> System<'a> for Use { WriteStorage<'a, Position>, WriteStorage<'a, Inventory>, Write<'a, NewEntities>, - WriteStorage<'a, Attacked> + WriteStorage<'a, AttackInbox> ); fn run(&mut self, (entities, controllers, positions, mut inventories, mut new, mut attacked): Self::SystemData) { @@ -45,7 +45,7 @@ impl <'a> System<'a> for Use { inventory.items.remove(*rank); } Eat(health_diff) => { - Attacked::add_attack(&mut attacked, ent, Attack::new(-*health_diff)); + AttackInbox::add_message(&mut attacked, ent, AttackMessage::new(-*health_diff)); inventory.items.remove(*rank); } None => {} |
