From 2d21d709901c96b05d7f0169dd9d1207436c658c Mon Sep 17 00:00:00 2001 From: Alexander Foremny Date: Tue, 19 Mar 2024 14:13:16 +0100 Subject: feat: area of effect --- src/client.rs | 27 +++++++++++++++++++ src/protocol.rs | 2 ++ src/server.rs | 54 ++++++++++++++++++++++++++++++++++++- src/shared.rs | 1 + src/shared/ability.rs | 12 ++++++++- src/shared/area_of_effect.rs | 64 ++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 158 insertions(+), 2 deletions(-) create mode 100644 src/shared/area_of_effect.rs diff --git a/src/client.rs b/src/client.rs index 8da77dc..7e0cebf 100644 --- a/src/client.rs +++ b/src/client.rs @@ -2,6 +2,7 @@ use crate::client::network::*; use crate::protocol::*; use crate::shared::ability::*; use crate::shared::activation::*; +use crate::shared::area_of_effect::*; use crate::shared::champion::*; use crate::shared::cooldown::*; use crate::shared::health::*; @@ -76,6 +77,7 @@ impl Plugin for ClientPlugin { ( render_players.after(move_players), render_projectiles.after(move_projectiles), + render_area_of_effects, render_health, ), ) @@ -226,6 +228,31 @@ fn render_projectiles( } } +fn render_area_of_effects( + mut commands: Commands, + mut materials: ResMut>, + mut meshes: ResMut>, + area_of_effects: Query<(Entity, &AreaOfEffect), Added>, +) { + for (entity, area_of_effect) in area_of_effects.iter() { + if area_of_effect.duration.is_none() { + continue; + } + commands.entity(entity).insert(MaterialMesh2dBundle { + mesh: Mesh2dHandle(meshes.add(Circle { + radius: area_of_effect.radius, + })), + material: materials.add(Color::BLACK), + transform: Transform::from_xyz( + area_of_effect.position.x, + area_of_effect.position.y, + 1., + ), + ..Default::default() + }); + } +} + fn move_projectiles(mut projectiles: Query<(&mut Transform, &Projectile), Changed>) { for (mut transform, projectile) in projectiles.iter_mut() { let Some(position) = (match projectile.type_ { diff --git a/src/protocol.rs b/src/protocol.rs index 8a83260..646974c 100644 --- a/src/protocol.rs +++ b/src/protocol.rs @@ -1,4 +1,5 @@ use crate::shared::activation::*; +use crate::shared::area_of_effect::*; use crate::shared::champion::*; use crate::shared::cooldown::*; use crate::shared::health::*; @@ -42,6 +43,7 @@ pub enum Components { Health(Health), Champion(Champion), EffectiveStats(EffectiveStats), + AreaOfEffect(AreaOfEffect), } #[derive(Channel)] 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