Skip to content

Commit

Permalink
Spell: Fix spells with negative SPELL_EFFECT_THREAT and SPELL_ATTR_EX…
Browse files Browse the repository at this point in the history
…_NO_THREAT
  • Loading branch information
killerwife committed Nov 21, 2023
1 parent 38a0373 commit 389d920
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 33 deletions.
29 changes: 6 additions & 23 deletions src/game/Combat/ThreatManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -502,7 +485,7 @@ void ThreatManager::addThreat(Unit* victim, float threat, bool crit, SpellSchool
{
float redirectedThreat = threat * redirectedMod;
totalMod += redirectedMod;
addThreatDirectly(redirectedTarget, redirectedThreat);
addThreatDirectly(redirectedTarget, redirectedThreat, false);
}
}
if (totalMod != 0.f)
Expand All @@ -512,10 +495,10 @@ void ThreatManager::addThreat(Unit* victim, float threat, bool crit, SpellSchool
}
}

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 online
Expand All @@ -525,7 +508,7 @@ void ThreatManager::addThreatDirectly(Unit* victim, float threat)
else
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);
Expand Down
2 changes: 1 addition & 1 deletion src/game/Combat/ThreatManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,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);
Expand Down
10 changes: 1 addition & 9 deletions src/game/Spells/SpellEffects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7664,7 +7664,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:
Expand Down Expand Up @@ -7975,14 +7975,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);
}

Expand Down

0 comments on commit 389d920

Please sign in to comment.