Skip to content

Commit 1f35acf

Browse files
committed
Add RegisterEvent support to World State
1 parent d1f1b62 commit 1f35acf

File tree

5 files changed

+33
-13
lines changed

5 files changed

+33
-13
lines changed

src/server/game/Entities/GameObject/GameObject.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -475,8 +475,11 @@ void GameObject::Update(uint32 diff)
475475
{
476476
e->UpdateAI(this, diff);
477477

478-
if (elunaEvents) // can be null on maps without eluna
479-
elunaEvents->Update(diff);
478+
if (elunaMapEvents) // can be null on maps without eluna
479+
elunaMapEvents->Update(diff);
480+
481+
if (elunaWorldEvents)
482+
elunaWorldEvents->Update(diff);
480483
}
481484
#endif
482485
m_Events.Update(diff);

src/server/game/Entities/Object/Object.cpp

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1825,13 +1825,24 @@ void WorldObject::SetMap(Map* map)
18251825
m_mapId = map->GetId();
18261826
m_InstanceId = map->GetInstanceId();
18271827
#ifdef ELUNA
1828-
// in multistate mode, always reset in case Eluna is not active on the new map
1829-
if (elunaEvents && !sElunaConfig->IsElunaCompatibilityMode())
1830-
elunaEvents.reset();
1831-
1832-
if (Eluna* e = map->GetEluna())
1833-
if (!elunaEvents)
1834-
elunaEvents = std::make_unique<ElunaEventProcessor>(e, this);
1828+
// in multistate mode, always reset Map events, then recreate the Map events procesor
1829+
if (!sElunaConfig->IsElunaCompatibilityMode())
1830+
{
1831+
auto& events = GetElunaEvents(m_mapId);
1832+
if (events)
1833+
events.reset();
1834+
1835+
if (Eluna* e = map->GetEluna())
1836+
events = std::make_unique<ElunaEventProcessor>(e, this);
1837+
}
1838+
1839+
// create the World events processor
1840+
if (Eluna* e = sWorld->GetEluna())
1841+
{
1842+
auto& events = GetElunaEvents(-1);
1843+
if (!events)
1844+
events = std::make_unique<ElunaEventProcessor>(e, this);
1845+
}
18351846
#endif
18361847
if (IsStoredInWorldObjectGridContainer())
18371848
m_currMap->AddWorldObject(this);

src/server/game/Entities/Object/Object.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -568,10 +568,13 @@ class TC_GAME_API WorldObject : public Object, public WorldLocation
568568
uint32 LastUsedScriptID;
569569

570570
#ifdef ELUNA
571-
std::unique_ptr <ElunaEventProcessor> elunaEvents;
571+
std::unique_ptr <ElunaEventProcessor> elunaMapEvents;
572+
std::unique_ptr <ElunaEventProcessor> elunaWorldEvents;
572573

573574
Eluna* GetEluna() const;
574575

576+
std::unique_ptr<ElunaEventProcessor>& GetElunaEvents(int32 mapId) { return (mapId == -1) ? elunaWorldEvents : elunaMapEvents; }
577+
575578
LuaVal lua_data = LuaVal({});
576579
#endif
577580

src/server/game/Entities/Unit/Unit.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -438,8 +438,11 @@ Unit::~Unit()
438438
void Unit::Update(uint32 p_time)
439439
{
440440
#ifdef ELUNA
441-
if(elunaEvents) // can be null on maps without eluna
442-
elunaEvents->Update(p_time);
441+
if(elunaMapEvents) // can be null on maps without eluna
442+
elunaMapEvents->Update(p_time);
443+
444+
if (elunaWorldEvents) // can be null on maps without eluna
445+
elunaWorldEvents->Update(p_time);
443446
#endif
444447

445448
// WARNING! Order of execution here is important, do not change.

0 commit comments

Comments
 (0)