From 3274117cec9c25f619d6bd0e6dc9915cee6abaf7 Mon Sep 17 00:00:00 2001 From: Ovahlord Date: Wed, 9 Sep 2020 20:08:35 +0200 Subject: [PATCH] Core/Spells: cleaned up and improved spell focusing behavior * removed hacky update_object call from SetSpellFocus helper * corrected facing behaivior in SetSpellFocus * spells with SPELL_ATTR5_DONT_TURN_DURING_CAST will no longer set a target guid for proper clientside facing behaivior * channeled spells with a destination target will no longer pick a objectTarget * update serverside orientation for channeled spells with SPELL_ATTR1_CHANNEL_TRACK_TARGET --- .../game/Entities/Creature/Creature.cpp | 44 +++---------------- src/server/game/Entities/Unit/Unit.cpp | 7 --- src/server/game/Spells/Spell.cpp | 42 +++++++++--------- .../boss_theralion_and_valiona.cpp | 4 -- .../GrimBatol/boss_drahga_shadowburner.cpp | 31 ++++++------- .../GrimBatol/boss_general_umbriss.cpp | 8 ---- 6 files changed, 38 insertions(+), 98 deletions(-) diff --git a/src/server/game/Entities/Creature/Creature.cpp b/src/server/game/Entities/Creature/Creature.cpp index b630b12f11..89157716d5 100644 --- a/src/server/game/Entities/Creature/Creature.cpp +++ b/src/server/game/Entities/Creature/Creature.cpp @@ -842,13 +842,6 @@ void Creature::Update(uint32 diff) Regenerate(GetPowerType(), diff); - // Update serverside orientation of channeled spells that are suposed to track the channel target - if (Spell const* spell = m_currentSpells[CURRENT_CHANNELED_SPELL]) - if (spell->GetSpellInfo()->HasAttribute(SPELL_ATTR1_CHANNEL_TRACK_TARGET)) - if (ObjectGuid guid = GetChannelObjectGuid()) - if (WorldObject* target = ObjectAccessor::GetWorldObject(*this, guid)) - SetOrientation(GetAngle(target)); - if (CanNotReachTarget() && !IsInEvadeMode() && !GetMap()->IsRaid()) { m_cannotReachTimer += diff; @@ -3089,42 +3082,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 = HasFlag(UNIT_FIELD_FLAGS_2, UNIT_FLAG2_DISABLE_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 (GetGuidValue(UNIT_FIELD_TARGET) != newTarget) - { SetGuidValue(UNIT_FIELD_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->SpellVisual[0] || - spellInfo->SpellVisual[1] - ) && ( - !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 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 (!HasFlag(UNIT_FIELD_FLAGS_2, UNIT_FLAG2_DISABLE_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/Entities/Unit/Unit.cpp b/src/server/game/Entities/Unit/Unit.cpp index 2957654620..e9be0eca55 100644 --- a/src/server/game/Entities/Unit/Unit.cpp +++ b/src/server/game/Entities/Unit/Unit.cpp @@ -500,13 +500,6 @@ void Unit::Update(uint32 p_time) // All position info based actions have been executed, reset info _positionUpdateInfo.Reset(); - // Update serverside orientation of channeled spells that are suposed to track the channel target - if (Spell const* spell = m_currentSpells[CURRENT_CHANNELED_SPELL]) - if (spell->GetSpellInfo()->HasAttribute(SPELL_ATTR1_CHANNEL_TRACK_TARGET)) - if (ObjectGuid guid = GetChannelObjectGuid()) - if (WorldObject* target = ObjectAccessor::GetWorldObject(*this, guid)) - SetOrientation(GetAngle(target)); - // Update Power regeneration interval if (_regenerationTimer >= int32(GetRegenerationInterval())) _regenerationTimer -= (GetRegenerationInterval() - p_time); diff --git a/src/server/game/Spells/Spell.cpp b/src/server/game/Spells/Spell.cpp index 028bb90420..18c00b829b 100644 --- a/src/server/game/Spells/Spell.cpp +++ b/src/server/game/Spells/Spell.cpp @@ -3277,18 +3277,15 @@ void Spell::prepare(SpellCastTargets const* targets, AuraEffect const* triggered } } - // 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_spellInfo->HasAttribute(SPELL_ATTR1_CHANNEL_TRACK_TARGET)) - m_caster->ToCreature()->SetSpellFocus(this, nullptr); - else - 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 @@ -3458,10 +3455,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->SetInFront(m_targets.GetObjectTarget()); - // Should this be done for original caster? Player* modOwner = m_caster->GetSpellModOwner(); if (modOwner) @@ -3543,12 +3536,9 @@ 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::FocusTarget - 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->SetInFront(objTarget); + // The spell focusing is making sure that we have a valid cast targe guid when we need it so only check for a guid value here. + if (m_caster->IsCreature() && !m_caster->GetTarget().IsEmpty() && !m_caster->HasFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_POSSESSED)) + m_caster->SetInFront(ObjectAccessor::GetUnit(*m_caster, m_caster->GetTarget())); SelectSpellTargets(); @@ -3954,6 +3944,14 @@ void Spell::update(uint32 difftime) if (Unit* unit = m_caster->GetGUID() == target.targetGUID ? m_caster : ObjectAccessor::GetUnit(*m_caster, target.targetGUID)) unit->RemoveOwnedAura(m_spellInfo->Id, m_originalCasterGUID, 0, AuraRemoveFlags::ByCancel); } + else + { + // Update serverside orientation of channeling units + ObjectGuid const channelGuid = m_caster->GetChannelObjectGuid(); + if (!channelGuid.IsEmpty() && channelGuid != m_caster->GetGUID() && GetSpellInfo()->HasAttribute(SPELL_ATTR1_CHANNEL_TRACK_TARGET)) + if (WorldObject const* objectTarget = ObjectAccessor::GetWorldObject(*m_caster, channelGuid)) + m_caster->SetInFront(objectTarget); + } if (m_timer > 0) { @@ -4794,7 +4792,7 @@ void Spell::SendChannelUpdate(uint32 time) void Spell::SendChannelStart(uint32 duration) { - ObjectGuid channelTarget = m_targets.GetObjectTargetGUID(); + ObjectGuid channelTarget = m_targets.HasDst() ? m_caster->GetGUID() : m_targets.GetObjectTargetGUID(); if (!channelTarget && !m_spellInfo->NeedsExplicitUnitTarget()) { // this is for TARGET_SELECT_CATEGORY_NEARBY diff --git a/src/server/scripts/EasternKingdoms/BastionOfTwilight/boss_theralion_and_valiona.cpp b/src/server/scripts/EasternKingdoms/BastionOfTwilight/boss_theralion_and_valiona.cpp index b2473f915a..585a30b0cd 100644 --- a/src/server/scripts/EasternKingdoms/BastionOfTwilight/boss_theralion_and_valiona.cpp +++ b/src/server/scripts/EasternKingdoms/BastionOfTwilight/boss_theralion_and_valiona.cpp @@ -604,12 +604,8 @@ class boss_valiona : public CreatureScript switch (summon->GetEntry()) { case NPC_CONVECTIVE_FLAMES: - me->AttackStop(); - me->SetReactState(REACT_PASSIVE); - me->StopMoving(); me->SetFacingToObject(summon); DoCast(summon, SPELL_DEVOURING_FLAMES); - events.ScheduleEvent(EVENT_ATTACK_PLAYERS, Seconds(8)); break; case NPC_COLLAPSING_TWILIGHT_PORTAL: if (Creature* valionaDummy = ObjectAccessor::GetCreature(*me, instance->GetGuidData(DATA_VALIONA_AURA_DUMMY))) diff --git a/src/server/scripts/EasternKingdoms/GrimBatol/boss_drahga_shadowburner.cpp b/src/server/scripts/EasternKingdoms/GrimBatol/boss_drahga_shadowburner.cpp index 17cd5540c3..3508193955 100644 --- a/src/server/scripts/EasternKingdoms/GrimBatol/boss_drahga_shadowburner.cpp +++ b/src/server/scripts/EasternKingdoms/GrimBatol/boss_drahga_shadowburner.cpp @@ -81,9 +81,7 @@ enum Events EVENT_MOVE_INTRO, EVENT_SHREDDING_SWIPE, EVENT_DEVOURING_FLAMES, - EVENT_DEVOURING_FLAMES_CAST, EVENT_VALIONAS_FLAME, - EVENT_MAKE_AGGRESSIVE, // Invoked Flaming Spirit EVENT_CHASE_PLAYER @@ -182,7 +180,20 @@ struct boss_drahga_shadowburner : public BossAI void JustSummoned(Creature* summon) override { if (summon->GetEntry() != NPC_VALIONA) + { summons.Summon(summon); + + if (summon->GetEntry() == NPC_DEVOURING_FLAMES) + { + if (Creature* valiona = instance->GetCreature(DATA_VALIONA)) + { + valiona->SetFacingToObject(summon); + if (valiona->IsAIEnabled) + valiona->AI()->Talk(SAY_ANNOUNCE_DEVOURING_FLAMES); + valiona->CastSpell(summon, SPELL_DEVOURING_FLAMES); + } + } + } } void DamageTaken(Unit* /*attacker*/, uint32& damage) override @@ -414,28 +425,12 @@ struct npc_drahga_valiona : public ScriptedAI break; case EVENT_DEVOURING_FLAMES: if (IsHeroic()) - { DoCast(SPELL_DEVOURING_FLAMES_AOE); - _events.ScheduleEvent(EVENT_DEVOURING_FLAMES_CAST, 400ms); - } else if (Unit* target = SelectTarget(SELECT_TARGET_RANDOM, 0, 100.0f, true)) DoCast(target, SPELL_VALIONAS_FLAME); _events.Repeat(25s); break; - case EVENT_DEVOURING_FLAMES_CAST: - if (Creature* dummy = me->FindNearestCreature(NPC_DEVOURING_FLAMES, 200.0f, true)) - { - Talk(SAY_ANNOUNCE_DEVOURING_FLAMES); - me->StopMoving(); - me->SetFacingToObject(dummy); - DoCast(dummy, SPELL_DEVOURING_FLAMES); - _events.ScheduleEvent(EVENT_MAKE_AGGRESSIVE, 7s + 500ms); - } - break; - case EVENT_MAKE_AGGRESSIVE: - me->SetReactState(REACT_AGGRESSIVE); - break; default: break; } diff --git a/src/server/scripts/EasternKingdoms/GrimBatol/boss_general_umbriss.cpp b/src/server/scripts/EasternKingdoms/GrimBatol/boss_general_umbriss.cpp index 7a638552c8..cc5aee766a 100644 --- a/src/server/scripts/EasternKingdoms/GrimBatol/boss_general_umbriss.cpp +++ b/src/server/scripts/EasternKingdoms/GrimBatol/boss_general_umbriss.cpp @@ -55,7 +55,6 @@ enum Events EVENT_BLITZ, EVENT_GROUND_SIEGE, EVENT_SUMMON_SKARDYN, - EVENT_MAKE_AGGRESSIVE, // Skardyn EVENT_ATTACK_PLAYER, @@ -158,13 +157,9 @@ struct boss_general_umbriss : public BossAI DoCast(summon, SPELL_BLITZ); break; case NPC_GROUND_SIEGE_STALKER: - me->AttackStop(); - me->SetReactState(REACT_PASSIVE); - me->StopMoving(); me->SetFacingToObject(summon); DoCast(summon, SPELL_GROUND_SIEGE); Talk(SAY_ANNOUNCE_GROUND_SIEGE); - events.ScheduleEvent(EVENT_MAKE_AGGRESSIVE, Seconds(4) + Milliseconds(500)); break; default: break; @@ -226,9 +221,6 @@ struct boss_general_umbriss : public BossAI } events.Repeat(Seconds(23)); break; - case EVENT_MAKE_AGGRESSIVE: - me->SetReactState(REACT_AGGRESSIVE); - break; default: break; }