aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorOvah <dreadkiller@gmx.de>2020-09-14 19:47:51 +0200
committerShauren <shauren.trinity@gmail.com>2022-02-06 00:29:15 +0100
commitc295cb9814f4c2a1878aa047cefe0cfbc7958f93 (patch)
tree278fa921d1b7f7ae86c9639048351185663446c2 /src
parent51622e6642e787ee68f8b38ed2382f26ca9f4b8b (diff)
Core/Spells: cleaned up and improved spell focusing behavior (PR #25440)
(cherry picked from commit 39a436bd658790d39d3cfa64e18f49544475dfe3)
Diffstat (limited to 'src')
-rw-r--r--src/server/game/Entities/Creature/Creature.cpp36
-rw-r--r--src/server/game/Spells/Auras/SpellAuraEffects.cpp9
-rw-r--r--src/server/game/Spells/Spell.cpp32
3 files changed, 26 insertions, 51 deletions
diff --git a/src/server/game/Entities/Creature/Creature.cpp b/src/server/game/Entities/Creature/Creature.cpp
index 8688592fc0b..04f85e9a502 100644
--- a/src/server/game/Entities/Creature/Creature.cpp
+++ b/src/server/game/Entities/Creature/Creature.cpp
@@ -3256,41 +3256,15 @@ void Creature::SetSpellFocus(Spell const* focusSpell, WorldObject const* target)
_spellFocusInfo.Spell = focusSpell;
bool const noTurnDuringCast = spellInfo->HasAttribute(SPELL_ATTR5_DONT_TURN_DURING_CAST);
+ bool const turnDisabled = HasUnitFlag2(UNIT_FLAG2_CANNOT_TURN);
// set target, then force send update packet to players if it changed to provide appropriate facing
- ObjectGuid newTarget = target ? target->GetGUID() : ObjectGuid::Empty;
+ ObjectGuid newTarget = (target && !noTurnDuringCast && !turnDisabled) ? target->GetGUID() : ObjectGuid::Empty;
if (GetTarget() != newTarget)
- {
SetUpdateFieldValue(m_values.ModifyValue(&Unit::m_unitData).ModifyValue(&UF::UnitData::Target), newTarget);
- if ( // here we determine if the (relatively expensive) forced update is worth it, or whether we can afford to wait until the scheduled update tick
- ( // only require instant update for spells that actually have a visual
- spellInfo->GetSpellVisual()
- ) && (
- !focusSpell->GetCastTime() || // if the spell is instant cast
- noTurnDuringCast // client gets confused if we attempt to turn at the regularly scheduled update packet
- )
- )
- {
- std::vector<Player*> playersNearby;
- GetPlayerListInGrid(playersNearby, GetVisibilityRange());
- for (Player* player : playersNearby)
- {
- // only update players that are known to the client (have already been created)
- if (player->HaveAtClient(this))
- SendUpdateToPlayer(player);
- }
- }
- }
-
- if (!HasUnitFlag2(UNIT_FLAG2_CANNOT_TURN))
- {
- // Face the target - we need to do this before the unit state is modified for no-turn spells
- if (target)
- SetFacingToObject(target, false);
- else if (noTurnDuringCast)
- if (Unit* victim = GetVictim())
- SetFacingToObject(victim, false); // ensure orientation is correct at beginning of cast
- }
+ // If we are not allowed to turn during cast but have a focus target, face the target
+ if (!turnDisabled && noTurnDuringCast && target)
+ SetFacingToObject(target, false);
if (noTurnDuringCast)
AddUnitState(UNIT_STATE_FOCUSING);
diff --git a/src/server/game/Spells/Auras/SpellAuraEffects.cpp b/src/server/game/Spells/Auras/SpellAuraEffects.cpp
index 90682731ef0..1f8799239a0 100644
--- a/src/server/game/Spells/Auras/SpellAuraEffects.cpp
+++ b/src/server/game/Spells/Auras/SpellAuraEffects.cpp
@@ -1065,6 +1065,15 @@ void AuraEffect::PeriodicTick(AuraApplication* aurApp, Unit* caster) const
Unit* target = aurApp->GetTarget();
+ // Update serverside orientation of tracking channeled auras on periodic update ticks
+ if (caster && m_spellInfo->IsChanneled() && m_spellInfo->HasAttribute(SPELL_ATTR1_CHANNEL_TRACK_TARGET) && caster->m_unitData->ChannelObjects.size())
+ {
+ ObjectGuid const channelGuid = caster->m_unitData->ChannelObjects[0];
+ if (channelGuid != caster->GetGUID())
+ if (WorldObject const* objectTarget = ObjectAccessor::GetWorldObject(*caster, channelGuid))
+ caster->SetInFront(objectTarget);
+ }
+
switch (GetAuraType())
{
case SPELL_AURA_PERIODIC_DUMMY:
diff --git a/src/server/game/Spells/Spell.cpp b/src/server/game/Spells/Spell.cpp
index 2cbfb94b1b7..2952294b8d4 100644
--- a/src/server/game/Spells/Spell.cpp
+++ b/src/server/game/Spells/Spell.cpp
@@ -3308,16 +3308,15 @@ SpellCastResult Spell::prepare(SpellCastTargets const& targets, AuraEffect const
}
}
- // focus if not controlled creature
- if (m_caster->GetTypeId() == TYPEID_UNIT && !m_caster->ToUnit()->HasUnitFlag(UNIT_FLAG_POSSESSED))
+ // Creatures focus their target when possible
+ if (m_casttime && m_caster->IsCreature() && !m_spellInfo->IsNextMeleeSwingSpell() && !IsAutoRepeat() && !m_caster->ToUnit()->HasUnitFlag(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
@@ -3469,10 +3468,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)
@@ -3554,13 +3549,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->ToUnit()->HasUnitFlag(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->HasUnitFlag(UNIT_FLAG_POSSESSED))
+ creatureCaster->SetInFront(ObjectAccessor::GetUnit(*creatureCaster, creatureCaster->GetTarget()));
SelectSpellTargets();