From a8b8199acb7f3222ab48c78c5b2e69c5bb777330 Mon Sep 17 00:00:00 2001 From: UltraNix <80540499+UltraNix@users.noreply.github.com> Date: Mon, 20 Mar 2023 14:45:41 +0100 Subject: [PATCH] fix(Core/Grids): Creatures should attack when loaded into grid. (#15453) * fix(Core/Grids): Creatures should attack when loaded into grid. Fixes #14645 * Update. --- src/server/game/Grids/ObjectGridLoader.cpp | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/src/server/game/Grids/ObjectGridLoader.cpp b/src/server/game/Grids/ObjectGridLoader.cpp index 25ff2343b..ac1631caf 100644 --- a/src/server/game/Grids/ObjectGridLoader.cpp +++ b/src/server/game/Grids/ObjectGridLoader.cpp @@ -18,6 +18,7 @@ #include "ObjectGridLoader.h" #include "CellImpl.h" #include "Corpse.h" +#include "GridNotifiers.h" #include "Creature.h" #include "CreatureAI.h" #include "DynamicObject.h" @@ -97,13 +98,17 @@ void AddObjectHelper(CellCoord& cell, GameObjectMapType& m, uint32& count, Map* } template -void LoadHelper(CellGuidSet const& guid_set, CellCoord& cell, GridRefMgr& m, uint32& count, Map* map) +void LoadHelper(CellGuidSet const& /*guid_set*/, CellCoord& /*cell*/, GridRefMgr& /*m*/, uint32& /*count*/, Map* /*map*/) +{ +} + +template <> +void LoadHelper(CellGuidSet const& guid_set, CellCoord& cell, GridRefMgr& m, uint32& count, Map* map) { for (CellGuidSet::const_iterator i_guid = guid_set.begin(); i_guid != guid_set.end(); ++i_guid) { - T* obj = new T; + Creature* obj = new Creature(); ObjectGuid::LowType guid = *i_guid; - if (!obj->LoadFromDB(guid, map)) { delete obj; @@ -111,6 +116,16 @@ void LoadHelper(CellGuidSet const& guid_set, CellCoord& cell, GridRefMgr& m, } AddObjectHelper(cell, m, count, map, obj); + + if (!obj->IsMoveInLineOfSightDisabled() && obj->GetDefaultMovementType() == IDLE_MOTION_TYPE && !obj->isNeedNotify(NOTIFY_VISIBILITY_CHANGED | NOTIFY_AI_RELOCATION)) + { + if (obj->IsAlive() && !obj->HasUnitState(UNIT_STATE_SIGHTLESS) && obj->HasReactState(REACT_AGGRESSIVE) && !obj->IsImmuneToNPC()) + { + // call MoveInLineOfSight for nearby grid creatures + Acore::AIRelocationNotifier notifier(*obj); + Cell::VisitGridObjects(obj, notifier, 60.f); + } + } } }