aboutsummaryrefslogtreecommitdiffstats
path: root/src/client.rs
diff options
context:
space:
mode:
authorLibravatar Alexander Foremny <aforemny@posteo.de>2024-03-17 13:37:58 +0100
committerLibravatar Alexander Foremny <aforemny@posteo.de>2024-03-17 13:40:26 +0100
commit885d0bf2c02fc69fc890765d65067c01741ce47b (patch)
tree3aaee8b6fb196aa94f46d393d41a2bdf99d6942a /src/client.rs
parent601474aa84cfc071c724051ac121e3c9cc796577 (diff)
chore: refactor abilities
Diffstat (limited to 'src/client.rs')
-rw-r--r--src/client.rs51
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 {