From ad3b8dffa1a2816985d8cee84de0d674a730316a Mon Sep 17 00:00:00 2001 From: timokoesters Date: Mon, 20 May 2019 22:27:19 +0200 Subject: [PATCH] Limit attack direction Former-commit-id: b132f01f86814d2f8dd10d6d1454b6e2a95595f8 --- common/src/sys/action.rs | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/common/src/sys/action.rs b/common/src/sys/action.rs index b8b55a046f..98f775d31a 100644 --- a/common/src/sys/action.rs +++ b/common/src/sys/action.rs @@ -5,7 +5,7 @@ use vek::*; // Crate use crate::{ comp::{ - phys::{ForceUpdate, Pos, Vel}, + phys::{Dir, ForceUpdate, Pos, Vel}, Action, Actions, Control, Stats, }, state::{DeltaTime, Time}, @@ -22,15 +22,28 @@ impl<'a> System<'a> for Sys { WriteStorage<'a, Actions>, ReadStorage<'a, Pos>, WriteStorage<'a, Vel>, + ReadStorage<'a, Dir>, WriteStorage<'a, Stats>, WriteStorage<'a, ForceUpdate>, ); fn run( &mut self, - (entities, time, dt, mut actions, positions, mut velocities, mut stats, mut force_updates): Self::SystemData, + ( + entities, + time, + dt, + mut actions, + positions, + mut velocities, + directions, + mut stats, + mut force_updates, + ): Self::SystemData, ) { - for (a, actions_a, pos_a) in (&entities, &mut actions, &positions).join() { + for (a, actions_a, pos_a, dir_a) in + (&entities, &mut actions, &positions, &directions).join() + { for event in actions_a.0.drain(..) { match event { Action::Attack => { @@ -40,7 +53,10 @@ impl<'a> System<'a> for Sys { if a == b { continue; } - if pos_a.0.distance_squared(pos_b.0) < 50.0 { + if a != b + && pos_a.0.distance_squared(pos_b.0) < 50.0 + && dir_a.0.angle_between_degrees(pos_b.0 - pos_a.0) < 70.0 + { stat_b.hp.change_by(-10); // TODO: variable damage vel_b.0 += (pos_b.0 - pos_a.0).normalized() * 20.0; vel_b.0.z = 20.0;