From 4fd1626e5fcf0a25c433edc3b586bf8f34efd70a Mon Sep 17 00:00:00 2001 From: Sam Date: Mon, 26 Jun 2023 21:27:52 -0400 Subject: [PATCH] Address review comments --- common/src/combat.rs | 6 +++--- common/src/comp/ability.rs | 8 +++++--- common/src/comp/inventory/item/tool.rs | 17 +++++++++-------- common/src/states/charged_melee.rs | 9 +++------ 4 files changed, 20 insertions(+), 20 deletions(-) diff --git a/common/src/combat.rs b/common/src/combat.rs index b97f80b15f..2f74fbe4d5 100644 --- a/common/src/combat.rs +++ b/common/src/combat.rs @@ -139,11 +139,11 @@ impl Attack { if damage.value > 0.0 { let attacker_penetration = attacker .and_then(|a| a.stats) - .map_or(0.0, |s| dbg!(s.mitigations_penetration)) + .map_or(0.0, |s| s.mitigations_penetration) .clamp(0.0, 1.0); let raw_damage_reduction = Damage::compute_damage_reduction(Some(damage), target.inventory, target.stats, msm); - let damage_reduction = (1.0 - dbg!(attacker_penetration)) * dbg!(raw_damage_reduction); + let damage_reduction = (1.0 - attacker_penetration) * raw_damage_reduction; let block_reduction = if let (Some(char_state), Some(ori)) = (target.char_state, target.ori) { if ori.look_vec().angle_between(-*dir) < char_state.block_angle() { @@ -175,7 +175,7 @@ impl Attack { } else { 0.0 }; - 1.0 - (1.0 - dbg!(damage_reduction)) * (1.0 - block_reduction) + 1.0 - (1.0 - damage_reduction) * (1.0 - block_reduction) } else { 0.0 } diff --git a/common/src/comp/ability.rs b/common/src/comp/ability.rs index c77e3a0efd..81035c749a 100644 --- a/common/src/comp/ability.rs +++ b/common/src/comp/ability.rs @@ -6,7 +6,9 @@ use crate::{ character_state::AttackFilters, inventory::{ item::{ - tool::{AbilityContext, AbilityItem, AbilityKind, Stats, ToolKind}, + tool::{ + AbilityContext, AbilityItem, AbilityKind, ContextualIndex, Stats, ToolKind, + }, ItemKind, }, slot::EquipSlot, @@ -462,7 +464,7 @@ impl From for Ability { #[derive(Copy, Clone, Serialize, Deserialize, Debug, PartialEq, Eq)] pub struct SpecifiedAbility { pub ability: Ability, - pub context_index: Option, + pub context_index: Option, } impl SpecifiedAbility { @@ -480,7 +482,7 @@ impl SpecifiedAbility { abilities, } => spec_ability .context_index - .and_then(|i| abilities.get(i)) + .and_then(|i| abilities.get(i.0)) .map_or(pseudo_id.as_str(), |(_, (_, a))| a.id.as_str()), } } diff --git a/common/src/comp/inventory/item/tool.rs b/common/src/comp/inventory/item/tool.rs index 60ffb0d456..513d564935 100644 --- a/common/src/comp/inventory/item/tool.rs +++ b/common/src/comp/inventory/item/tool.rs @@ -309,6 +309,9 @@ pub enum AbilityKind { }, } +#[derive(Clone, Debug, Serialize, Deserialize, Copy, Eq, PartialEq)] +pub struct ContextualIndex(pub usize); + impl AbilityKind { pub fn map U>(self, mut f: F) -> AbilityKind { match self { @@ -346,7 +349,7 @@ impl AbilityKind { &self, skillset: Option<&SkillSet>, contexts: &[AbilityContext], - ) -> Option<(&T, Option)> { + ) -> Option<(&T, Option)> { let unlocked = |s: Option, a| { // If there is a skill requirement and the skillset does not contain the // required skill, return None @@ -369,7 +372,7 @@ impl AbilityKind { req_contexts .iter() .all(|req| req.fulfilled_by(contexts)) - .then_some((a, Some(i))) + .then_some((a, Some(ContextualIndex(i)))) }), } } @@ -420,9 +423,7 @@ impl AbilityContext { fn fulfilled_by(&self, contexts: &[AbilityContext]) -> bool { match self { - basic_context @ Self::Stance(_) | basic_context @ Self::DualWieldingSameKind => { - contexts.contains(basic_context) - }, + Self::Stance(_) | Self::DualWieldingSameKind => contexts.contains(self), Self::Combo(required) => contexts .iter() .filter_map(|context| { @@ -486,7 +487,7 @@ impl AbilitySet { &self, skillset: Option<&SkillSet>, contexts: &[AbilityContext], - ) -> Option<(&T, Option)> { + ) -> Option<(&T, Option)> { self.primary.ability(skillset, contexts) } @@ -494,7 +495,7 @@ impl AbilitySet { &self, skillset: Option<&SkillSet>, contexts: &[AbilityContext], - ) -> Option<(&T, Option)> { + ) -> Option<(&T, Option)> { self.secondary.ability(skillset, contexts) } @@ -503,7 +504,7 @@ impl AbilitySet { index: usize, skillset: Option<&SkillSet>, contexts: &[AbilityContext], - ) -> Option<(&T, Option)> { + ) -> Option<(&T, Option)> { self.abilities .get(index) .and_then(|a| a.ability(skillset, contexts)) diff --git a/common/src/states/charged_melee.rs b/common/src/states/charged_melee.rs index 3fcd53ae53..e12340b049 100644 --- a/common/src/states/charged_melee.rs +++ b/common/src/states/charged_melee.rs @@ -155,12 +155,9 @@ impl CharacterBehavior for Data { let crit_data = get_crit_data(data, self.static_data.ability_info); let tool_stats = get_tool_stats(data, self.static_data.ability_info); - let additional_combo = if self.static_data.additional_combo != 0 { - let increment = 1.0 / self.static_data.additional_combo as f32; - (self.charge_amount / increment + 0.5).floor() as i32 - } else { - 0 - }; + let additional_combo = + (self.charge_amount * self.static_data.additional_combo as f32 + 0.5) + .floor() as i32; data.updater.insert( data.entity,