From de5e26777e8bb8bef2fb3d758388694f6e7ee7ff Mon Sep 17 00:00:00 2001 From: killerwife Date: Sat, 18 Nov 2023 11:00:44 +0100 Subject: [PATCH] Spell: Fix spells with negative SPELL_EFFECT_THREAT and SPELL_ATTR_EX_NO_THREAT --- src/game/Combat/ThreatManager.cpp | 29 ++++++----------------------- src/game/Combat/ThreatManager.h | 2 +- src/game/Spells/SpellEffects.cpp | 10 +--------- 3 files changed, 8 insertions(+), 33 deletions(-) diff --git a/src/game/Combat/ThreatManager.cpp b/src/game/Combat/ThreatManager.cpp index cd275eb17b..522035154b 100644 --- a/src/game/Combat/ThreatManager.cpp +++ b/src/game/Combat/ThreatManager.cpp @@ -48,25 +48,8 @@ float ThreatCalcHelper::CalcThreat(Unit* hatedUnit, Unit* hatingUnit, float thre if (threatSpell) { - // Keep exception to calculate the real threat for SPELL_AURA_MOD_TOTAL_THREAT - bool HasExceptionForNoThreat = false; - for (int i = 0; i < MAX_EFFECT_INDEX; i++) - { - if (threatSpell->EffectApplyAuraName[i] == SPELL_AURA_MOD_TOTAL_THREAT && threatSpell->EffectBasePoints[i] < 0) - { - HasExceptionForNoThreat = true; - break; - } - } - - if (!HasExceptionForNoThreat) - { - if (threatSpell->HasAttribute(SPELL_ATTR_EX_NO_THREAT)) - return 0.0f; - - if (Player* modOwner = hatedUnit->GetSpellModOwner()) - modOwner->ApplySpellMod(threatSpell->Id, SPELLMOD_THREAT, threat); - } + if (Player* modOwner = hatedUnit->GetSpellModOwner()) + modOwner->ApplySpellMod(threatSpell->Id, SPELLMOD_THREAT, threat); if (crit) threat *= hatedUnit->GetTotalAuraMultiplierByMiscMask(SPELL_AURA_MOD_CRITICAL_THREAT, schoolMask); @@ -491,23 +474,23 @@ void ThreatManager::addThreat(Unit* victim, float threat, bool crit, SpellSchool { if (redirectedTarget != getOwner() && redirectedTarget->IsAlive()) { - addThreatDirectly(redirectedTarget, calculatedThreat); + addThreatDirectly(redirectedTarget, calculatedThreat, false); calculatedThreat = 0; // but still need add to threat list } } } - addThreatDirectly(victim, calculatedThreat); + addThreatDirectly(victim, calculatedThreat, threatSpell && threatSpell->HasAttribute(SPELL_ATTR_EX_NO_THREAT)); } -void ThreatManager::addThreatDirectly(Unit* victim, float threat) +void ThreatManager::addThreatDirectly(Unit* victim, float threat, bool noNew) { HostileReference* ref = iThreatContainer.addThreat(victim, threat); // Ref is not in the online refs, search the offline refs next if (!ref) ref = iThreatOfflineContainer.addThreat(victim, threat); - if (!ref) // there was no ref => create a new one + if (!ref && !noNew) // there was no ref => create a new one { HostileReference* hostileReference = new HostileReference(victim, this, 0); // threat has to be 0 here iThreatContainer.addReference(hostileReference); diff --git a/src/game/Combat/ThreatManager.h b/src/game/Combat/ThreatManager.h index e4d15f4cf0..fd6bf15f1d 100644 --- a/src/game/Combat/ThreatManager.h +++ b/src/game/Combat/ThreatManager.h @@ -202,7 +202,7 @@ class ThreatManager void addThreat(Unit* victim, float threat) { addThreat(victim, threat, false, SPELL_SCHOOL_MASK_NONE, nullptr, false); } // add threat as raw value (ignore redirections and expection all mods applied already to it - void addThreatDirectly(Unit* victim, float threat); + void addThreatDirectly(Unit* victim, float threat, bool noNew); void modifyThreatPercent(Unit* victim, int32 threatPercent); // -101 removes whole ref, -100 sets threat to 0, rest modifies it void modifyAllThreatPercent(int32 threatPercent); diff --git a/src/game/Spells/SpellEffects.cpp b/src/game/Spells/SpellEffects.cpp index 75ccf9bdea..10394a1c75 100644 --- a/src/game/Spells/SpellEffects.cpp +++ b/src/game/Spells/SpellEffects.cpp @@ -5551,7 +5551,7 @@ void Spell::EffectTaunt(SpellEffectIndex eff_idx) if (unitTarget->CanHaveThreatList()) { float addedThreat = unitTarget->getThreatManager().GetHighestThreat() - unitTarget->getThreatManager().getThreat(m_caster); - unitTarget->getThreatManager().addThreatDirectly(m_caster, addedThreat); + unitTarget->getThreatManager().addThreatDirectly(m_caster, addedThreat, false); unitTarget->getThreatManager().setCurrentVictimByTarget(m_caster); // force changes the target to caster of taunt } // Units without threat lists but with AI are susceptible to attack target interference by taunt effect: @@ -5750,14 +5750,6 @@ void Spell::EffectThreat(SpellEffectIndex /*eff_idx*/) if (!unitTarget->CanHaveThreatList()) return; - if (!m_caster->IsInCombat() || !unitTarget->IsInCombat()) - { - if (unitTarget->AI()) - unitTarget->AI()->AttackStart(m_caster); - else - unitTarget->EngageInCombatWith(m_caster); - } - unitTarget->AddThreat(m_caster, float(damage), false, GetSpellSchoolMask(m_spellInfo), m_spellInfo); }