diff --git a/common/src/combat.rs b/common/src/combat.rs index bed6ab1f87..00cbca8b08 100644 --- a/common/src/combat.rs +++ b/common/src/combat.rs @@ -258,8 +258,7 @@ impl Attack { by: attacker.map(|x| x.into()), cause: Some(damage.damage.source), time, - crit: Some(is_crit), - crit_mult: self.crit_multiplier, + crit_mult: is_crit.then(|| self.crit_multiplier), instance: damage.instance, }; emit(ServerEvent::HealthChange { @@ -358,8 +357,7 @@ impl Attack { by: attacker.map(|a| a.into()), cause: None, time, - crit: None, - crit_mult: self.crit_multiplier, + crit_mult: None, instance: rand::random(), }; if change.amount.abs() > Health::HEALTH_EPSILON { @@ -393,8 +391,7 @@ impl Attack { by: attacker.map(|a| a.into()), cause: None, time, - crit: None, - crit_mult: self.crit_multiplier, + crit_mult: None, instance: rand::random(), }; if change.amount.abs() > Health::HEALTH_EPSILON { @@ -507,8 +504,7 @@ impl Attack { by: attacker.map(|a| a.into()), cause: None, time, - crit: None, - crit_mult: self.crit_multiplier, + crit_mult: None, instance: rand::random(), }; if change.amount.abs() > Health::HEALTH_EPSILON { @@ -542,8 +538,7 @@ impl Attack { by: attacker.map(|a| a.into()), cause: None, time, - crit: None, - crit_mult: self.crit_multiplier, + crit_mult: None, instance: rand::random(), }; if change.amount.abs() > Health::HEALTH_EPSILON { @@ -861,8 +856,7 @@ impl Damage { by: damage_contributor, cause: Some(self.source), time, - crit: Some(is_crit), - crit_mult, + crit_mult: is_crit.then(|| crit_mult), instance, } }, @@ -876,8 +870,7 @@ impl Damage { by: None, cause: Some(self.source), time, - crit: None, - crit_mult, + crit_mult: None, instance, } }, @@ -886,8 +879,7 @@ impl Damage { by: None, cause: Some(self.source), time, - crit: None, - crit_mult, + crit_mult: None, instance, }, } diff --git a/common/src/comp/health.rs b/common/src/comp/health.rs index 61e898f855..fa0425cd6e 100644 --- a/common/src/comp/health.rs +++ b/common/src/comp/health.rs @@ -25,10 +25,8 @@ pub struct HealthChange { pub cause: Option, /// The time that the health change occurred at pub time: Time, - /// Whether or not the health change was caused by a crit (None if it - /// couldn't have been a crit) - pub crit: Option, - pub crit_mult: f32, + /// The crit multiplier (None if it isn't a crit) + pub crit_mult: Option, /// A random ID, used to group up health changes // Note: Two or more changes could have the same instance number, if they // came from the same attack (for example - the extra damage caused by @@ -142,8 +140,7 @@ impl Health { amount: 0.0, by: None, cause: None, - crit: None, - crit_mult: 1.0, + crit_mult: None, time: Time(0.0), instance: rand::random(), }, @@ -225,8 +222,7 @@ impl Health { amount: 0.0, by: None, cause: None, - crit: None, - crit_mult: 1.0, + crit_mult: None, time: Time(0.0), instance: rand::random(), }, @@ -262,8 +258,7 @@ mod tests { time: Time(123.0), by: Some(damage_contrib), cause: None, - crit: None, - crit_mult: 1.0, + crit_mult: None, instance: rand::random(), }; @@ -290,8 +285,7 @@ mod tests { time: Time(123.0), by: Some(damage_contrib), cause: None, - crit: None, - crit_mult: 1.0, + crit_mult: None, instance: rand::random(), }; @@ -312,8 +306,7 @@ mod tests { time: Time(123.0), by: Some(damage_contrib), cause: None, - crit: None, - crit_mult: 1.0, + crit_mult: None, instance: rand::random(), }; health.change_by(health_change); @@ -340,8 +333,7 @@ mod tests { time: Time(10.0), by: Some(damage_contrib1), cause: None, - crit: None, - crit_mult: 1.0, + crit_mult: None, instance: rand::random(), }; health.change_by(health_change); @@ -352,8 +344,7 @@ mod tests { time: Time(100.0), by: Some(damage_contrib2), cause: None, - crit: None, - crit_mult: 1.0, + crit_mult: None, instance: rand::random(), }; health.change_by(health_change); @@ -368,8 +359,7 @@ mod tests { time: Time(620.0), by: Some(damage_contrib2), cause: None, - crit: None, - crit_mult: 1.0, + crit_mult: None, instance: rand::random(), }; health.change_by(health_change); diff --git a/common/src/comp/projectile.rs b/common/src/comp/projectile.rs index a09f240d10..a083d3edfc 100644 --- a/common/src/comp/projectile.rs +++ b/common/src/comp/projectile.rs @@ -98,7 +98,6 @@ impl ProjectileConstructor { crit_chance: f32, crit_mult: f32, buff_strength: f32, - instance: u64, ) -> Projectile { use ProjectileConstructor::*; match self { @@ -123,6 +122,7 @@ impl ProjectileConstructor { strength: CombatBuffStrength::DamageFraction(0.1 * buff_strength), chance: 0.1, }); + let instance = rand::random(); let damage = AttackDamage::new( Damage { source: DamageSource::Projectile, diff --git a/common/src/outcome.rs b/common/src/outcome.rs index a9bb66cd28..f98d73f95e 100644 --- a/common/src/outcome.rs +++ b/common/src/outcome.rs @@ -7,10 +7,9 @@ use vek::*; #[derive(Debug, Clone, Copy, Serialize, Deserialize)] pub struct DamageInfo { pub amount: f32, - pub crit: Option, + pub crit_mult: Option, pub target: Uid, pub by: Option, - pub crit_mult: f32, pub instance: u64, } diff --git a/common/src/states/basic_ranged.rs b/common/src/states/basic_ranged.rs index abf6523dd6..cc08ad9f9f 100644 --- a/common/src/states/basic_ranged.rs +++ b/common/src/states/basic_ranged.rs @@ -84,7 +84,6 @@ impl CharacterBehavior for Data { crit_chance, crit_mult, buff_strength, - rand::random(), ); // Shoots all projectiles simultaneously for i in 0..self.static_data.num_projectiles { diff --git a/common/src/states/charged_ranged.rs b/common/src/states/charged_ranged.rs index cfdcb34c01..ac94a19035 100644 --- a/common/src/states/charged_ranged.rs +++ b/common/src/states/charged_ranged.rs @@ -119,7 +119,6 @@ impl CharacterBehavior for Data { crit_chance, crit_mult, buff_strength, - rand::random(), ); output_events.emit_server(ServerEvent::Shoot { entity: data.entity, diff --git a/common/src/states/repeater_ranged.rs b/common/src/states/repeater_ranged.rs index 433c62743e..131f4f5ed6 100644 --- a/common/src/states/repeater_ranged.rs +++ b/common/src/states/repeater_ranged.rs @@ -100,7 +100,6 @@ impl CharacterBehavior for Data { crit_chance, crit_mult, buff_strength, - rand::random(), ); output_events.emit_server(ServerEvent::Shoot { entity: data.entity, diff --git a/common/systems/src/buff.rs b/common/systems/src/buff.rs index 3cdc4e3064..a40345fb36 100644 --- a/common/systems/src/buff.rs +++ b/common/systems/src/buff.rs @@ -274,8 +274,7 @@ impl<'a> System<'a> for Sys { by: damage_contributor, cause, time: *read_data.time, - crit: None, - crit_mult: 1.0, + crit_mult: None, instance: rand::random(), }, }); diff --git a/server/src/cmd.rs b/server/src/cmd.rs index b7edf07935..e0f624d643 100644 --- a/server/src/cmd.rs +++ b/server/src/cmd.rs @@ -1056,8 +1056,7 @@ fn handle_health( amount: hp - health.current(), by: None, cause: None, - crit: None, - crit_mult: 1.0, + crit_mult: None, time: *time, instance: rand::random(), }; diff --git a/server/src/events/entity_manipulation.rs b/server/src/events/entity_manipulation.rs index f1dcba1818..8808ee7c1b 100644 --- a/server/src/events/entity_manipulation.rs +++ b/server/src/events/entity_manipulation.rs @@ -89,7 +89,6 @@ pub fn handle_health_change(server: &Server, entity: EcsEntity, change: HealthCh pos: pos.0, info: DamageInfo { amount: change.amount, - crit: change.crit, by: change.by, target: *uid, crit_mult: change.crit_mult, diff --git a/server/src/sys/wiring/dispatch_actions.rs b/server/src/sys/wiring/dispatch_actions.rs index dc841158ab..b6a88fde3c 100644 --- a/server/src/sys/wiring/dispatch_actions.rs +++ b/server/src/sys/wiring/dispatch_actions.rs @@ -115,7 +115,7 @@ fn dispatch_action_spawn_projectile( pos: Pos(Vec3::zero()), dir: Dir::forward(), body: Body::Object(object::Body::Arrow), - projectile: constr.create_projectile(None, 0.0, 1.0, 1.0, rand::random()), + projectile: constr.create_projectile(None, 0.0, 1.0, 1.0), light: None, speed: 5.0, object: None, diff --git a/voxygen/src/ecs/sys/floater.rs b/voxygen/src/ecs/sys/floater.rs index 8133e4002f..6e783b87a8 100644 --- a/voxygen/src/ecs/sys/floater.rs +++ b/voxygen/src/ecs/sys/floater.rs @@ -85,7 +85,7 @@ impl<'a> System<'a> for Sys { floater.timer += dt.0; } - // Clear floaters if newest floater is past show time or health runs out + // Clear floaters if newest floater is past show time if floaters.last().map_or(false, |f| { f.timer > if Some(entity) != my_entity.0 { diff --git a/voxygen/src/hud/mod.rs b/voxygen/src/hud/mod.rs index 51dbd2fa6c..a336024768 100644 --- a/voxygen/src/hud/mod.rs +++ b/voxygen/src/hud/mod.rs @@ -1449,10 +1449,11 @@ impl Hud { let crit = damage_floaters .iter() .rev() - .find(|f| f.info.crit != None) - .map_or(false, |f| f.info.crit.unwrap_or(false)); - let crit_mult = - damage_floaters.last().map_or(1.0, |f| f.info.crit_mult); + .find(|f| f.info.crit_mult.is_some()) + .map_or(false, |f| f.info.crit_mult.is_some()); + let crit_mult = damage_floaters + .last() + .map_or(1.0, |f| f.info.crit_mult.unwrap_or(1.0)); // Increase font size based on fraction of maximum health // "flashes" by having a larger size in the first 100ms @@ -1523,28 +1524,21 @@ impl Hud { .abs() .clamp(Health::HEALTH_EPSILON, health.maximum()) / health.maximum(); - let crit = floater.info.crit.unwrap_or(false); + let crit = floater.info.crit_mult.is_some(); + let crit_mult = floater.info.crit_mult.unwrap_or(1.0); // Increase font size based on fraction of maximum health // "flashes" by having a larger size in the first 100ms // TODO: example let font_size = 30 - + (max_hp_frac - * 10.0 - * if crit { - 1.25 * floater.info.crit_mult - } else { - 1.0 - }) as u32 + + (max_hp_frac * 10.0 * if crit { 1.25 * crit_mult } else { 1.0 }) + as u32 * 3 + if floater.timer < 0.1 { FLASH_MAX * (((1.0 - floater.timer / 0.1) * 10.0 - * if crit { - 1.25 * floater.info.crit_mult - } else { - 1.0 - }) as u32) + * if crit { 1.25 * crit_mult } else { 1.0 }) + as u32) } else { 0 }; @@ -2323,10 +2317,11 @@ impl Hud { let crit = damage_floaters .iter() .rev() - .find(|f| f.info.crit != None) - .map_or(false, |f| f.info.crit.unwrap_or(false)); - let crit_mult = - damage_floaters.last().map_or(1.0, |f| f.info.crit_mult); + .find(|f| f.info.crit_mult.is_some()) + .map_or(false, |f| f.info.crit_mult.is_some()); + let crit_mult = damage_floaters + .last() + .map_or(1.0, |f| f.info.crit_mult.unwrap_or(1.0)); // Increase font size based on fraction of maximum health // "flashes" by having a larger size in the first 100ms @@ -2410,29 +2405,20 @@ impl Hud { Health::HEALTH_EPSILON, health.map_or(1.0, |h| h.maximum()), ) / health.map_or(1.0, |h| h.maximum()); - let crit = floater.info.crit.map_or(false, |c| c); + let crit = floater.info.crit_mult.is_some(); + let crit_mult = floater.info.crit_mult.unwrap_or(1.0); // Increase font size based on fraction of maximum health // "flashes" by having a larger size in the first 100ms let font_size = 30 - + (max_hp_frac - * 10.0 - * if crit { - 1.25 * floater.info.crit_mult - } else { - 1.0 - }) as u32 + + (max_hp_frac * 10.0 * if crit { 1.25 * crit_mult } else { 1.0 }) + as u32 * 3 + if floater.timer < 0.1 { FLASH_MAX * (((1.0 - floater.timer / 0.1) * 10.0 - * if crit { - // FIXME: later - 1.25 * floater.info.crit_mult - //1.0 - } else { - 1.0 - }) as u32) + * if crit { 1.25 * crit_mult } else { 1.0 }) + as u32) } else { 0 }; @@ -4668,15 +4654,16 @@ impl Hud { break; } if floater.info.instance == info.instance - && floater.info.crit.unwrap_or(false) - == info.crit.unwrap_or(false) + && floater.info.crit_mult.is_some() == info.crit_mult.is_some() { floater.info.amount += info.amount; floater.info.crit_mult = info.crit_mult; - floater.info.crit = Some( - floater.info.crit.unwrap_or(false) - || info.crit.unwrap_or(false), - ); + floater.info.crit_mult = if info.crit_mult.is_some() { + info.crit_mult + } else { + floater.info.crit_mult + }; + dbg!(&floater.info.crit_mult); return; } } @@ -4686,14 +4673,12 @@ impl Hud { let last_floater = if info.amount < Health::HEALTH_EPSILON { floater_list.floaters.iter_mut().rev().find(|f| { f.info.amount < Health::HEALTH_EPSILON - && info.crit.unwrap_or(false) - == f.info.crit.unwrap_or(false) + && info.crit_mult.is_some() == f.info.crit_mult.is_some() }) } else { floater_list.floaters.iter_mut().rev().find(|f| { f.info.amount > Health::HEALTH_EPSILON - && info.crit.unwrap_or(false) - == f.info.crit.unwrap_or(false) + && info.crit_mult.is_some() == f.info.crit_mult.is_some() }) }; dbg!(&last_floater); @@ -4701,16 +4686,19 @@ impl Hud { match last_floater { Some(f) // TODO: Change later so it's based on options - if (f.timer < floater::HP_ACCUMULATETIME && !f.info.crit.unwrap_or(false)) => + if f.timer < floater::HP_ACCUMULATETIME && !f.info.crit_mult.is_some() => { //TODO: Add "jumping" animation on floater when it changes its // value f.info.amount += info.amount; f.info.crit_mult = info.crit_mult; - f.info.crit = Some(f.info.crit.unwrap_or(false) || info.crit.unwrap_or(false)); + f.info.crit_mult = if info.crit_mult.is_some() { + info.crit_mult + } else { + f.info.crit_mult + }; }, _ => { - dbg!(&info.amount); floater_list.floaters.push(HpFloater { timer: 0.0, info: *info,