From e9dce64b009455163f2a262ed481c37300917c4a Mon Sep 17 00:00:00 2001 From: Alexander Foremny Date: Tue, 19 Mar 2024 05:50:53 +0100 Subject: chore: tweak champions --- src/shared/ability.rs | 348 ++++++++++++++++++++++++++++---------------------- 1 file changed, 195 insertions(+), 153 deletions(-) (limited to 'src/shared/ability.rs') diff --git a/src/shared/ability.rs b/src/shared/ability.rs index 2c581e7..4d45a4d 100644 --- a/src/shared/ability.rs +++ b/src/shared/ability.rs @@ -14,8 +14,18 @@ pub enum Ability { #[derive(Copy, Clone, PartialEq, Debug, Deserialize, Serialize)] pub enum TargetedAbility { - MeeleAttack, - RangedAttack, + MeeleAttack(MeeleAttack), + RangedAttack(RangedAttack), +} + +#[derive(Copy, Clone, PartialEq, Debug, Deserialize, Serialize)] +pub struct MeeleAttack { + pub damage: f32, +} + +#[derive(Copy, Clone, PartialEq, Debug, Deserialize, Serialize)] +pub struct RangedAttack { + pub damage: f32, } impl TargetedAbility { @@ -26,18 +36,18 @@ impl TargetedAbility { target_player: PlayerId, ) -> Projectile { match self { - TargetedAbility::MeeleAttack => Projectile { + TargetedAbility::MeeleAttack(MeeleAttack { damage }) => Projectile { type_: ProjectileType::Instant(InstantProjectile { target_player }), source_player, - damage: 5., + damage, }, - TargetedAbility::RangedAttack => Projectile { + TargetedAbility::RangedAttack(RangedAttack { damage }) => Projectile { type_: ProjectileType::Targeted(TargetedProjectile { target_player, position, }), source_player, - damage: 6., + damage, }, } } @@ -45,81 +55,104 @@ impl TargetedAbility { #[derive(Copy, Clone, PartialEq, Debug, Deserialize, Serialize)] pub enum ActivatedAbility { - Speed, + Speed(Speed), +} + +#[derive(Copy, Clone, PartialEq, Debug, Deserialize, Serialize)] +pub struct Speed { + pub duration: f32, } #[derive(Copy, Clone, PartialEq, Debug, Deserialize, Serialize)] pub enum DirectionalAbility { - Dash, - Pull, - Spear, + Dash(Dash), + Pull(Pull), + Spear(Spear), } -pub struct DirectionalAbilityActivation( - pub fn(commands: &mut Commands, source_player: PlayerId, direction: Vec2) -> (), -); +#[derive(Copy, Clone, PartialEq, Debug, Deserialize, Serialize)] +pub struct Dash { + pub max_distance: f32, +} + +#[derive(Copy, Clone, PartialEq, Debug, Deserialize, Serialize)] +pub struct Pull { + pub max_distance: f32, +} + +#[derive(Copy, Clone, PartialEq, Debug, Deserialize, Serialize)] +pub struct Spear { + pub max_distance: f32, + pub damage: f32, +} + +pub type DirectionalAbilityActivation = Box ()>; impl DirectionalAbility { pub fn activate(self) -> DirectionalAbilityActivation { match self { - DirectionalAbility::Dash => DirectionalAbilityActivation(dash_activation), - DirectionalAbility::Pull => DirectionalAbilityActivation(pull_activation), - DirectionalAbility::Spear => DirectionalAbilityActivation(spear_activation), + DirectionalAbility::Dash(dash) => dash_activation(dash), + DirectionalAbility::Pull(pull) => pull_activation(pull), + DirectionalAbility::Spear(spear) => spear_activation(spear), } } } -fn dash_activation(commands: &mut Commands, source_player: PlayerId, direction: Vec2) { - commands.add(move |world: &mut World| { - world.run_system_once( - move |players: Query<(Entity, &PlayerId)>, - mut set: ParamSet<( - Query<&mut PlayerPosition>, - Query<(&PlayerId, &PlayerPosition)>, - )>| { - let Some(source_entity) = ({ - let mut source_entity = None; - for (entity, player_id) in players.iter() { - if *player_id != source_player { - continue; +fn dash_activation(dash: Dash) -> DirectionalAbilityActivation { + Box::new( + move |commands: &mut Commands, source_player: PlayerId, direction: Vec2| { + commands.add(move |world: &mut World| { + world.run_system_once( + move |players: Query<(Entity, &PlayerId)>, + mut set: ParamSet<( + Query<&mut PlayerPosition>, + Query<(&PlayerId, &PlayerPosition)>, + )>| { + 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 { + return; + }; + + let Some(source_position) = ({ + let positions = set.p0(); + if let Ok(position) = positions.get(source_entity) { + Some(*position) + } else { + None + } + }) else { + return; + }; + + let dash_end = { + let dash_targets = set.p1(); + dash_collision( + source_player, + source_position.0, + direction, + dash.max_distance, + &dash_targets, + ) + }; + + let mut positions = set.p0(); + if let Ok(mut position) = positions.get_mut(source_entity) { + position.0 = dash_end; } - source_entity = Some(entity); - break; - } - source_entity - }) else { - return; - }; - - let Some(source_position) = ({ - let positions = set.p0(); - if let Ok(position) = positions.get(source_entity) { - Some(*position) - } else { - None - } - }) else { - return; - }; - - let dash_end = { - let dash_targets = set.p1(); - dash_collision( - source_player, - source_position.0, - direction, - 150., - &dash_targets, - ) - }; - - let mut positions = set.p0(); - if let Ok(mut position) = positions.get_mut(source_entity) { - position.0 = dash_end; - } - }, - ) - }); + }, + ) + }); + }, + ) } pub fn dash_collision( @@ -161,73 +194,77 @@ pub fn dash_collision( } } -fn pull_activation(commands: &mut Commands, source_player: PlayerId, direction: Vec2) { - commands.add(move |world: &mut World| { - world.run_system_once( - move |players: Query<(Entity, &PlayerId)>, - mut set: ParamSet<( - Query<&mut PlayerPosition>, - Query<(&PlayerId, &PlayerPosition)>, - )>| { - 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 { - return; - }; - - let Some(source_position) = ({ - let positions = set.p0(); - if let Ok(position) = positions.get(source_entity) { - Some(*position) - } else { - None - } - }) else { - return; - }; - - let Some((target_player, _, pull_end)) = ({ - let pull_targets = set.p1(); - pull_collision( - source_player, - source_position.0, - direction, - 150., - &pull_targets, - ) - }) else { - return; - }; - - let Some(target_entity) = ({ - let mut target_entity = None; - for (entity, player_id) in players.iter() { - if *player_id != target_player { - continue; +fn pull_activation(pull: Pull) -> DirectionalAbilityActivation { + Box::new( + move |commands: &mut Commands, source_player: PlayerId, direction: Vec2| { + commands.add(move |world: &mut World| { + world.run_system_once( + move |players: Query<(Entity, &PlayerId)>, + mut set: ParamSet<( + Query<&mut PlayerPosition>, + Query<(&PlayerId, &PlayerPosition)>, + )>| { + 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 { + return; + }; + + let Some(source_position) = ({ + let positions = set.p0(); + if let Ok(position) = positions.get(source_entity) { + Some(*position) + } else { + None + } + }) else { + return; + }; + + let Some((target_player, _, pull_end)) = ({ + let pull_targets = set.p1(); + pull_collision( + source_player, + source_position.0, + direction, + pull.max_distance, + &pull_targets, + ) + }) else { + return; + }; + + let Some(target_entity) = ({ + let mut target_entity = None; + for (entity, player_id) in players.iter() { + if *player_id != target_player { + continue; + } + target_entity = Some(entity); + break; + } + target_entity + }) else { + return; + }; + + let mut positions = set.p0(); + if let Ok(mut position) = positions.get_mut(target_entity) { + position.0 = pull_end; } - target_entity = Some(entity); - break; - } - target_entity - }) else { - return; - }; - - let mut positions = set.p0(); - if let Ok(mut position) = positions.get_mut(target_entity) { - position.0 = pull_end; - } - }, - ) - }); + }, + ) + }); + }, + ) } pub fn pull_collision( @@ -281,27 +318,32 @@ pub fn pull_collision( } } -fn spear_activation(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 { - type_: ProjectileType::Free(FreeProjectile { - position: position.0, - direction, - starting_position: position.0, - }), - source_player, - damage: 15., - })); - } - }, - ) - }); +fn spear_activation(spear: Spear) -> DirectionalAbilityActivation { + Box::new( + 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 { + type_: ProjectileType::Free(FreeProjectile { + position: position.0, + direction, + starting_position: position.0, + max_distance: spear.max_distance, + }), + source_player, + damage: spear.damage, + })); + } + }, + ) + }); + }, + ) } #[derive(Debug, Serialize, Deserialize, Clone, Copy, PartialEq, Eq)] -- cgit v1.2.3