diff options
Diffstat (limited to 'src/client.rs')
-rw-r--r-- | src/client.rs | 51 |
1 files changed, 33 insertions, 18 deletions
diff --git a/src/client.rs b/src/client.rs index 7f70549..886afd0 100644 --- a/src/client.rs +++ b/src/client.rs @@ -1,5 +1,6 @@ use crate::client::network::*; use crate::protocol::*; +use crate::shared::ability::*; use crate::shared::champion::*; use crate::shared::health::*; use crate::shared::imperative::*; @@ -156,31 +157,45 @@ fn buffer_input( mouse_input: Res<ButtonInput<MouseButton>>, mut client: ClientMut, windows: Query<&Window>, + champion: Res<MyChampion>, ) { if mouse_input.just_pressed(MouseButton::Left) { match attack.0 { - Some(AttackKey::Q) => { - let Some(world_position) = cursor_world_position(&windows, &cameras) else { - return; - }; - let Some(position) = player_position(&client_id, &players) else { - return; - }; - let Some(direction) = (world_position - position.0).try_normalize() else { - return; - }; - client.add_input(Inputs::Imperative(Imperative::AttackDirection( - AttackKey::Q, - direction, - ))); - attack.0 = None; - } - _ => { + Some(attack_key) => match champion.0.to_ability(attack_key) { + Ability::Directional(ability) => { + let Some(world_position) = cursor_world_position(&windows, &cameras) else { + return; + }; + let Some(position) = player_position(&client_id, &players) else { + return; + }; + let Some(direction) = (world_position - position.0).try_normalize() else { + return; + }; + client.add_input(Inputs::Imperative(Imperative::AttackDirection( + ability, direction, + ))); + attack.0 = None; + } + Ability::Targeted(ability) => { + let Some((target_player, _)) = + hovered_other_player(&cameras, &client_id, &players, &windows) + else { + return; + }; + client.add_input(Inputs::Imperative(Imperative::AttackTarget( + ability, + target_player, + ))); + attack.0 = None; + } + }, + None => { if let Some((target_player, _)) = hovered_other_player(&cameras, &client_id, &players, &windows) { client.add_input(Inputs::Imperative(Imperative::AttackTarget( - attack.0.unwrap_or(AttackKey::A), + TargetedAbility::MeeleAttack, target_player, ))); } else { |