Skip to content

Commit 9cc6067

Browse files
committed
Add method changes for other cores
1 parent 71e0aa7 commit 9cc6067

File tree

4 files changed

+65
-14
lines changed

4 files changed

+65
-14
lines changed

ElunaEventMgr.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ void ElunaEventProcessor::SetStates(LuaEventState state)
6868
return;
6969
}
7070

71-
for (EventList::iterator it = eventList.begin(); it != eventList.end(); ++it)
72-
it->second->SetState(state);
71+
for (auto& [time, event] : eventList)
72+
event->SetState(state);
7373

7474
if (state == LUAEVENT_STATE_ERASE)
7575
eventMap.clear();
@@ -83,8 +83,8 @@ void ElunaEventProcessor::ClearAllEvents()
8383
return;
8484
}
8585

86-
for (EventList::iterator it = eventList.begin(); it != eventList.end(); ++it)
87-
RemoveEvent(it->second);
86+
for (auto& [time, event] : eventList)
87+
RemoveEvent(event);
8888

8989
deferredOps.clear();
9090
eventList.clear();

methods/CMangos/WorldObjectMethods.h

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -766,7 +766,15 @@ namespace LuaWorldObject
766766
int functionRef = luaL_ref(E->L, LUA_REGISTRYINDEX);
767767
if (functionRef != LUA_REFNIL && functionRef != LUA_NOREF)
768768
{
769-
obj->GetElunaEvents(E->GetBoundMapId())->AddEvent(functionRef, min, max, repeats);
769+
ElunaEventProcessor* proc = obj->GetElunaEvents(E->GetBoundMapId());
770+
if (!proc)
771+
{
772+
luaL_unref(E->L, LUA_REGISTRYINDEX, functionRef);
773+
E->Push();
774+
return 1;
775+
}
776+
777+
proc->AddEvent(functionRef, min, max, repeats);
770778
E->Push(functionRef);
771779
}
772780
return 1;
@@ -780,7 +788,12 @@ namespace LuaWorldObject
780788
int RemoveEventById(Eluna* E, WorldObject* obj)
781789
{
782790
int eventId = E->CHECKVAL<int>(2);
783-
obj->GetElunaEvents(E->GetBoundMapId())->SetState(eventId, LUAEVENT_STATE_ABORT);
791+
792+
ElunaEventProcessor* proc = obj->GetElunaEvents(E->GetBoundMapId());
793+
if (!proc)
794+
return 0;
795+
796+
proc->SetState(eventId, LUAEVENT_STATE_ABORT);
784797
return 0;
785798
}
786799

@@ -790,7 +803,11 @@ namespace LuaWorldObject
790803
*/
791804
int RemoveEvents(Eluna* E, WorldObject* obj)
792805
{
793-
obj->GetElunaEvents(E->GetBoundMapId())->SetStates(LUAEVENT_STATE_ABORT);
806+
ElunaEventProcessor* proc = obj->GetElunaEvents(E->GetBoundMapId());
807+
if (!proc)
808+
return 0;
809+
810+
proc->SetStates(LUAEVENT_STATE_ABORT);
794811
return 0;
795812
}
796813

methods/Mangos/WorldObjectMethods.h

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -768,7 +768,15 @@ namespace LuaWorldObject
768768
int functionRef = luaL_ref(E->L, LUA_REGISTRYINDEX);
769769
if (functionRef != LUA_REFNIL && functionRef != LUA_NOREF)
770770
{
771-
obj->elunaEvents->AddEvent(functionRef, min, max, repeats);
771+
ElunaEventProcessor* proc = obj->GetElunaEvents(E->GetBoundMapId());
772+
if (!proc)
773+
{
774+
luaL_unref(E->L, LUA_REGISTRYINDEX, functionRef);
775+
E->Push();
776+
return 1;
777+
}
778+
779+
proc->AddEvent(functionRef, min, max, repeats);
772780
E->Push(functionRef);
773781
}
774782
return 1;
@@ -782,17 +790,26 @@ namespace LuaWorldObject
782790
int RemoveEventById(Eluna* E, WorldObject* obj)
783791
{
784792
int eventId = E->CHECKVAL<int>(2);
785-
obj->elunaEvents->SetState(eventId, LUAEVENT_STATE_ABORT);
793+
794+
ElunaEventProcessor* proc = obj->GetElunaEvents(E->GetBoundMapId());
795+
if (!proc)
796+
return 0;
797+
798+
proc->SetState(eventId, LUAEVENT_STATE_ABORT);
786799
return 0;
787800
}
788801

789802
/**
790803
* Removes all timed events from a [WorldObject]
791804
*
792805
*/
793-
int RemoveEvents(Eluna* /*E*/, WorldObject* obj)
806+
int RemoveEvents(Eluna* E, WorldObject* obj)
794807
{
795-
obj->elunaEvents->SetStates(LUAEVENT_STATE_ABORT);
808+
ElunaEventProcessor* proc = obj->GetElunaEvents(E->GetBoundMapId());
809+
if (!proc)
810+
return 0;
811+
812+
proc->SetStates(LUAEVENT_STATE_ABORT);
796813
return 0;
797814
}
798815

methods/VMangos/WorldObjectMethods.h

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -735,7 +735,15 @@ namespace LuaWorldObject
735735
int functionRef = luaL_ref(E->L, LUA_REGISTRYINDEX);
736736
if (functionRef != LUA_REFNIL && functionRef != LUA_NOREF)
737737
{
738-
obj->GetElunaEvents(E->GetBoundMapId())->AddEvent(functionRef, min, max, repeats);
738+
ElunaEventProcessor* proc = obj->GetElunaEvents(E->GetBoundMapId());
739+
if (!proc)
740+
{
741+
luaL_unref(E->L, LUA_REGISTRYINDEX, functionRef);
742+
E->Push();
743+
return 1;
744+
}
745+
746+
proc->AddEvent(functionRef, min, max, repeats);
739747
E->Push(functionRef);
740748
}
741749
return 1;
@@ -749,7 +757,12 @@ namespace LuaWorldObject
749757
int RemoveEventById(Eluna* E, WorldObject* obj)
750758
{
751759
int eventId = E->CHECKVAL<int>(2);
752-
obj->GetElunaEvents(E->GetBoundMapId())->SetState(eventId, LUAEVENT_STATE_ABORT);
760+
761+
ElunaEventProcessor* proc = obj->GetElunaEvents(E->GetBoundMapId());
762+
if (!proc)
763+
return 0;
764+
765+
proc->SetState(eventId, LUAEVENT_STATE_ABORT);
753766
return 0;
754767
}
755768

@@ -759,7 +772,11 @@ namespace LuaWorldObject
759772
*/
760773
int RemoveEvents(Eluna* E, WorldObject* obj)
761774
{
762-
obj->GetElunaEvents(E->GetBoundMapId())->SetStates(LUAEVENT_STATE_ABORT);
775+
ElunaEventProcessor* proc = obj->GetElunaEvents(E->GetBoundMapId());
776+
if (!proc)
777+
return 0;
778+
779+
proc->SetStates(LUAEVENT_STATE_ABORT);
763780
return 0;
764781
}
765782

0 commit comments

Comments
 (0)