diff options
Diffstat (limited to 'src/server.rs')
-rw-r--r-- | src/server.rs | 42 |
1 files changed, 23 insertions, 19 deletions
diff --git a/src/server.rs b/src/server.rs index 165c5f0..038f854 100644 --- a/src/server.rs +++ b/src/server.rs @@ -1,5 +1,6 @@ use crate::protocol::*; use crate::server::network::*; +use crate::shared::ability::*; use crate::shared::champion::*; use crate::shared::cooldown::*; use crate::shared::health::*; @@ -9,7 +10,6 @@ use crate::shared::player::*; use crate::shared::projectile::*; use crate::shared::*; use bevy::prelude::*; -use bevy::utils::Duration; use bevy::utils::HashMap; use lightyear::prelude::*; use lightyear::server::events::MessageEvent; @@ -247,13 +247,17 @@ fn imperative_attack_attack( champions: Query<&Champion>, ) { for (id, mut imperative) in players.iter_mut() { + let Some(entity) = entity_map.0.get(&id.0) else { + *imperative = Imperative::Idle; + return; + }; + let Ok(champion) = champions.get(*entity) else { + *imperative = Imperative::Idle; + return; + }; match *imperative { - Imperative::AttackTarget(ability, target_player) => { - let Some(entity) = entity_map.0.get(&id.0) else { - *imperative = Imperative::Idle; - return; - }; - let Ok(champion) = champions.get(*entity) else { + Imperative::AttackTarget(ability_slot, target_player) => { + let Ability::Targeted(ability) = champion.to_ability(ability_slot) else { *imperative = Imperative::Idle; return; }; @@ -273,8 +277,9 @@ fn imperative_attack_attack( *imperative = Imperative::Idle; return; }; - if cooldown.a_cooldown.is_zero() { - cooldown.a_cooldown = Duration::from_secs_f32(1.5); + let base_cooldown = BaseCooldown::from_champion(*champion); + if cooldown.0[ability_slot].is_zero() { + cooldown.0[ability_slot] = base_cooldown.0[ability_slot]; commands.spawn(ProjectileBundle::new(ability.to_projectile( *id, position.0, @@ -283,8 +288,8 @@ fn imperative_attack_attack( } } } - Imperative::AttackDirection(ability, direction) => { - let Some(entity) = entity_map.0.get(&id.0) else { + Imperative::AttackDirection(ability_slot, direction) => { + let Ability::Directional(ability) = champion.to_ability(ability_slot) else { *imperative = Imperative::Idle; return; }; @@ -296,8 +301,9 @@ fn imperative_attack_attack( *imperative = Imperative::Idle; return; }; - if cooldown.a_cooldown.is_zero() { - cooldown.a_cooldown = Duration::from_secs_f32(1.5); + let base_cooldown = BaseCooldown::from_champion(*champion); + if cooldown.0[ability_slot].is_zero() { + cooldown.0[ability_slot] = base_cooldown.0[ability_slot]; commands.spawn(ProjectileBundle::new( ability.to_projectile(*id, position.0, direction), )); @@ -435,13 +441,11 @@ fn projectile_despawn( } fn cooldown_decrement(mut cooldowns: Query<&mut Cooldown>, time: Res<Time>) { + let dt = time.delta(); for mut cooldown in cooldowns.iter_mut() { - cooldown.a_cooldown = cooldown.a_cooldown.saturating_sub(time.delta()); - cooldown.q_cooldown = cooldown.q_cooldown.saturating_sub(time.delta()); - cooldown.w_cooldown = cooldown.w_cooldown.saturating_sub(time.delta()); - cooldown.e_cooldown = cooldown.e_cooldown.saturating_sub(time.delta()); - cooldown.d_cooldown = cooldown.d_cooldown.saturating_sub(time.delta()); - cooldown.f_cooldown = cooldown.f_cooldown.saturating_sub(time.delta()); + for ability_slot in AbilitySlot::all() { + cooldown.0[ability_slot] = cooldown.0[ability_slot].saturating_sub(dt); + } } } |