From 3ef4af0195e327ed713410f2d6e908e4a87e5b73 Mon Sep 17 00:00:00 2001 From: Imbris Date: Fri, 7 Apr 2023 02:10:24 -0400 Subject: [PATCH] Various tweaks: * Store result of large condition expression in a variable before using in if statement (improves readability of code). * Buff doc comment improvements. Adding periods is neccessary since these will be merged into one line in the generated docs. * Add note on AbilityContext that AbilityContext::None is intended to be used rather than AbilityContext::Stance(Stance::None) perhaps in the future we can add some serde shenanigans to make this work better, but it is probably best to wait to see how this type evolves first. --- common/src/combat.rs | 5 +- common/src/comp/buff.rs | 76 +++++++++++++------------- common/src/comp/inventory/item/tool.rs | 4 ++ 3 files changed, 45 insertions(+), 40 deletions(-) diff --git a/common/src/combat.rs b/common/src/combat.rs index 4f72e7ffa8..df66b1d41d 100644 --- a/common/src/combat.rs +++ b/common/src/combat.rs @@ -517,7 +517,7 @@ impl Attack { .filter(|e| e.target.map_or(true, |t| t == target_group)) .filter(|e| !avoid_effect(e)) { - if effect.requirements.iter().all(|req| match req { + let requirements_met = effect.requirements.iter().all(|req| match req { CombatRequirement::AnyDamage => accumulated_damage > 0.0 && target.health.is_some(), CombatRequirement::Energy(r) => { if let Some(AttackerInfo { @@ -559,7 +559,8 @@ impl Attack { false } }, - }) { + }); + if requirements_met { is_applied = true; match effect.effect { CombatEffect::Knockback(kb) => { diff --git a/common/src/comp/buff.rs b/common/src/comp/buff.rs index caac506636..5a29d122da 100644 --- a/common/src/comp/buff.rs +++ b/common/src/comp/buff.rs @@ -22,67 +22,67 @@ use super::Body; )] pub enum BuffKind { // Buffs - /// Restores health/time for some period - /// Strength should be the healing per second + /// Restores health/time for some period. + /// Strength should be the healing per second. Regeneration, - /// Restores health/time for some period for consumables - /// Strength should be the healing per second + /// Restores health/time for some period for consumables. + /// Strength should be the healing per second. Saturation, - /// Applied when drinking a potion - /// Strength should be the healing per second + /// Applied when drinking a potion. + /// Strength should be the healing per second. Potion, - /// Applied when sitting at a campfire - /// Strength is fraction of health restored per second + /// Applied when sitting at a campfire. + /// Strength is fraction of health restored per second. CampfireHeal, - /// Restores energy/time for some period - /// Strength should be the healing per second + /// Restores energy/time for some period. + /// Strength should be the healing per second. EnergyRegen, - /// Raises maximum energy - /// Strength should be 10x the effect to max energy + /// Raises maximum energy. + /// Strength should be 10x the effect to max energy. IncreaseMaxEnergy, - /// Raises maximum health - /// Strength should be the effect to max health + /// Raises maximum health. + /// Strength should be the effect to max health. IncreaseMaxHealth, - /// Makes you immune to attacks - /// Strength does not affect this buff + /// Makes you immune to attacks. + /// Strength does not affect this buff. Invulnerability, - /// Reduces incoming damage + /// Reduces incoming damage. /// Strength scales the damage reduction non-linearly. 0.5 provides 50% DR, - /// 1.0 provides 67% DR + /// 1.0 provides 67% DR. ProtectingWard, - /// Increases movement speed and gives health regeneration + /// Increases movement speed and gives health regeneration. /// Strength scales the movement speed linearly. 0.5 is 150% speed, 1.0 is - /// 200% speed. Provides regeneration at 10x the value of the strength + /// 200% speed. Provides regeneration at 10x the value of the strength. Frenzied, /// Increases movement and attack speed, but removes chance to get critical /// hits. Strength scales strength of both effects linearly. 0.5 is a /// 50% increase, 1.0 is a 100% increase. Hastened, /// Increases resistance to incoming poise, and poise damage dealt as health - /// is lost from the time the buff activated + /// is lost from the time the buff activated. /// Strength scales the resistance non-linearly. 0.5 provides 50%, 1.0 - /// provides 67% + /// provides 67%. /// Strength scales the poise damage increase linearly, a strength of 1.0 /// and n health less from activation will cause poise damage to increase by - /// n% + /// n%. Fortitude, - /// Increases both attack damage and vulnerability to damage - /// Damage increases linearly with strength, 1.0 is a 100% increase + /// Increases both attack damage and vulnerability to damage. + /// Damage increases linearly with strength, 1.0 is a 100% increase. /// Damage reduction decreases linearly with strength, 1.0 is a 100% - /// decrease + /// decrease. Reckless, // Debuffs - /// Does damage to a creature over time - /// Strength should be the DPS of the debuff + /// Does damage to a creature over time. + /// Strength should be the DPS of the debuff. Burning, - /// Lowers health over time for some duration - /// Strength should be the DPS of the debuff + /// Lowers health over time for some duration. + /// Strength should be the DPS of the debuff. Bleeding, - /// Lower a creature's max health over time + /// Lower a creature's max health over time. /// Strength only affects the target max health, 0.5 targets 50% of base - /// max, 1.0 targets 100% of base max + /// max, 1.0 targets 100% of base max. Cursed, - /// Reduces movement speed and causes bleeding damage + /// Reduces movement speed and causes bleeding damage. /// Strength scales the movement speed debuff non-linearly. 0.5 is 50% /// speed, 1.0 is 33% speed. Bleeding is at 4x the value of the strength. Crippled, @@ -99,8 +99,8 @@ pub enum BuffKind { /// Strength scales the movement speed debuff non-linearly. 0.5 is 50% /// speed, 1.0 is 33% speed. Ensnared, - /// Drain stamina to a creature over time - /// Strength should be the energy per second of the debuff + /// Drain stamina to a creature over time. + /// Strength should be the energy per second of the debuff. Poisoned, /// Results from having an attack parried. /// Causes your attack speed to be slower to emulate the recover duration of @@ -115,7 +115,7 @@ pub enum BuffKind { #[cfg(not(target_arch = "wasm32"))] impl BuffKind { - /// Checks if buff is buff or debuff + /// Checks if buff is buff or debuff. pub fn is_buff(self) -> bool { match self { BuffKind::Regeneration @@ -145,7 +145,7 @@ impl BuffKind { } } - /// Checks if buff should queue + /// Checks if buff should queue. pub fn queues(self) -> bool { matches!(self, BuffKind::Saturation) } /// Checks if the buff can affect other buff effects applied in the same @@ -417,7 +417,7 @@ pub enum BuffChange { any_required: Vec, none_required: Vec, }, - // Refreshes durations of all buffs with this kind + /// Refreshes durations of all buffs with this kind. Refresh(BuffKind), } diff --git a/common/src/comp/inventory/item/tool.rs b/common/src/comp/inventory/item/tool.rs index f1fe2f7ef3..75f455234a 100644 --- a/common/src/comp/inventory/item/tool.rs +++ b/common/src/comp/inventory/item/tool.rs @@ -360,6 +360,10 @@ impl AbilityKind { #[derive(Clone, Debug, Serialize, Deserialize, Copy, Eq, PartialEq, Hash)] pub enum AbilityContext { + /// Note, in this context `Stance::None` isn't intended to be used. e.g. + /// `AbilityContext::None` should always be used instead of + /// `AbilityContext::Stance(Stance::None)` in the ability map config + /// files(s). Stance(Stance), None, }