aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/server.rs47
1 files changed, 42 insertions, 5 deletions
diff --git a/src/server.rs b/src/server.rs
index 1b9b7ef..1fe20a4 100644
--- a/src/server.rs
+++ b/src/server.rs
@@ -55,7 +55,9 @@ impl Plugin for ServerPlugin {
.add_systems(
Update,
(
- imperative_attack.after(cooldown_decrement),
+ (imperative_attack_approach, imperative_attack_attack)
+ .chain()
+ .after(cooldown_decrement),
imperative_walk_to,
)
.after(player_input),
@@ -187,10 +189,8 @@ fn move_to_target(position: Vec2, target_position: Vec2, max_distance: f32) -> (
}
}
-fn imperative_attack(
+fn imperative_attack_approach(
entity_map: Res<EntityMap>,
- mut commands: Commands,
- mut cooldowns: Query<&mut Cooldown>,
mut players: Query<(&PlayerId, &mut Imperative)>,
mut positions: Query<&mut PlayerPosition>,
champions: Query<&Champion>,
@@ -225,7 +225,44 @@ fn imperative_attack(
MOVEMENT_SPEED * time.delta().as_secs_f32(),
);
position.0 = new_position;
- } else {
+ }
+ }
+ _ => {}
+ }
+ }
+}
+
+fn imperative_attack_attack(
+ entity_map: Res<EntityMap>,
+ mut commands: Commands,
+ mut cooldowns: Query<&mut Cooldown>,
+ mut players: Query<(&PlayerId, &mut Imperative)>,
+ mut positions: Query<&mut PlayerPosition>,
+ champions: Query<&Champion>,
+) {
+ for (id, mut imperative) in players.iter_mut() {
+ match *imperative {
+ Imperative::Attack(target_player) => {
+ let Some(entity) = entity_map.0.get(&id.0) else {
+ *imperative = Imperative::Idle;
+ return;
+ };
+ let Ok(champion) = champions.get(*entity) else {
+ *imperative = Imperative::Idle;
+ return;
+ };
+ let Some(target_entity) = entity_map.0.get(&target_player.0) else {
+ *imperative = Imperative::Idle;
+ return;
+ };
+ let Ok([position, target_position]) =
+ positions.get_many_mut([*entity, *target_entity])
+ else {
+ *imperative = Imperative::Idle;
+ return;
+ };
+ let distance = target_position.0.distance(position.0);
+ if distance <= Stats::from_champion(*champion).attack_range {
let Ok(mut cooldown) = cooldowns.get_mut(*entity) else {
*imperative = Imperative::Idle;
return;