From 03fda1b0fe974c4ebc906caf0db7bfa854abd3cc Mon Sep 17 00:00:00 2001 From: Eduardo Dantas Date: Wed, 6 Dec 2023 23:23:39 -0300 Subject: [PATCH 1/5] fix: division by zero exception --- src/creatures/combat/spells.cpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/creatures/combat/spells.cpp b/src/creatures/combat/spells.cpp index 4ae9d69ae6b..096768f1eac 100644 --- a/src/creatures/combat/spells.cpp +++ b/src/creatures/combat/spells.cpp @@ -609,7 +609,11 @@ void Spell::setWheelOfDestinyBoost(WheelSpellBoost_t boost, WheelSpellGrade_t gr void Spell::applyCooldownConditions(std::shared_ptr player) const { WheelSpellGrade_t spellGrade = player->wheel()->getSpellUpgrade(getName()); bool isUpgraded = getWheelOfDestinyUpgraded() && static_cast(spellGrade) > 0; - auto rate_cooldown = (int32_t)g_configManager().getFloat(RATE_SPELL_COOLDOWN, __FUNCTION__); + auto rate_cooldown = g_configManager().getFloat(RATE_SPELL_COOLDOWN, __FUNCTION__); + if (std::abs(rate_cooldown) < std::numeric_limits::epsilon()) { + rate_cooldown = 0.1; + } + if (cooldown > 0) { int32_t spellCooldown = cooldown; if (isUpgraded) { From 16ce41a45db483b59995b230e285dd10e76c8dbc Mon Sep 17 00:00:00 2001 From: Eduardo Dantas Date: Wed, 6 Dec 2023 23:27:45 -0300 Subject: [PATCH 2/5] fix: add comments --- src/creatures/combat/spells.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/creatures/combat/spells.cpp b/src/creatures/combat/spells.cpp index 096768f1eac..0d20149e4d8 100644 --- a/src/creatures/combat/spells.cpp +++ b/src/creatures/combat/spells.cpp @@ -609,9 +609,9 @@ void Spell::setWheelOfDestinyBoost(WheelSpellBoost_t boost, WheelSpellGrade_t gr void Spell::applyCooldownConditions(std::shared_ptr player) const { WheelSpellGrade_t spellGrade = player->wheel()->getSpellUpgrade(getName()); bool isUpgraded = getWheelOfDestinyUpgraded() && static_cast(spellGrade) > 0; - auto rate_cooldown = g_configManager().getFloat(RATE_SPELL_COOLDOWN, __FUNCTION__); + // Safety check to prevent division by zero if (std::abs(rate_cooldown) < std::numeric_limits::epsilon()) { - rate_cooldown = 0.1; + rate_cooldown = 0.1; // Safe minimum value } if (cooldown > 0) { From 8689df7b1241adbbcd96eac29a8da623b3b5384f Mon Sep 17 00:00:00 2001 From: GitHub Actions Date: Thu, 7 Dec 2023 02:28:19 +0000 Subject: [PATCH 3/5] Code format - (Clang-format) --- src/creatures/combat/spells.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/creatures/combat/spells.cpp b/src/creatures/combat/spells.cpp index 0d20149e4d8..412d1c97932 100644 --- a/src/creatures/combat/spells.cpp +++ b/src/creatures/combat/spells.cpp @@ -611,7 +611,7 @@ void Spell::applyCooldownConditions(std::shared_ptr player) const { bool isUpgraded = getWheelOfDestinyUpgraded() && static_cast(spellGrade) > 0; // Safety check to prevent division by zero if (std::abs(rate_cooldown) < std::numeric_limits::epsilon()) { - rate_cooldown = 0.1; // Safe minimum value + rate_cooldown = 0.1; // Safe minimum value } if (cooldown > 0) { From 3e460e28db70d043417ac36ef61d833c486345c9 Mon Sep 17 00:00:00 2001 From: Eduardo Dantas Date: Wed, 6 Dec 2023 23:54:07 -0300 Subject: [PATCH 4/5] fix: compilation --- src/creatures/combat/spells.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/creatures/combat/spells.cpp b/src/creatures/combat/spells.cpp index 412d1c97932..3cf08480d67 100644 --- a/src/creatures/combat/spells.cpp +++ b/src/creatures/combat/spells.cpp @@ -610,6 +610,7 @@ void Spell::applyCooldownConditions(std::shared_ptr player) const { WheelSpellGrade_t spellGrade = player->wheel()->getSpellUpgrade(getName()); bool isUpgraded = getWheelOfDestinyUpgraded() && static_cast(spellGrade) > 0; // Safety check to prevent division by zero + auto rate_cooldown = g_configManager().getFloat(RATE_SPELL_COOLDOWN, __FUNCTION__); if (std::abs(rate_cooldown) < std::numeric_limits::epsilon()) { rate_cooldown = 0.1; // Safe minimum value } From 8d089e5e06b29fa6ee7e4dd4ca6bc95977324203 Mon Sep 17 00:00:00 2001 From: Eduardo Dantas Date: Thu, 7 Dec 2023 09:24:03 -0300 Subject: [PATCH 5/5] fix: to camel case --- src/creatures/combat/spells.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/creatures/combat/spells.cpp b/src/creatures/combat/spells.cpp index 3cf08480d67..d8c71c2a93c 100644 --- a/src/creatures/combat/spells.cpp +++ b/src/creatures/combat/spells.cpp @@ -610,9 +610,9 @@ void Spell::applyCooldownConditions(std::shared_ptr player) const { WheelSpellGrade_t spellGrade = player->wheel()->getSpellUpgrade(getName()); bool isUpgraded = getWheelOfDestinyUpgraded() && static_cast(spellGrade) > 0; // Safety check to prevent division by zero - auto rate_cooldown = g_configManager().getFloat(RATE_SPELL_COOLDOWN, __FUNCTION__); - if (std::abs(rate_cooldown) < std::numeric_limits::epsilon()) { - rate_cooldown = 0.1; // Safe minimum value + auto rateCooldown = g_configManager().getFloat(RATE_SPELL_COOLDOWN, __FUNCTION__); + if (std::abs(rateCooldown) < std::numeric_limits::epsilon()) { + rateCooldown = 0.1; // Safe minimum value } if (cooldown > 0) { @@ -621,7 +621,7 @@ void Spell::applyCooldownConditions(std::shared_ptr player) const { spellCooldown -= getWheelOfDestinyBoost(WheelSpellBoost_t::COOLDOWN, spellGrade); } if (spellCooldown > 0) { - std::shared_ptr condition = Condition::createCondition(CONDITIONID_DEFAULT, CONDITION_SPELLCOOLDOWN, spellCooldown / rate_cooldown, 0, false, spellId); + std::shared_ptr condition = Condition::createCondition(CONDITIONID_DEFAULT, CONDITION_SPELLCOOLDOWN, spellCooldown / rateCooldown, 0, false, spellId); player->addCondition(condition); } } @@ -632,7 +632,7 @@ void Spell::applyCooldownConditions(std::shared_ptr player) const { spellGroupCooldown -= getWheelOfDestinyBoost(WheelSpellBoost_t::GROUP_COOLDOWN, spellGrade); } if (spellGroupCooldown > 0) { - std::shared_ptr condition = Condition::createCondition(CONDITIONID_DEFAULT, CONDITION_SPELLGROUPCOOLDOWN, spellGroupCooldown / rate_cooldown, 0, false, group); + std::shared_ptr condition = Condition::createCondition(CONDITIONID_DEFAULT, CONDITION_SPELLGROUPCOOLDOWN, spellGroupCooldown / rateCooldown, 0, false, group); player->addCondition(condition); } } @@ -643,7 +643,7 @@ void Spell::applyCooldownConditions(std::shared_ptr player) const { spellSecondaryGroupCooldown -= getWheelOfDestinyBoost(WheelSpellBoost_t::SECONDARY_GROUP_COOLDOWN, spellGrade); } if (spellSecondaryGroupCooldown > 0) { - std::shared_ptr condition = Condition::createCondition(CONDITIONID_DEFAULT, CONDITION_SPELLGROUPCOOLDOWN, spellSecondaryGroupCooldown / rate_cooldown, 0, false, secondaryGroup); + std::shared_ptr condition = Condition::createCondition(CONDITIONID_DEFAULT, CONDITION_SPELLGROUPCOOLDOWN, spellSecondaryGroupCooldown / rateCooldown, 0, false, secondaryGroup); player->addCondition(condition); } }