From 5f2b1e45e4544c3887db170fac51fa0367257213 Mon Sep 17 00:00:00 2001 From: Ovahlord Date: Thu, 10 Mar 2022 20:43:12 +0100 Subject: [PATCH] Core/Spells: improve integer to float conversions and checks for spell proc entries --- src/server/game/Entities/Player/Player.cpp | 8 ++++---- src/server/game/Spells/SpellMgr.cpp | 18 +++++++++--------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/src/server/game/Entities/Player/Player.cpp b/src/server/game/Entities/Player/Player.cpp index ffd1e9cd94..a9d6ba4769 100644 --- a/src/server/game/Entities/Player/Player.cpp +++ b/src/server/game/Entities/Player/Player.cpp @@ -7987,7 +7987,7 @@ void Player::CastItemCombatSpell(DamageInfo const& damageInfo, Item* item, ItemT if (m_extraAttacks && spellInfo->HasEffect(SPELL_EFFECT_ADD_EXTRA_ATTACKS)) return; - float chance = (float)spellInfo->ProcChance; + float chance = static_cast(spellInfo->ProcChance); if (proto->SpellPPMRate) { @@ -8048,10 +8048,10 @@ void Player::CastItemCombatSpell(DamageInfo const& damageInfo, Item* item, ItemT float chance = pEnchant->EffectPointsMin[s] != 0 ? float(pEnchant->EffectPointsMin[s]) : GetWeaponProcChance(); if (entry) { - if (entry->ProcsPerMinute) + if (entry->ProcsPerMinute != 0.f) chance = GetPPMProcChance(proto->GetDelay(), entry->ProcsPerMinute, spellInfo); - else if (entry->Chance) - chance = (float)entry->Chance; + else if (entry->Chance != 0.f) + chance = entry->Chance; } // Apply spell mods diff --git a/src/server/game/Spells/SpellMgr.cpp b/src/server/game/Spells/SpellMgr.cpp index aa64d1170a..2ba7b9f1c6 100644 --- a/src/server/game/Spells/SpellMgr.cpp +++ b/src/server/game/Spells/SpellMgr.cpp @@ -1638,23 +1638,23 @@ void SpellMgr::LoadSpellProcs() procEntry.ProcFlags = spellInfo->ProcFlags; if (!procEntry.Charges) procEntry.Charges = spellInfo->ProcCharges; - if (!procEntry.Chance && !procEntry.ProcsPerMinute) - procEntry.Chance = float(spellInfo->ProcChance); + if (procEntry.Chance == 0.f && procEntry.ProcsPerMinute == 0.f) + procEntry.Chance = static_cast(spellInfo->ProcChance); // validate data if (procEntry.SchoolMask & ~SPELL_SCHOOL_MASK_ALL) TC_LOG_ERROR("sql.sql", "`spell_proc` table entry for spellId %u has wrong `SchoolMask` set: %u", spellInfo->Id, procEntry.SchoolMask); if (procEntry.SpellFamilyName && (procEntry.SpellFamilyName < SPELLFAMILY_MAGE || procEntry.SpellFamilyName > SPELLFAMILY_PET || procEntry.SpellFamilyName == 14 || procEntry.SpellFamilyName == 16)) TC_LOG_ERROR("sql.sql", "`spell_proc` table entry for spellId %u has wrong `SpellFamilyName` set: %u", spellInfo->Id, procEntry.SpellFamilyName); - if (procEntry.Chance < 0) + if (procEntry.Chance < 0.f) { TC_LOG_ERROR("sql.sql", "`spell_proc` table entry for spellId %u has negative value in the `Chance` field", spellInfo->Id); - procEntry.Chance = 0; + procEntry.Chance = 0.f; } - if (procEntry.ProcsPerMinute < 0) + if (procEntry.ProcsPerMinute < 0.f) { TC_LOG_ERROR("sql.sql", "`spell_proc` table entry for spellId %u has negative value in the `ProcsPerMinute` field", spellInfo->Id); - procEntry.ProcsPerMinute = 0; + procEntry.ProcsPerMinute = 0.f; } if (!procEntry.ProcFlags) TC_LOG_ERROR("sql.sql", "The `spell_proc` table entry for spellId %u doesn't have any `ProcFlags` value defined, proc will not be triggered.", spellInfo->Id); @@ -1856,7 +1856,7 @@ void SpellMgr::LoadSpellProcs() */ SpellProcEntry procEntry; - procEntry.SchoolMask = 0; + procEntry.SchoolMask = 0; procEntry.ProcFlags = spellInfo->ProcFlags; procEntry.SpellFamilyName = 0; for (uint32 i = 0; i < MAX_SPELL_EFFECTS; ++i) @@ -1908,8 +1908,8 @@ void SpellMgr::LoadSpellProcs() if (addTriggerFlag) procEntry.AttributesMask |= PROC_ATTR_TRIGGERED_CAN_PROC; - procEntry.ProcsPerMinute = 0; - procEntry.Chance = spellInfo->ProcChance; + procEntry.ProcsPerMinute = 0.f; + procEntry.Chance = static_cast(spellInfo->ProcChance); procEntry.Cooldown = Milliseconds::zero(); procEntry.Charges = spellInfo->ProcCharges;