Project SkyFire Core
SkyFire 5.4.8 server core API documentation
Loading...
Searching...
No Matches
LuaEngine.h
Go to the documentation of this file.
1/*
2* Copyright (C) 2010 - 2013 Eluna Lua Engine <http://emudevs.com/>
3* This program is free software licensed under GPL version 3
4* Please see the included DOCS/LICENSE.TXT for more information
5*/
6
7#ifndef __ELUNA__H
8#define __ELUNA__H
9
10extern "C"
11{
12#include "lua.h"
13#include "lualib.h"
14#include "lauxlib.h"
15};
16
17#include "Includes.h"
18#include "ElunaCompatibility.h"
19#include "HookMgr.h"
20
21#include <type_traits>
22
23typedef std::set<std::string> LoadedScripts;
24
25template<typename T> const char* GetTName();
26
27template<class T>
29{
30 const char* name;
31 int(*mfunc)(lua_State*, T*);
32};
33
34template<typename T>
36{
37 public:
38 static int type(lua_State* L)
39 {
40 lua_pushstring(L, GetTName<T>());
41 return 1;
42 }
43
44 static void Register(lua_State* L)
45 {
46 lua_settop(L, 0); // clean stack
47
48 lua_newtable(L);
49 int methods = lua_gettop(L);
50
51 luaL_newmetatable(L, GetTName<T>());
52 int metatable = lua_gettop(L);
53
54 // store method table in globals so that
55 // scripts can add functions in Lua
56 lua_pushvalue(L, methods);
57 lua_setglobal(L, GetTName<T>());
58
59 // hide metatable
60 lua_pushvalue(L, methods);
61 lua_setfield(L, metatable, "__metatable");
62
63 lua_pushvalue(L, methods);
64 lua_setfield(L, metatable, "__index");
65
66 lua_pushcfunction(L, tostringT);
67 lua_setfield(L, metatable, "__tostring");
68
69 lua_pushcfunction(L, gcT);
70 lua_setfield(L, metatable, "__gc");
71
72 lua_newtable(L);
73 lua_setmetatable(L, methods);
74 }
75
76 static int push(lua_State* L, T const* obj, bool gc = false)
77 {
78 if (!obj)
79 {
80 lua_pushnil(L);
81 return lua_gettop(L);
82 }
83 luaL_getmetatable(L, GetTName<T>());
84 if (lua_isnil(L, -1))
85 luaL_error(L, "%s missing metatable", GetTName<T>());
86 int idxMt = lua_gettop(L);
87 T const** ptrHold = (T const**)lua_newuserdata(L, sizeof(T**));
88 int ud = lua_gettop(L);
89 if (ptrHold)
90 {
91 *ptrHold = obj;
92 lua_pushvalue(L, idxMt);
93 lua_setmetatable(L, -2);
94 char name[32];
95 tostring(name, obj);
96 lua_getfield(L, LUA_REGISTRYINDEX, "DO NOT TRASH");
97 if (lua_isnil(L, -1))
98 {
99 luaL_newmetatable(L, "DO NOT TRASH");
100 lua_pop(L, 1);
101 }
102 lua_getfield(L, LUA_REGISTRYINDEX, "DO NOT TRASH");
103 if (gc == false)
104 {
105 lua_pushboolean(L, 1);
106 lua_setfield(L, -2, name);
107 }
108 lua_pop(L, 1);
109 }
110 lua_settop(L, ud);
111 lua_replace(L, idxMt);
112 lua_settop(L, idxMt);
113 return idxMt;
114 }
115
116 static T* check(lua_State* L, int narg)
117 {
118 T** ptrHold = static_cast<T**>(lua_touserdata(L, narg));
119 if (!ptrHold)
120 return NULL;
121 return *ptrHold;
122 }
123
124 static int thunk(lua_State* L)
125 {
126 T* obj = check(L, 1); // get self
127 lua_remove(L, 1); // remove self
128 ElunaRegister<T>* l = static_cast<ElunaRegister<T>*>(lua_touserdata(L, lua_upvalueindex(1)));
129 if (!obj)
130 return 0;
131 return l->mfunc(L, obj);
132 }
133
134 static int gcT(lua_State* L)
135 {
136 T* obj = check(L, 1);
137 if (!obj)
138 return 0;
139 lua_getfield(L, LUA_REGISTRYINDEX, "DO NOT TRASH");
140 if (lua_istable(L, -1))
141 {
142 char name[32];
143 tostring(name, obj);
144 lua_getfield(L, -1, std::string(name).c_str());
145 }
146 return 1;
147 }
148
149 static int tostringT(lua_State* L)
150 {
151 char buff[32];
152 T** ptrHold = (T**)lua_touserdata(L, 1);
153 T* obj = *ptrHold;
154 sprintf(buff, "%p", obj);
155 lua_pushfstring(L, "%s (%s)", GetTName<T>(), buff);
156 return 1;
157 }
158
159 inline static void tostring(char* buff, void const* obj)
160 {
161 sprintf(buff, "%p", obj);
162 }
163
164 static int index(lua_State* L)
165 {
166 lua_getglobal(L, GetTName<T>());
167 const char* key = lua_tostring(L, 2);
168 if (lua_istable(L, - 1))
169 {
170 lua_pushvalue(L, 2);
171 lua_rawget(L, -2);
172 if (lua_isnil(L, -1))
173 {
174 lua_getmetatable(L, -2);
175 if (lua_istable(L, -1))
176 {
177 lua_getfield(L, -1, "__index");
178 if (lua_isfunction(L, -1))
179 {
180 lua_pushvalue(L, 1);
181 lua_pushvalue(L, 2);
182 lua_pcall(L, 2, 1, 0);
183 }
184 else if (lua_istable(L, -1))
185 lua_getfield(L, -1, key);
186 else
187 lua_pushnil(L);
188 }
189 else
190 lua_pushnil(L);
191 }
192 else if (lua_istable(L, -1))
193 {
194 lua_pushvalue(L, 2);
195 lua_rawget(L, -2);
196 }
197 }
198 else
199 lua_pushnil(L);
200 lua_insert(L, 1);
201 lua_settop(L, 1);
202 return 1;
203 }
204};
205
206template<typename T>
207void SetMethods(lua_State* L, ElunaRegister<T>* methodTable)
208{
209 if (!methodTable)
210 return;
211 if (!lua_istable(L, 1))
212 return;
213 lua_pushstring(L, "GetObjectType");
214 lua_pushcclosure(L, ElunaTemplate<T>::type, 0);
215 lua_settable(L, 1);
216 for (; methodTable->name; ++methodTable)
217 {
218 lua_pushstring(L, methodTable->name);
219 lua_pushlightuserdata(L, (void*)methodTable);
220 lua_pushcclosure(L, ElunaTemplate<T>::thunk, 1);
221 lua_settable(L, 1);
222 }
223}
224
226{
227 struct LuaEvent;
228
229 typedef std::set<LuaEvent*> EventSet;
230 typedef std::map<EventProcessor*, EventSet> EventMap;
231 typedef std::unordered_map<uint64, EventProcessor> ProcessorMap;
232
233 EventMap LuaEvents; // LuaEvents[events] = {LuaEvents}
234 ProcessorMap Processors; // Processors[guid] = processor
236
237 struct LuaEvent : public BasicEvent
238 {
239 LuaEvent(EventProcessor* _events, int _funcRef, uint32 _delay, uint32 _calls, Object* _obj);
240
241 ~LuaEvent();
242
243 // Should never execute on dead events
244 bool Execute(uint64 time, uint32 diff);
245
246 bool hasObject; // Dont call event if object no longer exists
247 Object* obj; // Object to push
248 int funcRef; // Lua function reference ID, also used as event ID
249 uint32 delay; // Delay between event calls
250 uint32 calls; // Amount of calls to make, 0 for infinite
251 EventProcessor* events; // Pointer to events (holds the timed event)
252 };
253
254 // Updates all processors stored in the manager
255 // Should be run on world tick
256 void Update(uint32 diff)
257 {
258 GlobalEvents.Update(diff);
259 for (ProcessorMap::iterator it = Processors.begin(); it != Processors.end(); ++it)
260 it->second.Update(diff);
261 }
262
263 /*
264 // Updates processor stored for guid || remove from Update()
265 // Should be run on gameobject tick
266 static void Update(uint64 guid, uint32 diff)
267 {
268 if (Processors.find(guid) == Processors.end())
269 return;
270 Processors[guid].Update(diff);
271 }
272 */
273
274 // Aborts all lua events
276 {
277 if (!events)
278 return;
279 EventMap::const_iterator it = LuaEvents.find(events); // Get event set
280 if (it == LuaEvents.end())
281 return;
282 for (EventSet::const_iterator itr = it->second.begin(); itr != it->second.end(); ++itr) // Loop events
283 (*itr)->to_Abort = true; // Abort event
284 }
285
286 // Remove all timed events
288 {
289 for (ProcessorMap::iterator it = Processors.begin(); it != Processors.end(); ++it)
290 it->second.KillAllEvents(true);
291 Processors.clear();
292 for (EventMap::const_iterator it = LuaEvents.begin(); it != LuaEvents.end(); ++it) // loop processors
293 KillAllEvents(it->first);
294 LuaEvents.clear(); // remove pointer sets
295 }
296
297 // Remove timed events from processor
299 {
300 if (!events)
301 return;
302 KillAllEvents(events);
303 LuaEvents.erase(events); // remove pointer set
304 }
305
306 // Remove timed events from guid
308 {
309 if (Processors.find(guid) == Processors.end())
310 return;
311 Processors[guid].KillAllEvents(true); // remove events
312 Processors.erase(guid); // remove processor
313 }
314
315 // Adds a new event to the processor and returns the eventID or 0 (Never negative)
316 int AddEvent(EventProcessor* events, int funcRef, uint32 delay, uint32 calls, Object* obj = NULL)
317 {
318 if (!events || funcRef <= 0) // If funcRef <= 0, function reference failed
319 return 0; // on fail always return 0. funcRef can be negative.
320 events->AddEvent(new LuaEvent(events, funcRef, delay, calls, obj), events->CalculateTime(delay));
321 return funcRef; // return the event ID
322 }
323
324 // Creates a processor for the guid if needed and adds the event to it
325 int AddEvent(uint64 guid, int funcRef, uint32 delay, uint32 calls, Object* obj = NULL)
326 {
327 if (!guid) // 0 should be unused
328 return 0;
329 return AddEvent(&Processors[guid], funcRef, delay, calls, obj);
330 }
331
332 // Finds the event that has the ID from events
333 LuaEvent* GetEvent(EventProcessor* events, int eventId)
334 {
335 if (!events || !eventId)
336 return NULL;
337 EventMap::const_iterator it = LuaEvents.find(events); // Get event set
338 if (it == LuaEvents.end())
339 return NULL;
340 for (EventSet::const_iterator itr = it->second.begin(); itr != it->second.end(); ++itr) // Loop events
341 if ((*itr) && (*itr)->funcRef == eventId) // Check if the event has our ID
342 return *itr; // Return the event if found
343 return NULL;
344 }
345
346 // Remove the event with the eventId from processor
347 // Returns true if event is removed
348 bool RemoveEvent(EventProcessor* events, int eventId) // eventId = funcRef
349 {
350 if (!events || !eventId)
351 return false;
352 LuaEvent* luaEvent = GetEvent(events, eventId);
353 if (!luaEvent)
354 return false;
355 luaEvent->to_Abort = true; // Set to remove on next call
356 // LuaEvents[events].erase(luaEvent); // Remove pointer
357 return true;
358 }
359
360 // Remove event by ID from processor stored for guid
361 bool RemoveEvent(uint64 guid, int eventId)
362 {
363 if (!guid || Processors.find(guid) == Processors.end())
364 return false;
365 return RemoveEvent(&Processors[guid], eventId);
366 }
367
368 // Removes the eventId from all events
369 void RemoveEvent(int eventId)
370 {
371 if (!eventId)
372 return;
373 for (EventMap::const_iterator it = LuaEvents.begin(); it != LuaEvents.end(); ++it) // loop processors
374 if (RemoveEvent(it->first, eventId))
375 break; // succesfully remove the event, stop loop.
376 }
377};
378
379class Eluna
380{
381 public:
382 friend class ScriptMgr;
383 static Eluna* instance();
384 lua_State* L;
386
387 typedef std::map<int, int> ElunaBindingMap;
388 typedef std::unordered_map<uint32, ElunaBindingMap> ElunaEntryMap;
389 struct ElunaBind;
390 std::map<int, std::vector<int> > ServerEventBindings;
391 std::map<int, std::vector<int> > PlayerEventBindings;
392 std::map<int, std::vector<int> > VehicleEventBindings;
393 std::map<int, std::vector<int> > GuildEventBindings;
394 std::map<int, std::vector<int> > GroupEventBindings;
402
403 void Initialize();
404 static void report(lua_State*);
405 void Register(uint8 reg, uint32 id, uint32 evt, int func);
406 void BeginCall(int fReference);
407 bool ExecuteCall(uint8 params, uint8 res);
408 void EndCall(uint8 res);
409 void LoadDirectory(const char* directory, LoadedScripts* scr);
410 // Pushes
411 void Push(lua_State*); // nil
412 void Push(lua_State*, uint64);
413 void Push(lua_State*, int64);
414 void Push(lua_State*, uint32);
415 void Push(lua_State*, int32);
416 void Push(lua_State*, bool);
417 void Push(lua_State*, float);
418 void Push(lua_State*, double);
419 void Push(lua_State*, const char*);
420 void Push(lua_State*, std::string);
421 template<typename T, typename std::enable_if<std::is_enum<T>::value, int>::type = 0>
422 void Push(lua_State* L, T value)
423 {
424 Push(L, static_cast<uint32>(value));
425 }
426 template<typename T> void Push(lua_State* L, T const* ptr)
427 {
429 }
430
431 void Push(lua_State* L, Pet const* pet)
432 {
433 Push(L, pet->ToCreature());
434 }
435
436 void Push(lua_State* L, TempSummon const* summon)
437 {
438 Push(L, summon->ToCreature());
439 }
440
441 void Push(lua_State* L, Unit const* unit)
442 {
443 if (!unit)
444 {
445 Push(L);
446 return;
447 }
448 switch (unit->GetTypeId())
449 {
450 case TYPEID_UNIT:
451 Push(L, unit->ToCreature());
452 break;
453 case TYPEID_PLAYER:
454 Push(L, unit->ToPlayer());
455 break;
456 default:
458 }
459 }
460
461 void Push(lua_State*, WorldObject const* obj)
462 {
463 if (!obj)
464 {
465 Push(L);
466 return;
467 }
468 switch (obj->GetTypeId())
469 {
470 case TYPEID_UNIT:
471 Push(L, obj->ToCreature());
472 break;
473 case TYPEID_PLAYER:
474 Push(L, obj->ToPlayer());
475 break;
477 Push(L, obj->ToGameObject());
478 break;
479 case TYPEID_CORPSE:
480 Push(L, obj->ToCorpse());
481 break;
482 default:
484 }
485 }
486
487 void Push(lua_State* L, Object const* obj)
488 {
489 if (!obj)
490 {
491 Push(L);
492 return;
493 }
494 switch (obj->GetTypeId())
495 {
496 case TYPEID_UNIT:
497 Push(L, obj->ToCreature());
498 break;
499 case TYPEID_PLAYER:
500 Push(L, obj->ToPlayer());
501 break;
503 Push(L, obj->ToGameObject());
504 break;
505 case TYPEID_CORPSE:
506 Push(L, obj->ToCorpse());
507 break;
508 default:
510 }
511 }
512
513 // Checks
514 WorldPacket* CHECK_PACKET(lua_State* L, int narg);
515 Object* CHECK_OBJECT(lua_State* L, int narg);
516 WorldObject* CHECK_WORLDOBJECT(lua_State* L, int narg);
517 Unit* CHECK_UNIT(lua_State* L, int narg);
518 Player* CHECK_PLAYER(lua_State* L, int narg);
519 Creature* CHECK_CREATURE(lua_State* L, int narg);
520 GameObject* CHECK_GAMEOBJECT(lua_State* L, int narg);
521 Vehicle* CHECK_VEHICLE(lua_State* L, int narg);
522 Corpse* CHECK_CORPSE(lua_State* L, int narg);
523 Quest* CHECK_QUEST(lua_State* L, int narg);
524 Spell* CHECK_SPELL(lua_State* L, int narg);
525 uint64 CHECK_ULONG(lua_State* L, int narg);
526 int64 CHECK_LONG(lua_State* L, int narg);
527 Item* CHECK_ITEM(lua_State* L, int narg);
528
529 // Creates new binding stores
531 {
532 L = NULL;
533
534 for (int i = 0; i < SERVER_EVENT_COUNT; ++i)
535 {
536 std::vector<int> _vector;
537 ServerEventBindings.insert(std::pair<int, std::vector<int> >(i, _vector));
538 }
539
540 for (int i = 0; i < PLAYER_EVENT_COUNT; ++i)
541 {
542 std::vector<int> _vector;
543 PlayerEventBindings.insert(std::pair<int, std::vector<int> >(i, _vector));
544 }
545
546 for (int i = 0; i < VEHICLE_EVENT_COUNT; ++i)
547 {
548 std::vector<int> _vector;
549 VehicleEventBindings.insert(std::pair<int, std::vector<int> >(i, _vector));
550 }
551
552 for (int i = 0; i < GUILD_EVENT_COUNT; ++i)
553 {
554 std::vector<int> _vector;
555 GuildEventBindings.insert(std::pair<int, std::vector<int> >(i, _vector));
556 }
557
558 for (int i = 0; i < GROUP_EVENT_COUNT; ++i)
559 {
560 std::vector<int> _vector;
561 GroupEventBindings.insert(std::pair<int, std::vector<int> >(i, _vector));
562 }
570 }
571
573 {
574 for (std::map<int, std::vector<int> >::iterator itr = ServerEventBindings.begin(); itr != ServerEventBindings.end(); ++itr)
575 {
576 for (std::vector<int>::iterator it = itr->second.begin(); it != itr->second.end(); ++it)
577 luaL_unref(L, LUA_REGISTRYINDEX, (*it));
578 itr->second.clear();
579 }
580
581 for (std::map<int, std::vector<int> >::iterator itr = PlayerEventBindings.begin(); itr != PlayerEventBindings.end(); ++itr)
582 {
583 for (std::vector<int>::iterator it = itr->second.begin(); it != itr->second.end(); ++it)
584 luaL_unref(L, LUA_REGISTRYINDEX, (*it));
585 itr->second.clear();
586 }
587
588 for (std::map<int, std::vector<int> >::iterator itr = VehicleEventBindings.begin(); itr != VehicleEventBindings.end(); ++itr)
589 {
590 for (std::vector<int>::iterator it = itr->second.begin(); it != itr->second.end(); ++it)
591 luaL_unref(L, LUA_REGISTRYINDEX, (*it));
592 itr->second.clear();
593 }
594
595 for (std::map<int, std::vector<int> >::iterator itr = GuildEventBindings.begin(); itr != GuildEventBindings.end(); ++itr)
596 {
597 for (std::vector<int>::iterator it = itr->second.begin(); it != itr->second.end(); ++it)
598 luaL_unref(L, LUA_REGISTRYINDEX, (*it));
599 itr->second.clear();
600 }
601
602 for (std::map<int, std::vector<int> >::iterator itr = GroupEventBindings.begin(); itr != GroupEventBindings.end(); ++itr)
603 {
604 for (std::vector<int>::iterator it = itr->second.begin(); it != itr->second.end(); ++it)
605 luaL_unref(L, LUA_REGISTRYINDEX, (*it));
606 itr->second.clear();
607 }
608 ServerEventBindings.clear();
609 PlayerEventBindings.clear();
610 VehicleEventBindings.clear();
611 GuildEventBindings.clear();
612 GroupEventBindings.clear();
613 CreatureEventBindings->Clear();
614 CreatureGossipBindings->Clear();
617 ItemEventBindings->Clear();
618 ItemGossipBindings->Clear();
619 playerGossipBindings->Clear();
620
621 lua_close(L); // Closing
622 }
623
625 {
626 void Clear(); // unregisters all registered functions and clears all registered events from the bind std::maps (reset)
627 void Insert(uint32 entryId, uint32 eventId, int funcRef); // Inserts a new registered event
628
629 // Gets the function ref of an entry for an event
630 int GetBind(uint32 entryId, uint32 eventId)
631 {
632 ElunaEntryMap::iterator itr = Bindings.find(entryId);
633 if (itr == Bindings.end())
634 return 0;
635
636 return itr->second[eventId];
637 }
638
639 // Gets the binding std::map containing all registered events with the function refs for the entry
641 {
642 ElunaEntryMap::iterator itr = Bindings.find(entryId);
643 if (itr == Bindings.end())
644 return NULL;
645
646 return &itr->second;
647 }
648
649 ElunaEntryMap Bindings; // Binding store Bindings[entryId][eventId] = funcRef;
650 };
651
653 {
654 ObjectGUIDCheck(uint64 GUID) : _GUID(GUID) { }
656 {
657 return object->GetGUID() == _GUID;
658 }
659
661 };
662
663 // Binary predicate to sort WorldObjects based on the distance to a reference WorldObject
665 {
666 ObjectDistanceOrderPred(WorldObject const* pRefObj, bool ascending = true) : m_refObj(pRefObj), m_ascending(ascending) { }
667 bool operator()(WorldObject const* pLeft, WorldObject const* pRight) const
668 {
669 return m_ascending ? m_refObj->GetDistanceOrder(pLeft, pRight) : !m_refObj->GetDistanceOrder(pLeft, pRight);
670 }
671
673 const bool m_ascending;
674 };
675
676 // Doesn't get self
678 {
679 WorldObjectInRangeCheck(bool nearest, WorldObject const* obj, float range,
680 TypeID typeId = TYPEID_OBJECT, uint32 entry = 0) : i_nearest(nearest),
681 i_obj(obj), i_range(range), i_typeId(typeId), i_entry(entry) {}
682 WorldObject const& GetFocusObject() const { return *i_obj; }
684 {
685 if (i_typeId != TYPEID_OBJECT && u->GetTypeId() != i_typeId)
686 return false;
687 if (i_entry && u->GetEntry() != i_entry)
688 return false;
689 if (i_obj->GetGUID() == u->GetGUID())
690 return false;
691 if (!i_obj->IsWithinDistInMap(u, i_range))
692 return false;
693 if (Unit* unit = u->ToUnit())
694 if (!unit->IsAlive())
695 return false;
696 if (i_nearest)
697 i_range = i_obj->GetDistance(u);
698 return true;
699 }
700
702 float i_range;
706
708 };
709};
710#define sEluna Eluna::instance()
711
713{
714 private:
716 public:
717 static void StartTaxi(Player* player, uint32 pathid);
718 static uint32 AddPath(std::list<TaxiPathNodeEntry> nodes, uint32 mountA, uint32 mountH, uint32 price = 0, uint32 pathId = 0);
719};
720
721void StartEluna(bool restart);
722
723#endif
std::int32_t int32
Definition Define.h:73
std::uint8_t uint8
Definition Define.h:79
std::uint32_t uint32
Definition Define.h:77
std::uint64_t uint64
Definition Define.h:76
std::int64_t int64
Definition Define.h:72
static constexpr TypeID TYPEID_PLAYER
static constexpr TypeID TYPEID_OBJECT
static constexpr TypeID TYPEID_CORPSE
static constexpr TypeID TYPEID_UNIT
static constexpr TypeID TYPEID_GAMEOBJECT
@ GUILD_EVENT_COUNT
Definition HookMgr.h:170
@ PLAYER_EVENT_COUNT
Definition HookMgr.h:138
@ SERVER_EVENT_COUNT
Definition HookMgr.h:93
@ GROUP_EVENT_COUNT
Definition HookMgr.h:184
@ VEHICLE_EVENT_COUNT
Definition HookMgr.h:151
void StartEluna(bool restart)
Definition LuaEngine.cpp:41
void SetMethods(lua_State *L, ElunaRegister< T > *methodTable)
Definition LuaEngine.h:207
const char * GetTName()
Definition LuaEngine.cpp:20
std::set< std::string > LoadedScripts
Definition LuaEngine.h:23
TypeID
Definition Object.h:50
WorldObject const * i_obj
Definition LuaEngine.h:701
bool operator()(WorldObject *u)
Definition LuaEngine.h:683
WorldObjectInRangeCheck(bool nearest, WorldObject const *obj, float range, TypeID typeId=TYPEID_OBJECT, uint32 entry=0)
Definition LuaEngine.h:679
WorldObjectInRangeCheck(WorldObjectInRangeCheck const &)
WorldObject const & GetFocusObject() const
Definition LuaEngine.h:682
int64 CHECK_LONG(lua_State *L, int narg)
void Push(lua_State *, WorldObject const *obj)
Definition LuaEngine.h:461
void Push(lua_State *)
lua_State * L
Definition LuaEngine.h:384
Quest * CHECK_QUEST(lua_State *L, int narg)
Corpse * CHECK_CORPSE(lua_State *L, int narg)
ElunaBind * CreatureGossipBindings
Definition LuaEngine.h:396
~Eluna()
Definition LuaEngine.h:572
void Push(lua_State *L, T const *ptr)
Definition LuaEngine.h:426
Spell * CHECK_SPELL(lua_State *L, int narg)
void Push(lua_State *L, TempSummon const *summon)
Definition LuaEngine.h:436
Item * CHECK_ITEM(lua_State *L, int narg)
void BeginCall(int fReference)
std::map< int, std::vector< int > > PlayerEventBindings
Definition LuaEngine.h:391
Eluna()
Definition LuaEngine.h:530
ElunaBind * ItemEventBindings
Definition LuaEngine.h:399
ElunaBind * CreatureEventBindings
Definition LuaEngine.h:395
std::map< int, std::vector< int > > GuildEventBindings
Definition LuaEngine.h:393
Object * CHECK_OBJECT(lua_State *L, int narg)
void Push(lua_State *L, Pet const *pet)
Definition LuaEngine.h:431
std::map< int, std::vector< int > > VehicleEventBindings
Definition LuaEngine.h:392
void Register(uint8 reg, uint32 id, uint32 evt, int func)
std::map< int, std::vector< int > > ServerEventBindings
Definition LuaEngine.h:390
WorldObject * CHECK_WORLDOBJECT(lua_State *L, int narg)
ElunaBind * playerGossipBindings
Definition LuaEngine.h:401
friend class ScriptMgr
Definition LuaEngine.h:382
std::unordered_map< uint32, ElunaBindingMap > ElunaEntryMap
Definition LuaEngine.h:388
static void report(lua_State *)
std::map< int, std::vector< int > > GroupEventBindings
Definition LuaEngine.h:394
Vehicle * CHECK_VEHICLE(lua_State *L, int narg)
std::map< int, int > ElunaBindingMap
Definition LuaEngine.h:387
Creature * CHECK_CREATURE(lua_State *L, int narg)
static Eluna * instance()
EventMgr m_EventMgr
Definition LuaEngine.h:385
void Push(lua_State *L, Unit const *unit)
Definition LuaEngine.h:441
void LoadDirectory(const char *directory, LoadedScripts *scr)
ElunaBind * ItemGossipBindings
Definition LuaEngine.h:400
void EndCall(uint8 res)
uint64 CHECK_ULONG(lua_State *L, int narg)
GameObject * CHECK_GAMEOBJECT(lua_State *L, int narg)
void Push(lua_State *L, T value)
Definition LuaEngine.h:422
void Initialize()
Player * CHECK_PLAYER(lua_State *L, int narg)
ElunaBind * GameObjectEventBindings
Definition LuaEngine.h:397
WorldPacket * CHECK_PACKET(lua_State *L, int narg)
bool ExecuteCall(uint8 params, uint8 res)
void Push(lua_State *L, Object const *obj)
Definition LuaEngine.h:487
ElunaBind * GameObjectGossipBindings
Definition LuaEngine.h:398
Unit * CHECK_UNIT(lua_State *L, int narg)
static int tostringT(lua_State *L)
Definition LuaEngine.h:149
static int thunk(lua_State *L)
Definition LuaEngine.h:124
static T * check(lua_State *L, int narg)
Definition LuaEngine.h:116
static int index(lua_State *L)
Definition LuaEngine.h:164
static int type(lua_State *L)
Definition LuaEngine.h:38
static void tostring(char *buff, void const *obj)
Definition LuaEngine.h:159
static int gcT(lua_State *L)
Definition LuaEngine.h:134
static int push(lua_State *L, T const *obj, bool gc=false)
Definition LuaEngine.h:76
static void Register(lua_State *L)
Definition LuaEngine.h:44
void AddEvent(BasicEvent *Event, uint64 e_time, bool set_addtime=true)
uint64 CalculateTime(uint64 t_offset) const
Definition Item.h:202
static void StartTaxi(Player *player, uint32 pathid)
static uint32 nodeId
Definition LuaEngine.h:715
static uint32 AddPath(std::list< TaxiPathNodeEntry > nodes, uint32 mountA, uint32 mountH, uint32 price=0, uint32 pathId=0)
Corpse * ToCorpse()
Definition Object.h:216
uint64 GetGUID() const
Definition Object.h:119
Player * ToPlayer()
Definition Object.h:204
TypeID GetTypeId() const
Definition Object.h:131
GameObject * ToGameObject()
Definition Object.h:213
uint32 GetEntry() const
Definition Object.h:125
Creature * ToCreature()
Definition Object.h:207
Unit * ToUnit()
Definition Object.h:210
Definition Pet.h:28
Definition Spell.h:289
Definition Unit.h:1367
ElunaBindingMap * GetBindMap(uint32 entryId)
Definition LuaEngine.h:640
ElunaEntryMap Bindings
Definition LuaEngine.h:649
void Insert(uint32 entryId, uint32 eventId, int funcRef)
int GetBind(uint32 entryId, uint32 eventId)
Definition LuaEngine.h:630
bool operator()(WorldObject const *pLeft, WorldObject const *pRight) const
Definition LuaEngine.h:667
WorldObject const * m_refObj
Definition LuaEngine.h:672
ObjectDistanceOrderPred(WorldObject const *pRefObj, bool ascending=true)
Definition LuaEngine.h:666
ObjectGUIDCheck(uint64 GUID)
Definition LuaEngine.h:654
bool operator()(WorldObject *object)
Definition LuaEngine.h:655
const char * name
Definition LuaEngine.h:30
int(* mfunc)(lua_State *, T *)
Definition LuaEngine.h:31
EventProcessor * events
Definition LuaEngine.h:251
LuaEvent(EventProcessor *_events, int _funcRef, uint32 _delay, uint32 _calls, Object *_obj)
bool Execute(uint64 time, uint32 diff)
EventProcessor GlobalEvents
Definition LuaEngine.h:235
void RemoveEvents(uint64 guid)
Definition LuaEngine.h:307
std::unordered_map< uint64, EventProcessor > ProcessorMap
Definition LuaEngine.h:231
bool RemoveEvent(uint64 guid, int eventId)
Definition LuaEngine.h:361
void RemoveEvents(EventProcessor *events)
Definition LuaEngine.h:298
std::map< EventProcessor *, EventSet > EventMap
Definition LuaEngine.h:230
void RemoveEvents()
Definition LuaEngine.h:287
EventMap LuaEvents
Definition LuaEngine.h:233
void KillAllEvents(EventProcessor *events)
Definition LuaEngine.h:275
void RemoveEvent(int eventId)
Definition LuaEngine.h:369
bool RemoveEvent(EventProcessor *events, int eventId)
Definition LuaEngine.h:348
std::set< LuaEvent * > EventSet
Definition LuaEngine.h:229
int AddEvent(uint64 guid, int funcRef, uint32 delay, uint32 calls, Object *obj=NULL)
Definition LuaEngine.h:325
ProcessorMap Processors
Definition LuaEngine.h:234
LuaEvent * GetEvent(EventProcessor *events, int eventId)
Definition LuaEngine.h:333
int AddEvent(EventProcessor *events, int funcRef, uint32 delay, uint32 calls, Object *obj=NULL)
Definition LuaEngine.h:316
void Update(uint32 diff)
Definition LuaEngine.h:256