aboutsummaryrefslogtreecommitdiffstats
path: root/src/server.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/server.rs')
-rw-r--r--src/server.rs47
1 files changed, 29 insertions, 18 deletions
diff --git a/src/server.rs b/src/server.rs
index b3c2a30..483314d 100644
--- a/src/server.rs
+++ b/src/server.rs
@@ -1,4 +1,5 @@
use crate::protocol::*;
+use crate::server::entity_map::*;
use crate::server::network::*;
use crate::shared::ability::*;
use crate::shared::activation::*;
@@ -13,16 +14,14 @@ use crate::shared::projectile::*;
use crate::shared::stats::*;
use crate::shared::*;
use bevy::prelude::*;
-use bevy::utils::HashMap;
+use bevy::utils::*;
use lightyear::prelude::*;
use lightyear::server::events::MessageEvent;
use rand::Rng;
+pub mod entity_map;
mod network;
-#[derive(Resource, Default)]
-struct EntityMap(HashMap<ClientId, Entity>);
-
pub fn main(transport: TransportConfig) {
App::new()
.add_plugins(MinimalPlugins)
@@ -284,7 +283,11 @@ fn imperative_attack_attack(
};
let base_cooldown = champion.base_cooldown();
if cooldown.0[ability_slot].is_zero() {
- cooldown.0[ability_slot] = base_cooldown.0[ability_slot];
+ cooldown.0[ability_slot] = if ability_slot == AbilitySlot::A {
+ Duration::from_secs_f32(effective_stats.0.attack_speed)
+ } else {
+ base_cooldown.0[ability_slot]
+ };
commands.spawn(ProjectileBundle::new(ability.to_projectile(
*id,
position.0,
@@ -318,12 +321,13 @@ fn imperative_attack_attack(
}
fn activation(
+ champions: Query<&Champion>,
+ mut commands: Commands,
entity_map: Res<EntityMap>,
mut cooldowns: Query<&mut Cooldown>,
- mut players: Query<(&PlayerId, &mut Activation, &mut Buffs)>,
- champions: Query<&Champion>,
+ mut players: Query<(&PlayerId, &mut Activation)>,
) {
- for (id, mut activation, mut buffs) in players.iter_mut() {
+ for (id, mut activation) in players.iter_mut() {
let Some(entity) = entity_map.0.get(&id.0) else {
*activation = Activation::None;
continue;
@@ -344,15 +348,11 @@ fn activation(
*activation = Activation::None;
continue;
};
- match ability {
- ActivatedAbility::Speed(Speed { duration }) => {
- let base_cooldown = champion.base_cooldown();
- if cooldown.0[ability_slot].is_zero() {
- cooldown.0[ability_slot] = base_cooldown.0[ability_slot];
- buffs.speed = Some(Timer::from_seconds(duration, TimerMode::Once));
- *activation = Activation::None;
- }
- }
+ let base_cooldown = champion.base_cooldown();
+ if cooldown.0[ability_slot].is_zero() {
+ cooldown.0[ability_slot] = base_cooldown.0[ability_slot];
+ ability.activate()(&mut commands, *id);
+ *activation = Activation::None;
}
}
}
@@ -440,7 +440,7 @@ fn projectile_despawn(
free_projectile
.position
.distance(free_projectile.starting_position)
- >= 10000.0,
+ >= free_projectile.max_distance,
None,
)
}
@@ -527,6 +527,9 @@ fn effective_stats(
if buffs.speed.is_some() {
stats.movement_speed *= 1.25;
}
+ if buffs.haste.is_some() {
+ stats.attack_speed *= 0.5;
+ }
effective_stats.0 = stats;
health.0 = health.0.min(effective_stats.0.max_health);
}
@@ -535,6 +538,9 @@ fn effective_stats(
fn buffs_tick(mut buffses: Query<&mut Buffs>, time: Res<Time>) {
let dt = time.delta();
for mut buffs in buffses.iter_mut() {
+ if let Some(ref mut timer) = &mut buffs.haste {
+ timer.tick(dt);
+ }
if let Some(ref mut timer) = &mut buffs.slow {
timer.tick(dt);
}
@@ -546,6 +552,11 @@ fn buffs_tick(mut buffses: Query<&mut Buffs>, time: Res<Time>) {
fn buffs_despawn(mut buffses: Query<&mut Buffs>) {
for mut buffs in buffses.iter_mut() {
+ if let Some(timer) = &buffs.haste {
+ if timer.finished() {
+ buffs.haste = None;
+ }
+ }
if let Some(timer) = &buffs.slow {
if timer.finished() {
buffs.slow = None;