aboutsummaryrefslogtreecommitdiff
path: root/src/server/game/Spells/Spell.cpp
diff options
context:
space:
mode:
authorOvah <dreadkiller@gmx.de>2020-09-14 19:47:51 +0200
committerGitHub <noreply@github.com>2020-09-14 19:47:51 +0200
commit39a436bd658790d39d3cfa64e18f49544475dfe3 (patch)
treea99e66b80e2aadd787d01ec3fc61ee60ef3d7db4 /src/server/game/Spells/Spell.cpp
parentd52acf1b72c702637d10cce19e121435308e8410 (diff)
Core/Spells: cleaned up and improved spell focusing behavior (PR #25440)
Diffstat (limited to 'src/server/game/Spells/Spell.cpp')
-rw-r--r--src/server/game/Spells/Spell.cpp34
1 files changed, 13 insertions, 21 deletions
diff --git a/src/server/game/Spells/Spell.cpp b/src/server/game/Spells/Spell.cpp
index 012d95132f7..ea34d8c2ddc 100644
--- a/src/server/game/Spells/Spell.cpp
+++ b/src/server/game/Spells/Spell.cpp
@@ -3116,16 +3116,15 @@ SpellCastResult Spell::prepare(SpellCastTargets const& targets, AuraEffect const
}
}
- // focus if not controlled creature
- if (m_caster->GetTypeId() == TYPEID_UNIT && !m_caster->HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_POSSESSED))
+ // Creatures focus their target when possible
+ if (m_casttime && m_caster->IsCreature() && !m_spellInfo->IsNextMeleeSwingSpell() && !IsAutoRepeat() && !m_caster->HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_POSSESSED))
{
- if (!(m_spellInfo->IsNextMeleeSwingSpell() || IsAutoRepeat()))
- {
- if (m_targets.GetObjectTarget() && m_caster != m_targets.GetObjectTarget())
- m_caster->ToCreature()->SetSpellFocus(this, m_targets.GetObjectTarget());
- else if (m_spellInfo->HasAttribute(SPELL_ATTR5_DONT_TURN_DURING_CAST))
- m_caster->ToCreature()->SetSpellFocus(this, nullptr);
- }
+ // Channeled spells and some triggered spells do not focus a cast target. They face their target later on via channel object guid and via spell attribute or not at all
+ bool const focusTarget = !m_spellInfo->IsChanneled() && !(_triggeredCastFlags & TRIGGERED_IGNORE_SET_FACING);
+ if (focusTarget && m_targets.GetObjectTarget() && m_caster != m_targets.GetObjectTarget())
+ m_caster->ToCreature()->SetSpellFocus(this, m_targets.GetObjectTarget());
+ else
+ m_caster->ToCreature()->SetSpellFocus(this, nullptr);
}
// set timer base at cast time
@@ -3282,10 +3281,6 @@ void Spell::_cast(bool skipCheck)
SetExecutedCurrently(true);
- if (!(_triggeredCastFlags & TRIGGERED_IGNORE_SET_FACING))
- if (m_caster->GetTypeId() == TYPEID_UNIT && m_targets.GetObjectTarget() && m_caster != m_targets.GetObjectTarget())
- m_caster->ToCreature()->SetInFront(m_targets.GetObjectTarget());
-
// Should this be done for original caster?
Player* modOwner = m_caster->GetSpellModOwner();
if (modOwner)
@@ -3368,13 +3363,10 @@ void Spell::_cast(bool skipCheck)
}
}
}
-
- // if the spell allows the creature to turn while casting, then adjust server-side orientation to face the target now
- // client-side orientation is handled by the client itself, as the cast target is targeted due to Creature::SetSpellFocusTarget
- if (m_caster->GetTypeId() == TYPEID_UNIT && !m_caster->HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_POSSESSED))
- if (!m_spellInfo->HasAttribute(SPELL_ATTR5_DONT_TURN_DURING_CAST))
- if (WorldObject* objTarget = m_targets.GetObjectTarget())
- m_caster->ToCreature()->SetInFront(objTarget);
+ // The spell focusing is making sure that we have a valid cast target guid when we need it so only check for a guid value here.
+ if (Creature* creatureCaster = m_caster->ToCreature())
+ if (!creatureCaster->GetTarget().IsEmpty() && !creatureCaster->HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_POSSESSED))
+ creatureCaster->SetInFront(ObjectAccessor::GetUnit(*creatureCaster, creatureCaster->GetTarget()));
SelectSpellTargets();
@@ -4615,7 +4607,7 @@ void Spell::SendChannelStart(uint32 duration)
if (!unitCaster)
return;
- ObjectGuid channelTarget = m_targets.GetObjectTargetGUID();
+ ObjectGuid channelTarget = m_targets.HasDst() ? unitCaster->GetGUID() : m_targets.GetObjectTargetGUID();
if (!channelTarget && !m_spellInfo->NeedsExplicitUnitTarget())
if (m_UniqueTargetInfo.size() + m_UniqueGOTargetInfo.size() == 1) // this is for TARGET_SELECT_CATEGORY_NEARBY
channelTarget = !m_UniqueTargetInfo.empty() ? m_UniqueTargetInfo.front().TargetGUID : m_UniqueGOTargetInfo.front().TargetGUID;