wip: impl Stats::attack_speed_modifier

This commit is contained in:
Adam Whitehurst 2021-05-30 09:40:11 -07:00
parent e06bd0eaa3
commit eea7eead2e
4 changed files with 20 additions and 1 deletions

View File

@ -151,6 +151,8 @@ pub enum BuffEffect {
}, },
/// Modifies move speed of target /// Modifies move speed of target
MovementSpeed(f32), MovementSpeed(f32),
/// Modifies attack speed of target
AttackSpeed(f32),
} }
/// Actual de/buff. /// Actual de/buff.

View File

@ -26,6 +26,7 @@ pub struct Stats {
pub damage_reduction: f32, pub damage_reduction: f32,
pub max_health_modifier: f32, pub max_health_modifier: f32,
pub move_speed_modifier: f32, pub move_speed_modifier: f32,
pub attack_speed_modifier: f32,
} }
impl Stats { impl Stats {
@ -35,6 +36,7 @@ impl Stats {
damage_reduction: 0.0, damage_reduction: 0.0,
max_health_modifier: 1.0, max_health_modifier: 1.0,
move_speed_modifier: 1.0, move_speed_modifier: 1.0,
attack_speed_modifier: 1.0,
} }
} }
@ -46,6 +48,7 @@ impl Stats {
damage_reduction: 0.0, damage_reduction: 0.0,
max_health_modifier: 1.0, max_health_modifier: 1.0,
move_speed_modifier: 1.0, move_speed_modifier: 1.0,
attack_speed_modifier: 1.0,
} }
} }
@ -54,6 +57,7 @@ impl Stats {
self.damage_reduction = 0.0; self.damage_reduction = 0.0;
self.max_health_modifier = 1.0; self.max_health_modifier = 1.0;
self.move_speed_modifier = 1.0; self.move_speed_modifier = 1.0;
self.attack_speed_modifier = 1.0;
} }
} }

View File

@ -764,6 +764,12 @@ pub fn input_is_pressed(data: &JoinData, input: InputKind) -> bool {
data.controller.queued_inputs.contains_key(&input) data.controller.queued_inputs.contains_key(&input)
} }
pub fn tick_attack_duraction(data: &JoinData, timer: Duration) -> Duration {
timer
.checked_add(data.dt.0 * data.stats.attack_speed_modifier)
.unwrap_or_default()
}
/// Determines what portion a state is in. Used in all attacks (eventually). Is /// Determines what portion a state is in. Used in all attacks (eventually). Is
/// used to control aspects of animation code, as well as logic within the /// used to control aspects of animation code, as well as logic within the
/// character states. /// character states.

View File

@ -9,6 +9,7 @@ use common::{
Damage, DamageSource, Damage, DamageSource,
}; };
use common_ecs::{Job, Origin, Phase, System}; use common_ecs::{Job, Origin, Phase, System};
use hashbrown::HashMap;
use specs::{ use specs::{
shred::ResourceId, Entities, Join, Read, ReadStorage, SystemData, World, WriteStorage, shred::ResourceId, Entities, Join, Read, ReadStorage, SystemData, World, WriteStorage,
}; };
@ -57,7 +58,10 @@ impl<'a> System<'a> for Sys {
) )
.join() .join()
{ {
let (buff_comp_kinds, buff_comp_buffs) = buff_comp.parts(); let (buff_comp_kinds, buff_comp_buffs): (
&HashMap<BuffKind, Vec<BuffId>>,
&mut HashMap<BuffId, Buff>,
) = buff_comp.parts();
let mut expired_buffs = Vec::<BuffId>::new(); let mut expired_buffs = Vec::<BuffId>::new();
// For each buff kind present on entity, if the buff kind queues, only ticks // For each buff kind present on entity, if the buff kind queues, only ticks
// duration of strongest buff of that kind, else it ticks durations of all buffs // duration of strongest buff of that kind, else it ticks durations of all buffs
@ -207,6 +211,9 @@ impl<'a> System<'a> for Sys {
BuffEffect::MovementSpeed(ms) => { BuffEffect::MovementSpeed(ms) => {
stat.move_speed_modifier *= *ms; stat.move_speed_modifier *= *ms;
}, },
BuffEffect::AttackSpeed(ms) => {
stat.attack_speed_modifier *= *ms;
},
}; };
} }
} }