From eaa635ab3284652e652f299bf90c679c6a76ecde Mon Sep 17 00:00:00 2001 From: Ovahlord Date: Fri, 31 Jan 2020 06:34:18 +0100 Subject: [PATCH] Core/Movement: backported cleanup for determining follow movement on appearing instead of calling evade modes right away --- src/server/game/AI/CreatureAI.cpp | 50 +++++++++++++++++++++++++ src/server/game/AI/CreatureAI.h | 2 +- src/server/game/Spells/SpellEffects.cpp | 4 -- 3 files changed, 51 insertions(+), 5 deletions(-) diff --git a/src/server/game/AI/CreatureAI.cpp b/src/server/game/AI/CreatureAI.cpp index 13f185fc6ed..c27b3af782b 100644 --- a/src/server/game/AI/CreatureAI.cpp +++ b/src/server/game/AI/CreatureAI.cpp @@ -186,6 +186,56 @@ void CreatureAI::TriggerAlert(Unit const* who) const me->SetFacingTo(me->GetAngle(who)); } +// adapted from logic in Spell:EFfectSummonType before commit 8499434 +static bool ShouldFollowOnSpawn(SummonPropertiesEntry const* properties) +{ + // Summons without SummonProperties are generally scripted summons that don't belong to any owner + if (!properties) + return false; + + switch (properties->Control) + { + case SUMMON_CATEGORY_PET: + return true; + case SUMMON_CATEGORY_WILD: + case SUMMON_CATEGORY_ALLY: + case SUMMON_CATEGORY_UNK: + if (properties->Flags & 512) + return true; + switch (properties->Title) + { + case SUMMON_TYPE_PET: + case SUMMON_TYPE_GUARDIAN: + case SUMMON_TYPE_GUARDIAN2: + case SUMMON_TYPE_MINION: + case SUMMON_TYPE_MINIPET: + return true; + default: + return false; + } + default: + return false; + } +} +void CreatureAI::JustAppeared() +{ + if (!me->IsInCombat()) + { + if (TempSummon* summon = me->ToTempSummon()) + { + // Only apply this to specific types of summons + if (!summon->GetVehicle() && ShouldFollowOnSpawn(summon->m_Properties)) + { + if (Unit* owner = summon->GetCharmerOrOwner()) + { + summon->GetMotionMaster()->Clear(); + summon->GetMotionMaster()->MoveFollow(owner, PET_FOLLOW_DIST, summon->GetFollowAngle()); + } + } + } + } +} + void CreatureAI::EnterEvadeMode(EvadeReason why) { if (!_EnterEvadeMode(why)) diff --git a/src/server/game/AI/CreatureAI.h b/src/server/game/AI/CreatureAI.h index 581e409d21b..f950b236de2 100644 --- a/src/server/game/AI/CreatureAI.h +++ b/src/server/game/AI/CreatureAI.h @@ -143,7 +143,7 @@ class TC_GAME_API CreatureAI : public UnitAI virtual bool IsEscorted() const { return false; } // Called when creature appears in the world (spawn, respawn, grid load etc...) - virtual void JustAppeared() { } + virtual void JustAppeared(); // Called at waypoint reached or point movement finished virtual void MovementInform(uint32 /*type*/, uint32 /*id*/) { } diff --git a/src/server/game/Spells/SpellEffects.cpp b/src/server/game/Spells/SpellEffects.cpp index 67ff0db9921..b59ccb96de2 100644 --- a/src/server/game/Spells/SpellEffects.cpp +++ b/src/server/game/Spells/SpellEffects.cpp @@ -1929,8 +1929,6 @@ void Spell::EffectSummonType(SpellEffIndex effIndex) summon->SetUInt32Value(UNIT_NPC_FLAGS, summon->GetCreatureTemplate()->npcflag); summon->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_IMMUNE_TO_PC | UNIT_FLAG_IMMUNE_TO_NPC); - - summon->AI()->EnterEvadeMode(); break; } default: @@ -5383,8 +5381,6 @@ void Spell::SummonGuardian(uint32 i, uint32 entry, SummonPropertiesEntry const* summon->SetDisplayId(1126); // modelid1 } - summon->AI()->EnterEvadeMode(); - ExecuteLogEffectSummonObject(i, summon); } }