diff options
Diffstat (limited to 'src/client.rs')
-rw-r--r-- | src/client.rs | 83 |
1 files changed, 58 insertions, 25 deletions
diff --git a/src/client.rs b/src/client.rs index 7ccced7..3679b85 100644 --- a/src/client.rs +++ b/src/client.rs @@ -1,6 +1,7 @@ use crate::client::network::*; use crate::protocol::*; use crate::shared::ability::*; +use crate::shared::activation::*; use crate::shared::champion::*; use crate::shared::cooldown::*; use crate::shared::health::*; @@ -8,6 +9,7 @@ use crate::shared::health_event::*; use crate::shared::imperative::*; use crate::shared::player::*; use crate::shared::projectile::*; +use crate::shared::stats::*; use crate::shared::*; use bevy::input::keyboard::*; use bevy::input::mouse::MouseButton; @@ -255,7 +257,8 @@ fn buffer_input( ) { if mouse_input.just_pressed(MouseButton::Left) { match attack.0 { - Some(attack_key) => match champion.0.to_ability(attack_key) { + Some(ability_slot) => match champion.0.to_ability(ability_slot) { + Ability::Activated(_) => {} Ability::Directional(_) => { let Some(world_position) = cursor_world_position(&windows, &cameras) else { return; @@ -267,7 +270,8 @@ fn buffer_input( return; }; client.add_input(Inputs::Imperative(Imperative::AttackDirection( - attack_key, direction, + ability_slot, + direction, ))); attack.0 = None; } @@ -278,7 +282,7 @@ fn buffer_input( return; }; client.add_input(Inputs::Imperative(Imperative::AttackTarget( - attack_key, + ability_slot, target_player, ))); attack.0 = None; @@ -299,26 +303,45 @@ fn buffer_input( } } } + } else { + client.add_input(Inputs::None); } } -fn choose_attack(keyboard_input: Res<ButtonInput<KeyCode>>, mut attack_key: ResMut<Attack>) { +fn choose_attack( + champion: Res<MyChampion>, + keyboard_input: Res<ButtonInput<KeyCode>>, + mut attack: ResMut<Attack>, + mut client: ClientMut, +) { if keyboard_input.just_pressed(KeyCode::KeyA) { - attack_key.0 = Some(AbilitySlot::A); + attack.0 = Some(AbilitySlot::A); } else if keyboard_input.just_pressed(KeyCode::KeyQ) { - attack_key.0 = Some(AbilitySlot::Q); + attack.0 = Some(AbilitySlot::Q); } else if keyboard_input.just_pressed(KeyCode::KeyW) { - attack_key.0 = Some(AbilitySlot::W); + attack.0 = Some(AbilitySlot::W); } else if keyboard_input.just_pressed(KeyCode::KeyE) { - attack_key.0 = Some(AbilitySlot::E); + attack.0 = Some(AbilitySlot::E); } else if keyboard_input.just_pressed(KeyCode::KeyR) { - attack_key.0 = Some(AbilitySlot::R); + attack.0 = Some(AbilitySlot::R); } else if keyboard_input.just_pressed(KeyCode::KeyF) { - attack_key.0 = Some(AbilitySlot::F); + attack.0 = Some(AbilitySlot::F); } else if keyboard_input.just_pressed(KeyCode::KeyG) { - attack_key.0 = Some(AbilitySlot::G); + attack.0 = Some(AbilitySlot::G); } else if keyboard_input.just_pressed(KeyCode::Escape) { - attack_key.0 = None; + attack.0 = None; + } else if keyboard_input.just_pressed(KeyCode::ShiftLeft) { + attack.0 = None; + } + match attack.0 { + Some(ability_slot) => match champion.0.to_ability(ability_slot) { + Ability::Activated(_) => { + client.add_input(Inputs::Activation(Activation::Activate(ability_slot))); + attack.0 = None; + } + _ => {} + }, + None => {} } } @@ -383,6 +406,7 @@ fn gizmos_attack_indicator( attack: Res<Attack>, cameras: Query<(&Camera, &GlobalTransform)>, client_id: Res<ClientId>, + effective_statses: Query<(&PlayerId, &EffectiveStats)>, hoverables: Query<(&PlayerId, &PlayerPosition)>, mut gizmos: Gizmos, player_champions: Query<(&PlayerId, &Champion)>, @@ -395,19 +419,16 @@ fn gizmos_attack_indicator( let Some(champion) = player_champion(&client_id, &player_champions) else { return; }; - let Some(attack_key) = attack.0.or_else(|| { + let Some(ability_slot) = attack.0.or_else(|| { hovered_other_player(&cameras, &client_id, &hoverables, &windows).map(|_| AbilitySlot::A) }) else { return; }; - match champion.to_ability(attack_key) { - Ability::Targeted(_) => { - gizmos.circle_2d( - position.0, - Stats::from_champion(champion).attack_range, - Color::YELLOW, - ); - } + let Some(effective_stats) = player_effective_stats(&client_id, &effective_statses) else { + return; + }; + match champion.to_ability(ability_slot) { + Ability::Activated(_) => {} Ability::Directional(_) => { let Some(world_position) = cursor_world_position(&windows, &cameras) else { return; @@ -417,6 +438,9 @@ fn gizmos_attack_indicator( }; gizmos.arrow_2d(position.0, position.0 + 75. * direction, Color::YELLOW); } + Ability::Targeted(_) => { + gizmos.circle_2d(position.0, effective_stats.0.attack_range, Color::YELLOW); + } } } @@ -432,6 +456,18 @@ fn player_position( None } +fn player_effective_stats( + client_id: &Res<ClientId>, + players: &Query<(&PlayerId, &EffectiveStats)>, +) -> Option<EffectiveStats> { + for (id, effective_stats) in players.iter() { + if id.0 == client_id.0 { + return Some(*effective_stats); + } + } + None +} + fn player_champion( client_id: &Res<ClientId>, players: &Query<(&PlayerId, &Champion)>, @@ -506,11 +542,8 @@ fn hotbar_hotbar_display( } fn hotbar_hotbar_highlight(attack: Res<Attack>, mut hotbars: Query<(&Hotbar, &mut Text)>) { - let Some(ability_slot) = attack.0 else { - return; - }; for (hotbar, mut text) in hotbars.iter_mut() { - let is_highlighted = ability_slot == hotbar.0; + let is_highlighted = attack.0 == Some(hotbar.0); if text.sections.len() <= 0 { continue; } |