Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 26 additions & 15 deletions src/server/game/Entities/Object/Object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1809,21 +1809,9 @@ void WorldObject::SetMap(Map* map)
m_mapId = map->GetId();
m_InstanceId = map->GetInstanceId();
#ifdef ELUNA
// always reset Map events, then recreate the Map events procesor if Eluna is enabled for the map
auto& events = GetElunaEvents(m_mapId);
if (events)
events.reset();

if (Eluna* e = map->GetEluna())
events = std::make_unique<ElunaEventProcessor>(e, this);

// create the World events processor
if (Eluna* e = sWorld->GetEluna())
{
auto& events = GetElunaEvents(-1);
if (!events)
events = std::make_unique<ElunaEventProcessor>(e, this);
}
// Reset MAP processor
if (elunaMapEvents)
elunaMapEvents.reset();
#endif
if (IsStoredInWorldObjectGridContainer())
m_currMap->AddWorldObject(this);
Expand Down Expand Up @@ -3634,6 +3622,29 @@ Eluna* WorldObject::GetEluna() const

return nullptr;
}

ElunaEventProcessor* WorldObject::GetElunaEvents(int32 mapId)
{
Eluna* eluna = mapId == -1 ? sWorld->GetEluna() : GetEluna();
if (!eluna)
return nullptr;

EventMgr* mgr = eluna->eventMgr.get();
if (!mgr)
return nullptr;

// Select the correct ProcessorInfo slot
std::unique_ptr<ElunaProcessorInfo>& info = (mapId == -1) ? elunaWorldEvents : elunaMapEvents;

// Lazily create processor + ProcessorInfo handle
if (!info)
{
uint64 id = mgr->CreateObjectProcessor(this);
info = std::make_unique<ElunaProcessorInfo>(mgr, id);
}

return mgr->GetObjectProcessor(info->GetProcessorId());
}
#endif

template TC_GAME_API void WorldObject::GetGameObjectListWithEntryInGrid(std::list<GameObject*>&, uint32, float) const;
Expand Down
7 changes: 4 additions & 3 deletions src/server/game/Entities/Object/Object.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ class WorldObject;
class WorldPacket;
class ZoneScript;
#ifdef ELUNA
class ElunaEventProcessorInfo;
class ElunaEventProcessor;
class Eluna;
#endif
Expand Down Expand Up @@ -568,12 +569,12 @@ class TC_GAME_API WorldObject : public Object, public WorldLocation
uint32 LastUsedScriptID;

#ifdef ELUNA
std::unique_ptr <ElunaEventProcessor> elunaMapEvents;
std::unique_ptr <ElunaEventProcessor> elunaWorldEvents;
std::unique_ptr<ElunaProcessorInfo> elunaMapEvents;
std::unique_ptr<ElunaProcessorInfo> elunaWorldEvents;

Eluna* GetEluna() const;

std::unique_ptr<ElunaEventProcessor>& GetElunaEvents(int32 mapId) { return (mapId == -1) ? elunaWorldEvents : elunaMapEvents; }
ElunaEventProcessor* GetElunaEvents(int32 mapId);

LuaVal lua_data = LuaVal({});
#endif
Expand Down