LuaInterface.cpp 81 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342
  1. /*
  2. EQ2Emulator: Everquest II Server Emulator
  3. Copyright (C) 2007 EQ2EMulator Development Team (http://www.eq2emulator.net)
  4. This file is part of EQ2Emulator.
  5. EQ2Emulator is free software: you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation, either version 3 of the License, or
  8. (at your option) any later version.
  9. EQ2Emulator is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with EQ2Emulator. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. #include "LuaInterface.h"
  17. #include "LuaFunctions.h"
  18. #include "WorldDatabase.h"
  19. #include "SpellProcess.h"
  20. #include "../common/Log.h"
  21. #ifndef WIN32
  22. #include <stdio.h>
  23. #include <sys/types.h>
  24. #include <sys/stat.h>
  25. #include <dirent.h>
  26. #include <pthread.h>
  27. #else
  28. #include <process.h>
  29. #endif
  30. extern WorldDatabase database;
  31. LuaInterface::LuaInterface() {
  32. shutting_down = false;
  33. spawn_scripts_reloading = false;
  34. MDebugClients.SetName("LuaInterface::MDebugClients");
  35. MSpells.SetName("LuaInterface::MSpells");
  36. MSpawnScripts.SetName("LuaInterface::MSpawnScripts");
  37. MZoneScripts.SetName("LuaInterface::MZoneScripts");
  38. MQuests.SetName("LuaInterface::MQuests");
  39. MLUAUserData.SetName("LuaInterface::MLUAUserData");
  40. MLUAMain.SetName("LuaInterface::MLUAMain");
  41. MItemScripts.SetName("LuaInterface::MItemScripts");
  42. MSpellDelete.SetName("LuaInterface::MSpellDelete");
  43. MCustomSpell.SetName("LuaInterface::MCustomSpell");
  44. MRegionScripts.SetName("LuaInterface::MRegionScripts");
  45. user_data_timer = new Timer(20000);
  46. user_data_timer->Start();
  47. spell_delete_timer = new Timer(5000);
  48. spell_delete_timer->Start();
  49. }
  50. #ifdef WIN32
  51. vector<string>* LuaInterface::GetDirectoryListing(const char* directory) {
  52. vector<string>* ret = new vector<string>;
  53. WIN32_FIND_DATA fdata;
  54. HANDLE dhandle;
  55. char buf[MAX_PATH];
  56. snprintf(buf, sizeof(buf), "%s\\*", directory);
  57. if((dhandle = FindFirstFile(buf, &fdata)) == INVALID_HANDLE_VALUE) {
  58. safe_delete(ret);
  59. return 0;
  60. }
  61. ret->push_back(string(fdata.cFileName));
  62. while(1) {
  63. if(FindNextFile(dhandle, &fdata)) {
  64. ret->push_back(string(fdata.cFileName));
  65. }
  66. else{
  67. if(GetLastError() == ERROR_NO_MORE_FILES) {
  68. break;
  69. } else {
  70. safe_delete(ret);
  71. FindClose(dhandle);
  72. return 0;
  73. }
  74. }
  75. }
  76. if(FindClose(dhandle) == 0) {
  77. safe_delete(ret);
  78. return 0;
  79. }
  80. return ret;
  81. }
  82. #else
  83. vector<string>* LuaInterface::GetDirectoryListing(const char* directory) {
  84. vector<string>* ret = new vector<string>;
  85. DIR *dp;
  86. struct dirent *ep;
  87. dp = opendir (directory);
  88. if (dp != NULL){
  89. while ((ep = readdir (dp)))
  90. ret->push_back(string(ep->d_name));
  91. (void) closedir (dp);
  92. }
  93. else {
  94. safe_delete(ret);
  95. return 0;
  96. }
  97. return ret;
  98. }
  99. #endif
  100. LuaInterface::~LuaInterface() {
  101. shutting_down = true;
  102. MLUAMain.lock();
  103. DestroySpells();
  104. DestroySpawnScripts();
  105. DestroyQuests();
  106. DestroyItemScripts();
  107. DestroyZoneScripts();
  108. DestroyRegionScripts();
  109. DeleteUserDataPtrs(true);
  110. DeletePendingSpells(true);
  111. safe_delete(user_data_timer);
  112. safe_delete(spell_delete_timer);
  113. }
  114. int LuaInterface::GetNumberOfArgs(lua_State* state) {
  115. return lua_gettop(state);
  116. }
  117. void LuaInterface::Process() {
  118. if(shutting_down)
  119. return;
  120. MLUAMain.lock();
  121. if(user_data_timer && user_data_timer->Check())
  122. DeleteUserDataPtrs(false);
  123. if(spell_delete_timer && spell_delete_timer->Check())
  124. DeletePendingSpells(false);
  125. MLUAMain.unlock();
  126. }
  127. void LuaInterface::DestroySpells() {
  128. map<string, LuaSpell*>::iterator itr;
  129. MSpells.lock();
  130. for(itr = spells.begin(); itr != spells.end(); itr++){
  131. lua_close(itr->second->state);
  132. safe_delete(itr->second);
  133. }
  134. spells.clear();
  135. MSpells.unlock();
  136. }
  137. void LuaInterface::DestroyQuests(bool reload) {
  138. map<int32, lua_State*>::iterator itr;
  139. MQuests.lock();
  140. for(itr = quest_states.begin(); itr != quest_states.end(); itr++){
  141. safe_delete(quests[itr->first]);
  142. lua_close(itr->second);
  143. }
  144. quests.clear();
  145. quest_states.clear();
  146. map<int32, Mutex*>::iterator mutex_itr;
  147. for(mutex_itr = quests_mutex.begin(); mutex_itr != quests_mutex.end(); mutex_itr++){
  148. safe_delete(mutex_itr->second);
  149. }
  150. quests_mutex.clear();
  151. if(reload)
  152. database.LoadQuests();
  153. MQuests.unlock();
  154. }
  155. void LuaInterface::DestroyItemScripts() {
  156. map<string, map<lua_State*, bool> >::iterator itr;
  157. map<lua_State*, bool>::iterator state_itr;
  158. Mutex* mutex = 0;
  159. MItemScripts.writelock(__FUNCTION__, __LINE__);
  160. for(itr = item_scripts.begin(); itr != item_scripts.end(); itr++){
  161. mutex = GetItemScriptMutex(itr->first.c_str());
  162. mutex->writelock(__FUNCTION__, __LINE__);
  163. for(state_itr = itr->second.begin(); state_itr != itr->second.end(); state_itr++)
  164. lua_close(state_itr->first);
  165. mutex->releasewritelock(__FUNCTION__, __LINE__);
  166. safe_delete(mutex);
  167. }
  168. item_scripts.clear();
  169. item_inverse_scripts.clear();
  170. item_scripts_mutex.clear();
  171. MItemScripts.releasewritelock(__FUNCTION__, __LINE__);
  172. }
  173. void LuaInterface::DestroySpawnScripts() {
  174. map<string, map<lua_State*, bool> >::iterator itr;
  175. map<lua_State*, bool>::iterator state_itr;
  176. Mutex* mutex = 0;
  177. MSpawnScripts.writelock(__FUNCTION__, __LINE__);
  178. for(itr = spawn_scripts.begin(); itr != spawn_scripts.end(); itr++){
  179. mutex = GetSpawnScriptMutex(itr->first.c_str());
  180. mutex->writelock(__FUNCTION__, __LINE__);
  181. for(state_itr = itr->second.begin(); state_itr != itr->second.end(); state_itr++)
  182. lua_close(state_itr->first);
  183. mutex->releasewritelock(__FUNCTION__, __LINE__);
  184. safe_delete(mutex);
  185. }
  186. spawn_scripts.clear();
  187. spawn_inverse_scripts.clear();
  188. spawn_scripts_mutex.clear();
  189. MSpawnScripts.releasewritelock(__FUNCTION__, __LINE__);
  190. }
  191. void LuaInterface::DestroyZoneScripts() {
  192. map<string, map<lua_State*, bool> >::iterator itr;
  193. map<lua_State*, bool>::iterator state_itr;
  194. Mutex* mutex = 0;
  195. MZoneScripts.writelock(__FUNCTION__, __LINE__);
  196. for (itr = zone_scripts.begin(); itr != zone_scripts.end(); itr++){
  197. mutex = GetZoneScriptMutex(itr->first.c_str());
  198. mutex->writelock(__FUNCTION__, __LINE__);
  199. for(state_itr = itr->second.begin(); state_itr != itr->second.end(); state_itr++)
  200. lua_close(state_itr->first);
  201. mutex->releasewritelock(__FUNCTION__, __LINE__);
  202. safe_delete(mutex);
  203. }
  204. zone_scripts.clear();
  205. zone_inverse_scripts.clear();
  206. zone_scripts_mutex.clear();
  207. MZoneScripts.releasewritelock(__FUNCTION__, __LINE__);
  208. }
  209. void LuaInterface::DestroyRegionScripts() {
  210. map<string, map<lua_State*, bool> >::iterator itr;
  211. map<lua_State*, bool>::iterator state_itr;
  212. Mutex* mutex = 0;
  213. MRegionScripts.writelock(__FUNCTION__, __LINE__);
  214. for (itr = region_scripts.begin(); itr != region_scripts.end(); itr++){
  215. mutex = GetRegionScriptMutex(itr->first.c_str());
  216. mutex->writelock(__FUNCTION__, __LINE__);
  217. for(state_itr = itr->second.begin(); state_itr != itr->second.end(); state_itr++)
  218. lua_close(state_itr->first);
  219. mutex->releasewritelock(__FUNCTION__, __LINE__);
  220. safe_delete(mutex);
  221. }
  222. region_scripts.clear();
  223. region_inverse_scripts.clear();
  224. region_scripts_mutex.clear();
  225. MRegionScripts.releasewritelock(__FUNCTION__, __LINE__);
  226. }
  227. void LuaInterface::ReloadSpells() {
  228. DestroySpells();
  229. database.LoadSpellScriptData();
  230. }
  231. bool LuaInterface::LoadLuaSpell(const char* name) {
  232. LuaSpell* spell = 0;
  233. string lua_script = string(name);
  234. if (lua_script.find(".lua") == string::npos)
  235. lua_script.append(".lua");
  236. lua_State* state = LoadLuaFile(lua_script.c_str());
  237. if(state){
  238. spell = new LuaSpell;
  239. spell->file_name = lua_script;
  240. spell->state = state;
  241. spell->spell = 0;
  242. spell->caster = 0;
  243. spell->initial_target = 0;
  244. spell->resisted = false;
  245. spell->interrupted = false;
  246. spell->last_spellattack_hit = false;
  247. spell->crit = false;
  248. spell->MSpellTargets.SetName("LuaSpell.MSpellTargets");
  249. spell->cancel_after_all_triggers = false;
  250. spell->num_triggers = 0;
  251. spell->had_triggers = false;
  252. spell->had_dmg_remaining = false;
  253. spell->slot_pos = 0;
  254. spell->damage_remaining = 0;
  255. spell->effect_bitmask = 0;
  256. MSpells.lock();
  257. if (spells.count(lua_script) > 0) {
  258. lua_close(spells[lua_script]->state);
  259. safe_delete(spells[lua_script]);
  260. }
  261. spells[lua_script] = spell;
  262. MSpells.unlock();
  263. return true;
  264. }
  265. return false;
  266. }
  267. bool LuaInterface::LoadLuaSpell(string name) {
  268. return LoadLuaSpell(name.c_str());
  269. }
  270. bool LuaInterface::LoadItemScript(string name) {
  271. return LoadItemScript(name.c_str());
  272. }
  273. bool LuaInterface::LoadItemScript(const char* name) {
  274. bool ret = false;
  275. if(name){
  276. lua_State* state = LoadLuaFile(name);
  277. if(state){
  278. MItemScripts.writelock(__FUNCTION__, __LINE__);
  279. item_scripts[name][state] = false;
  280. MItemScripts.releasewritelock(__FUNCTION__, __LINE__);
  281. ret = true;
  282. }
  283. }
  284. return ret;
  285. }
  286. bool LuaInterface::LoadSpawnScript(const char* name) {
  287. bool ret = false;
  288. if(name){
  289. lua_State* state = LoadLuaFile(name);
  290. if(state){
  291. MSpawnScripts.writelock(__FUNCTION__, __LINE__);
  292. spawn_scripts[name][state] = false;
  293. MSpawnScripts.releasewritelock(__FUNCTION__, __LINE__);
  294. ret = true;
  295. }
  296. }
  297. return ret;
  298. }
  299. bool LuaInterface::LoadZoneScript(const char* name) {
  300. bool ret = false;
  301. if (name) {
  302. lua_State* state = LoadLuaFile(name);
  303. if (state) {
  304. MZoneScripts.writelock(__FUNCTION__, __LINE__);
  305. zone_scripts[name][state] = false;
  306. MZoneScripts.releasewritelock(__FUNCTION__, __LINE__);
  307. ret = true;
  308. }
  309. }
  310. return ret;
  311. }
  312. bool LuaInterface::LoadRegionScript(const char* name) {
  313. bool ret = false;
  314. if (name) {
  315. lua_State* state = LoadLuaFile(name);
  316. if (state) {
  317. MRegionScripts.writelock(__FUNCTION__, __LINE__);
  318. region_scripts[name][state] = false;
  319. MRegionScripts.releasewritelock(__FUNCTION__, __LINE__);
  320. ret = true;
  321. }
  322. }
  323. return ret;
  324. }
  325. void LuaInterface::ProcessErrorMessage(const char* message) {
  326. MDebugClients.lock();
  327. vector<Client*> delete_clients;
  328. map<Client*, int32>::iterator itr;
  329. for(itr = debug_clients.begin(); itr != debug_clients.end(); itr++){
  330. if((Timer::GetCurrentTime2() - itr->second) > 60000)
  331. delete_clients.push_back(itr->first);
  332. else
  333. itr->first->Message(CHANNEL_COLOR_RED, "LUA Error: %s", message);
  334. }
  335. for(int32 i=0;i<delete_clients.size();i++)
  336. debug_clients.erase(delete_clients[i]);
  337. MDebugClients.unlock();
  338. }
  339. void LuaInterface::RemoveDebugClients(Client* client) {
  340. MDebugClients.lock();
  341. debug_clients.erase(client);
  342. MDebugClients.unlock();
  343. }
  344. void LuaInterface::UpdateDebugClients(Client* client) {
  345. MDebugClients.lock();
  346. debug_clients[client] = Timer::GetCurrentTime2();
  347. MDebugClients.unlock();
  348. }
  349. Mutex* LuaInterface::GetQuestMutex(Quest* quest) {
  350. Mutex* ret = 0;
  351. MQuests.lock();
  352. if(quests_mutex.count(quest->GetQuestID()) == 0){
  353. ret = new Mutex();
  354. quests_mutex[quest->GetQuestID()] = ret;
  355. ret->SetName(string("Quest::").append(quest->GetName()));
  356. }
  357. else
  358. ret = quests_mutex[quest->GetQuestID()];
  359. MQuests.unlock();
  360. return ret;
  361. }
  362. void LuaInterface::CallQuestFunction(Quest* quest, const char* function, Spawn* player, int32 step_id) {
  363. if(shutting_down)
  364. return;
  365. lua_State* state = 0;
  366. if(quest){
  367. LogWrite(LUA__DEBUG, 0, "LUA", "Quest: %s, function: %s", quest->GetName(), function);
  368. Mutex* mutex = GetQuestMutex(quest);
  369. mutex->lock();
  370. if(quest_states.count(quest->GetQuestID()) > 0)
  371. state = quest_states[quest->GetQuestID()];
  372. if(state){
  373. int8 arg_count = 3;
  374. lua_getglobal(state, function);
  375. SetQuestValue(state, quest);
  376. Spawn* spawn = player->GetZone()->GetSpawnByDatabaseID(quest->GetQuestGiver());
  377. SetSpawnValue(state, spawn);
  378. SetSpawnValue(state, player);
  379. if(step_id != 0xFFFFFFFF){
  380. SetInt32Value(state, step_id);
  381. arg_count++;
  382. }
  383. if(lua_pcall(state, arg_count, 0, 0) != 0){
  384. LogError("%s: Error processing quest function '%s': %s ", GetScriptName(state), function, lua_tostring(state, -1));
  385. lua_pop(state, 1);
  386. mutex->unlock();
  387. return;
  388. }
  389. }
  390. mutex->unlock();
  391. LogWrite(LUA__DEBUG, 0, "LUA", "Done!");
  392. }
  393. }
  394. Quest* LuaInterface::LoadQuest(int32 id, const char* name, const char* type, const char* zone, int8 level, const char* description, char* script_name) {
  395. if(shutting_down)
  396. return 0;
  397. lua_State* state = LoadLuaFile(script_name);
  398. Quest* quest = 0;
  399. if(state){
  400. quest = new Quest(id);
  401. if (name)
  402. quest->SetName(string(name));
  403. if (type)
  404. quest->SetType(string(type));
  405. if (zone)
  406. quest->SetZone(string(zone));
  407. quest->SetLevel(level);
  408. if (description)
  409. quest->SetDescription(string(description));
  410. lua_getglobal(state, "Init");
  411. SetQuestValue(state, quest);
  412. if(lua_pcall(state, 1, 0, 0) != 0){
  413. LogError("Error processing Quest \"%s\" (%u): %s", name ? name : "unknown", id, lua_tostring(state, -1));
  414. lua_pop(state, 1);
  415. safe_delete(quest);
  416. return 0;
  417. }
  418. if(!quest->GetName()){
  419. safe_delete(quest);
  420. return 0;
  421. }
  422. quest_states[id] = state;
  423. quests[id] = quest;
  424. }
  425. return quest;
  426. }
  427. const char* LuaInterface::GetScriptName(lua_State* state)
  428. {
  429. map<lua_State*, string>::iterator itr;
  430. MItemScripts.writelock(__FUNCTION__, __LINE__);
  431. itr = item_inverse_scripts.find(state);
  432. if (itr != item_inverse_scripts.end())
  433. {
  434. const char* scriptName = itr->second.c_str();
  435. MItemScripts.releasewritelock(__FUNCTION__, __LINE__);
  436. return scriptName;
  437. }
  438. MItemScripts.releasewritelock(__FUNCTION__, __LINE__);
  439. MSpawnScripts.writelock(__FUNCTION__, __LINE__);
  440. itr = spawn_inverse_scripts.find(state);
  441. if (itr != spawn_inverse_scripts.end())
  442. {
  443. const char* scriptName = itr->second.c_str();
  444. MSpawnScripts.releasewritelock(__FUNCTION__, __LINE__);
  445. return scriptName;
  446. }
  447. MSpawnScripts.releasewritelock(__FUNCTION__, __LINE__);
  448. MZoneScripts.writelock(__FUNCTION__, __LINE__);
  449. itr = zone_inverse_scripts.find(state);
  450. if (itr != zone_inverse_scripts.end())
  451. {
  452. const char* scriptName = itr->second.c_str();
  453. MZoneScripts.releasewritelock(__FUNCTION__, __LINE__);
  454. return scriptName;
  455. }
  456. MZoneScripts.releasewritelock(__FUNCTION__, __LINE__);
  457. MRegionScripts.writelock(__FUNCTION__, __LINE__);
  458. itr = region_inverse_scripts.find(state);
  459. if (itr != region_inverse_scripts.end())
  460. {
  461. const char* scriptName = itr->second.c_str();
  462. MRegionScripts.releasewritelock(__FUNCTION__, __LINE__);
  463. return scriptName;
  464. }
  465. MRegionScripts.releasewritelock(__FUNCTION__, __LINE__);
  466. MSpells.lock();
  467. LuaSpell* spell = GetCurrentSpell(state);
  468. if (spell)
  469. {
  470. const char* fileName = (spell->file_name.length() > 0) ? spell->file_name.c_str() : "";
  471. MSpells.unlock();
  472. return fileName;
  473. }
  474. MSpells.unlock();
  475. return "";
  476. }
  477. bool LuaInterface::LoadSpawnScript(string name) {
  478. return LoadSpawnScript(name.c_str());
  479. }
  480. bool LuaInterface::LoadZoneScript(string name) {
  481. return LoadZoneScript(name.c_str());
  482. }
  483. bool LuaInterface::LoadRegionScript(string name) {
  484. return LoadRegionScript(name.c_str());
  485. }
  486. void LuaInterface::AddSpawnPointers(LuaSpell* spell, bool first_cast, bool precast, const char* function, SpellScriptTimer* timer, bool passLuaSpell) {
  487. if (function)
  488. lua_getglobal(spell->state, function);
  489. else if (precast)
  490. lua_getglobal(spell->state, "precast");
  491. else if(first_cast)
  492. lua_getglobal(spell->state, "cast");
  493. else
  494. lua_getglobal(spell->state, "tick");
  495. if(passLuaSpell)
  496. SetSpellValue(spell->state, spell);
  497. Spawn* temp_spawn = 0;
  498. if (timer && timer->caster && spell->caster)
  499. temp_spawn = spell->caster->GetZone()->GetSpawnByID(timer->caster);
  500. if (temp_spawn)
  501. SetSpawnValue(spell->state, temp_spawn);
  502. else if (spell->caster)
  503. SetSpawnValue(spell->state, spell->caster);
  504. temp_spawn = 0;
  505. if (timer && timer->target && spell->caster)
  506. temp_spawn = spell->caster->GetZone()->GetSpawnByID(timer->target);
  507. if (temp_spawn)
  508. SetSpawnValue(spell->state, temp_spawn);
  509. else {
  510. if(spell->caster && spell->caster->GetZone() != nullptr && spell->initial_target)
  511. {
  512. // easier to debug target id as ptr
  513. Spawn* new_target = spell->caster->GetZone()->GetSpawnByID(spell->initial_target);
  514. SetSpawnValue(spell->state, new_target);
  515. }
  516. else if(spell->caster && spell->caster->GetTarget())
  517. SetSpawnValue(spell->state, spell->caster->GetTarget());
  518. else
  519. SetSpawnValue(spell->state, 0);
  520. }
  521. }
  522. LuaSpell* LuaInterface::GetCurrentSpell(lua_State* state) {
  523. if(current_spells.count(state) > 0)
  524. return current_spells[state];
  525. return 0;
  526. }
  527. bool LuaInterface::CallSpellProcess(LuaSpell* spell, int8 num_parameters) {
  528. if(shutting_down || !spell || !spell->caster)
  529. return false;
  530. MSpells.lock();
  531. current_spells[spell->state] = spell;
  532. MSpells.unlock();
  533. if(lua_pcall(spell->state, num_parameters, 0, 0) != 0){
  534. LogError("Error running %s", lua_tostring(spell->state, -1));
  535. lua_pop(spell->state, 1);
  536. RemoveSpell(spell, false);
  537. return false;
  538. }
  539. return true;
  540. }
  541. void LuaInterface::RemoveSpawnScript(const char* name) {
  542. lua_State* state = 0;
  543. Mutex* mutex = GetSpawnScriptMutex(name);
  544. while((state = GetSpawnScript(name, false))){
  545. mutex->writelock(__FUNCTION__, __LINE__);
  546. lua_close(state);
  547. spawn_scripts[name].erase(state);
  548. mutex->releasewritelock(__FUNCTION__, __LINE__);
  549. }
  550. MSpawnScripts.writelock(__FUNCTION__, __LINE__);
  551. spawn_scripts.erase(name);
  552. MSpawnScripts.releasewritelock(__FUNCTION__, __LINE__);
  553. }
  554. bool LuaInterface::CallItemScript(lua_State* state, int8 num_parameters) {
  555. if(shutting_down)
  556. return false;
  557. if(!state || lua_pcall(state, num_parameters, 0, 0) != 0){
  558. if (state){
  559. const char* err = lua_tostring(state, -1);
  560. LogError("%s: %s", GetScriptName(state), err);
  561. lua_pop(state, 1);
  562. }
  563. return false;
  564. }
  565. return true;
  566. }
  567. bool LuaInterface::CallSpawnScript(lua_State* state, int8 num_parameters) {
  568. if(shutting_down)
  569. return false;
  570. if(!state || lua_pcall(state, num_parameters, 0, 0) != 0){
  571. if (state){
  572. const char* err = lua_tostring(state, -1);
  573. LogError("%s: %s", GetScriptName(state), err);
  574. lua_pop(state, 1);
  575. }
  576. return false;
  577. }
  578. return true;
  579. }
  580. bool LuaInterface::CallZoneScript(lua_State* state, int8 num_parameters) {
  581. if(shutting_down)
  582. return false;
  583. if (!state || lua_pcall(state, num_parameters, 0, 0) != 0) {
  584. if (state){
  585. const char* err = lua_tostring(state, -1);
  586. LogError("%s: %s", GetScriptName(state), err);
  587. lua_pop(state, 1);
  588. }
  589. return false;
  590. }
  591. return true;
  592. }
  593. bool LuaInterface::CallRegionScript(lua_State* state, int8 num_parameters, int32* returnValue) {
  594. if(shutting_down)
  595. return false;
  596. if (!state || lua_pcall(state, num_parameters, 1, 0) != 0) {
  597. if (state){
  598. const char* err = lua_tostring(state, -1);
  599. LogError("%s: %s", GetScriptName(state), err);
  600. lua_pop(state, 1);
  601. }
  602. return false;
  603. }
  604. int32 result = 0;
  605. if (lua_isnumber(state, -1))
  606. {
  607. result = (int32)lua_tonumber(state, -1);
  608. lua_pop(state, 1);
  609. }
  610. if(returnValue)
  611. *returnValue = result;
  612. return true;
  613. }
  614. lua_State* LuaInterface::LoadLuaFile(const char* name) {
  615. if(shutting_down)
  616. return 0;
  617. lua_State* state = luaL_newstate();
  618. luaL_openlibs(state);
  619. if(luaL_dofile(state, name) == 0){
  620. RegisterFunctions(state);
  621. return state;
  622. }
  623. else{
  624. LogError("Error loading %s (file name: '%s')", lua_tostring(state, -1), name);
  625. lua_pop(state, 1);
  626. lua_close(state);
  627. }
  628. return 0;
  629. }
  630. void LuaInterface::RemoveSpell(LuaSpell* spell, bool call_remove_function, bool can_delete, string reason) {
  631. if(shutting_down)
  632. return;
  633. if(call_remove_function){
  634. lua_getglobal(spell->state, "remove");
  635. LUASpawnWrapper* spawn_wrapper = new LUASpawnWrapper();
  636. spawn_wrapper->spawn = spell->caster;
  637. AddUserDataPtr(spawn_wrapper);
  638. lua_pushlightuserdata(spell->state, spawn_wrapper);
  639. if(spell->caster && (spell->initial_target || spell->caster->GetTarget())){
  640. spawn_wrapper = new LUASpawnWrapper();
  641. if(!spell->initial_target)
  642. spawn_wrapper->spawn = spell->caster->GetTarget();
  643. else
  644. spawn_wrapper->spawn = spell->caster->GetZone()->GetSpawnByID(spell->initial_target);
  645. AddUserDataPtr(spawn_wrapper);
  646. lua_pushlightuserdata(spell->state, spawn_wrapper);
  647. }
  648. else
  649. lua_pushlightuserdata(spell->state, 0);
  650. if (spell->caster && !spell->caster->Alive())
  651. reason = "dead";
  652. lua_pushstring(spell->state, (char*)reason.c_str());
  653. MSpells.lock();
  654. current_spells[spell->state] = spell;
  655. MSpells.unlock();
  656. lua_pcall(spell->state, 3, 0, 0);
  657. ResetFunctionStack(spell->state);
  658. }
  659. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  660. for (int8 i = 0; i < spell->targets.size(); i++) {
  661. Spawn* target = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  662. if (!target || !target->IsEntity())
  663. continue;
  664. ((Entity*)target)->RemoveProc(0, spell);
  665. }
  666. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  667. // we need to make sure all memory is purged for a copied spell, its only used once
  668. if (spell->spell->IsCopiedSpell())
  669. can_delete = true;
  670. if (can_delete) {
  671. AddPendingSpellDelete(spell);
  672. }
  673. if (spell->caster)
  674. {
  675. spell->caster->GetZone()->GetSpellProcess()->RemoveSpellScriptTimerBySpell(spell, false);
  676. spell->caster->RemoveProc(0, spell);
  677. spell->caster->RemoveMaintainedSpell(spell);
  678. }
  679. }
  680. void LuaInterface::RegisterFunctions(lua_State* state) {
  681. lua_register(state, "SetHP", EQ2Emu_lua_SetCurrentHP);
  682. lua_register(state, "SetMaxHP", EQ2Emu_lua_SetMaxHP);
  683. lua_register(state, "SetMaxHPBase", EQ2Emu_lua_SetMaxHPBase);
  684. lua_register(state, "SetPower", EQ2Emu_lua_SetCurrentPower);
  685. lua_register(state, "SetMaxPower", EQ2Emu_lua_SetMaxPower);
  686. lua_register(state, "SetMaxPowerBase", EQ2Emu_lua_SetMaxPowerBase);
  687. lua_register(state, "SetPosition", EQ2Emu_lua_SetPosition);
  688. lua_register(state, "SetHeading", EQ2Emu_lua_SetHeading);
  689. lua_register(state, "SetModelType", EQ2Emu_lua_SetModelType);
  690. lua_register(state, "SetAdventureClass", EQ2Emu_lua_SetAdventureClass);
  691. lua_register(state, "SetTradeskillClass", EQ2Emu_lua_SetTradeskillClass);
  692. lua_register(state, "SetMount", EQ2Emu_lua_SetMount);
  693. lua_register(state, "SetMountColor", EQ2Emu_lua_SetMountColor);
  694. lua_register(state, "GetMount", EQ2Emu_lua_GetMount);
  695. lua_register(state, "GetRace", EQ2Emu_lua_GetRace);
  696. lua_register(state, "GetRaceName", EQ2Emu_lua_GetRaceName);
  697. lua_register(state, "GetClass", EQ2Emu_lua_GetClass);
  698. lua_register(state, "GetClassName", EQ2Emu_lua_GetClassName);
  699. lua_register(state, "GetArchetypeName", EQ2Emu_lua_GetArchetypeName);
  700. lua_register(state, "SetSpeed", EQ2Emu_lua_SetSpeed);
  701. lua_register(state, "ModifyPower", EQ2Emu_lua_ModifyPower);
  702. lua_register(state, "ModifyHP", EQ2Emu_lua_ModifyHP);
  703. lua_register(state, "GetDistance", EQ2Emu_lua_GetDistance);
  704. lua_register(state, "GetHeading", EQ2Emu_lua_GetHeading);
  705. lua_register(state, "GetLevel", EQ2Emu_lua_GetLevel);
  706. lua_register(state, "GetHP", EQ2Emu_lua_GetCurrentHP);
  707. lua_register(state, "GetMaxHP", EQ2Emu_lua_GetMaxHP);
  708. lua_register(state, "GetMaxHPBase", EQ2Emu_lua_GetMaxHPBase);
  709. lua_register(state, "GetMaxPower", EQ2Emu_lua_GetMaxPower);
  710. lua_register(state, "GetMaxPowerBase", EQ2Emu_lua_GetMaxPowerBase);
  711. lua_register(state, "GetName", EQ2Emu_lua_GetName);
  712. lua_register(state, "GetPower", EQ2Emu_lua_GetCurrentPower);
  713. lua_register(state, "GetX", EQ2Emu_lua_GetX);
  714. lua_register(state, "GetY", EQ2Emu_lua_GetY);
  715. lua_register(state, "GetZ", EQ2Emu_lua_GetZ);
  716. lua_register(state, "GetSpawnID", EQ2Emu_lua_GetSpawnID);
  717. lua_register(state, "GetSpawnGroupID", EQ2Emu_lua_GetSpawnGroupID);
  718. lua_register(state, "SetSpawnGroupID", EQ2Emu_lua_SetSpawnGroupID);
  719. lua_register(state, "GetSpawnLocationID", EQ2Emu_lua_GetSpawnLocationID);
  720. lua_register(state, "GetSpawnLocationPlacementID", EQ2Emu_lua_GetSpawnLocationPlacementID);
  721. lua_register(state, "CreateSpawnList", EQ2Emu_lua_CreateSpawnList);
  722. lua_register(state, "AddSpawnToSpawnList", EQ2Emu_lua_AddSpawnToSpawnList);
  723. lua_register(state, "RemoveSpawnFromSpawnList", EQ2Emu_lua_RemoveSpawnFromSpawnList);
  724. lua_register(state, "GetSpawnListBySpawnID", EQ2Emu_lua_GetSpawnListBySpawnID);
  725. lua_register(state, "GetSpawnFromList", EQ2Emu_lua_GetSpawnFromList);
  726. lua_register(state, "GetSpawnListSize", EQ2Emu_lua_GetSpawnListSize);
  727. lua_register(state, "SetFactionID", EQ2Emu_lua_SetFactionID);
  728. lua_register(state, "GetFactionID", EQ2Emu_lua_GetFactionID);
  729. lua_register(state, "GetFactionAmount", EQ2Emu_lua_GetFactionAmount);
  730. lua_register(state, "GetGender", EQ2Emu_lua_GetGender);
  731. lua_register(state, "GetTarget", EQ2Emu_lua_GetTarget);
  732. lua_register(state, "HasFreeSlot", EQ2Emu_lua_HasFreeSlot);
  733. lua_register(state, "HasItemEquipped", EQ2Emu_lua_HasItemEquipped);
  734. lua_register(state, "GetEquippedItemByID", EQ2Emu_lua_GetEquippedItemByID);
  735. lua_register(state, "SetEquippedItemByID", EQ2Emu_lua_SetEquippedItemByID);
  736. lua_register(state, "SetEquippedItem", EQ2Emu_lua_SetEquippedItem);
  737. lua_register(state, "UnequipSlot", EQ2Emu_lua_UnequipSlot);
  738. lua_register(state, "SetEquipment", EQ2Emu_lua_SetEquipment);
  739. lua_register(state, "GetEquippedItemBySlot", EQ2Emu_lua_GetEquippedItemBySlot);
  740. lua_register(state, "GetItemByID", EQ2Emu_lua_GetItemByID);
  741. lua_register(state, "GetItemType", EQ2Emu_lua_GetItemType);
  742. lua_register(state, "GetSpellName", EQ2Emu_lua_GetSpellName);
  743. lua_register(state, "PerformCameraShake", EQ2Emu_lua_PerformCameraShake);
  744. lua_register(state, "GetModelType", EQ2Emu_lua_GetModelType);
  745. lua_register(state, "GetSpeed", EQ2Emu_lua_GetSpeed);
  746. lua_register(state, "HasMoved", EQ2Emu_lua_HasMoved);
  747. lua_register(state, "SpellDamage", EQ2Emu_lua_SpellDamage);
  748. lua_register(state, "CastSpell", EQ2Emu_lua_CastSpell);
  749. lua_register(state, "SpellHeal", EQ2Emu_lua_SpellHeal);
  750. lua_register(state, "SpellHealPct", EQ2Emu_lua_SpellHealPct);
  751. lua_register(state, "AddItem", EQ2Emu_lua_AddItem);
  752. lua_register(state, "SummonItem", EQ2Emu_lua_SummonItem);
  753. lua_register(state, "RemoveItem", EQ2Emu_lua_RemoveItem);
  754. lua_register(state, "HasItem", EQ2Emu_lua_HasItem);
  755. lua_register(state, "SpawnMob", EQ2Emu_lua_Spawn);
  756. lua_register(state, "SummonPet", EQ2Emu_lua_SummonPet);
  757. lua_register(state, "AddSpawnAccess", EQ2Emu_lua_AddSpawnAccess);
  758. lua_register(state, "GetZone", EQ2Emu_lua_GetZone);
  759. lua_register(state, "GetZoneName", EQ2Emu_lua_GetZoneName);
  760. lua_register(state, "GetZoneID", EQ2Emu_lua_GetZoneID);
  761. lua_register(state, "Zone", EQ2Emu_lua_Zone);
  762. lua_register(state, "AddHate", EQ2Emu_lua_AddHate);
  763. lua_register(state, "IsAlive", EQ2Emu_lua_IsAlive);
  764. lua_register(state, "IsInCombat", EQ2Emu_lua_IsInCombat);
  765. lua_register(state, "Attack", EQ2Emu_lua_Attack);
  766. lua_register(state, "ApplySpellVisual", EQ2Emu_lua_ApplySpellVisual);
  767. lua_register(state, "IsPlayer", EQ2Emu_lua_IsPlayer);
  768. lua_register(state, "GetCharacterID", EQ2Emu_lua_GetCharacterID);
  769. lua_register(state, "FaceTarget", EQ2Emu_lua_FaceTarget);
  770. lua_register(state, "MoveToLocation", EQ2Emu_lua_MoveToLocation);
  771. lua_register(state, "ClearRunningLocations", EQ2Emu_lua_ClearRunningLocations);
  772. lua_register(state, "Shout", EQ2Emu_lua_Shout);
  773. lua_register(state, "Say", EQ2Emu_lua_Say);
  774. lua_register(state, "SayOOC", EQ2Emu_lua_SayOOC);
  775. lua_register(state, "Emote", EQ2Emu_lua_Emote);
  776. lua_register(state, "MovementLoopAddLocation", EQ2Emu_lua_MovementLoopAdd); // do not remove this function, it is already heavily used by the content team
  777. lua_register(state, "MovementLoopAdd", EQ2Emu_lua_MovementLoopAdd);
  778. lua_register(state, "GetCurrentZoneSafeLocation", EQ2Emu_lua_GetCurrentZoneSafeLocation);
  779. lua_register(state, "AddTimer", EQ2Emu_lua_AddTimer);
  780. lua_register(state, "Harvest", EQ2Emu_lua_Harvest);
  781. lua_register(state, "SetAttackable", EQ2Emu_lua_SetAttackable);
  782. lua_register(state, "AddSpellBonus", EQ2Emu_lua_AddSpellBonus);
  783. lua_register(state, "RemoveSpellBonus", EQ2Emu_lua_RemoveSpellBonus);
  784. lua_register(state, "AddSkillBonus", EQ2Emu_lua_AddSkillBonus);
  785. lua_register(state, "RemoveSkillBonus", EQ2Emu_lua_RemoveSkillBonus);
  786. lua_register(state, "AddControlEffect", EQ2Emu_lua_AddControlEffect);
  787. lua_register(state, "RemoveControlEffect", EQ2Emu_lua_RemoveControlEffect);
  788. lua_register(state, "HasControlEffect", EQ2Emu_lua_HasControlEffect);
  789. lua_register(state, "GetBaseAggroRadius", EQ2Emu_lua_GetBaseAggroRadius);
  790. lua_register(state, "GetAggroRadius", EQ2Emu_lua_GetAggroRadius);
  791. lua_register(state, "SetAggroRadius", EQ2Emu_lua_SetAggroRadius);
  792. lua_register(state, "GetCurrentZoneSafeLocation", EQ2Emu_lua_GetCurrentZoneSafeLocation);
  793. lua_register(state, "SetDeity", EQ2Emu_lua_SetDeity);
  794. lua_register(state, "GetDeity", EQ2Emu_lua_GetDeity);
  795. lua_register(state, "GetInt", EQ2Emu_lua_GetInt);
  796. lua_register(state, "GetWis", EQ2Emu_lua_GetWis);
  797. lua_register(state, "GetSta", EQ2Emu_lua_GetSta);
  798. lua_register(state, "GetStr", EQ2Emu_lua_GetStr);
  799. lua_register(state, "GetAgi", EQ2Emu_lua_GetAgi);
  800. lua_register(state, "SetInt", EQ2Emu_lua_SetInt);
  801. lua_register(state, "SetWis", EQ2Emu_lua_SetWis);
  802. lua_register(state, "SetSta", EQ2Emu_lua_SetSta);
  803. lua_register(state, "SetStr", EQ2Emu_lua_SetStr);
  804. lua_register(state, "SetAgi", EQ2Emu_lua_SetAgi);
  805. lua_register(state, "GetIntBase", EQ2Emu_lua_GetIntBase);
  806. lua_register(state, "GetWisBase", EQ2Emu_lua_GetWisBase);
  807. lua_register(state, "GetStaBase", EQ2Emu_lua_GetStaBase);
  808. lua_register(state, "GetStrBase", EQ2Emu_lua_GetStrBase);
  809. lua_register(state, "GetAgiBase", EQ2Emu_lua_GetAgiBase);
  810. lua_register(state, "SetIntBase", EQ2Emu_lua_SetIntBase);
  811. lua_register(state, "SetWisBase", EQ2Emu_lua_SetWisBase);
  812. lua_register(state, "SetStaBase", EQ2Emu_lua_SetStaBase);
  813. lua_register(state, "SetStrBase", EQ2Emu_lua_SetStrBase);
  814. lua_register(state, "SetAgiBase", EQ2Emu_lua_SetAgiBase);
  815. lua_register(state, "GetSpawn", EQ2Emu_lua_GetSpawn);
  816. lua_register(state, "GetVariableValue", EQ2Emu_lua_GetVariableValue);
  817. lua_register(state, "GetCoinMessage", EQ2Emu_lua_GetCoinMessage);
  818. lua_register(state, "GetSpawnByGroupID", EQ2Emu_lua_GetSpawnByGroupID);
  819. lua_register(state, "GetSpawnByLocationID", EQ2Emu_lua_GetSpawnByLocationID);
  820. lua_register(state, "PlayFlavor", EQ2Emu_lua_PlayFlavor);
  821. lua_register(state, "PlaySound", EQ2Emu_lua_PlaySound);
  822. lua_register(state, "PlayVoice", EQ2Emu_lua_PlayVoice);
  823. lua_register(state, "PlayAnimation", EQ2Emu_lua_PlayAnimation);
  824. lua_register(state, "AddLootItem", EQ2Emu_lua_AddLootItem);
  825. lua_register(state, "HasLootItem", EQ2Emu_lua_HasLootItem);
  826. lua_register(state, "RemoveLootItem", EQ2Emu_lua_RemoveLootItem);
  827. lua_register(state, "AddLootCoin", EQ2Emu_lua_AddLootCoin);
  828. lua_register(state, "GiveLoot", EQ2Emu_lua_GiveLoot);
  829. lua_register(state, "HasPendingLootItem", EQ2Emu_lua_HasPendingLootItem);
  830. lua_register(state, "HasPendingLoot", EQ2Emu_lua_HasPendingLoot);
  831. lua_register(state, "SetLootCoin", EQ2Emu_lua_SetLootCoin);
  832. lua_register(state, "GetLootCoin", EQ2Emu_lua_GetLootCoin);
  833. lua_register(state, "SetPlayerProximityFunction", EQ2Emu_lua_SetPlayerProximityFunction);
  834. lua_register(state, "SetLocationProximityFunction", EQ2Emu_lua_SetLocationProximityFunction);
  835. lua_register(state, "CreateConversation", EQ2Emu_lua_CreateConversation);
  836. lua_register(state, "AddConversationOption", EQ2Emu_lua_AddConversationOption);
  837. lua_register(state, "StartConversation", EQ2Emu_lua_StartConversation);
  838. lua_register(state, "CloseConversation", EQ2Emu_lua_CloseConversation);
  839. lua_register(state, "CloseItemConversation", EQ2Emu_lua_CloseItemConversation);
  840. //lua_register(state, "StartItemConversation", EQ2Emu_lua_StartItemConversation);
  841. lua_register(state, "StartDialogConversation", EQ2Emu_lua_StartDialogConversation);
  842. lua_register(state, "SendStateCommand", EQ2Emu_lua_SendStateCommand);
  843. lua_register(state, "SpawnSet", EQ2Emu_lua_SpawnSet);
  844. lua_register(state, "SpawnSetByDistance", EQ2Emu_lua_SpawnSetByDistance);
  845. lua_register(state, "SpawnMove", EQ2Emu_lua_SpawnMove);
  846. lua_register(state, "KillSpawn", EQ2Emu_lua_KillSpawn);
  847. lua_register(state, "KillSpawnByDistance", EQ2Emu_lua_KillSpawnByDistance);
  848. lua_register(state, "Despawn", EQ2Emu_lua_Despawn);
  849. lua_register(state, "ChangeHandIcon", EQ2Emu_lua_ChangeHandIcon);
  850. lua_register(state, "SetVisualFlag", EQ2Emu_lua_SetVisualFlag);
  851. lua_register(state, "SetInfoFlag", EQ2Emu_lua_SetInfoFlag);
  852. lua_register(state, "IsBindAllowed", EQ2Emu_lua_IsBindAllowed);
  853. lua_register(state, "IsGateAllowed", EQ2Emu_lua_IsGateAllowed);
  854. lua_register(state, "Bind", EQ2Emu_lua_Bind);
  855. lua_register(state, "Gate", EQ2Emu_lua_Gate);
  856. lua_register(state, "SendMessage", EQ2Emu_lua_SendMessage);
  857. lua_register(state, "SendPopUpMessage", EQ2Emu_lua_SendPopUpMessage);
  858. lua_register(state, "SetServerControlFlag", EQ2Emu_lua_SetServerControlFlag);
  859. lua_register(state, "ToggleTracking", EQ2Emu_lua_ToggleTracking);
  860. lua_register(state, "AddPrimaryEntityCommand", EQ2Emu_lua_AddPrimaryEntityCommand);
  861. lua_register(state, "AddSpellBookEntry", EQ2Emu_lua_AddSpellBookEntry);
  862. lua_register(state, "HasSpell", EQ2Emu_lua_HasSpell);
  863. lua_register(state, "Interrupt", EQ2Emu_lua_Interrupt);
  864. lua_register(state, "Stealth", EQ2Emu_lua_Stealth);
  865. lua_register(state, "IsInvis", EQ2Emu_lua_IsInvis);
  866. lua_register(state, "IsStealthed", EQ2Emu_lua_IsStealthed);
  867. lua_register(state, "AddSpawnIDAccess", EQ2Emu_lua_AddSpawnIDAccess);
  868. lua_register(state, "RemoveSpawnIDAccess", EQ2Emu_lua_RemoveSpawnIDAccess);
  869. lua_register(state, "HasRecipeBook", EQ2Emu_lua_HasRecipeBook);
  870. lua_register(state, "SetRequiredQuest", EQ2Emu_lua_SetRequiredQuest);
  871. lua_register(state, "SetRequiredHistory", EQ2Emu_lua_SetRequiredHistory);
  872. lua_register(state, "SetStepComplete", EQ2Emu_lua_SetStepComplete);
  873. lua_register(state, "AddStepProgress", EQ2Emu_lua_AddStepProgress);
  874. lua_register(state, "UpdateQuestTaskGroupDescription", EQ2Emu_lua_UpdateQuestTaskGroupDescription);
  875. lua_register(state, "GetTaskGroupStep", EQ2Emu_lua_GetTaskGroupStep);
  876. lua_register(state, "GetQuestStep", EQ2Emu_lua_GetQuestStep);
  877. lua_register(state, "QuestStepIsComplete", EQ2Emu_lua_QuestStepIsComplete);
  878. lua_register(state, "RegisterQuest", EQ2Emu_lua_RegisterQuest);
  879. lua_register(state, "SetQuestPrereqLevel", EQ2Emu_lua_SetQuestPrereqLevel);
  880. lua_register(state, "AddQuestPrereqQuest", EQ2Emu_lua_AddQuestPrereqQuest);
  881. lua_register(state, "AddQuestPrereqItem", EQ2Emu_lua_AddQuestPrereqItem);
  882. lua_register(state, "AddQuestPrereqFaction", EQ2Emu_lua_AddQuestPrereqFaction);
  883. lua_register(state, "AddQuestPrereqRace", EQ2Emu_lua_AddQuestPrereqRace);
  884. lua_register(state, "AddQuestPrereqModelType", EQ2Emu_lua_AddQuestPrereqModelType);
  885. lua_register(state, "AddQuestPrereqClass", EQ2Emu_lua_AddQuestPrereqClass);
  886. lua_register(state, "AddQuestPrereqTradeskillLevel", EQ2Emu_lua_AddQuestPrereqTradeskillLevel);
  887. lua_register(state, "AddQuestPrereqTradeskillClass", EQ2Emu_lua_AddQuestPrereqTradeskillClass);
  888. lua_register(state, "AddQuestSelectableRewardItem", EQ2Emu_lua_AddQuestSelectableRewardItem);
  889. lua_register(state, "HasQuestRewardItem", EQ2Emu_lua_HasQuestRewardItem);
  890. lua_register(state, "AddQuestRewardItem", EQ2Emu_lua_AddQuestRewardItem);
  891. lua_register(state, "AddQuestRewardCoin", EQ2Emu_lua_AddQuestRewardCoin);
  892. lua_register(state, "AddQuestRewardFaction", EQ2Emu_lua_AddQuestRewardFaction);
  893. lua_register(state, "SetQuestRewardStatus", EQ2Emu_lua_SetQuestRewardStatus);
  894. lua_register(state, "SetQuestRewardComment", EQ2Emu_lua_SetQuestRewardComment);
  895. lua_register(state, "SetQuestRewardExp", EQ2Emu_lua_SetQuestRewardExp);
  896. lua_register(state, "AddQuestStepKill", EQ2Emu_lua_AddQuestStepKill);
  897. lua_register(state, "AddQuestStep", EQ2Emu_lua_AddQuestStep);
  898. lua_register(state, "AddQuestStepChat", EQ2Emu_lua_AddQuestStepChat);
  899. lua_register(state, "AddQuestStepObtainItem", EQ2Emu_lua_AddQuestStepObtainItem);
  900. lua_register(state, "AddQuestStepLocation", EQ2Emu_lua_AddQuestStepLocation);
  901. lua_register(state, "AddQuestStepSpell", EQ2Emu_lua_AddQuestStepSpell);
  902. lua_register(state, "AddQuestStepCraft", EQ2Emu_lua_AddQuestStepCraft);
  903. lua_register(state, "AddQuestStepHarvest", EQ2Emu_lua_AddQuestStepHarvest);
  904. lua_register(state, "AddQuestStepCompleteAction", EQ2Emu_lua_AddQuestStepCompleteAction);
  905. lua_register(state, "AddQuestStepProgressAction", EQ2Emu_lua_AddQuestStepProgressAction);
  906. lua_register(state, "SetQuestCompleteAction", EQ2Emu_lua_SetQuestCompleteAction);
  907. lua_register(state, "GiveQuestReward", EQ2Emu_lua_GiveQuestReward);
  908. lua_register(state, "GiveImmediateQuestReward", EQ2Emu_lua_GiveImmediateQuestReward);
  909. lua_register(state, "UpdateQuestStepDescription", EQ2Emu_lua_UpdateQuestStepDescription);
  910. lua_register(state, "UpdateQuestDescription", EQ2Emu_lua_UpdateQuestDescription);
  911. lua_register(state, "UpdateQuestZone", EQ2Emu_lua_UpdateQuestZone);
  912. lua_register(state, "SetCompletedDescription", EQ2Emu_lua_SetCompletedDescription);
  913. lua_register(state, "OfferQuest", EQ2Emu_lua_OfferQuest);
  914. lua_register(state, "ProvidesQuest", EQ2Emu_lua_ProvidesQuest);
  915. lua_register(state, "HasQuest", EQ2Emu_lua_HasQuest);
  916. lua_register(state, "HasCompletedQuest", EQ2Emu_lua_HasCompletedQuest);
  917. lua_register(state, "QuestIsComplete", EQ2Emu_lua_QuestIsComplete);
  918. lua_register(state, "QuestReturnNPC", EQ2Emu_lua_QuestReturnNPC);
  919. lua_register(state, "GetQuest", EQ2Emu_lua_GetQuest);
  920. lua_register(state, "HasCollectionsToHandIn", EQ2Emu_lua_HasCollectionsToHandIn);
  921. lua_register(state, "HandInCollections", EQ2Emu_lua_HandInCollections);
  922. lua_register(state, "UseWidget", EQ2Emu_lua_UseWidget);
  923. lua_register(state, "SetSpellList", EQ2Emu_lua_SetSpellList);
  924. lua_register(state, "GetPet", EQ2Emu_lua_GetPet);
  925. lua_register(state, "Charm", EQ2Emu_lua_Charm);
  926. lua_register(state, "GetGroup", EQ2Emu_lua_GetGroup);
  927. lua_register(state, "SetCompleteFlag", EQ2Emu_lua_SetCompleteFlag);
  928. lua_register(state, "SetQuestYellow", EQ2Emu_lua_SetQuestYellow);
  929. lua_register(state, "CanReceiveQuest", EQ2Emu_lua_CanReceiveQuest);
  930. lua_register(state, "AddTransportSpawn", EQ2Emu_lua_AddTransportSpawn);
  931. // Option window
  932. lua_register(state, "CreateOptionWindow", EQ2Emu_lua_CreateOptionWindow);
  933. lua_register(state, "AddOptionWindowOption", EQ2Emu_lua_AddOptionWindowOption);
  934. lua_register(state, "SendOptionWindow", EQ2Emu_lua_SendOptionWindow);
  935. lua_register(state, "GetTradeskillClass", EQ2Emu_lua_GetTradeskillClass);
  936. lua_register(state, "GetTradeskillLevel", EQ2Emu_lua_GetTradeskillLevel);
  937. lua_register(state, "GetTradeskillClassName", EQ2Emu_lua_GetTradeskillClassName);
  938. lua_register(state, "SetTradeskillLevel", EQ2Emu_lua_SetTradeskillLevel);
  939. lua_register(state, "SummonDeityPet", EQ2Emu_lua_SummonDeityPet);
  940. lua_register(state, "SummonCosmeticPet", EQ2Emu_lua_SummonCosmeticPet);
  941. lua_register(state, "DismissPet", EQ2Emu_lua_DismissPet);
  942. lua_register(state, "GetCharmedPet", EQ2Emu_lua_GetCharmedPet);
  943. lua_register(state, "GetDeityPet", EQ2Emu_lua_GetDeityPet);
  944. lua_register(state, "GetCosmeticPet", EQ2Emu_lua_GetCosmeticPet);
  945. lua_register(state, "SetQuestFeatherColor", EQ2Emu_lua_SetQuestFeatherColor);
  946. lua_register(state, "RemoveSpawnAccess", EQ2Emu_lua_RemoveSpawnAccess);
  947. lua_register(state, "SpawnByLocationID", EQ2Emu_lua_SpawnByLocationID);
  948. lua_register(state, "CastEntityCommand", EQ2Emu_lua_CastEntityCommand);
  949. lua_register(state, "SetLuaBrain", EQ2Emu_lua_SetLuaBrain);
  950. lua_register(state, "SetBrainTick", EQ2Emu_lua_SetBrainTick);
  951. lua_register(state, "SetFollowTarget", EQ2Emu_lua_SetFollowTarget);
  952. lua_register(state, "GetFollowTarget", EQ2Emu_lua_GetFollowTarget);
  953. lua_register(state, "ToggleFollow", EQ2Emu_lua_ToggleFollow);
  954. lua_register(state, "IsFollowing", EQ2Emu_lua_IsFollowing);
  955. lua_register(state, "SetTempVariable", EQ2Emu_lua_SetTempVariable);
  956. lua_register(state, "GetTempVariable", EQ2Emu_lua_GetTempVariable);
  957. lua_register(state, "GiveQuestItem", EQ2Emu_lua_GiveQuestItem);
  958. lua_register(state, "SetQuestRepeatable", EQ2Emu_lua_SetQuestRepeatable);
  959. lua_register(state, "AddWaypoint", EQ2Emu_lua_AddWaypoint);
  960. lua_register(state, "RemoveWaypoint", EQ2Emu_lua_RemoveWaypoint);
  961. lua_register(state, "SendWaypoints", EQ2Emu_lua_SendWaypoints);
  962. lua_register(state, "AddWard", EQ2Emu_lua_AddWard);
  963. lua_register(state, "AddToWard", EQ2Emu_lua_AddToWard);
  964. lua_register(state, "RemoveWard", EQ2Emu_lua_RemoveWard);
  965. lua_register(state, "GetWardAmountLeft", EQ2Emu_lua_GetWardAmountLeft);
  966. lua_register(state, "GetWardValue", EQ2Emu_lua_GetWardValue);
  967. lua_register(state, "SetTarget", EQ2Emu_lua_SetTarget);
  968. lua_register(state, "IsPet", EQ2Emu_lua_IsPet);
  969. lua_register(state, "GetOwner", EQ2Emu_lua_GetOwner);
  970. lua_register(state, "SetInCombat", EQ2Emu_lua_SetInCombat);
  971. lua_register(state, "CompareSpawns", EQ2Emu_lua_CompareSpawns);
  972. lua_register(state, "Runback", EQ2Emu_lua_Runback);
  973. lua_register(state, "GetRunbackDistance", EQ2Emu_lua_GetRunbackDistance);
  974. lua_register(state, "IsCasting", EQ2Emu_lua_IsCasting);
  975. lua_register(state, "IsMezzed", EQ2Emu_lua_IsMezzed);
  976. lua_register(state, "IsStunned", EQ2Emu_lua_IsStunned);
  977. lua_register(state, "IsMezzedOrStunned", EQ2Emu_lua_IsMezzedOrStunned);
  978. lua_register(state, "ProcessSpell", EQ2Emu_lua_ProcessSpell);
  979. lua_register(state, "ProcessMelee", EQ2Emu_lua_ProcessMelee);
  980. lua_register(state, "HasRecovered", EQ2Emu_lua_HasRecovered);
  981. lua_register(state, "GetEncounterSize", EQ2Emu_lua_GetEncounterSize);
  982. lua_register(state, "GetMostHated", EQ2Emu_lua_GetMostHated);
  983. lua_register(state, "ClearHate", EQ2Emu_lua_ClearHate);
  984. lua_register(state, "ClearEncounter", EQ2Emu_lua_ClearEncounter);
  985. lua_register(state, "GetEncounter", EQ2Emu_lua_GetEncounter);
  986. lua_register(state, "GetHateList", EQ2Emu_lua_GetHateList);
  987. lua_register(state, "HasGroup", EQ2Emu_lua_HasGroup);
  988. lua_register(state, "HasSpellEffect", EQ2Emu_lua_HasSpellEffect);
  989. lua_register(state, "SetSuccessTimer", EQ2Emu_lua_SetSuccessTimer);
  990. lua_register(state, "SetFailureTimer", EQ2Emu_lua_SetFailureTimer);
  991. lua_register(state, "IsGroundSpawn", EQ2Emu_lua_IsGroundSpawn);
  992. lua_register(state, "CanHarvest", EQ2Emu_lua_CanHarvest);
  993. lua_register(state, "SummonDumbFirePet", EQ2Emu_lua_SummonDumbFirePet);
  994. lua_register(state, "GetSkillValue", EQ2Emu_lua_GetSkillValue);
  995. lua_register(state, "GetSkillMaxValue", EQ2Emu_lua_GetSkillMaxValue);
  996. lua_register(state, "GetSkillName", EQ2Emu_lua_GetSkillName);
  997. lua_register(state, "SetSkillMaxValue", EQ2Emu_lua_SetSkillMaxValue);
  998. lua_register(state, "SetSkillValue", EQ2Emu_lua_SetSkillValue);
  999. lua_register(state, "GetSkill", EQ2Emu_lua_GetSkill);
  1000. lua_register(state, "GetSkillIDByName", EQ2Emu_lua_GetSkillIDByName);
  1001. lua_register(state, "HasSkill", EQ2Emu_lua_HasSkill);
  1002. lua_register(state, "AddSkill", EQ2Emu_lua_AddSkill);
  1003. lua_register(state, "IncreaseSkillCapsByType", EQ2Emu_lua_IncreaseSkillCapsByType);
  1004. lua_register(state, "RemoveSkill", EQ2Emu_lua_RemoveSkill);
  1005. lua_register(state, "AddProc", EQ2Emu_lua_AddProc);
  1006. lua_register(state, "RemoveProc", EQ2Emu_lua_RemoveProc);
  1007. lua_register(state, "Knockback", EQ2Emu_lua_Knockback);
  1008. lua_register(state, "IsEpic", EQ2Emu_lua_IsEpic);
  1009. lua_register(state, "IsHeroic", EQ2Emu_lua_IsHeroic);
  1010. lua_register(state, "ProcDamage", EQ2Emu_lua_ProcDamage);
  1011. lua_register(state, "LastSpellAttackHit", EQ2Emu_lua_LastSpellAttackHit);
  1012. lua_register(state, "IsBehind", EQ2Emu_lua_IsBehind);
  1013. lua_register(state, "IsFlanking", EQ2Emu_lua_IsFlanking);
  1014. lua_register(state, "AddSpellTimer", EQ2Emu_lua_AddSpellTimer);
  1015. lua_register(state, "GetItemCount", EQ2Emu_lua_GetItemCount);
  1016. lua_register(state, "SetItemCount", EQ2Emu_lua_SetItemCount);
  1017. lua_register(state, "Resurrect", EQ2Emu_lua_Resurrect);
  1018. lua_register(state, "BreatheUnderwater", EQ2Emu_lua_BreatheUnderwater);
  1019. lua_register(state, "BlurVision", EQ2Emu_lua_BlurVision);
  1020. lua_register(state, "SetVision", EQ2Emu_lua_SetVision);
  1021. lua_register(state, "GetItemSkillReq", EQ2Emu_lua_GetItemSkillReq);
  1022. lua_register(state, "SetSpeedMultiplier", EQ2Emu_lua_SetSpeedMultiplier);
  1023. lua_register(state, "SetIllusion", EQ2Emu_lua_SetIllusion);
  1024. lua_register(state, "ResetIllusion", EQ2Emu_lua_ResetIllusion);
  1025. lua_register(state, "AddThreatTransfer", EQ2Emu_lua_AddThreatTransfer);
  1026. lua_register(state, "RemoveThreatTransfer", EQ2Emu_lua_RemoveThreatTransfer);
  1027. lua_register(state, "CureByType", EQ2Emu_lua_CureByType);
  1028. lua_register(state, "CureByControlEffect", EQ2Emu_lua_CureByControlEffect);
  1029. lua_register(state, "AddSpawnSpellBonus", EQ2Emu_lua_AddSpawnSpellBonus);
  1030. lua_register(state, "RemoveSpawnSpellBonus", EQ2Emu_lua_RemoveSpawnSpellBonus);
  1031. lua_register(state, "CancelSpell", EQ2Emu_lua_CancelSpell);
  1032. lua_register(state, "RemoveStealth", EQ2Emu_lua_RemoveStealth);
  1033. lua_register(state, "RemoveInvis", EQ2Emu_lua_RemoveInvis);
  1034. lua_register(state, "StartHeroicOpportunity", EQ2Emu_lua_StartHeroicOpportunity);
  1035. lua_register(state, "CopySpawnAppearance", EQ2Emu_lua_CopySpawnAppearance);
  1036. lua_register(state, "SetSpellTriggerCount", EQ2Emu_lua_SetSpellTriggerCount);
  1037. lua_register(state, "GetSpellTriggerCount", EQ2Emu_lua_GetSpellTriggerCount);
  1038. lua_register(state, "RemoveTriggerFromSpell", EQ2Emu_lua_RemoveTriggerFromSpell);
  1039. lua_register(state, "HasSpellImmunity", EQ2Emu_lua_HasSpellImmunity);
  1040. lua_register(state, "AddImmunitySpell", EQ2Emu_lua_AddImmunitySpell);
  1041. lua_register(state, "RemoveImmunitySpell", EQ2Emu_lua_RemoveImmunitySpell);
  1042. lua_register(state, "SetSpellSnareValue", EQ2Emu_lua_SetSpellSnareValue);
  1043. lua_register(state, "CheckRaceType", EQ2Emu_lua_CheckRaceType);
  1044. lua_register(state, "GetRaceType", EQ2Emu_lua_GetRaceType);
  1045. lua_register(state, "GetRaceBaseType", EQ2Emu_lua_GetRaceBaseType);
  1046. lua_register(state, "GetQuestFlags", EQ2Emu_lua_GetQuestFlags);
  1047. lua_register(state, "SetQuestFlags", EQ2Emu_lua_SetQuestFlags);
  1048. lua_register(state, "SetQuestTimer", EQ2Emu_lua_SetQuestTimer);
  1049. lua_register(state, "RemoveQuestStep", EQ2Emu_lua_RemoveQuestStep);
  1050. lua_register(state, "ResetQuestStep", EQ2Emu_lua_ResetQuestStep);
  1051. lua_register(state, "SetQuestTimerComplete", EQ2Emu_lua_SetQuestTimerComplete);
  1052. lua_register(state, "AddQuestStepFailureAction", EQ2Emu_lua_AddQuestStepFailureAction);
  1053. lua_register(state, "SetStepFailed", EQ2Emu_lua_SetStepFailed);
  1054. lua_register(state, "GetQuestCompleteCount", EQ2Emu_lua_GetQuestCompleteCount);
  1055. lua_register(state, "SetServerVariable", EQ2Emu_lua_SetServerVariable);
  1056. lua_register(state, "GetServerVariable", EQ2Emu_lua_GetServerVariable);
  1057. lua_register(state, "HasLanguage", EQ2Emu_lua_HasLanguage);
  1058. lua_register(state, "AddLanguage", EQ2Emu_lua_AddLanguage);
  1059. lua_register(state, "IsNight", EQ2Emu_lua_IsNight);
  1060. lua_register(state, "AddMultiFloorLift", EQ2Emu_lua_AddMultiFloorLift);
  1061. lua_register(state, "StartAutoMount", EQ2Emu_lua_StartAutoMount);
  1062. lua_register(state, "EndAutoMount", EQ2Emu_lua_EndAutoMount);
  1063. lua_register(state, "IsOnAutoMount", EQ2Emu_lua_IsOnAutoMount);
  1064. lua_register(state, "SetPlayerHistory", EQ2Emu_lua_SetPlayerHistory);
  1065. lua_register(state, "GetPlayerHistory", EQ2Emu_lua_GetPlayerHistory);
  1066. lua_register(state, "SetGridID", EQ2Emu_lua_SetGridID);
  1067. lua_register(state, "GetQuestStepProgress", EQ2Emu_lua_GetQuestStepProgress);
  1068. lua_register(state, "SetPlayerLevel", EQ2Emu_lua_SetPlayerLevel);
  1069. lua_register(state, "AddCoin", EQ2Emu_lua_AddCoin);
  1070. lua_register(state, "RemoveCoin", EQ2Emu_lua_RemoveCoin);
  1071. lua_register(state, "GetPlayersInZone", EQ2Emu_lua_GetPlayersInZone);
  1072. lua_register(state, "SpawnGroupByID", EQ2Emu_lua_SpawnGroupByID);
  1073. lua_register(state, "SetSpawnAnimation", EQ2Emu_lua_SetSpawnAnimation);
  1074. lua_register(state, "GetClientVersion", EQ2Emu_lua_GetClientVersion);
  1075. lua_register(state, "GetItemID", EQ2Emu_lua_GetItemID);
  1076. lua_register(state, "IsEntity", EQ2Emu_lua_IsEntity);
  1077. lua_register(state, "GetOrigX", EQ2Emu_lua_GetOrigX);
  1078. lua_register(state, "GetOrigY", EQ2Emu_lua_GetOrigY);
  1079. lua_register(state, "GetOrigZ", EQ2Emu_lua_GetOrigZ);
  1080. lua_register(state, "GetPCTOfHP", EQ2Emu_lua_GetPCTOfHP);
  1081. lua_register(state, "GetPCTOfPower", EQ2Emu_lua_GetPCTOfPower);
  1082. lua_register(state, "GetBoundZoneID", EQ2Emu_lua_GetBoundZoneID);
  1083. lua_register(state, "Evac", EQ2Emu_lua_Evac);
  1084. lua_register(state, "GetSpellTier", EQ2Emu_lua_GetSpellTier);
  1085. lua_register(state, "GetSpellID", EQ2Emu_lua_GetSpellID);
  1086. lua_register(state, "StartTransmute", EQ2Emu_lua_StartTransmute);
  1087. lua_register(state, "CompleteTransmute", EQ2Emu_lua_CompleteTransmute);
  1088. lua_register(state, "ProcHate", EQ2Emu_lua_ProcHate);
  1089. lua_register(state, "GetRandomSpawnByID", EQ2Emu_lua_GetRandomSpawnByID);
  1090. lua_register(state, "ShowLootWindow", EQ2Emu_lua_ShowLootWindow);
  1091. lua_register(state, "AddPrimaryEntityCommandAllSpawns", EQ2Emu_lua_AddPrimaryEntityCommandAllSpawns);
  1092. lua_register(state, "InstructionWindow", EQ2Emu_lua_InstructionWindow);
  1093. lua_register(state, "InstructionWindowClose", EQ2Emu_lua_InstructionWindowClose);
  1094. lua_register(state, "InstructionWindowGoal", EQ2Emu_lua_InstructionWindowGoal);
  1095. lua_register(state, "ShowWindow", EQ2Emu_lua_ShowWindow);
  1096. lua_register(state, "FlashWindow", EQ2Emu_lua_FlashWindow);
  1097. lua_register(state, "EnableGameEvent", EQ2Emu_lua_EnableGameEvent);
  1098. lua_register(state, "GetTutorialStep", EQ2Emu_lua_GetTutorialStep);
  1099. lua_register(state, "SetTutorialStep", EQ2Emu_lua_SetTutorialStep);
  1100. lua_register(state, "DisplayText", EQ2Emu_lua_DisplayText);
  1101. lua_register(state, "GiveExp", EQ2Emu_lua_GiveExp);
  1102. lua_register(state, "CheckLOS", EQ2Emu_lua_CheckLOS);
  1103. lua_register(state, "CheckLOSByCoordinates", EQ2Emu_lua_CheckLOSByCoordinates);
  1104. lua_register(state, "SetZoneExpansionFlag", EQ2Emu_lua_SetZoneExpansionFlag);
  1105. lua_register(state, "GetZoneExpansionFlag", EQ2Emu_lua_GetZoneExpansionFlag);
  1106. lua_register(state, "SetZoneHolidayFlag", EQ2Emu_lua_SetZoneHolidayFlag);
  1107. lua_register(state, "GetZoneHolidayFlag", EQ2Emu_lua_GetZoneHolidayFlag);
  1108. lua_register(state, "AddSpawnProximity", EQ2Emu_lua_AddSpawnProximity);
  1109. lua_register(state, "CanSeeInvis", EQ2Emu_lua_CanSeeInvis);
  1110. lua_register(state, "SetSeeInvis", EQ2Emu_lua_SetSeeInvis);
  1111. lua_register(state, "SetSeeHide", EQ2Emu_lua_SetSeeHide);
  1112. lua_register(state, "SetAccessToEntityCommand", EQ2Emu_lua_SetAccessToEntityCommand);
  1113. lua_register(state, "SetAccessToEntityCommandByCharID", EQ2Emu_lua_SetAccessToEntityCommandByCharID);
  1114. lua_register(state, "RemovePrimaryEntityCommand", EQ2Emu_lua_RemovePrimaryEntityCommand);
  1115. lua_register(state, "SendUpdateDefaultCommand", EQ2Emu_lua_SendUpdateDefaultCommand);
  1116. lua_register(state, "SendTransporters", EQ2Emu_lua_SendTransporters);
  1117. lua_register(state, "SetTemporaryTransportID", EQ2Emu_lua_SetTemporaryTransportID);
  1118. lua_register(state, "GetTemporaryTransportID", EQ2Emu_lua_GetTemporaryTransportID);
  1119. lua_register(state, "SetAlignment", EQ2Emu_lua_SetAlignment);
  1120. lua_register(state, "GetAlignment", EQ2Emu_lua_GetAlignment);
  1121. lua_register(state, "GetSpell", EQ2Emu_lua_GetSpell);
  1122. lua_register(state, "GetSpellData", EQ2Emu_lua_GetSpellData);
  1123. lua_register(state, "SetSpellData", EQ2Emu_lua_SetSpellData);
  1124. lua_register(state, "CastCustomSpell", EQ2Emu_lua_CastCustomSpell);
  1125. lua_register(state, "SetSpellDataIndex", EQ2Emu_lua_SetSpellDataIndex);
  1126. lua_register(state, "GetSpellDataIndex", EQ2Emu_lua_GetSpellDataIndex);
  1127. lua_register(state, "SetSpellDisplayEffect", EQ2Emu_lua_SetSpellDisplayEffect);
  1128. lua_register(state, "GetSpellDisplayEffect", EQ2Emu_lua_GetSpellDisplayEffect);
  1129. lua_register(state, "InWater", EQ2Emu_lua_InWater);
  1130. lua_register(state, "InLava", EQ2Emu_lua_InLava);
  1131. lua_register(state, "DamageSpawn", EQ2Emu_lua_DamageSpawn);
  1132. lua_register(state, "IsInvulnerable", EQ2Emu_lua_IsInvulnerable);
  1133. lua_register(state, "SetInvulnerable", EQ2Emu_lua_SetInvulnerable);
  1134. lua_register(state, "GetRuleFlagBool", EQ2Emu_lua_GetRuleFlagBool);
  1135. lua_register(state, "GetRuleFlagInt32", EQ2Emu_lua_GetRuleFlagInt32);
  1136. lua_register(state, "GetRuleFlagFloat", EQ2Emu_lua_GetRuleFlagFloat);
  1137. lua_register(state, "GetAAInfo", EQ2Emu_lua_GetAAInfo);
  1138. lua_register(state, "SetAAInfo", EQ2Emu_lua_SetAAInfo);
  1139. lua_register(state, "AddMasterTitle", EQ2Emu_lua_AddMasterTitle);
  1140. lua_register(state, "AddCharacterTitle", EQ2Emu_lua_AddCharacterTitle);
  1141. lua_register(state, "SetCharacterTitleSuffix", EQ2Emu_lua_SetCharacterTitleSuffix);
  1142. lua_register(state, "SetCharacterTitlePrefix", EQ2Emu_lua_SetCharacterTitlePrefix);
  1143. lua_register(state, "ResetCharacterTitleSuffix", EQ2Emu_lua_ResetCharacterTitleSuffix);
  1144. lua_register(state, "ResetCharacterTitlePrefix", EQ2Emu_lua_ResetCharacterTitlePrefix);
  1145. lua_register(state, "GetInfoStructString", EQ2Emu_lua_GetInfoStructString);
  1146. lua_register(state, "GetInfoStructUInt", EQ2Emu_lua_GetInfoStructUInt);
  1147. lua_register(state, "GetInfoStructSInt", EQ2Emu_lua_GetInfoStructSInt);
  1148. lua_register(state, "GetInfoStructFloat", EQ2Emu_lua_GetInfoStructFloat);
  1149. lua_register(state, "SetInfoStructString", EQ2Emu_lua_SetInfoStructString);
  1150. lua_register(state, "SetInfoStructUInt", EQ2Emu_lua_SetInfoStructUInt);
  1151. lua_register(state, "SetInfoStructSInt", EQ2Emu_lua_SetInfoStructSInt);
  1152. lua_register(state, "SetInfoStructFloat", EQ2Emu_lua_SetInfoStructFloat);
  1153. lua_register(state, "SetCharSheetChanged", EQ2Emu_lua_SetCharSheetChanged);
  1154. lua_register(state, "AddPlayerMail", EQ2Emu_lua_AddPlayerMail);
  1155. lua_register(state, "AddPlayerMailByCharID", EQ2Emu_lua_AddPlayerMailByCharID);
  1156. lua_register(state, "OpenDoor", EQ2Emu_lua_OpenDoor);
  1157. lua_register(state, "CloseDoor", EQ2Emu_lua_CloseDoor);
  1158. lua_register(state, "IsOpen", EQ2Emu_lua_IsOpen);
  1159. lua_register(state, "MakeRandomInt", EQ2Emu_lua_MakeRandomInt);
  1160. lua_register(state, "MakeRandomFloat", EQ2Emu_lua_MakeRandomFloat);
  1161. lua_register(state, "AddIconValue", EQ2Emu_lua_AddIconValue);
  1162. lua_register(state, "RemoveIconValue", EQ2Emu_lua_RemoveIconValue);
  1163. lua_register(state, "GetShardID", EQ2Emu_lua_GetShardID);
  1164. lua_register(state, "GetShardCharID", EQ2Emu_lua_GetShardCharID);
  1165. lua_register(state, "GetShardCreatedTimestamp", EQ2Emu_lua_GetShardCreatedTimestamp);
  1166. lua_register(state, "DeleteDBShardID", EQ2Emu_lua_DeleteDBShardID);
  1167. lua_register(state, "PauseMovement", EQ2Emu_lua_PauseMovement);
  1168. lua_register(state, "GetArrowColor", EQ2Emu_lua_GetArrowColor);
  1169. lua_register(state, "GetTSArrowColor", EQ2Emu_lua_GetTSArrowColor);
  1170. }
  1171. void LuaInterface::LogError(const char* error, ...) {
  1172. va_list argptr;
  1173. char buffer[4096];
  1174. va_start(argptr, error);
  1175. vsnprintf(buffer, sizeof(buffer), error, argptr);
  1176. va_end(argptr);
  1177. SimpleLogError(buffer);
  1178. }
  1179. void LuaInterface::SimpleLogError(const char* error) {
  1180. ProcessErrorMessage(error);
  1181. LogWrite(LUA__ERROR, 0, "LUA", "%s", error);
  1182. }
  1183. void LuaInterface::ResetFunctionStack(lua_State* state) {
  1184. lua_settop(state, 0);
  1185. }
  1186. void LuaInterface::AddUserDataPtr(LUAUserData* data) {
  1187. MLUAUserData.lock();
  1188. user_data[data] = Timer::GetCurrentTime2() + 300000; //allow a function to use this pointer for 5 minutes
  1189. MLUAUserData.unlock();
  1190. }
  1191. void LuaInterface::DeletePendingSpells(bool all) {
  1192. MSpellDelete.lock();
  1193. if (spells_pending_delete.size() > 0) {
  1194. int32 time = Timer::GetCurrentTime2();
  1195. map<LuaSpell*, int32>::iterator itr;
  1196. vector<LuaSpell*> tmp_deletes;
  1197. vector<LuaSpell*>::iterator del_itr;
  1198. for (itr = spells_pending_delete.begin(); itr != spells_pending_delete.end(); itr++) {
  1199. if (all || time >= itr->second)
  1200. tmp_deletes.push_back(itr->first);
  1201. }
  1202. LuaSpell* spell = 0;
  1203. for (del_itr = tmp_deletes.begin(); del_itr != tmp_deletes.end(); del_itr++) {
  1204. spell = *del_itr;
  1205. spells_pending_delete.erase(spell);
  1206. if (spell->spell->IsCopiedSpell())
  1207. {
  1208. RemoveCustomSpell(spell->spell->GetSpellID());
  1209. safe_delete(spell->spell);
  1210. }
  1211. safe_delete(spell);
  1212. }
  1213. }
  1214. MSpellDelete.unlock();
  1215. }
  1216. void LuaInterface::DeletePendingSpell(LuaSpell* spell) {
  1217. MSpellDelete.lock();
  1218. if (spells_pending_delete.size() > 0) {
  1219. map<LuaSpell*, int32>::iterator itr = spells_pending_delete.find(spell);
  1220. if (itr != spells_pending_delete.end())
  1221. spells_pending_delete.erase(itr);
  1222. }
  1223. MSpellDelete.unlock();
  1224. }
  1225. void LuaInterface::DeleteUserDataPtrs(bool all) {
  1226. MLUAUserData.lock();
  1227. if(user_data.size() > 0){
  1228. map<LUAUserData*, int32>::iterator itr;
  1229. int32 time = Timer::GetCurrentTime2();
  1230. vector<LUAUserData*> tmp_deletes;
  1231. vector<LUAUserData*>::iterator del_itr;
  1232. for(itr = user_data.begin(); itr != user_data.end(); itr++){
  1233. if(all || time >= itr->second)
  1234. tmp_deletes.push_back(itr->first);
  1235. }
  1236. LUAUserData* data = 0;
  1237. for(del_itr = tmp_deletes.begin(); del_itr != tmp_deletes.end(); del_itr++){
  1238. data = *del_itr;
  1239. user_data.erase(data);
  1240. safe_delete(data);
  1241. }
  1242. }
  1243. MLUAUserData.unlock();
  1244. }
  1245. Spawn* LuaInterface::GetSpawn(lua_State* state, int8 arg_num) {
  1246. Spawn* ret = 0;
  1247. if (lua_islightuserdata(state, arg_num)){
  1248. LUAUserData* data = (LUAUserData*)lua_touserdata(state, arg_num);
  1249. if(!data || !data->IsCorrectlyInitialized()){
  1250. LogError("%s: GetSpawn error while processing %s", GetScriptName(state), lua_tostring(state, -1));
  1251. }
  1252. else if(!data->IsSpawn()){
  1253. lua_Debug ar;
  1254. lua_getstack (state, 1, &ar);
  1255. lua_getinfo(state, "Sln", &ar);
  1256. LogError("%s: Invalid data type used for GetSpawn in %s (line %d)", GetScriptName(state), ar.source, ar.currentline);
  1257. }
  1258. else
  1259. ret = data->spawn;
  1260. }
  1261. return ret;
  1262. }
  1263. vector<ConversationOption>* LuaInterface::GetConversation(lua_State* state, int8 arg_num) {
  1264. vector<ConversationOption>* ret = 0;
  1265. if(lua_islightuserdata(state, arg_num)){
  1266. LUAUserData* data = (LUAUserData*)lua_touserdata(state, arg_num);
  1267. if(!data || !data->IsCorrectlyInitialized()){
  1268. LogError("%s: GetConversation error while processing %s", GetScriptName(state), lua_tostring(state, -1));
  1269. }
  1270. else if(!data->IsConversationOption()){
  1271. lua_Debug ar;
  1272. lua_getstack (state, 1, &ar);
  1273. lua_getinfo(state, "Sln", &ar);
  1274. LogError("%s: Invalid data type used for GetConversation in %s (line %d)", GetScriptName(state), ar.source, ar.currentline);
  1275. }
  1276. else
  1277. ret = data->conversation_options;
  1278. }
  1279. return ret;
  1280. }
  1281. vector<Spawn*>* LuaInterface::GetSpawnList(lua_State* state, int8 arg_num) {
  1282. vector<Spawn*>* ret = 0;
  1283. if (lua_islightuserdata(state, arg_num)) {
  1284. LUAUserData* data = (LUAUserData*)lua_touserdata(state, arg_num);
  1285. if (!data || !data->IsCorrectlyInitialized()) {
  1286. LogError("%s: GetSpawnList error while processing %s", GetScriptName(state), lua_tostring(state, -1));
  1287. }
  1288. else if (!data->IsSpawnList()) {
  1289. lua_Debug ar;
  1290. lua_getstack(state, 1, &ar);
  1291. lua_getinfo(state, "Sln", &ar);
  1292. LogError("%s: Invalid data type used for GetSpawnList in %s (line %d)", GetScriptName(state), ar.source, ar.currentline);
  1293. }
  1294. else
  1295. ret = data->spawn_list;
  1296. }
  1297. return ret;
  1298. }
  1299. vector<OptionWindowOption>* LuaInterface::GetOptionWindow(lua_State* state, int8 arg_num) {
  1300. vector<OptionWindowOption>* ret = 0;
  1301. if(lua_islightuserdata(state, arg_num)){
  1302. LUAUserData* data = (LUAUserData*)lua_touserdata(state, arg_num);
  1303. if(!data || !data->IsCorrectlyInitialized()){
  1304. LogError("%s: GetOptionWindow error while processing %s", GetScriptName(state), lua_tostring(state, -1));
  1305. }
  1306. else if(!data->IsOptionWindow()){
  1307. lua_Debug ar;
  1308. lua_getstack (state, 1, &ar);
  1309. lua_getinfo(state, "Sln", &ar);
  1310. LogError("%s: Invalid data type used for GetOptionWindow in %s (line %d)", GetScriptName(state), ar.source, ar.currentline);
  1311. }
  1312. else
  1313. ret = data->option_window_option;
  1314. }
  1315. return ret;
  1316. }
  1317. Quest* LuaInterface::GetQuest(lua_State* state, int8 arg_num) {
  1318. Quest* ret = 0;
  1319. if(lua_islightuserdata(state, arg_num)){
  1320. LUAUserData* data = (LUAUserData*)lua_touserdata(state, arg_num);
  1321. if(!data || !data->IsCorrectlyInitialized()){
  1322. LogError("%s: GetQuest error while processing %s", GetScriptName(state), lua_tostring(state, 0));
  1323. }
  1324. else if(!data->IsQuest()){
  1325. lua_Debug ar;
  1326. lua_getstack (state, 1, &ar);
  1327. lua_getinfo(state, "Sln", &ar);
  1328. LogError("%s: Invalid data type used for GetQuest in %s (line %d)", GetScriptName(state), ar.source, ar.currentline);
  1329. }
  1330. else
  1331. ret = data->quest;
  1332. }
  1333. return ret;
  1334. }
  1335. Item* LuaInterface::GetItem(lua_State* state, int8 arg_num) {
  1336. Item* ret = 0;
  1337. if(lua_islightuserdata(state, arg_num)){
  1338. LUAUserData* data = (LUAUserData*)lua_touserdata(state, arg_num);
  1339. if(!data || !data->IsCorrectlyInitialized()){
  1340. LogError("%s: GetItem error while processing %s", GetScriptName(state), lua_tostring(state, 0));
  1341. }
  1342. else if(!data->IsItem()){
  1343. lua_Debug ar;
  1344. lua_getstack (state, 1, &ar);
  1345. lua_getinfo(state, "Sln", &ar);
  1346. LogError("%s: Invalid data type used for GetItem in %s (line %d)", GetScriptName(state), ar.source, ar.currentline);
  1347. }
  1348. else
  1349. ret = data->item;
  1350. }
  1351. return ret;
  1352. }
  1353. Skill* LuaInterface::GetSkill(lua_State* state, int8 arg_num) {
  1354. Skill* ret = 0;
  1355. if (lua_islightuserdata(state, arg_num)) {
  1356. LUAUserData* data = (LUAUserData*)lua_touserdata(state, arg_num);
  1357. if (!data || !data->IsCorrectlyInitialized()) {
  1358. LogError("%s: GetSkill error while processing %s", GetScriptName(state), lua_tostring(state, 0));
  1359. }
  1360. else if (!data->IsSkill()) {
  1361. lua_Debug ar;
  1362. lua_getstack(state, 1, &ar);
  1363. lua_getinfo(state, "Sln", &ar);
  1364. LogError("%s: Invalid data type used for GetSkill in %s (line %d)", GetScriptName(state), ar.source, ar.currentline);
  1365. }
  1366. else
  1367. ret = data->skill;
  1368. }
  1369. return ret;
  1370. }
  1371. LuaSpell* LuaInterface::GetSpell(lua_State* state, int8 arg_num) {
  1372. LuaSpell* ret = 0;
  1373. if (lua_islightuserdata(state, arg_num)) {
  1374. LUAUserData* data = (LUAUserData*)lua_touserdata(state, arg_num);
  1375. if (!data || !data->IsCorrectlyInitialized()) {
  1376. LogError("%s: GetSpell error while processing %s", GetScriptName(state), lua_tostring(state, 0));
  1377. }
  1378. else if (!data->IsSpell()) {
  1379. lua_Debug ar;
  1380. lua_getstack(state, 1, &ar);
  1381. lua_getinfo(state, "Sln", &ar);
  1382. LogError("%s: Invalid data type used for GetSpell in %s (line %d)", GetScriptName(state), ar.source, ar.currentline);
  1383. }
  1384. else
  1385. ret = data->spell;
  1386. }
  1387. return ret;
  1388. }
  1389. ZoneServer* LuaInterface::GetZone(lua_State* state, int8 arg_num) {
  1390. ZoneServer* ret = 0;
  1391. if(lua_islightuserdata(state, arg_num)){
  1392. LUAUserData* data = (LUAUserData*)lua_touserdata(state, arg_num);
  1393. if(!data || !data->IsCorrectlyInitialized()){
  1394. LogError("%s: GetZone error while processing %s", GetScriptName(state), lua_tostring(state, -1));
  1395. }
  1396. else if(!data->IsZone()){
  1397. lua_Debug ar;
  1398. lua_getstack (state, 1, &ar);
  1399. lua_getinfo(state, "Sln", &ar);
  1400. LogError("%s: Invalid data type used for GetZone in %s (line %d)", GetScriptName(state), ar.source, ar.currentline);
  1401. }
  1402. else
  1403. ret = data->zone;
  1404. }
  1405. return ret;
  1406. }
  1407. sint64 LuaInterface::GetSInt64Value(lua_State* state, int8 arg_num) {
  1408. sint64 val = 0;
  1409. if(lua_isnumber(state, arg_num)){
  1410. val = (sint64)lua_tointeger(state, arg_num);
  1411. }
  1412. return val;
  1413. }
  1414. int64 LuaInterface::GetInt64Value(lua_State* state, int8 arg_num) {
  1415. int64 val = 0;
  1416. if(lua_isnumber(state, arg_num)){
  1417. val = (int64)lua_tonumber(state, arg_num);
  1418. }
  1419. return val;
  1420. }
  1421. sint32 LuaInterface::GetSInt32Value(lua_State* state, int8 arg_num) {
  1422. sint32 val = 0;
  1423. if(lua_isnumber(state, arg_num)){
  1424. val = lua_tointeger(state, arg_num);
  1425. }
  1426. return val;
  1427. }
  1428. int32 LuaInterface::GetInt32Value(lua_State* state, int8 arg_num) {
  1429. int32 val = 0;
  1430. if(lua_isnumber(state, arg_num)){
  1431. val = (int32)lua_tonumber(state, arg_num);
  1432. }
  1433. return val;
  1434. }
  1435. int16 LuaInterface::GetInt16Value(lua_State* state, int8 arg_num) {
  1436. int16 val = 0;
  1437. if(lua_isnumber(state, arg_num)){
  1438. val = lua_tointeger(state, arg_num);
  1439. }
  1440. return val;
  1441. }
  1442. int8 LuaInterface::GetInt8Value(lua_State* state, int8 arg_num) {
  1443. int8 val = 0;
  1444. if(lua_isnumber(state, arg_num)){
  1445. val = lua_tointeger(state, arg_num);
  1446. }
  1447. return val;
  1448. }
  1449. float LuaInterface::GetFloatValue(lua_State* state, int8 arg_num) {
  1450. float val = 0;
  1451. if(lua_isnumber(state, arg_num))
  1452. val = (float)lua_tonumber(state, arg_num);
  1453. return val;
  1454. }
  1455. string LuaInterface::GetStringValue(lua_State* state, int8 arg_num) {
  1456. string val;
  1457. if(lua_isstring(state, arg_num)){
  1458. size_t size = 0;
  1459. const char* str = lua_tolstring(state, arg_num, &size);
  1460. if(str)
  1461. val = string(str);
  1462. }
  1463. return val;
  1464. }
  1465. bool LuaInterface::GetBooleanValue(lua_State* state, int8 arg_num) {
  1466. return lua_toboolean(state, arg_num) == 1;
  1467. }
  1468. void LuaInterface::SetStringValue(lua_State* state, const char* value) {
  1469. lua_pushstring(state, value);
  1470. }
  1471. void LuaInterface::SetBooleanValue(lua_State* state, bool value) {
  1472. lua_pushboolean(state, value);
  1473. }
  1474. void LuaInterface::SetFloatValue(lua_State* state, float value) {
  1475. lua_pushnumber(state, value);
  1476. }
  1477. void LuaInterface::SetInt32Value(lua_State* state, int32 value) {
  1478. lua_pushinteger(state, value);
  1479. }
  1480. void LuaInterface::SetSInt32Value(lua_State* state, sint32 value) {
  1481. lua_pushinteger(state, value);
  1482. }
  1483. void LuaInterface::SetInt64Value(lua_State* state, int64 value) {
  1484. lua_pushinteger(state, value);
  1485. }
  1486. void LuaInterface::SetSInt64Value(lua_State* state, sint64 value) {
  1487. lua_pushinteger(state, value);
  1488. }
  1489. void LuaInterface::SetSpawnValue(lua_State* state, Spawn* spawn) {
  1490. LUASpawnWrapper* spawn_wrapper = new LUASpawnWrapper();
  1491. spawn_wrapper->spawn = spawn;
  1492. AddUserDataPtr(spawn_wrapper);
  1493. lua_pushlightuserdata(state, spawn_wrapper);
  1494. }
  1495. void LuaInterface::SetSpawnListValue(lua_State* state, vector<Spawn*>* spawnList) {
  1496. LUASpawnListWrapper* spawnList_wrapper = new LUASpawnListWrapper();
  1497. spawnList_wrapper->spawn_list = spawnList;
  1498. AddUserDataPtr(spawnList_wrapper);
  1499. lua_pushlightuserdata(state, spawnList_wrapper);
  1500. }
  1501. void LuaInterface::SetConversationValue(lua_State* state, vector<ConversationOption>* conversation) {
  1502. LUAConversationOptionWrapper* conv_wrapper = new LUAConversationOptionWrapper();
  1503. conv_wrapper->conversation_options = conversation;
  1504. AddUserDataPtr(conv_wrapper);
  1505. lua_pushlightuserdata(state, conv_wrapper);
  1506. }
  1507. void LuaInterface::SetOptionWindowValue(lua_State* state, vector<OptionWindowOption>* optionWindow) {
  1508. LUAOptionWindowWrapper* option_wrapper = new LUAOptionWindowWrapper();
  1509. option_wrapper->option_window_option = optionWindow;
  1510. AddUserDataPtr(option_wrapper);
  1511. lua_pushlightuserdata(state, option_wrapper);
  1512. }
  1513. void LuaInterface::SetItemValue(lua_State* state, Item* item) {
  1514. LUAItemWrapper* item_wrapper = new LUAItemWrapper();
  1515. item_wrapper->item = item;
  1516. AddUserDataPtr(item_wrapper);
  1517. lua_pushlightuserdata(state, item_wrapper);
  1518. }
  1519. void LuaInterface::SetSkillValue(lua_State* state, Skill* skill) {
  1520. LUASkillWrapper* skill_wrapper = new LUASkillWrapper();
  1521. skill_wrapper->skill = skill;
  1522. AddUserDataPtr(skill_wrapper);
  1523. lua_pushlightuserdata(state, skill_wrapper);
  1524. }
  1525. void LuaInterface::SetQuestValue(lua_State* state, Quest* quest) {
  1526. LUAQuestWrapper* quest_wrapper = new LUAQuestWrapper();
  1527. quest_wrapper->quest = quest;
  1528. AddUserDataPtr(quest_wrapper);
  1529. lua_pushlightuserdata(state, quest_wrapper);
  1530. }
  1531. void LuaInterface::SetZoneValue(lua_State* state, ZoneServer* zone) {
  1532. LUAZoneWrapper* zone_wrapper = new LUAZoneWrapper();
  1533. zone_wrapper->zone = zone;
  1534. AddUserDataPtr(zone_wrapper);
  1535. lua_pushlightuserdata(state, zone_wrapper);
  1536. }
  1537. void LuaInterface::SetSpellValue(lua_State* state, LuaSpell* spell) {
  1538. LUASpellWrapper* spell_wrapper = new LUASpellWrapper();
  1539. spell_wrapper->spell = spell;
  1540. AddUserDataPtr(spell_wrapper);
  1541. lua_pushlightuserdata(state, spell_wrapper);
  1542. }
  1543. LuaSpell* LuaInterface::GetSpell(const char* name) {
  1544. string lua_script = string(name);
  1545. if (lua_script.find(".lua") == string::npos)
  1546. lua_script.append(".lua");
  1547. if(spells.count(lua_script) > 0)
  1548. {
  1549. LogWrite(LUA__DEBUG, 0, "LUA", "Found LUA Spell Script: '%s'", lua_script.c_str());
  1550. LuaSpell* spell = spells[lua_script];
  1551. LuaSpell* new_spell = new LuaSpell;
  1552. new_spell->state = spell->state;
  1553. new_spell->file_name = string(spell->file_name);
  1554. new_spell->timer = spell->timer;
  1555. new_spell->timer.Disable();
  1556. new_spell->resisted = false;
  1557. new_spell->interrupted = false;
  1558. new_spell->crit = false;
  1559. new_spell->last_spellattack_hit = false;
  1560. new_spell->MSpellTargets.SetName("LuaSpell.MSpellTargets");
  1561. new_spell->cancel_after_all_triggers = false;
  1562. new_spell->num_triggers = 0;
  1563. new_spell->had_triggers = false;
  1564. new_spell->had_dmg_remaining = false;
  1565. new_spell->slot_pos = 0;
  1566. new_spell->damage_remaining = 0;
  1567. new_spell->effect_bitmask = 0;
  1568. new_spell->caster = 0;
  1569. new_spell->initial_target = 0;
  1570. new_spell->spell = 0;
  1571. return new_spell;
  1572. }
  1573. else{
  1574. LogWrite(LUA__ERROR, 0, "LUA", "Error LUA Spell Script: '%s'", name);
  1575. return 0;
  1576. }
  1577. }
  1578. Mutex* LuaInterface::GetItemScriptMutex(const char* name) {
  1579. Mutex* mutex = 0;
  1580. if(item_scripts_mutex.count(name) > 0)
  1581. mutex = item_scripts_mutex[name];
  1582. if(!mutex){
  1583. mutex = new Mutex();
  1584. item_scripts_mutex[name] = mutex;
  1585. }
  1586. return mutex;
  1587. }
  1588. Mutex* LuaInterface::GetSpawnScriptMutex(const char* name) {
  1589. Mutex* mutex = 0;
  1590. if(spawn_scripts_mutex.count(string(name)) > 0)
  1591. mutex = spawn_scripts_mutex[name];
  1592. if(!mutex){
  1593. mutex = new Mutex();
  1594. spawn_scripts_mutex[name] = mutex;
  1595. }
  1596. return mutex;
  1597. }
  1598. Mutex* LuaInterface::GetZoneScriptMutex(const char* name) {
  1599. Mutex* mutex = 0;
  1600. if(zone_scripts_mutex.count(name) > 0)
  1601. mutex = zone_scripts_mutex[name];
  1602. if(!mutex){
  1603. mutex = new Mutex();
  1604. zone_scripts_mutex[name] = mutex;
  1605. }
  1606. return mutex;
  1607. }
  1608. Mutex* LuaInterface::GetRegionScriptMutex(const char* name) {
  1609. Mutex* mutex = 0;
  1610. if(region_scripts_mutex.count(name) > 0)
  1611. mutex = region_scripts_mutex[name];
  1612. if(!mutex){
  1613. mutex = new Mutex();
  1614. region_scripts_mutex[name] = mutex;
  1615. }
  1616. return mutex;
  1617. }
  1618. void LuaInterface::UseItemScript(const char* name, lua_State* state, bool val) {
  1619. MItemScripts.writelock(__FUNCTION__, __LINE__);
  1620. item_scripts[name][state] = val;
  1621. item_inverse_scripts[state] = name;
  1622. MItemScripts.releasewritelock(__FUNCTION__, __LINE__);
  1623. }
  1624. void LuaInterface::UseSpawnScript(const char* name, lua_State* state, bool val) {
  1625. MSpawnScripts.writelock(__FUNCTION__, __LINE__);
  1626. spawn_scripts[name][state] = val;
  1627. spawn_inverse_scripts[state] = name;
  1628. MSpawnScripts.releasewritelock(__FUNCTION__, __LINE__);
  1629. }
  1630. void LuaInterface::UseZoneScript(const char* name, lua_State* state, bool val) {
  1631. MZoneScripts.writelock(__FUNCTION__, __LINE__);
  1632. zone_scripts[name][state] = val;
  1633. zone_inverse_scripts[state] = name;
  1634. MZoneScripts.releasewritelock(__FUNCTION__, __LINE__);
  1635. }
  1636. void LuaInterface::UseRegionScript(const char* name, lua_State* state, bool val) {
  1637. MRegionScripts.writelock(__FUNCTION__, __LINE__);
  1638. region_scripts[name][state] = val;
  1639. region_inverse_scripts[state] = name;
  1640. MRegionScripts.releasewritelock(__FUNCTION__, __LINE__);
  1641. }
  1642. lua_State* LuaInterface::GetItemScript(const char* name, bool create_new, bool use) {
  1643. map<string, map<lua_State*, bool> >::iterator itr;
  1644. map<lua_State*, bool>::iterator item_script_itr;
  1645. lua_State* ret = 0;
  1646. Mutex* mutex = 0;
  1647. itr = item_scripts.find(name);
  1648. if(itr != item_scripts.end()) {
  1649. mutex = GetItemScriptMutex(name);
  1650. mutex->readlock(__FUNCTION__, __LINE__);
  1651. for(item_script_itr = itr->second.begin(); item_script_itr != itr->second.end(); item_script_itr++){
  1652. if(!item_script_itr->second){ //not in use
  1653. ret = item_script_itr->first;
  1654. if (use)
  1655. {
  1656. item_script_itr->second = true;
  1657. break; // don't keep iterating, we already have our result
  1658. }
  1659. }
  1660. }
  1661. mutex->releasereadlock(__FUNCTION__, __LINE__);
  1662. }
  1663. if(!ret && create_new){
  1664. if(name && LoadItemScript(name))
  1665. ret = GetItemScript(name, create_new, use);
  1666. else{
  1667. LogError("Error LUA Item Script '%s'", name);
  1668. return 0;
  1669. }
  1670. }
  1671. return ret;
  1672. }
  1673. lua_State* LuaInterface::GetSpawnScript(const char* name, bool create_new, bool use) {
  1674. if (spawn_scripts_reloading)
  1675. return 0;
  1676. map<string, map<lua_State*, bool> >::iterator itr;
  1677. map<lua_State*, bool>::iterator spawn_script_itr;
  1678. lua_State* ret = 0;
  1679. Mutex* mutex = 0;
  1680. itr = spawn_scripts.find(name);
  1681. if(itr != spawn_scripts.end()) {
  1682. mutex = GetSpawnScriptMutex(name);
  1683. mutex->readlock(__FUNCTION__, __LINE__);
  1684. for(spawn_script_itr = itr->second.begin(); spawn_script_itr != itr->second.end(); spawn_script_itr++){
  1685. if(!spawn_script_itr->second){ //not in use
  1686. ret = spawn_script_itr->first;
  1687. if (use)
  1688. {
  1689. spawn_script_itr->second = true;
  1690. break; // don't keep iterating, we already have our result
  1691. }
  1692. }
  1693. }
  1694. mutex->releasereadlock(__FUNCTION__, __LINE__);
  1695. }
  1696. if(!ret && create_new){
  1697. if(name && LoadSpawnScript(name))
  1698. ret = GetSpawnScript(name, create_new, use);
  1699. else{
  1700. LogError("Error LUA Spawn Script '%s'", name);
  1701. return 0;
  1702. }
  1703. }
  1704. return ret;
  1705. }
  1706. lua_State* LuaInterface::GetZoneScript(const char* name, bool create_new, bool use) {
  1707. map<string, map<lua_State*, bool> >::iterator itr;
  1708. map<lua_State*, bool>::iterator zone_script_itr;
  1709. lua_State* ret = 0;
  1710. Mutex* mutex = 0;
  1711. itr = zone_scripts.find(name);
  1712. if(itr != zone_scripts.end()) {
  1713. mutex = GetZoneScriptMutex(name);
  1714. mutex->readlock(__FUNCTION__, __LINE__);
  1715. for(zone_script_itr = itr->second.begin(); zone_script_itr != itr->second.end(); zone_script_itr++){
  1716. if(!zone_script_itr->second){ //not in use
  1717. ret = zone_script_itr->first;
  1718. if (use)
  1719. {
  1720. zone_script_itr->second = true;
  1721. break; // don't keep iterating, we already have our result
  1722. }
  1723. }
  1724. }
  1725. mutex->releasereadlock(__FUNCTION__, __LINE__);
  1726. }
  1727. if(!ret && create_new){
  1728. if(name && LoadZoneScript(name))
  1729. ret = GetZoneScript(name);
  1730. else{
  1731. LogError("Error LUA Zone Script '%s'", name);
  1732. return 0;
  1733. }
  1734. }
  1735. return ret;
  1736. }
  1737. lua_State* LuaInterface::GetRegionScript(const char* name, bool create_new, bool use) {
  1738. map<string, map<lua_State*, bool> >::iterator itr;
  1739. map<lua_State*, bool>::iterator region_script_itr;
  1740. lua_State* ret = 0;
  1741. Mutex* mutex = 0;
  1742. itr = region_scripts.find(name);
  1743. if(itr != region_scripts.end()) {
  1744. mutex = GetRegionScriptMutex(name);
  1745. mutex->readlock(__FUNCTION__, __LINE__);
  1746. for(region_script_itr = itr->second.begin(); region_script_itr != itr->second.end(); region_script_itr++){
  1747. if(!region_script_itr->second){ //not in use
  1748. ret = region_script_itr->first;
  1749. if (use)
  1750. {
  1751. region_script_itr->second = true;
  1752. break; // don't keep iterating, we already have our result
  1753. }
  1754. }
  1755. }
  1756. mutex->releasereadlock(__FUNCTION__, __LINE__);
  1757. }
  1758. if(!ret && create_new){
  1759. if(name && LoadRegionScript(name))
  1760. ret = GetRegionScript(name);
  1761. else{
  1762. LogError("Error LUA Zone Script '%s'", name);
  1763. return 0;
  1764. }
  1765. }
  1766. return ret;
  1767. }
  1768. bool LuaInterface::RunItemScript(string script_name, const char* function_name, Item* item, Spawn* spawn) {
  1769. if(!item)
  1770. return false;
  1771. lua_State* state = GetItemScript(script_name.c_str(), true, true);
  1772. if(state){
  1773. Mutex* mutex = GetItemScriptMutex(script_name.c_str());
  1774. if(mutex)
  1775. mutex->readlock(__FUNCTION__, __LINE__);
  1776. else{
  1777. LogError("Error getting lock for '%s'", script_name.c_str());
  1778. UseItemScript(script_name.c_str(), state, false);
  1779. return false;
  1780. }
  1781. lua_getglobal(state, function_name);
  1782. if (!lua_isfunction(state, lua_gettop(state))){
  1783. lua_pop(state, 1);
  1784. mutex->releasereadlock(__FUNCTION__);
  1785. UseItemScript(script_name.c_str(), state, false);
  1786. return false;
  1787. }
  1788. SetItemValue(state, item);
  1789. int8 num_parms = 1;
  1790. if(spawn){
  1791. SetSpawnValue(state, spawn);
  1792. num_parms++;
  1793. }
  1794. if(!CallItemScript(state, num_parms)){
  1795. if(mutex)
  1796. mutex->releasereadlock(__FUNCTION__, __LINE__);
  1797. UseItemScript(script_name.c_str(), state, false);
  1798. return false;
  1799. }
  1800. if(mutex)
  1801. mutex->releasereadlock(__FUNCTION__, __LINE__);
  1802. UseItemScript(script_name.c_str(), state, false);
  1803. return true;
  1804. }
  1805. else
  1806. return false;
  1807. }
  1808. bool LuaInterface::RunSpawnScript(string script_name, const char* function_name, Spawn* npc, Spawn* spawn, const char* message, bool is_door_open) {
  1809. if(!npc || spawn_scripts_reloading)
  1810. return false;
  1811. bool isUseDoorFunction = false;
  1812. if(!strcmp(function_name,"usedoor"))
  1813. isUseDoorFunction = true;
  1814. lua_State* state = GetSpawnScript(script_name.c_str(), true, true);
  1815. if(state){
  1816. Mutex* mutex = GetSpawnScriptMutex(script_name.c_str());
  1817. if(mutex)
  1818. mutex->readlock(__FUNCTION__, __LINE__);
  1819. else{
  1820. LogError("Error getting lock for '%s'", script_name.c_str());
  1821. UseSpawnScript(script_name.c_str(), state, false);
  1822. return false;
  1823. }
  1824. lua_getglobal(state, function_name);
  1825. if (!lua_isfunction(state, lua_gettop(state))){
  1826. lua_pop(state, 1);
  1827. mutex->releasereadlock(__FUNCTION__);
  1828. UseSpawnScript(script_name.c_str(), state, false);
  1829. return false;
  1830. }
  1831. SetSpawnValue(state, npc);
  1832. int8 num_parms = 1;
  1833. // we always send spawn, even if null (nil) when its 'usedoor' function
  1834. if(spawn || isUseDoorFunction){
  1835. SetSpawnValue(state, spawn);
  1836. num_parms++;
  1837. }
  1838. // usedoor function always passes just npc, spawn and is_door_open
  1839. if(isUseDoorFunction){
  1840. SetBooleanValue(state, is_door_open);
  1841. num_parms++;
  1842. }
  1843. else if(message){
  1844. SetStringValue(state, message);
  1845. num_parms++;
  1846. }
  1847. if(!CallSpawnScript(state, num_parms)){
  1848. if(mutex)
  1849. mutex->releasereadlock(__FUNCTION__, __LINE__);
  1850. UseSpawnScript(script_name.c_str(), state, false);
  1851. return false;
  1852. }
  1853. if(mutex)
  1854. mutex->releasereadlock(__FUNCTION__, __LINE__);
  1855. UseSpawnScript(script_name.c_str(), state, false);
  1856. return true;
  1857. }
  1858. else
  1859. return false;
  1860. }
  1861. bool LuaInterface::RunZoneScript(string script_name, const char* function_name, ZoneServer* zone, Spawn* spawn, int32 int32_arg1, const char* str_arg1, Spawn* spawn_arg1, int32 int32_arg2, const char* str_arg2, Spawn* spawn_arg2) {
  1862. if (!zone)
  1863. return false;
  1864. lua_State* state = GetZoneScript(script_name.c_str(), true, true);
  1865. if (state) {
  1866. Mutex* mutex = GetZoneScriptMutex(script_name.c_str());
  1867. if (mutex)
  1868. mutex->readlock(__FUNCTION__, __LINE__);
  1869. else {
  1870. LogError("Error getting lock for '%s'", script_name.c_str());
  1871. UseZoneScript(script_name.c_str(), state, false);
  1872. return false;
  1873. }
  1874. lua_getglobal(state, function_name);
  1875. if (!lua_isfunction(state, lua_gettop(state))) {
  1876. lua_pop(state, 1);
  1877. mutex->releasereadlock(__FUNCTION__);
  1878. UseZoneScript(script_name.c_str(), state, false);
  1879. return false;
  1880. }
  1881. SetZoneValue(state, zone);
  1882. int8 num_params = 1;
  1883. if (spawn) {
  1884. SetSpawnValue(state, spawn);
  1885. num_params++;
  1886. }
  1887. if (int32_arg1 > 0) {
  1888. SetInt32Value(state, int32_arg1);
  1889. num_params++;
  1890. }
  1891. if (str_arg1) {
  1892. SetStringValue(state, str_arg1);
  1893. num_params++;
  1894. }
  1895. if (spawn_arg1) {
  1896. SetSpawnValue(state, spawn_arg1);
  1897. num_params++;
  1898. }
  1899. if (int32_arg2 > 0) {
  1900. SetInt32Value(state, int32_arg2);
  1901. num_params++;
  1902. }
  1903. if (str_arg2) {
  1904. SetStringValue(state, str_arg2);
  1905. num_params++;
  1906. }
  1907. if (spawn_arg2) {
  1908. SetSpawnValue(state, spawn_arg2);
  1909. num_params++;
  1910. }
  1911. if (!CallZoneScript(state, num_params)) {
  1912. if (mutex)
  1913. mutex->releasereadlock(__FUNCTION__, __LINE__);
  1914. UseZoneScript(script_name.c_str(), state, false);
  1915. return false;
  1916. }
  1917. if (mutex)
  1918. mutex->releasereadlock(__FUNCTION__, __LINE__);
  1919. UseZoneScript(script_name.c_str(), state, false);
  1920. return true;
  1921. }
  1922. else
  1923. return false;
  1924. }
  1925. bool LuaInterface::RunRegionScript(string script_name, const char* function_name, ZoneServer* zone, Spawn* spawn, sint32 int32_arg1, int32* returnValue) {
  1926. if (!zone)
  1927. return false;
  1928. lua_State* state = GetRegionScript(script_name.c_str(), true, true);
  1929. if (state) {
  1930. Mutex* mutex = GetRegionScriptMutex(script_name.c_str());
  1931. if (mutex)
  1932. mutex->readlock(__FUNCTION__, __LINE__);
  1933. else {
  1934. LogError("Error getting lock for '%s'", script_name.c_str());
  1935. UseRegionScript(script_name.c_str(), state, false);
  1936. return false;
  1937. }
  1938. lua_getglobal(state, function_name);
  1939. if (!lua_isfunction(state, lua_gettop(state))) {
  1940. lua_pop(state, 1);
  1941. mutex->releasereadlock(__FUNCTION__);
  1942. UseRegionScript(script_name.c_str(), state, false);
  1943. return false;
  1944. }
  1945. SetZoneValue(state, zone);
  1946. int8 num_params = 1;
  1947. if (spawn) {
  1948. SetSpawnValue(state, spawn);
  1949. num_params++;
  1950. }
  1951. if (int32_arg1 > 0) {
  1952. SetSInt32Value(state, int32_arg1);
  1953. num_params++;
  1954. }
  1955. if (!CallRegionScript(state, num_params, returnValue)) {
  1956. if (mutex)
  1957. mutex->releasereadlock(__FUNCTION__, __LINE__);
  1958. UseRegionScript(script_name.c_str(), state, false);
  1959. return false;
  1960. }
  1961. if (mutex)
  1962. mutex->releasereadlock(__FUNCTION__, __LINE__);
  1963. UseRegionScript(script_name.c_str(), state, false);
  1964. return true;
  1965. }
  1966. else
  1967. return false;
  1968. }
  1969. void LuaInterface::AddPendingSpellDelete(LuaSpell* spell) {
  1970. MSpellDelete.lock();
  1971. if ( spells_pending_delete.count(spell) == 0 )
  1972. spells_pending_delete[spell] = Timer::GetCurrentTime2() + 10000;
  1973. MSpellDelete.unlock();
  1974. }
  1975. void LuaInterface::AddCustomSpell(LuaSpell* spell)
  1976. {
  1977. MCustomSpell.writelock();
  1978. custom_spells[spell->spell->GetSpellID()] = spell;
  1979. MCustomSpell.releasewritelock();
  1980. }
  1981. void LuaInterface::RemoveCustomSpell(int32 id)
  1982. {
  1983. MCustomSpell.writelock();
  1984. map<int32, LuaSpell*>::iterator itr = custom_spells.find(id);
  1985. if (itr != custom_spells.end())
  1986. {
  1987. custom_spells.erase(itr);
  1988. custom_free_spell_ids.push_front(id);
  1989. }
  1990. MCustomSpell.releasewritelock();
  1991. }
  1992. // prior to calling FindCustomSpell you should call FindCustomSpellLock and after FindCustomSpellUnlock
  1993. LuaSpell* LuaInterface::FindCustomSpell(int32 id)
  1994. {
  1995. LuaSpell* spell = 0;
  1996. map<int32, LuaSpell*>::iterator itr = custom_spells.find(id);
  1997. if (itr != custom_spells.end())
  1998. spell = itr->second;
  1999. return spell;
  2000. }
  2001. int32 LuaInterface::GetFreeCustomSpellID()
  2002. {
  2003. int32 id = 0;
  2004. MCustomSpell.writelock();
  2005. if (!custom_free_spell_ids.empty())
  2006. {
  2007. id = custom_free_spell_ids.front();
  2008. custom_free_spell_ids.pop_front();
  2009. }
  2010. MCustomSpell.releasewritelock();
  2011. return id;
  2012. }
  2013. LUAUserData::LUAUserData(){
  2014. correctly_initialized = false;
  2015. quest = 0;
  2016. conversation_options = 0;
  2017. spawn = 0;
  2018. zone = 0;
  2019. skill = 0;
  2020. option_window_option = 0;
  2021. item = 0;
  2022. spawn_list = 0;
  2023. }
  2024. bool LUAUserData::IsCorrectlyInitialized(){
  2025. return correctly_initialized;
  2026. }
  2027. bool LUAUserData::IsConversationOption(){
  2028. return false;
  2029. }
  2030. bool LUAUserData::IsSpawnList() {
  2031. return false;
  2032. }
  2033. bool LUAUserData::IsOptionWindow() {
  2034. return false;
  2035. }
  2036. bool LUAUserData::IsSpawn(){
  2037. return false;
  2038. }
  2039. bool LUAUserData::IsQuest(){
  2040. return false;
  2041. }
  2042. bool LUAUserData::IsZone(){
  2043. return false;
  2044. }
  2045. bool LUAUserData::IsItem(){
  2046. return false;
  2047. }
  2048. bool LUAUserData::IsSkill() {
  2049. return false;
  2050. }
  2051. bool LUAUserData::IsSpell() {
  2052. return false;
  2053. }
  2054. LUAConversationOptionWrapper::LUAConversationOptionWrapper(){
  2055. correctly_initialized = true;
  2056. }
  2057. bool LUAConversationOptionWrapper::IsConversationOption(){
  2058. return true;
  2059. }
  2060. LUASpawnListWrapper::LUASpawnListWrapper() {
  2061. correctly_initialized = true;
  2062. }
  2063. bool LUASpawnListWrapper::IsSpawnList() {
  2064. return true;
  2065. }
  2066. LUAOptionWindowWrapper::LUAOptionWindowWrapper() {
  2067. correctly_initialized = true;
  2068. }
  2069. bool LUAOptionWindowWrapper::IsOptionWindow() {
  2070. return true;
  2071. }
  2072. LUASpawnWrapper::LUASpawnWrapper(){
  2073. correctly_initialized = true;
  2074. }
  2075. bool LUASpawnWrapper::IsSpawn(){
  2076. return true;
  2077. }
  2078. LUAZoneWrapper::LUAZoneWrapper(){
  2079. correctly_initialized = true;
  2080. }
  2081. bool LUAZoneWrapper::IsZone(){
  2082. return true;
  2083. }
  2084. LUAQuestWrapper::LUAQuestWrapper(){
  2085. correctly_initialized = true;
  2086. }
  2087. bool LUAQuestWrapper::IsQuest(){
  2088. return true;
  2089. }
  2090. LUAItemWrapper::LUAItemWrapper(){
  2091. correctly_initialized = true;
  2092. }
  2093. bool LUAItemWrapper::IsItem(){
  2094. return true;
  2095. }
  2096. LUASkillWrapper::LUASkillWrapper() {
  2097. correctly_initialized = true;
  2098. }
  2099. bool LUASkillWrapper::IsSkill() {
  2100. return true;
  2101. }
  2102. LUASpellWrapper::LUASpellWrapper() {
  2103. correctly_initialized = true;
  2104. }
  2105. bool LUASpellWrapper::IsSpell() {
  2106. return true;
  2107. }