mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
Limit attack direction
Former-commit-id: b132f01f86814d2f8dd10d6d1454b6e2a95595f8
This commit is contained in:
parent
e34a47d0d7
commit
ad3b8dffa1
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user