diff options
author | Alexander Foremny <aforemny@posteo.de> | 2024-03-20 02:09:36 +0100 |
---|---|---|
committer | Alexander Foremny <aforemny@posteo.de> | 2024-03-20 02:09:36 +0100 |
commit | b1c524ff645a680e1eea95d036b729125d4c3a32 (patch) | |
tree | 581932099b8e1d8a0cc9cdfd2fa2414ba6b2a192 | |
parent | 7b6d9242e4217c8229cb546de495cd2670b97f2d (diff) |
fix: dash deals damage
-rw-r--r-- | src/client.rs | 4 | ||||
-rw-r--r-- | src/shared/ability.rs | 70 | ||||
-rw-r--r-- | src/shared/champion.rs | 7 |
3 files changed, 61 insertions, 20 deletions
diff --git a/src/client.rs b/src/client.rs index 91d8c7f..dc5f4a8 100644 --- a/src/client.rs +++ b/src/client.rs @@ -466,8 +466,8 @@ fn gizmos_attack_indicator( return; }; match ability { - DirectionalAbility::Dash(Dash { max_distance }) => { - let dash_end = dash_collision( + DirectionalAbility::Dash(Dash { max_distance, .. }) => { + let DashCollisionResult { dash_end, .. } = dash_collision( PlayerId(client_id.0), position.0, direction, diff --git a/src/shared/ability.rs b/src/shared/ability.rs index d88b63b..f880fac 100644 --- a/src/shared/ability.rs +++ b/src/shared/ability.rs @@ -187,6 +187,7 @@ pub enum DirectionalAbility { #[derive(Copy, Clone, PartialEq, Debug, Deserialize, Serialize)] pub struct Dash { pub max_distance: f32, + pub damage: f32, } #[derive(Copy, Clone, PartialEq, Debug, Deserialize, Serialize)] @@ -248,7 +249,10 @@ fn dash_activation(dash: Dash) -> DirectionalAbilityActivation { return; }; - let dash_end = { + let DashCollisionResult { + dash_end, + dash_collision, + } = { let dash_targets = set.p1(); dash_collision( source_player, @@ -264,13 +268,26 @@ fn dash_activation(dash: Dash) -> DirectionalAbilityActivation { position.0 = dash_end; } - commands.spawn(AreaOfEffectBundle::new(AreaOfEffect { - position: dash_end, - radius: 1.5 * PLAYER_RADIUS, - duration: None, - source_player, - area_of_effect_type: AreaOfEffectType::Slow, - })); + if let Some(DashCollision { + collision_id, + collision_position, + }) = dash_collision + { + commands.spawn(AreaOfEffectBundle::new(AreaOfEffect { + position: collision_position, + radius: 1.5 * PLAYER_RADIUS, + duration: None, + source_player, + area_of_effect_type: AreaOfEffectType::Slow, + })); + commands.spawn(ProjectileBundle::new(Projectile { + type_: ProjectileType::Instant(InstantProjectile { + target_player: collision_id, + }), + source_player, + damage: dash.damage, + })); + } }, ) }); @@ -278,15 +295,26 @@ fn dash_activation(dash: Dash) -> DirectionalAbilityActivation { ) } +pub struct DashCollisionResult { + pub dash_end: Vec2, + pub dash_collision: Option<DashCollision>, +} + +pub struct DashCollision { + pub collision_id: PlayerId, + pub collision_position: Vec2, +} + pub fn dash_collision( source_id: PlayerId, dash_start: Vec2, dash_direction: Vec2, dash_max_distance: f32, player_positions: &Query<(&PlayerId, &PlayerPosition)>, -) -> Vec2 { +) -> DashCollisionResult { let mut dash_collision = dash_max_distance * dash_direction; - let mut collision = false; + let mut collision_id = None; + let mut collision_position = None; for (player_id, position) in player_positions.iter() { if *player_id == source_id { continue; @@ -304,16 +332,28 @@ pub fn dash_collision( } if player_rejection.length() < 2. * PLAYER_RADIUS { - collision = true; dash_collision = player_projection; + collision_id = Some(*player_id); + collision_position = Some(position.0); } } - if collision { - dash_start - + (dash_collision.length() - 2. * PLAYER_RADIUS) * dash_collision.normalize_or_zero() + if let (Some(collision_id), Some(collision_position)) = (collision_id, collision_position) { + let dash_end = dash_start + + (dash_collision.length() - 2. * PLAYER_RADIUS) * dash_collision.normalize_or_zero(); + DashCollisionResult { + dash_end, + dash_collision: Some(DashCollision { + collision_id, + collision_position, + }), + } } else { - dash_start + dash_max_distance * dash_direction + let dash_end = dash_start + dash_max_distance * dash_direction; + DashCollisionResult { + dash_end, + dash_collision: None, + } } } diff --git a/src/shared/champion.rs b/src/shared/champion.rs index 86bd41e..6e6b01b 100644 --- a/src/shared/champion.rs +++ b/src/shared/champion.rs @@ -49,9 +49,10 @@ impl Champion { pub fn ability(self, ability_slot: AbilitySlot) -> Ability { match self { Champion::Meele => match ability_slot { - AbilitySlot::Q => { - Ability::Directional(DirectionalAbility::Dash(Dash { max_distance: 60. })) - } + AbilitySlot::Q => Ability::Directional(DirectionalAbility::Dash(Dash { + max_distance: 60., + damage: 15., + })), AbilitySlot::W => { Ability::Directional(DirectionalAbility::Pull(Pull { max_distance: 60. })) } |