From 9d8bf0fde7b12fa77569333d17f310e55df58db9 Mon Sep 17 00:00:00 2001 From: Alexander Foremny Date: Tue, 19 Mar 2024 06:52:42 +0100 Subject: feat: focus ability --- src/server.rs | 47 +++++++++++++++++----------- src/server/entity_map.rs | 6 ++++ src/shared/ability.rs | 81 ++++++++++++++++++++++++++++++++++++++++++++++++ src/shared/buffs.rs | 1 + src/shared/champion.rs | 19 +++++++----- src/shared/cooldown.rs | 3 ++ src/shared/stats.rs | 3 +- 7 files changed, 134 insertions(+), 26 deletions(-) create mode 100644 src/server/entity_map.rs (limited to 'src') 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); - 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, 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