diff options
author | Alexander Foremny <aforemny@posteo.de> | 2024-03-20 02:18:33 +0100 |
---|---|---|
committer | Alexander Foremny <aforemny@posteo.de> | 2024-03-20 02:18:33 +0100 |
commit | 4d7cf2c97206adf7823bcc5aee8d4dc5d34e40ad (patch) | |
tree | fc261eab55cf6ab39f4acb14ca6d646baa43af84 | |
parent | b1c524ff645a680e1eea95d036b729125d4c3a32 (diff) |
fix: pull deals damage
-rw-r--r-- | src/client.rs | 13 | ||||
-rw-r--r-- | src/shared/ability.rs | 53 | ||||
-rw-r--r-- | src/shared/champion.rs | 7 |
3 files changed, 48 insertions, 25 deletions
diff --git a/src/client.rs b/src/client.rs index dc5f4a8..d24637b 100644 --- a/src/client.rs +++ b/src/client.rs @@ -476,14 +476,19 @@ fn gizmos_attack_indicator( ); gizmos.arrow_2d(position.0, dash_end, Color::YELLOW); } - DirectionalAbility::Pull(Pull { max_distance }) => { - let Some((_, pull_start, pull_end)) = pull_collision( + DirectionalAbility::Pull(Pull { max_distance, .. }) => { + let Some(PullCollision { + pull_end, + collision_position, + .. + }) = pull_collision( PlayerId(client_id.0), position.0, direction, max_distance, &player_positions, - ) else { + ) + else { let pull_direction = -max_distance * direction; let pull_start = position.0 - pull_direction; let pull_end = pull_start @@ -492,7 +497,7 @@ fn gizmos_attack_indicator( gizmos.arrow_2d(pull_start, pull_end, Color::YELLOW); return; }; - gizmos.arrow_2d(pull_start, pull_end, Color::YELLOW); + gizmos.arrow_2d(collision_position, pull_end, Color::YELLOW); } DirectionalAbility::Spear(Spear { max_distance, .. }) => { gizmos.arrow_2d( diff --git a/src/shared/ability.rs b/src/shared/ability.rs index f880fac..f6a0ff4 100644 --- a/src/shared/ability.rs +++ b/src/shared/ability.rs @@ -193,6 +193,7 @@ pub struct Dash { #[derive(Copy, Clone, PartialEq, Debug, Deserialize, Serialize)] pub struct Pull { pub max_distance: f32, + pub damage: f32, } #[derive(Copy, Clone, PartialEq, Debug, Deserialize, Serialize)] @@ -366,7 +367,8 @@ fn pull_activation(pull: Pull) -> DirectionalAbilityActivation { mut set: ParamSet<( Query<&mut PlayerPosition>, Query<(&PlayerId, &PlayerPosition)>, - )>| { + )>, + mut commands: Commands| { let Some(source_entity) = ({ let mut source_entity = None; for (entity, player_id) in players.iter() { @@ -392,7 +394,11 @@ fn pull_activation(pull: Pull) -> DirectionalAbilityActivation { return; }; - let Some((target_player, _, pull_end)) = ({ + let Some(PullCollision { + pull_end, + collision_id, + .. + }) = ({ let pull_targets = set.p1(); pull_collision( source_player, @@ -401,14 +407,15 @@ fn pull_activation(pull: Pull) -> DirectionalAbilityActivation { pull.max_distance, &pull_targets, ) - }) else { + }) + else { return; }; let Some(target_entity) = ({ let mut target_entity = None; for (entity, player_id) in players.iter() { - if *player_id != target_player { + if *player_id != collision_id { continue; } target_entity = Some(entity); @@ -423,6 +430,14 @@ fn pull_activation(pull: Pull) -> DirectionalAbilityActivation { if let Ok(mut position) = positions.get_mut(target_entity) { position.0 = pull_end; } + + commands.spawn(ProjectileBundle::new(Projectile { + type_: ProjectileType::Instant(InstantProjectile { + target_player: collision_id, + }), + source_player, + damage: pull.damage, + })); }, ) }); @@ -430,13 +445,19 @@ fn pull_activation(pull: Pull) -> DirectionalAbilityActivation { ) } +pub struct PullCollision { + pub pull_end: Vec2, + pub collision_id: PlayerId, + pub collision_position: Vec2, +} + pub fn pull_collision( source_id: PlayerId, pull_start: Vec2, pull_direction: Vec2, pull_max_distance: f32, player_positions: &Query<(&PlayerId, &PlayerPosition)>, -) -> Option<(PlayerId, Vec2, Vec2)> { +) -> Option<PullCollision> { let mut pull_collision = pull_max_distance * pull_direction; let mut pull_player_id = None; let mut pull_player_position = None; @@ -463,19 +484,15 @@ pub fn pull_collision( } } - if let Some(target_id) = pull_player_id { - if let Some(target_position) = pull_player_position { - let pull_direction = pull_start - target_position; - Some(( - *target_id, - target_position, - target_position - + (pull_direction.length() - 2. * PLAYER_RADIUS) - * pull_direction.normalize_or_zero(), - )) - } else { - None - } + if let (Some(target_id), Some(target_position)) = (pull_player_id, pull_player_position) { + let pull_direction = pull_start - target_position; + let pull_end = target_position + + (pull_direction.length() - 2. * PLAYER_RADIUS) * pull_direction.normalize_or_zero(); + Some(PullCollision { + pull_end, + collision_id: *target_id, + collision_position: target_position, + }) } else { None } diff --git a/src/shared/champion.rs b/src/shared/champion.rs index 6e6b01b..a4ca734 100644 --- a/src/shared/champion.rs +++ b/src/shared/champion.rs @@ -53,9 +53,10 @@ impl Champion { max_distance: 60., damage: 15., })), - AbilitySlot::W => { - Ability::Directional(DirectionalAbility::Pull(Pull { max_distance: 60. })) - } + AbilitySlot::W => Ability::Directional(DirectionalAbility::Pull(Pull { + max_distance: 60., + damage: 10., + })), AbilitySlot::E => Ability::Activated(ActivatedAbility::Shield(Shield { blocked_damage: 35., duration: 2., |