diff options
Diffstat (limited to 'src/shared/ability.rs')
-rw-r--r-- | src/shared/ability.rs | 103 |
1 files changed, 57 insertions, 46 deletions
diff --git a/src/shared/ability.rs b/src/shared/ability.rs index a9387f3..66d236f 100644 --- a/src/shared/ability.rs +++ b/src/shared/ability.rs @@ -253,7 +253,7 @@ fn dash_activation(dash: Dash) -> DirectionalAbilityActivation { move |entity_map: Res<EntityMap>, mut imperatives: Query<&mut Imperative>, mut set: ParamSet<( - Query<&mut PlayerPosition>, + Query<(&mut PlayerPosition, &PlayerColor)>, Query<(Entity, &PlayerId, &PlayerPosition, &Shape)>, )>, mut commands: Commands| { @@ -278,9 +278,12 @@ fn dash_activation(dash: Dash) -> DirectionalAbilityActivation { }; let mut positions = set.p0(); - if let Ok(mut position) = positions.get_mut(*source_entity) { - position.0 = dash_end; - } + let Ok((mut position, source_player_color)) = + positions.get_mut(*source_entity) + else { + return; + }; + position.0 = dash_end; if let Some(DashCollision { collision_player_id, @@ -295,13 +298,16 @@ fn dash_activation(dash: Dash) -> DirectionalAbilityActivation { source_player, area_of_effect_type: AreaOfEffectType::Slow, })); - commands.spawn(ProjectileBundle::new(Projectile { - type_: ProjectileType::Instant(InstantProjectile { - target_player: collision_player_id, - }), - source_player, - damage: dash.damage, - })); + commands.spawn(ProjectileBundle::new( + Projectile { + type_: ProjectileType::Instant(InstantProjectile { + target_player: collision_player_id, + }), + source_player, + damage: dash.damage, + }, + ProjectileColor(source_player_color.0), + )); if let Ok(mut imperative) = imperatives.get_mut(*source_entity) { *imperative = Imperative::AttackTarget(AbilitySlot::A, collision_player_id); @@ -375,21 +381,12 @@ fn pull_activation(pull: Pull) -> DirectionalAbilityActivation { move |players: Query<(Entity, &PlayerId)>, mut imperatives: Query<&mut Imperative>, mut set: ParamSet<( - Query<&mut PlayerPosition>, + Query<(&mut PlayerPosition, &PlayerColor)>, Query<(Entity, &PlayerId, &PlayerPosition, &Shape)>, )>, - mut commands: Commands| { - let Some(source_entity) = ({ - let mut source_entity = None; - for (entity, player_id) in players.iter() { - if *player_id != source_player { - continue; - } - source_entity = Some(entity); - break; - } - source_entity - }) else { + mut commands: Commands, + entity_map: Res<EntityMap>| { + let Some(source_entity) = entity_map.0.get(&source_player.0) else { return; }; @@ -400,7 +397,7 @@ fn pull_activation(pull: Pull) -> DirectionalAbilityActivation { }) = ({ let pull_targets = set.p1(); pull_collision( - source_entity, + *source_entity, direction.normalize_or_zero(), pull.max_distance, &pull_targets, @@ -425,18 +422,24 @@ fn pull_activation(pull: Pull) -> DirectionalAbilityActivation { }; let mut positions = set.p0(); - if let Ok(mut position) = positions.get_mut(target_entity) { - position.0 = pull_end; - } + let Ok([(_, source_player_color), (mut position, _)]) = + positions.get_many_mut([*source_entity, target_entity]) + else { + return; + }; + position.0 = pull_end; - commands.spawn(ProjectileBundle::new(Projectile { - type_: ProjectileType::Instant(InstantProjectile { - target_player: collision_player_id, - }), - source_player, - damage: pull.damage, - })); - if let Ok(mut imperative) = imperatives.get_mut(source_entity) { + commands.spawn(ProjectileBundle::new( + Projectile { + type_: ProjectileType::Instant(InstantProjectile { + target_player: collision_player_id, + }), + source_player, + damage: pull.damage, + }, + ProjectileColor(source_player_color.0), + )); + if let Ok(mut imperative) = imperatives.get_mut(*source_entity) { *imperative = Imperative::AttackTarget(AbilitySlot::A, collision_player_id); } @@ -571,23 +574,31 @@ fn spear_activation(spear: Spear) -> DirectionalAbilityActivation { move |commands: &mut Commands, source_player: PlayerId, direction: Vec2| { commands.add(move |world: &mut World| { world.run_system_once( - move |mut commands: Commands, players: Query<(&PlayerId, &PlayerPosition)>| { - for (id, position) in players.iter() { - if *id != source_player { - continue; - } - commands.spawn(ProjectileBundle::new(Projectile { + move |mut commands: Commands, + players: Query<(&PlayerId, &PlayerPosition, &PlayerColor)>, + entity_map: Res<EntityMap>| { + let Some(source_entity) = entity_map.0.get(&source_player.0) else { + return; + }; + let Ok((_source_player_id, source_player_position, source_player_color)) = + players.get(*source_entity) + else { + return; + }; + commands.spawn(ProjectileBundle::new( + Projectile { type_: ProjectileType::Free(FreeProjectile { - position: position.0, + position: source_player_position.0, direction: direction.normalize_or_zero(), - starting_position: position.0, + starting_position: source_player_position.0, max_distance: spear.max_distance, scale_damage: Some((0.75, 2.5)), }), source_player, damage: spear.damage, - })); - } + }, + ProjectileColor(source_player_color.0), + )); }, ) }); |