diff options
Diffstat (limited to 'src/shared/ability.rs')
-rw-r--r-- | src/shared/ability.rs | 53 |
1 files changed, 35 insertions, 18 deletions
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 } |