aboutsummaryrefslogtreecommitdiffstats
path: root/src/server.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/server.rs')
-rw-r--r--src/server.rs54
1 files changed, 53 insertions, 1 deletions
diff --git a/src/server.rs b/src/server.rs
index fc44120..4593cfa 100644
--- a/src/server.rs
+++ b/src/server.rs
@@ -3,6 +3,7 @@ use crate::server::entity_map::*;
use crate::server::network::*;
use crate::shared::ability::*;
use crate::shared::activation::*;
+use crate::shared::area_of_effect::*;
use crate::shared::buffs::*;
use crate::shared::champion::*;
use crate::shared::cooldown::*;
@@ -71,8 +72,17 @@ impl Plugin for ServerPlugin {
.add_systems(
FixedUpdate,
(
- projectile_move.after(imperative_walk_to),
projectile_despawn,
+ projectile_move.after(imperative_walk_to),
+ )
+ .chain(),
+ )
+ .add_systems(
+ FixedUpdate,
+ (
+ area_of_effect_despawn,
+ area_of_effect_tick.after(imperative_walk_to),
+ area_of_effect_activate,
)
.chain(),
)
@@ -580,3 +590,45 @@ fn buffs_despawn(mut buffses: Query<&mut Buffs>) {
}
}
}
+
+fn area_of_effect_tick(mut area_of_effects: Query<&mut AreaOfEffect>, time: Res<Time>) {
+ let dt = time.delta();
+ for mut area_of_effect in area_of_effects.iter_mut() {
+ if let Some(ref mut duration) = area_of_effect.duration {
+ *duration = (*duration - dt.as_secs_f32()).max(0.);
+ } else {
+ area_of_effect.duration = Some(0.);
+ }
+ }
+}
+
+fn area_of_effect_despawn(area_of_effects: Query<(Entity, &AreaOfEffect)>, mut commands: Commands) {
+ for (entity, area_of_effect) in area_of_effects.iter() {
+ let Some(duration) = area_of_effect.duration else {
+ continue;
+ };
+ if duration > 0. {
+ continue;
+ };
+ commands.entity(entity).despawn();
+ }
+}
+
+fn area_of_effect_activate(
+ players: Query<(&PlayerId, &PlayerPosition)>,
+ area_of_effects: Query<&AreaOfEffect>,
+ mut commands: Commands,
+) {
+ for area_of_effect in area_of_effects.iter() {
+ for (player_id, player_position) in players.iter() {
+ if *player_id == area_of_effect.source_player {
+ continue;
+ }
+ if area_of_effect.position.distance(player_position.0)
+ < area_of_effect.radius + PLAYER_RADIUS
+ {
+ area_of_effect.activate()(&mut commands, area_of_effect.source_player, *player_id);
+ }
+ }
+ }
+}