LuaInterface.cpp 64 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835
  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. user_data_timer = new Timer(20000);
  43. user_data_timer->Start();
  44. spell_delete_timer = new Timer(5000);
  45. spell_delete_timer->Start();
  46. }
  47. #ifdef WIN32
  48. vector<string>* LuaInterface::GetDirectoryListing(const char* directory) {
  49. vector<string>* ret = new vector<string>;
  50. WIN32_FIND_DATA fdata;
  51. HANDLE dhandle;
  52. char buf[MAX_PATH];
  53. snprintf(buf, sizeof(buf), "%s\\*", directory);
  54. if((dhandle = FindFirstFile(buf, &fdata)) == INVALID_HANDLE_VALUE) {
  55. safe_delete(ret);
  56. return 0;
  57. }
  58. ret->push_back(string(fdata.cFileName));
  59. while(1) {
  60. if(FindNextFile(dhandle, &fdata)) {
  61. ret->push_back(string(fdata.cFileName));
  62. }
  63. else{
  64. if(GetLastError() == ERROR_NO_MORE_FILES) {
  65. break;
  66. } else {
  67. safe_delete(ret);
  68. FindClose(dhandle);
  69. return 0;
  70. }
  71. }
  72. }
  73. if(FindClose(dhandle) == 0) {
  74. safe_delete(ret);
  75. return 0;
  76. }
  77. return ret;
  78. }
  79. #else
  80. vector<string>* LuaInterface::GetDirectoryListing(const char* directory) {
  81. vector<string>* ret = new vector<string>;
  82. DIR *dp;
  83. struct dirent *ep;
  84. dp = opendir (directory);
  85. if (dp != NULL){
  86. while ((ep = readdir (dp)))
  87. ret->push_back(string(ep->d_name));
  88. (void) closedir (dp);
  89. }
  90. else {
  91. safe_delete(ret);
  92. return 0;
  93. }
  94. return ret;
  95. }
  96. #endif
  97. LuaInterface::~LuaInterface() {
  98. shutting_down = true;
  99. MLUAMain.lock();
  100. DestroySpells();
  101. DestroySpawnScripts();
  102. DestroyQuests();
  103. DestroyItemScripts();
  104. DestroyZoneScripts();
  105. DeleteUserDataPtrs(true);
  106. DeletePendingSpells(true);
  107. safe_delete(user_data_timer);
  108. safe_delete(spell_delete_timer);
  109. }
  110. void LuaInterface::Process() {
  111. if(shutting_down)
  112. return;
  113. MLUAMain.lock();
  114. if(user_data_timer && user_data_timer->Check())
  115. DeleteUserDataPtrs(false);
  116. if(spell_delete_timer && spell_delete_timer->Check())
  117. DeletePendingSpells(false);
  118. MLUAMain.unlock();
  119. }
  120. void LuaInterface::DestroySpells() {
  121. map<string, LuaSpell*>::iterator itr;
  122. MSpells.lock();
  123. for(itr = spells.begin(); itr != spells.end(); itr++){
  124. lua_close(itr->second->state);
  125. safe_delete(itr->second);
  126. }
  127. spells.clear();
  128. MSpells.unlock();
  129. }
  130. void LuaInterface::DestroyQuests(bool reload) {
  131. map<int32, lua_State*>::iterator itr;
  132. MQuests.lock();
  133. for(itr = quest_states.begin(); itr != quest_states.end(); itr++){
  134. safe_delete(quests[itr->first]);
  135. lua_close(itr->second);
  136. }
  137. quests.clear();
  138. quest_states.clear();
  139. map<int32, Mutex*>::iterator mutex_itr;
  140. for(mutex_itr = quests_mutex.begin(); mutex_itr != quests_mutex.end(); mutex_itr++){
  141. safe_delete(mutex_itr->second);
  142. }
  143. quests_mutex.clear();
  144. if(reload)
  145. database.LoadQuests();
  146. MQuests.unlock();
  147. }
  148. void LuaInterface::DestroyItemScripts() {
  149. map<string, map<lua_State*, bool> >::iterator itr;
  150. map<lua_State*, bool>::iterator state_itr;
  151. Mutex* mutex = 0;
  152. MItemScripts.writelock(__FUNCTION__, __LINE__);
  153. for(itr = item_scripts.begin(); itr != item_scripts.end(); itr++){
  154. mutex = GetItemScriptMutex(itr->first.c_str());
  155. mutex->writelock(__FUNCTION__, __LINE__);
  156. for(state_itr = itr->second.begin(); state_itr != itr->second.end(); state_itr++)
  157. lua_close(state_itr->first);
  158. mutex->releasewritelock(__FUNCTION__, __LINE__);
  159. safe_delete(mutex);
  160. }
  161. item_scripts.clear();
  162. item_inverse_scripts.clear();
  163. item_scripts_mutex.clear();
  164. MItemScripts.releasewritelock(__FUNCTION__, __LINE__);
  165. }
  166. void LuaInterface::DestroySpawnScripts() {
  167. map<string, map<lua_State*, bool> >::iterator itr;
  168. map<lua_State*, bool>::iterator state_itr;
  169. Mutex* mutex = 0;
  170. MSpawnScripts.writelock(__FUNCTION__, __LINE__);
  171. for(itr = spawn_scripts.begin(); itr != spawn_scripts.end(); itr++){
  172. mutex = GetSpawnScriptMutex(itr->first.c_str());
  173. mutex->writelock(__FUNCTION__, __LINE__);
  174. for(state_itr = itr->second.begin(); state_itr != itr->second.end(); state_itr++)
  175. lua_close(state_itr->first);
  176. mutex->releasewritelock(__FUNCTION__, __LINE__);
  177. safe_delete(mutex);
  178. }
  179. spawn_scripts.clear();
  180. spawn_inverse_scripts.clear();
  181. spawn_scripts_mutex.clear();
  182. MSpawnScripts.releasewritelock(__FUNCTION__, __LINE__);
  183. }
  184. void LuaInterface::DestroyZoneScripts() {
  185. map<string, map<lua_State*, bool> >::iterator itr;
  186. map<lua_State*, bool>::iterator state_itr;
  187. Mutex* mutex = 0;
  188. MZoneScripts.writelock(__FUNCTION__, __LINE__);
  189. for (itr = zone_scripts.begin(); itr != zone_scripts.end(); itr++){
  190. mutex = GetZoneScriptMutex(itr->first.c_str());
  191. mutex->writelock(__FUNCTION__, __LINE__);
  192. for(state_itr = itr->second.begin(); state_itr != itr->second.end(); state_itr++)
  193. lua_close(state_itr->first);
  194. mutex->releasewritelock(__FUNCTION__, __LINE__);
  195. safe_delete(mutex);
  196. }
  197. zone_scripts.clear();
  198. zone_inverse_scripts.clear();
  199. zone_scripts_mutex.clear();
  200. MZoneScripts.releasewritelock(__FUNCTION__, __LINE__);
  201. }
  202. void LuaInterface::ReloadSpells() {
  203. DestroySpells();
  204. database.LoadSpellScriptData();
  205. }
  206. bool LuaInterface::LoadLuaSpell(const char* name) {
  207. LuaSpell* spell = 0;
  208. string lua_script = string(name);
  209. if (lua_script.find(".lua") == string::npos)
  210. lua_script.append(".lua");
  211. lua_State* state = LoadLuaFile(lua_script.c_str());
  212. if(state){
  213. spell = new LuaSpell;
  214. spell->file_name = lua_script;
  215. spell->state = state;
  216. spell->spell = 0;
  217. spell->caster = 0;
  218. spell->initial_target = 0;
  219. spell->resisted = false;
  220. spell->interrupted = false;
  221. spell->last_spellattack_hit = false;
  222. spell->crit = false;
  223. spell->MSpellTargets.SetName("LuaSpell.MSpellTargets");
  224. spell->cancel_after_all_triggers = false;
  225. spell->num_triggers = 0;
  226. spell->had_triggers = false;
  227. spell->had_dmg_remaining = false;
  228. spell->slot_pos = 0;
  229. spell->damage_remaining = 0;
  230. spell->effect_bitmask = 0;
  231. MSpells.lock();
  232. if (spells.count(lua_script) > 0) {
  233. lua_close(spells[lua_script]->state);
  234. safe_delete(spells[lua_script]);
  235. }
  236. spells[lua_script] = spell;
  237. MSpells.unlock();
  238. return true;
  239. }
  240. return false;
  241. }
  242. bool LuaInterface::LoadLuaSpell(string name) {
  243. return LoadLuaSpell(name.c_str());
  244. }
  245. bool LuaInterface::LoadItemScript(string name) {
  246. return LoadItemScript(name.c_str());
  247. }
  248. bool LuaInterface::LoadItemScript(const char* name) {
  249. bool ret = false;
  250. if(name){
  251. lua_State* state = LoadLuaFile(name);
  252. if(state){
  253. MItemScripts.writelock(__FUNCTION__, __LINE__);
  254. item_scripts[name][state] = false;
  255. MItemScripts.releasewritelock(__FUNCTION__, __LINE__);
  256. ret = true;
  257. }
  258. }
  259. return ret;
  260. }
  261. bool LuaInterface::LoadSpawnScript(const char* name) {
  262. bool ret = false;
  263. if(name){
  264. lua_State* state = LoadLuaFile(name);
  265. if(state){
  266. MSpawnScripts.writelock(__FUNCTION__, __LINE__);
  267. spawn_scripts[name][state] = false;
  268. MSpawnScripts.releasewritelock(__FUNCTION__, __LINE__);
  269. ret = true;
  270. }
  271. }
  272. return ret;
  273. }
  274. bool LuaInterface::LoadZoneScript(const char* name) {
  275. bool ret = false;
  276. if (name) {
  277. lua_State* state = LoadLuaFile(name);
  278. if (state) {
  279. MZoneScripts.writelock(__FUNCTION__, __LINE__);
  280. zone_scripts[name][state] = false;
  281. MZoneScripts.releasewritelock(__FUNCTION__, __LINE__);
  282. ret = true;
  283. }
  284. }
  285. return ret;
  286. }
  287. void LuaInterface::ProcessErrorMessage(const char* message) {
  288. MDebugClients.lock();
  289. vector<Client*> delete_clients;
  290. map<Client*, int32>::iterator itr;
  291. for(itr = debug_clients.begin(); itr != debug_clients.end(); itr++){
  292. if((Timer::GetCurrentTime2() - itr->second) > 60000)
  293. delete_clients.push_back(itr->first);
  294. else
  295. itr->first->Message(CHANNEL_COLOR_RED, "LUA Error: %s", message);
  296. }
  297. for(int32 i=0;i<delete_clients.size();i++)
  298. debug_clients.erase(delete_clients[i]);
  299. MDebugClients.unlock();
  300. }
  301. void LuaInterface::RemoveDebugClients(Client* client) {
  302. MDebugClients.lock();
  303. debug_clients.erase(client);
  304. MDebugClients.unlock();
  305. }
  306. void LuaInterface::UpdateDebugClients(Client* client) {
  307. MDebugClients.lock();
  308. debug_clients[client] = Timer::GetCurrentTime2();
  309. MDebugClients.unlock();
  310. }
  311. Mutex* LuaInterface::GetQuestMutex(Quest* quest) {
  312. Mutex* ret = 0;
  313. MQuests.lock();
  314. if(quests_mutex.count(quest->GetQuestID()) == 0){
  315. ret = new Mutex();
  316. quests_mutex[quest->GetQuestID()] = ret;
  317. ret->SetName(string("Quest::").append(quest->GetName()));
  318. }
  319. else
  320. ret = quests_mutex[quest->GetQuestID()];
  321. MQuests.unlock();
  322. return ret;
  323. }
  324. void LuaInterface::CallQuestFunction(Quest* quest, const char* function, Spawn* player, int32 step_id) {
  325. if(shutting_down)
  326. return;
  327. lua_State* state = 0;
  328. if(quest){
  329. LogWrite(LUA__DEBUG, 0, "LUA", "Quest: %s, function: %s", quest->GetName(), function);
  330. Mutex* mutex = GetQuestMutex(quest);
  331. mutex->lock();
  332. if(quest_states.count(quest->GetQuestID()) > 0)
  333. state = quest_states[quest->GetQuestID()];
  334. if(state){
  335. int8 arg_count = 3;
  336. lua_getglobal(state, function);
  337. SetQuestValue(state, quest);
  338. Spawn* spawn = player->GetZone()->GetSpawnByDatabaseID(quest->GetQuestGiver());
  339. SetSpawnValue(state, spawn);
  340. SetSpawnValue(state, player);
  341. if(step_id != 0xFFFFFFFF){
  342. SetInt32Value(state, step_id);
  343. arg_count++;
  344. }
  345. if(lua_pcall(state, arg_count, 0, 0) != 0){
  346. LogError("%s: Error processing quest function '%s': %s ", GetScriptName(state), function, lua_tostring(state, -1));
  347. lua_pop(state, 1);
  348. mutex->unlock();
  349. return;
  350. }
  351. }
  352. mutex->unlock();
  353. LogWrite(LUA__DEBUG, 0, "LUA", "Done!");
  354. }
  355. }
  356. Quest* LuaInterface::LoadQuest(int32 id, const char* name, const char* type, const char* zone, int8 level, const char* description, char* script_name) {
  357. if(shutting_down)
  358. return 0;
  359. lua_State* state = LoadLuaFile(script_name);
  360. Quest* quest = 0;
  361. if(state){
  362. quest = new Quest(id);
  363. if (name)
  364. quest->SetName(string(name));
  365. if (type)
  366. quest->SetType(string(type));
  367. if (zone)
  368. quest->SetZone(string(zone));
  369. quest->SetLevel(level);
  370. if (description)
  371. quest->SetDescription(string(description));
  372. lua_getglobal(state, "Init");
  373. SetQuestValue(state, quest);
  374. if(lua_pcall(state, 1, 0, 0) != 0){
  375. LogError("Error processing Quest \"%s\" (%u): %s", name ? name : "unknown", id, lua_tostring(state, -1));
  376. lua_pop(state, 1);
  377. safe_delete(quest);
  378. return 0;
  379. }
  380. if(!quest->GetName()){
  381. safe_delete(quest);
  382. return 0;
  383. }
  384. quest_states[id] = state;
  385. quests[id] = quest;
  386. }
  387. return quest;
  388. }
  389. const char* LuaInterface::GetScriptName(lua_State* state)
  390. {
  391. map<lua_State*, string>::iterator itr;
  392. MItemScripts.writelock(__FUNCTION__, __LINE__);
  393. itr = item_inverse_scripts.find(state);
  394. if (itr != item_inverse_scripts.end())
  395. {
  396. const char* scriptName = itr->second.c_str();
  397. MItemScripts.releasewritelock(__FUNCTION__, __LINE__);
  398. return scriptName;
  399. }
  400. MItemScripts.releasewritelock(__FUNCTION__, __LINE__);
  401. MSpawnScripts.writelock(__FUNCTION__, __LINE__);
  402. itr = spawn_inverse_scripts.find(state);
  403. if (itr != spawn_inverse_scripts.end())
  404. {
  405. const char* scriptName = itr->second.c_str();
  406. MSpawnScripts.releasewritelock(__FUNCTION__, __LINE__);
  407. return scriptName;
  408. }
  409. MSpawnScripts.releasewritelock(__FUNCTION__, __LINE__);
  410. MZoneScripts.writelock(__FUNCTION__, __LINE__);
  411. itr = zone_inverse_scripts.find(state);
  412. if (itr != zone_inverse_scripts.end())
  413. {
  414. const char* scriptName = itr->second.c_str();
  415. MZoneScripts.releasewritelock(__FUNCTION__, __LINE__);
  416. return scriptName;
  417. }
  418. MZoneScripts.releasewritelock(__FUNCTION__, __LINE__);
  419. MSpells.lock();
  420. LuaSpell* spell = GetCurrentSpell(state);
  421. if (spell)
  422. {
  423. const char* fileName = (spell->file_name.length() > 0) ? spell->file_name.c_str() : "";
  424. MSpells.unlock();
  425. return fileName;
  426. }
  427. MSpells.unlock();
  428. return "";
  429. }
  430. bool LuaInterface::LoadSpawnScript(string name) {
  431. return LoadSpawnScript(name.c_str());
  432. }
  433. bool LuaInterface::LoadZoneScript(string name) {
  434. return LoadZoneScript(name.c_str());
  435. }
  436. void LuaInterface::AddSpawnPointers(LuaSpell* spell, bool first_cast, bool precast, const char* function, SpellScriptTimer* timer) {
  437. if (function)
  438. lua_getglobal(spell->state, function);
  439. else if (precast)
  440. lua_getglobal(spell->state, "precast");
  441. else if(first_cast)
  442. lua_getglobal(spell->state, "cast");
  443. else
  444. lua_getglobal(spell->state, "tick");
  445. Spawn* temp_spawn = 0;
  446. if (timer && timer->caster && spell->caster)
  447. temp_spawn = spell->caster->GetZone()->GetSpawnByID(timer->caster);
  448. if (temp_spawn)
  449. SetSpawnValue(spell->state, temp_spawn);
  450. else if (spell->caster)
  451. SetSpawnValue(spell->state, spell->caster);
  452. temp_spawn = 0;
  453. if (timer && timer->target && spell->caster)
  454. temp_spawn = spell->caster->GetZone()->GetSpawnByID(timer->target);
  455. if (temp_spawn)
  456. SetSpawnValue(spell->state, temp_spawn);
  457. else {
  458. if(spell->caster && spell->initial_target)
  459. SetSpawnValue(spell->state, spell->caster->GetZone()->GetSpawnByID(spell->initial_target));
  460. else if(spell->caster && spell->caster->GetTarget())
  461. SetSpawnValue(spell->state, spell->caster->GetTarget());
  462. else
  463. SetSpawnValue(spell->state, 0);
  464. }
  465. }
  466. LuaSpell* LuaInterface::GetCurrentSpell(lua_State* state) {
  467. if(current_spells.count(state) > 0)
  468. return current_spells[state];
  469. return 0;
  470. }
  471. bool LuaInterface::CallSpellProcess(LuaSpell* spell, int8 num_parameters) {
  472. if(shutting_down || !spell || !spell->caster)
  473. return false;
  474. MSpells.lock();
  475. current_spells[spell->state] = spell;
  476. MSpells.unlock();
  477. if(lua_pcall(spell->state, num_parameters, 0, 0) != 0){
  478. LogError("Error running %s", lua_tostring(spell->state, -1));
  479. lua_pop(spell->state, 1);
  480. RemoveSpell(spell, false);
  481. return false;
  482. }
  483. return true;
  484. }
  485. void LuaInterface::RemoveSpawnScript(const char* name) {
  486. lua_State* state = 0;
  487. Mutex* mutex = GetSpawnScriptMutex(name);
  488. while((state = GetSpawnScript(name, false))){
  489. mutex->writelock(__FUNCTION__, __LINE__);
  490. lua_close(state);
  491. spawn_scripts[name].erase(state);
  492. mutex->releasewritelock(__FUNCTION__, __LINE__);
  493. }
  494. MSpawnScripts.writelock(__FUNCTION__, __LINE__);
  495. spawn_scripts.erase(name);
  496. MSpawnScripts.releasewritelock(__FUNCTION__, __LINE__);
  497. }
  498. bool LuaInterface::CallItemScript(lua_State* state, int8 num_parameters) {
  499. if(shutting_down)
  500. return false;
  501. if(!state || lua_pcall(state, num_parameters, 0, 0) != 0){
  502. if (state){
  503. const char* err = lua_tostring(state, -1);
  504. LogError("%s: %s", GetScriptName(state), err);
  505. lua_pop(state, 1);
  506. }
  507. return false;
  508. }
  509. return true;
  510. }
  511. bool LuaInterface::CallSpawnScript(lua_State* state, int8 num_parameters) {
  512. if(shutting_down)
  513. return false;
  514. if(!state || lua_pcall(state, num_parameters, 0, 0) != 0){
  515. if (state){
  516. const char* err = lua_tostring(state, -1);
  517. LogError("%s: %s", GetScriptName(state), err);
  518. lua_pop(state, 1);
  519. }
  520. return false;
  521. }
  522. return true;
  523. }
  524. bool LuaInterface::CallZoneScript(lua_State* state, int8 num_parameters) {
  525. if(shutting_down)
  526. return false;
  527. if (!state || lua_pcall(state, num_parameters, 0, 0) != 0) {
  528. if (state){
  529. const char* err = lua_tostring(state, -1);
  530. LogError("%s: %s", GetScriptName(state), err);
  531. lua_pop(state, 1);
  532. }
  533. return false;
  534. }
  535. return true;
  536. }
  537. lua_State* LuaInterface::LoadLuaFile(const char* name) {
  538. if(shutting_down)
  539. return 0;
  540. lua_State* state = luaL_newstate();
  541. luaL_openlibs(state);
  542. if(luaL_dofile(state, name) == 0){
  543. RegisterFunctions(state);
  544. return state;
  545. }
  546. else{
  547. LogError("Error loading %s (file name: '%s')", lua_tostring(state, -1), name);
  548. lua_pop(state, 1);
  549. lua_close(state);
  550. }
  551. return 0;
  552. }
  553. void LuaInterface::RemoveSpell(LuaSpell* spell, bool call_remove_function, bool can_delete) {
  554. if(shutting_down)
  555. return;
  556. if(call_remove_function){
  557. lua_getglobal(spell->state, "remove");
  558. LUASpawnWrapper* spawn_wrapper = new LUASpawnWrapper();
  559. spawn_wrapper->spawn = spell->caster;
  560. AddUserDataPtr(spawn_wrapper);
  561. lua_pushlightuserdata(spell->state, spawn_wrapper);
  562. if(spell->caster && (spell->initial_target || spell->caster->GetTarget())){
  563. spawn_wrapper = new LUASpawnWrapper();
  564. if(!spell->initial_target)
  565. spawn_wrapper->spawn = spell->caster->GetTarget();
  566. else
  567. spawn_wrapper->spawn = spell->caster->GetZone()->GetSpawnByID(spell->initial_target);
  568. AddUserDataPtr(spawn_wrapper);
  569. lua_pushlightuserdata(spell->state, spawn_wrapper);
  570. }
  571. else
  572. lua_pushlightuserdata(spell->state, 0);
  573. MSpells.lock();
  574. current_spells[spell->state] = spell;
  575. MSpells.unlock();
  576. lua_pcall(spell->state, 2, 0, 0);
  577. }
  578. if (can_delete) {
  579. AddPendingSpellDelete(spell);
  580. }
  581. if (spell->caster)
  582. {
  583. spell->caster->GetZone()->GetSpellProcess()->RemoveSpellScriptTimerBySpell(spell, false);
  584. spell->caster->RemoveProc(0, spell);
  585. spell->caster->RemoveMaintainedSpell(spell);
  586. }
  587. }
  588. void LuaInterface::RegisterFunctions(lua_State* state) {
  589. lua_register(state, "SetHP", EQ2Emu_lua_SetCurrentHP);
  590. lua_register(state, "SetMaxHP", EQ2Emu_lua_SetMaxHP);
  591. lua_register(state, "SetMaxHPBase", EQ2Emu_lua_SetMaxHPBase);
  592. lua_register(state, "SetPower", EQ2Emu_lua_SetCurrentPower);
  593. lua_register(state, "SetMaxPower", EQ2Emu_lua_SetMaxPower);
  594. lua_register(state, "SetMaxPowerBase", EQ2Emu_lua_SetMaxPowerBase);
  595. lua_register(state, "SetPosition", EQ2Emu_lua_SetPosition);
  596. lua_register(state, "SetHeading", EQ2Emu_lua_SetHeading);
  597. lua_register(state, "SetModelType", EQ2Emu_lua_SetModelType);
  598. lua_register(state, "SetAdventureClass", EQ2Emu_lua_SetAdventureClass);
  599. lua_register(state, "SetTradeskillClass", EQ2Emu_lua_SetTradeskillClass);
  600. lua_register(state, "SetMount", EQ2Emu_lua_SetMount);
  601. lua_register(state, "SetMountColor", EQ2Emu_lua_SetMountColor);
  602. lua_register(state, "GetMount", EQ2Emu_lua_GetMount);
  603. lua_register(state, "GetRace", EQ2Emu_lua_GetRace);
  604. lua_register(state, "GetRaceName", EQ2Emu_lua_GetRaceName);
  605. lua_register(state, "GetClass", EQ2Emu_lua_GetClass);
  606. lua_register(state, "GetClassName", EQ2Emu_lua_GetClassName);
  607. lua_register(state, "GetArchetypeName", EQ2Emu_lua_GetArchetypeName);
  608. lua_register(state, "SetSpeed", EQ2Emu_lua_SetSpeed);
  609. lua_register(state, "ModifyPower", EQ2Emu_lua_ModifyPower);
  610. lua_register(state, "ModifyHP", EQ2Emu_lua_ModifyHP);
  611. lua_register(state, "GetDistance", EQ2Emu_lua_GetDistance);
  612. lua_register(state, "GetHeading", EQ2Emu_lua_GetHeading);
  613. lua_register(state, "GetLevel", EQ2Emu_lua_GetLevel);
  614. lua_register(state, "GetHP", EQ2Emu_lua_GetCurrentHP);
  615. lua_register(state, "GetMaxHP", EQ2Emu_lua_GetMaxHP);
  616. lua_register(state, "GetMaxHPBase", EQ2Emu_lua_GetMaxHPBase);
  617. lua_register(state, "GetMaxPower", EQ2Emu_lua_GetMaxPower);
  618. lua_register(state, "GetMaxPowerBase", EQ2Emu_lua_GetMaxPowerBase);
  619. lua_register(state, "GetName", EQ2Emu_lua_GetName);
  620. lua_register(state, "GetPower", EQ2Emu_lua_GetCurrentPower);
  621. lua_register(state, "GetX", EQ2Emu_lua_GetX);
  622. lua_register(state, "GetY", EQ2Emu_lua_GetY);
  623. lua_register(state, "GetZ", EQ2Emu_lua_GetZ);
  624. lua_register(state, "GetSpawnID", EQ2Emu_lua_GetSpawnID);
  625. lua_register(state, "GetSpawnGroupID", EQ2Emu_lua_GetSpawnGroupID);
  626. lua_register(state, "GetSpawnLocationID", EQ2Emu_lua_GetSpawnLocationID);
  627. lua_register(state, "GetSpawnLocationPlacementID", EQ2Emu_lua_GetSpawnLocationPlacementID);
  628. lua_register(state, "SetFactionID", EQ2Emu_lua_SetFactionID);
  629. lua_register(state, "GetFactionID", EQ2Emu_lua_GetFactionID);
  630. lua_register(state, "GetFactionAmount", EQ2Emu_lua_GetFactionAmount);
  631. lua_register(state, "GetGender", EQ2Emu_lua_GetGender);
  632. lua_register(state, "GetTarget", EQ2Emu_lua_GetTarget);
  633. lua_register(state, "HasFreeSlot", EQ2Emu_lua_HasFreeSlot);
  634. lua_register(state, "HasItemEquipped", EQ2Emu_lua_HasItemEquipped);
  635. lua_register(state, "GetEquippedItemByID", EQ2Emu_lua_GetEquippedItemByID);
  636. lua_register(state, "GetEquippedItemBySlot", EQ2Emu_lua_GetEquippedItemBySlot);
  637. lua_register(state, "GetItemByID", EQ2Emu_lua_GetItemByID);
  638. lua_register(state, "GetItemType", EQ2Emu_lua_GetItemType);
  639. lua_register(state, "GetSpellName", EQ2Emu_lua_GetSpellName);
  640. lua_register(state, "PerformCameraShake", EQ2Emu_lua_PerformCameraShake);
  641. lua_register(state, "GetModelType", EQ2Emu_lua_GetModelType);
  642. lua_register(state, "GetSpeed", EQ2Emu_lua_GetSpeed);
  643. lua_register(state, "HasMoved", EQ2Emu_lua_HasMoved);
  644. lua_register(state, "SpellDamage", EQ2Emu_lua_SpellDamage);
  645. lua_register(state, "CastSpell", EQ2Emu_lua_CastSpell);
  646. lua_register(state, "SpellHeal", EQ2Emu_lua_SpellHeal);
  647. lua_register(state, "AddItem", EQ2Emu_lua_AddItem);
  648. lua_register(state, "SummonItem", EQ2Emu_lua_SummonItem);
  649. lua_register(state, "RemoveItem", EQ2Emu_lua_RemoveItem);
  650. lua_register(state, "HasItem", EQ2Emu_lua_HasItem);
  651. lua_register(state, "SpawnMob", EQ2Emu_lua_Spawn);
  652. lua_register(state, "SummonPet", EQ2Emu_lua_SummonPet);
  653. lua_register(state, "AddSpawnAccess", EQ2Emu_lua_AddSpawnAccess);
  654. lua_register(state, "GetZone", EQ2Emu_lua_GetZone);
  655. lua_register(state, "GetZoneName", EQ2Emu_lua_GetZoneName);
  656. lua_register(state, "GetZoneID", EQ2Emu_lua_GetZoneID);
  657. lua_register(state, "Zone", EQ2Emu_lua_Zone);
  658. lua_register(state, "AddHate", EQ2Emu_lua_AddHate);
  659. lua_register(state, "IsAlive", EQ2Emu_lua_IsAlive);
  660. lua_register(state, "IsInCombat", EQ2Emu_lua_IsInCombat);
  661. lua_register(state, "Attack", EQ2Emu_lua_Attack);
  662. lua_register(state, "ApplySpellVisual", EQ2Emu_lua_ApplySpellVisual);
  663. lua_register(state, "IsPlayer", EQ2Emu_lua_IsPlayer);
  664. lua_register(state, "FaceTarget", EQ2Emu_lua_FaceTarget);
  665. lua_register(state, "MoveToLocation", EQ2Emu_lua_MoveToLocation);
  666. lua_register(state, "Shout", EQ2Emu_lua_Shout);
  667. lua_register(state, "Say", EQ2Emu_lua_Say);
  668. lua_register(state, "SayOOC", EQ2Emu_lua_SayOOC);
  669. lua_register(state, "Emote", EQ2Emu_lua_Emote);
  670. lua_register(state, "MovementLoopAddLocation", EQ2Emu_lua_MovementLoopAdd);
  671. lua_register(state, "GetCurrentZoneSafeLocation", EQ2Emu_lua_GetCurrentZoneSafeLocation);
  672. lua_register(state, "AddTimer", EQ2Emu_lua_AddTimer);
  673. lua_register(state, "Harvest", EQ2Emu_lua_Harvest);
  674. lua_register(state, "AddSpellBonus", EQ2Emu_lua_AddSpellBonus);
  675. lua_register(state, "RemoveSpellBonus", EQ2Emu_lua_RemoveSpellBonus);
  676. lua_register(state, "AddSkillBonus", EQ2Emu_lua_AddSkillBonus);
  677. lua_register(state, "RemoveSkillBonus", EQ2Emu_lua_RemoveSkillBonus);
  678. lua_register(state, "AddControlEffect", EQ2Emu_lua_AddControlEffect);
  679. lua_register(state, "RemoveControlEffect", EQ2Emu_lua_RemoveControlEffect);
  680. lua_register(state, "GetCurrentZoneSafeLocation", EQ2Emu_lua_GetCurrentZoneSafeLocation);
  681. lua_register(state, "GetInt", EQ2Emu_lua_GetInt);
  682. lua_register(state, "GetWis", EQ2Emu_lua_GetWis);
  683. lua_register(state, "GetSta", EQ2Emu_lua_GetSta);
  684. lua_register(state, "GetStr", EQ2Emu_lua_GetStr);
  685. lua_register(state, "GetAgi", EQ2Emu_lua_GetAgi);
  686. lua_register(state, "SetInt", EQ2Emu_lua_SetInt);
  687. lua_register(state, "SetWis", EQ2Emu_lua_SetWis);
  688. lua_register(state, "SetSta", EQ2Emu_lua_SetSta);
  689. lua_register(state, "SetStr", EQ2Emu_lua_SetStr);
  690. lua_register(state, "SetAgi", EQ2Emu_lua_SetAgi);
  691. lua_register(state, "GetIntBase", EQ2Emu_lua_GetIntBase);
  692. lua_register(state, "GetWisBase", EQ2Emu_lua_GetWisBase);
  693. lua_register(state, "GetStaBase", EQ2Emu_lua_GetStaBase);
  694. lua_register(state, "GetStrBase", EQ2Emu_lua_GetStrBase);
  695. lua_register(state, "GetAgiBase", EQ2Emu_lua_GetAgiBase);
  696. lua_register(state, "SetIntBase", EQ2Emu_lua_SetIntBase);
  697. lua_register(state, "SetWisBase", EQ2Emu_lua_SetWisBase);
  698. lua_register(state, "SetStaBase", EQ2Emu_lua_SetStaBase);
  699. lua_register(state, "SetStrBase", EQ2Emu_lua_SetStrBase);
  700. lua_register(state, "SetAgiBase", EQ2Emu_lua_SetAgiBase);
  701. lua_register(state, "GetSpawn", EQ2Emu_lua_GetSpawn);
  702. lua_register(state, "GetVariableValue", EQ2Emu_lua_GetVariableValue);
  703. lua_register(state, "GetCoinMessage", EQ2Emu_lua_GetCoinMessage);
  704. lua_register(state, "GetSpawnByGroupID", EQ2Emu_lua_GetSpawnByGroupID);
  705. lua_register(state, "GetSpawnByLocationID", EQ2Emu_lua_GetSpawnByLocationID);
  706. lua_register(state, "PlayFlavor", EQ2Emu_lua_PlayFlavor);
  707. lua_register(state, "PlaySound", EQ2Emu_lua_PlaySound);
  708. lua_register(state, "PlayVoice", EQ2Emu_lua_PlayVoice);
  709. lua_register(state, "PlayAnimation", EQ2Emu_lua_PlayAnimation);
  710. lua_register(state, "AddLootItem", EQ2Emu_lua_AddLootItem);
  711. lua_register(state, "RemoveLootItem", EQ2Emu_lua_RemoveLootItem);
  712. lua_register(state, "AddLootCoin", EQ2Emu_lua_AddLootCoin);
  713. lua_register(state, "GiveLoot", EQ2Emu_lua_GiveLoot);
  714. lua_register(state, "HasPendingLootItem", EQ2Emu_lua_HasPendingLootItem);
  715. lua_register(state, "HasPendingLoot", EQ2Emu_lua_HasPendingLoot);
  716. lua_register(state, "SetLootCoin", EQ2Emu_lua_SetLootCoin);
  717. lua_register(state, "GetLootCoin", EQ2Emu_lua_GetLootCoin);
  718. lua_register(state, "SetPlayerProximityFunction", EQ2Emu_lua_SetPlayerProximityFunction);
  719. lua_register(state, "SetLocationProximityFunction", EQ2Emu_lua_SetLocationProximityFunction);
  720. lua_register(state, "CreateConversation", EQ2Emu_lua_CreateConversation);
  721. lua_register(state, "AddConversationOption", EQ2Emu_lua_AddConversationOption);
  722. lua_register(state, "StartConversation", EQ2Emu_lua_StartConversation);
  723. lua_register(state, "CloseConversation", EQ2Emu_lua_CloseConversation);
  724. lua_register(state, "CloseItemConversation", EQ2Emu_lua_CloseItemConversation);
  725. //lua_register(state, "StartItemConversation", EQ2Emu_lua_StartItemConversation);
  726. lua_register(state, "StartDialogConversation", EQ2Emu_lua_StartDialogConversation);
  727. lua_register(state, "SpawnSet", EQ2Emu_lua_SpawnSet);
  728. lua_register(state, "SpawnSetByDistance", EQ2Emu_lua_SpawnSetByDistance);
  729. lua_register(state, "SpawnMove", EQ2Emu_lua_SpawnMove);
  730. lua_register(state, "KillSpawn", EQ2Emu_lua_KillSpawn);
  731. lua_register(state, "KillSpawnByDistance", EQ2Emu_lua_KillSpawnByDistance);
  732. lua_register(state, "Despawn", EQ2Emu_lua_Despawn);
  733. lua_register(state, "IsBindAllowed", EQ2Emu_lua_IsBindAllowed);
  734. lua_register(state, "IsGateAllowed", EQ2Emu_lua_IsGateAllowed);
  735. lua_register(state, "Bind", EQ2Emu_lua_Bind);
  736. lua_register(state, "Gate", EQ2Emu_lua_Gate);
  737. lua_register(state, "SendMessage", EQ2Emu_lua_SendMessage);
  738. lua_register(state, "SendPopUpMessage", EQ2Emu_lua_SendPopUpMessage);
  739. lua_register(state, "SetServerControlFlag", EQ2Emu_lua_SetServerControlFlag);
  740. lua_register(state, "ToggleTracking", EQ2Emu_lua_ToggleTracking);
  741. lua_register(state, "AddPrimaryEntityCommand", EQ2Emu_lua_AddPrimaryEntityCommand);
  742. lua_register(state, "AddSpellBookEntry", EQ2Emu_lua_AddSpellBookEntry);
  743. lua_register(state, "Interrupt", EQ2Emu_lua_Interrupt);
  744. lua_register(state, "Stealth", EQ2Emu_lua_Stealth);
  745. lua_register(state, "IsInvis", EQ2Emu_lua_IsInvis);
  746. lua_register(state, "IsStealthed", EQ2Emu_lua_IsStealthed);
  747. lua_register(state, "AddSpawnIDAccess", EQ2Emu_lua_AddSpawnIDAccess);
  748. lua_register(state, "RemoveSpawnIDAccess", EQ2Emu_lua_RemoveSpawnIDAccess);
  749. lua_register(state, "HasRecipeBook", EQ2Emu_lua_HasRecipeBook);
  750. lua_register(state, "SetRequiredQuest", EQ2Emu_lua_SetRequiredQuest);
  751. lua_register(state, "SetRequiredHistory", EQ2Emu_lua_SetRequiredHistory);
  752. lua_register(state, "SetStepComplete", EQ2Emu_lua_SetStepComplete);
  753. lua_register(state, "AddStepProgress", EQ2Emu_lua_AddStepProgress);
  754. lua_register(state, "UpdateQuestTaskGroupDescription", EQ2Emu_lua_UpdateQuestTaskGroupDescription);
  755. lua_register(state, "GetTaskGroupStep", EQ2Emu_lua_GetTaskGroupStep);
  756. lua_register(state, "GetQuestStep", EQ2Emu_lua_GetQuestStep);
  757. lua_register(state, "QuestStepIsComplete", EQ2Emu_lua_QuestStepIsComplete);
  758. lua_register(state, "RegisterQuest", EQ2Emu_lua_RegisterQuest);
  759. lua_register(state, "SetQuestPrereqLevel", EQ2Emu_lua_SetQuestPrereqLevel);
  760. lua_register(state, "AddQuestPrereqQuest", EQ2Emu_lua_AddQuestPrereqQuest);
  761. lua_register(state, "AddQuestPrereqItem", EQ2Emu_lua_AddQuestPrereqItem);
  762. lua_register(state, "AddQuestPrereqFaction", EQ2Emu_lua_AddQuestPrereqFaction);
  763. lua_register(state, "AddQuestPrereqRace", EQ2Emu_lua_AddQuestPrereqRace);
  764. lua_register(state, "AddQuestPrereqModelType", EQ2Emu_lua_AddQuestPrereqModelType);
  765. lua_register(state, "AddQuestPrereqClass", EQ2Emu_lua_AddQuestPrereqClass);
  766. lua_register(state, "AddQuestPrereqTradeskillLevel", EQ2Emu_lua_AddQuestPrereqTradeskillLevel);
  767. lua_register(state, "AddQuestPrereqTradeskillClass", EQ2Emu_lua_AddQuestPrereqTradeskillClass);
  768. lua_register(state, "AddQuestSelectableRewardItem", EQ2Emu_lua_AddQuestSelectableRewardItem);
  769. lua_register(state, "AddQuestRewardItem", EQ2Emu_lua_AddQuestRewardItem);
  770. lua_register(state, "AddQuestRewardCoin", EQ2Emu_lua_AddQuestRewardCoin);
  771. lua_register(state, "AddQuestRewardFaction", EQ2Emu_lua_AddQuestRewardFaction);
  772. lua_register(state, "SetQuestRewardStatus", EQ2Emu_lua_SetQuestRewardStatus);
  773. lua_register(state, "SetQuestRewardComment", EQ2Emu_lua_SetQuestRewardComment);
  774. lua_register(state, "SetQuestRewardExp", EQ2Emu_lua_SetQuestRewardExp);
  775. lua_register(state, "AddQuestStepKill", EQ2Emu_lua_AddQuestStepKill);
  776. lua_register(state, "AddQuestStep", EQ2Emu_lua_AddQuestStep);
  777. lua_register(state, "AddQuestStepChat", EQ2Emu_lua_AddQuestStepChat);
  778. lua_register(state, "AddQuestStepObtainItem", EQ2Emu_lua_AddQuestStepObtainItem);
  779. lua_register(state, "AddQuestStepLocation", EQ2Emu_lua_AddQuestStepLocation);
  780. lua_register(state, "AddQuestStepSpell", EQ2Emu_lua_AddQuestStepSpell);
  781. lua_register(state, "AddQuestStepCraft", EQ2Emu_lua_AddQuestStepCraft);
  782. lua_register(state, "AddQuestStepHarvest", EQ2Emu_lua_AddQuestStepHarvest);
  783. lua_register(state, "AddQuestStepCompleteAction", EQ2Emu_lua_AddQuestStepCompleteAction);
  784. lua_register(state, "AddQuestStepProgressAction", EQ2Emu_lua_AddQuestStepProgressAction);
  785. lua_register(state, "SetQuestCompleteAction", EQ2Emu_lua_SetQuestCompleteAction);
  786. lua_register(state, "GiveQuestReward", EQ2Emu_lua_GiveQuestReward);
  787. lua_register(state, "UpdateQuestStepDescription", EQ2Emu_lua_UpdateQuestStepDescription);
  788. lua_register(state, "UpdateQuestDescription", EQ2Emu_lua_UpdateQuestDescription);
  789. lua_register(state, "UpdateQuestZone", EQ2Emu_lua_UpdateQuestZone);
  790. lua_register(state, "SetCompletedDescription", EQ2Emu_lua_SetCompletedDescription);
  791. lua_register(state, "OfferQuest", EQ2Emu_lua_OfferQuest);
  792. lua_register(state, "ProvidesQuest", EQ2Emu_lua_ProvidesQuest);
  793. lua_register(state, "HasQuest", EQ2Emu_lua_HasQuest);
  794. lua_register(state, "HasCompletedQuest", EQ2Emu_lua_HasCompletedQuest);
  795. lua_register(state, "QuestIsComplete", EQ2Emu_lua_QuestIsComplete);
  796. lua_register(state, "QuestReturnNPC", EQ2Emu_lua_QuestReturnNPC);
  797. lua_register(state, "GetQuest", EQ2Emu_lua_GetQuest);
  798. lua_register(state, "HasCollectionsToHandIn", EQ2Emu_lua_HasCollectionsToHandIn);
  799. lua_register(state, "HandInCollections", EQ2Emu_lua_HandInCollections);
  800. lua_register(state, "UseWidget", EQ2Emu_lua_UseWidget);
  801. lua_register(state, "SetSpellList", EQ2Emu_lua_SetSpellList);
  802. lua_register(state, "GetPet", EQ2Emu_lua_GetPet);
  803. lua_register(state, "Charm", EQ2Emu_lua_Charm);
  804. lua_register(state, "GetGroup", EQ2Emu_lua_GetGroup);
  805. lua_register(state, "SetCompleteFlag", EQ2Emu_lua_SetCompleteFlag);
  806. lua_register(state, "SetQuestYellow", EQ2Emu_lua_SetQuestYellow);
  807. lua_register(state, "CanReceiveQuest", EQ2Emu_lua_CanReceiveQuest);
  808. lua_register(state, "AddTransportSpawn", EQ2Emu_lua_AddTransportSpawn);
  809. // Option window
  810. lua_register(state, "CreateOptionWindow", EQ2Emu_lua_CreateOptionWindow);
  811. lua_register(state, "AddOptionWindowOption", EQ2Emu_lua_AddOptionWindowOption);
  812. lua_register(state, "SendOptionWindow", EQ2Emu_lua_SendOptionWindow);
  813. lua_register(state, "GetTradeskillClass", EQ2Emu_lua_GetTradeskillClass);
  814. lua_register(state, "GetTradeskillLevel", EQ2Emu_lua_GetTradeskillLevel);
  815. lua_register(state, "GetTradeskillClassName", EQ2Emu_lua_GetTradeskillClassName);
  816. lua_register(state, "SetTradeskillLevel", EQ2Emu_lua_SetTradeskillLevel);
  817. lua_register(state, "SummonDeityPet", EQ2Emu_lua_SummonDeityPet);
  818. lua_register(state, "SummonCosmeticPet", EQ2Emu_lua_SummonCosmeticPet);
  819. lua_register(state, "DismissPet", EQ2Emu_lua_DismissPet);
  820. lua_register(state, "GetCharmedPet", EQ2Emu_lua_GetCharmedPet);
  821. lua_register(state, "GetDeityPet", EQ2Emu_lua_GetDeityPet);
  822. lua_register(state, "GetCosmeticPet", EQ2Emu_lua_GetCosmeticPet);
  823. lua_register(state, "SetQuestFeatherColor", EQ2Emu_lua_SetQuestFeatherColor);
  824. lua_register(state, "RemoveSpawnAccess", EQ2Emu_lua_RemoveSpawnAccess);
  825. lua_register(state, "SpawnByLocationID", EQ2Emu_lua_SpawnByLocationID);
  826. lua_register(state, "CastEntityCommand", EQ2Emu_lua_CastEntityCommand);
  827. lua_register(state, "SetLuaBrain", EQ2Emu_lua_SetLuaBrain);
  828. lua_register(state, "SetBrainTick", EQ2Emu_lua_SetBrainTick);
  829. lua_register(state, "SetFollowTarget", EQ2Emu_lua_SetFollowTarget);
  830. lua_register(state, "GetFollowTarget", EQ2Emu_lua_GetFollowTarget);
  831. lua_register(state, "ToggleFollow", EQ2Emu_lua_ToggleFollow);
  832. lua_register(state, "IsFollowing", EQ2Emu_lua_IsFollowing);
  833. lua_register(state, "SetTempVariable", EQ2Emu_lua_SetTempVariable);
  834. lua_register(state, "GetTempVariable", EQ2Emu_lua_GetTempVariable);
  835. lua_register(state, "GiveQuestItem", EQ2Emu_lua_GiveQuestItem);
  836. lua_register(state, "SetQuestRepeatable", EQ2Emu_lua_SetQuestRepeatable);
  837. lua_register(state, "AddWard", EQ2Emu_lua_AddWard);
  838. lua_register(state, "AddToWard", EQ2Emu_lua_AddToWard);
  839. lua_register(state, "RemoveWard", EQ2Emu_lua_RemoveWard);
  840. lua_register(state, "GetWardAmountLeft", EQ2Emu_lua_GetWardAmountLeft);
  841. lua_register(state, "GetWardValue", EQ2Emu_lua_GetWardValue);
  842. lua_register(state, "SetTarget", EQ2Emu_lua_SetTarget);
  843. lua_register(state, "IsPet", EQ2Emu_lua_IsPet);
  844. lua_register(state, "GetOwner", EQ2Emu_lua_GetOwner);
  845. lua_register(state, "SetInCombat", EQ2Emu_lua_SetInCombat);
  846. lua_register(state, "CompareSpawns", EQ2Emu_lua_CompareSpawns);
  847. lua_register(state, "Runback", EQ2Emu_lua_Runback);
  848. lua_register(state, "GetRunbackDistance", EQ2Emu_lua_GetRunbackDistance);
  849. lua_register(state, "IsCasting", EQ2Emu_lua_IsCasting);
  850. lua_register(state, "IsMezzed", EQ2Emu_lua_IsMezzed);
  851. lua_register(state, "IsStunned", EQ2Emu_lua_IsStunned);
  852. lua_register(state, "IsMezzedOrStunned", EQ2Emu_lua_IsMezzedOrStunned);
  853. lua_register(state, "ProcessSpell", EQ2Emu_lua_ProcessSpell);
  854. lua_register(state, "ProcessMelee", EQ2Emu_lua_ProcessMelee);
  855. lua_register(state, "HasRecovered", EQ2Emu_lua_HasRecovered);
  856. lua_register(state, "GetEncounterSize", EQ2Emu_lua_GetEncounterSize);
  857. lua_register(state, "GetMostHated", EQ2Emu_lua_GetMostHated);
  858. lua_register(state, "ClearHate", EQ2Emu_lua_ClearHate);
  859. lua_register(state, "ClearEncounter", EQ2Emu_lua_ClearEncounter);
  860. lua_register(state, "GetEncounter", EQ2Emu_lua_GetEncounter);
  861. lua_register(state, "GetHateList", EQ2Emu_lua_GetHateList);
  862. lua_register(state, "HasGroup", EQ2Emu_lua_HasGroup);
  863. lua_register(state, "HasSpellEffect", EQ2Emu_lua_HasSpellEffect);
  864. lua_register(state, "SetSuccessTimer", EQ2Emu_lua_SetSuccessTimer);
  865. lua_register(state, "SetFailureTimer", EQ2Emu_lua_SetFailureTimer);
  866. lua_register(state, "IsGroundSpawn", EQ2Emu_lua_IsGroundSpawn);
  867. lua_register(state, "CanHarvest", EQ2Emu_lua_CanHarvest);
  868. lua_register(state, "SummonDumbFirePet", EQ2Emu_lua_SummonDumbFirePet);
  869. lua_register(state, "GetSkillValue", EQ2Emu_lua_GetSkillValue);
  870. lua_register(state, "GetSkillMaxValue", EQ2Emu_lua_GetSkillMaxValue);
  871. lua_register(state, "GetSkillName", EQ2Emu_lua_GetSkillName);
  872. lua_register(state, "SetSkillMaxValue", EQ2Emu_lua_SetSkillMaxValue);
  873. lua_register(state, "SetSkillValue", EQ2Emu_lua_SetSkillValue);
  874. lua_register(state, "GetSkill", EQ2Emu_lua_GetSkill);
  875. lua_register(state, "GetSkillIDByName", EQ2Emu_lua_GetSkillIDByName);
  876. lua_register(state, "AddProc", EQ2Emu_lua_AddProc);
  877. lua_register(state, "RemoveProc", EQ2Emu_lua_RemoveProc);
  878. lua_register(state, "Knockback", EQ2Emu_lua_Knockback);
  879. lua_register(state, "IsEpic", EQ2Emu_lua_IsEpic);
  880. lua_register(state, "IsHeroic", EQ2Emu_lua_IsHeroic);
  881. lua_register(state, "ProcDamage", EQ2Emu_lua_ProcDamage);
  882. lua_register(state, "LastSpellAttackHit", EQ2Emu_lua_LastSpellAttackHit);
  883. lua_register(state, "IsBehind", EQ2Emu_lua_IsBehind);
  884. lua_register(state, "IsFlanking", EQ2Emu_lua_IsFlanking);
  885. lua_register(state, "AddSpellTimer", EQ2Emu_lua_AddSpellTimer);
  886. lua_register(state, "GetItemCount", EQ2Emu_lua_GetItemCount);
  887. lua_register(state, "SetItemCount", EQ2Emu_lua_SetItemCount);
  888. lua_register(state, "Resurrect", EQ2Emu_lua_Resurrect);
  889. lua_register(state, "BreatheUnderwater", EQ2Emu_lua_BreatheUnderwater);
  890. lua_register(state, "BlurVision", EQ2Emu_lua_BlurVision);
  891. lua_register(state, "SetVision", EQ2Emu_lua_SetVision);
  892. lua_register(state, "GetItemSkillReq", EQ2Emu_lua_GetItemSkillReq);
  893. lua_register(state, "SetSpeedMultiplier", EQ2Emu_lua_SetSpeedMultiplier);
  894. lua_register(state, "SetIllusion", EQ2Emu_lua_SetIllusion);
  895. lua_register(state, "ResetIllusion", EQ2Emu_lua_ResetIllusion);
  896. lua_register(state, "AddThreatTransfer", EQ2Emu_lua_AddThreatTransfer);
  897. lua_register(state, "RemoveThreatTransfer", EQ2Emu_lua_RemoveThreatTransfer);
  898. lua_register(state, "CureByType", EQ2Emu_lua_CureByType);
  899. lua_register(state, "CureByControlEffect", EQ2Emu_lua_CureByControlEffect);
  900. lua_register(state, "AddSpawnSpellBonus", EQ2Emu_lua_AddSpawnSpellBonus);
  901. lua_register(state, "CancelSpell", EQ2Emu_lua_CancelSpell);
  902. lua_register(state, "RemoveStealth", EQ2Emu_lua_RemoveStealth);
  903. lua_register(state, "RemoveInvis", EQ2Emu_lua_RemoveInvis);
  904. lua_register(state, "StartHeroicOpportunity", EQ2Emu_lua_StartHeroicOpportunity);
  905. lua_register(state, "CopySpawnAppearance", EQ2Emu_lua_CopySpawnAppearance);
  906. lua_register(state, "SetSpellTriggerCount", EQ2Emu_lua_SetSpellTriggerCount);
  907. lua_register(state, "GetSpellTriggerCount", EQ2Emu_lua_GetSpellTriggerCount);
  908. lua_register(state, "RemoveTriggerFromSpell", EQ2Emu_lua_RemoveTriggerFromSpell);
  909. lua_register(state, "AddImmunitySpell", EQ2Emu_lua_AddImmunitySpell);
  910. lua_register(state, "RemoveImmunitySpell", EQ2Emu_lua_RemoveImmunitySpell);
  911. lua_register(state, "SetSpellSnareValue", EQ2Emu_lua_SetSpellSnareValue);
  912. lua_register(state, "CheckRaceType", EQ2Emu_lua_CheckRaceType);
  913. lua_register(state, "GetRaceType", EQ2Emu_lua_GetRaceType);
  914. lua_register(state, "GetRaceBaseType", EQ2Emu_lua_GetRaceBaseType);
  915. lua_register(state, "GetQuestFlags", EQ2Emu_lua_GetQuestFlags);
  916. lua_register(state, "SetQuestFlags", EQ2Emu_lua_SetQuestFlags);
  917. lua_register(state, "SetQuestTimer", EQ2Emu_lua_SetQuestTimer);
  918. lua_register(state, "RemoveQuestStep", EQ2Emu_lua_RemoveQuestStep);
  919. lua_register(state, "ResetQuestStep", EQ2Emu_lua_ResetQuestStep);
  920. lua_register(state, "SetQuestTimerComplete", EQ2Emu_lua_SetQuestTimerComplete);
  921. lua_register(state, "AddQuestStepFailureAction", EQ2Emu_lua_AddQuestStepFailureAction);
  922. lua_register(state, "SetStepFailed", EQ2Emu_lua_SetStepFailed);
  923. lua_register(state, "GetQuestCompleteCount", EQ2Emu_lua_GetQuestCompleteCount);
  924. lua_register(state, "SetServerVariable", EQ2Emu_lua_SetServerVariable);
  925. lua_register(state, "GetServerVariable", EQ2Emu_lua_GetServerVariable);
  926. lua_register(state, "HasLanguage", EQ2Emu_lua_HasLanguage);
  927. lua_register(state, "AddLanguage", EQ2Emu_lua_AddLanguage);
  928. lua_register(state, "IsNight", EQ2Emu_lua_IsNight);
  929. lua_register(state, "AddMultiFloorLift", EQ2Emu_lua_AddMultiFloorLift);
  930. lua_register(state, "StartAutoMount", EQ2Emu_lua_StartAutoMount);
  931. lua_register(state, "EndAutoMount", EQ2Emu_lua_EndAutoMount);
  932. lua_register(state, "IsOnAutoMount", EQ2Emu_lua_IsOnAutoMount);
  933. lua_register(state, "SetPlayerHistory", EQ2Emu_lua_SetPlayerHistory);
  934. lua_register(state, "GetPlayerHistory", EQ2Emu_lua_GetPlayerHistory);
  935. lua_register(state, "SetGridID", EQ2Emu_lua_SetGridID);
  936. lua_register(state, "GetQuestStepProgress", EQ2Emu_lua_GetQuestStepProgress);
  937. lua_register(state, "SetPlayerLevel", EQ2Emu_lua_SetPlayerLevel);
  938. lua_register(state, "AddCoin", EQ2Emu_lua_AddCoin);
  939. lua_register(state, "RemoveCoin", EQ2Emu_lua_RemoveCoin);
  940. lua_register(state, "GetPlayersInZone", EQ2Emu_lua_GetPlayersInZone);
  941. lua_register(state, "SpawnGroupByID", EQ2Emu_lua_SpawnGroupByID);
  942. lua_register(state, "SetSpawnAnimation", EQ2Emu_lua_SetSpawnAnimation);
  943. lua_register(state, "GetClientVersion", EQ2Emu_lua_GetClientVersion);
  944. lua_register(state, "GetItemID", EQ2Emu_lua_GetItemID);
  945. lua_register(state, "IsEntity", EQ2Emu_lua_IsEntity);
  946. lua_register(state, "GetOrigX", EQ2Emu_lua_GetOrigX);
  947. lua_register(state, "GetOrigY", EQ2Emu_lua_GetOrigY);
  948. lua_register(state, "GetOrigZ", EQ2Emu_lua_GetOrigZ);
  949. lua_register(state, "GetPCTOfHP", EQ2Emu_lua_GetPCTOfHP);
  950. lua_register(state, "GetPCTOfPower", EQ2Emu_lua_GetPCTOfPower);
  951. lua_register(state, "GetBoundZoneID", EQ2Emu_lua_GetBoundZoneID);
  952. lua_register(state, "Evac", EQ2Emu_lua_Evac);
  953. lua_register(state, "GetSpellTier", EQ2Emu_lua_GetSpellTier);
  954. lua_register(state, "GetSpellID", EQ2Emu_lua_GetSpellID);
  955. lua_register(state, "StartTransmute", EQ2Emu_lua_StartTransmute);
  956. lua_register(state, "CompleteTransmute", EQ2Emu_lua_CompleteTransmute);
  957. lua_register(state, "ProcHate", EQ2Emu_lua_ProcHate);
  958. lua_register(state, "GetRandomSpawnByID", EQ2Emu_lua_GetRandomSpawnByID);
  959. lua_register(state, "AddLootToObject", EQ2Emu_lua_AddLootToObject);
  960. lua_register(state, "ShowLootWindow", EQ2Emu_lua_ShowLootWindow);
  961. lua_register(state, "AddPrimaryEntityCommandAllSpawns", EQ2Emu_lua_AddPrimaryEntityCommandAllSpawns);
  962. lua_register(state, "InstructionWindow", EQ2Emu_lua_InstructionWindow);
  963. lua_register(state, "ShowWindow", EQ2Emu_lua_ShowWindow);
  964. lua_register(state, "FlashWindow", EQ2Emu_lua_FlashWindow);
  965. lua_register(state, "EnableGameEvent", EQ2Emu_lua_EnableGameEvent);
  966. lua_register(state, "DisplayText", EQ2Emu_lua_DisplayText);
  967. lua_register(state, "CheckLOS", EQ2Emu_lua_CheckLOS);
  968. lua_register(state, "CheckLOSByCoordinates", EQ2Emu_lua_CheckLOSByCoordinates);
  969. lua_register(state, "SetZoneExpansionFlag", EQ2Emu_lua_SetZoneExpansionFlag);
  970. lua_register(state, "GetZoneExpansionFlag", EQ2Emu_lua_GetZoneExpansionFlag);
  971. lua_register(state, "SetZoneHolidayFlag", EQ2Emu_lua_SetZoneHolidayFlag);
  972. lua_register(state, "GetZoneHolidayFlag", EQ2Emu_lua_GetZoneHolidayFlag);
  973. lua_register(state, "AddSpawnProximity", EQ2Emu_lua_AddSpawnProximity);
  974. lua_register(state, "CanSeeInvis", EQ2Emu_lua_CanSeeInvis);
  975. lua_register(state, "SetSeeInvis", EQ2Emu_lua_SetSeeInvis);
  976. lua_register(state, "SetSeeHide", EQ2Emu_lua_SetSeeHide);
  977. lua_register(state, "SetAccessToEntityCommand", EQ2Emu_lua_SetAccessToEntityCommand);
  978. lua_register(state, "RemovePrimaryEntityCommand", EQ2Emu_lua_RemovePrimaryEntityCommand);
  979. lua_register(state, "SendUpdateDefaultCommand", EQ2Emu_lua_SendUpdateDefaultCommand);
  980. lua_register(state, "SendTransporters", EQ2Emu_lua_SendTransporters);
  981. lua_register(state, "SetTemporaryTransportID", EQ2Emu_lua_SetTemporaryTransportID);
  982. lua_register(state, "GetTemporaryTransportID", EQ2Emu_lua_GetTemporaryTransportID);
  983. }
  984. void LuaInterface::LogError(const char* error, ...) {
  985. va_list argptr;
  986. char buffer[4096];
  987. va_start(argptr, error);
  988. vsnprintf(buffer, sizeof(buffer), error, argptr);
  989. va_end(argptr);
  990. SimpleLogError(buffer);
  991. }
  992. void LuaInterface::SimpleLogError(const char* error) {
  993. ProcessErrorMessage(error);
  994. LogWrite(LUA__ERROR, 0, "LUA", "%s", error);
  995. }
  996. void LuaInterface::ResetFunctionStack(lua_State* state) {
  997. lua_settop(state, 0);
  998. }
  999. void LuaInterface::AddUserDataPtr(LUAUserData* data) {
  1000. MLUAUserData.lock();
  1001. user_data[data] = Timer::GetCurrentTime2() + 300000; //allow a function to use this pointer for 5 minutes
  1002. MLUAUserData.unlock();
  1003. }
  1004. void LuaInterface::DeletePendingSpells(bool all) {
  1005. MSpellDelete.lock();
  1006. if (spells_pending_delete.size() > 0) {
  1007. int32 time = Timer::GetCurrentTime2();
  1008. map<LuaSpell*, int32>::iterator itr;
  1009. vector<LuaSpell*> tmp_deletes;
  1010. vector<LuaSpell*>::iterator del_itr;
  1011. for (itr = spells_pending_delete.begin(); itr != spells_pending_delete.end(); itr++) {
  1012. if (all || time >= itr->second)
  1013. tmp_deletes.push_back(itr->first);
  1014. }
  1015. LuaSpell* spell = 0;
  1016. for (del_itr = tmp_deletes.begin(); del_itr != tmp_deletes.end(); del_itr++) {
  1017. spell = *del_itr;
  1018. spells_pending_delete.erase(spell);
  1019. safe_delete(spell);
  1020. }
  1021. }
  1022. MSpellDelete.unlock();
  1023. }
  1024. void LuaInterface::DeletePendingSpell(LuaSpell* spell) {
  1025. MSpellDelete.lock();
  1026. if (spells_pending_delete.size() > 0) {
  1027. map<LuaSpell*, int32>::iterator itr = spells_pending_delete.find(spell);
  1028. if (itr != spells_pending_delete.end())
  1029. spells_pending_delete.erase(itr);
  1030. }
  1031. MSpellDelete.unlock();
  1032. }
  1033. void LuaInterface::DeleteUserDataPtrs(bool all) {
  1034. MLUAUserData.lock();
  1035. if(user_data.size() > 0){
  1036. map<LUAUserData*, int32>::iterator itr;
  1037. int32 time = Timer::GetCurrentTime2();
  1038. vector<LUAUserData*> tmp_deletes;
  1039. vector<LUAUserData*>::iterator del_itr;
  1040. for(itr = user_data.begin(); itr != user_data.end(); itr++){
  1041. if(all || time >= itr->second)
  1042. tmp_deletes.push_back(itr->first);
  1043. }
  1044. LUAUserData* data = 0;
  1045. for(del_itr = tmp_deletes.begin(); del_itr != tmp_deletes.end(); del_itr++){
  1046. data = *del_itr;
  1047. user_data.erase(data);
  1048. safe_delete(data);
  1049. }
  1050. }
  1051. MLUAUserData.unlock();
  1052. }
  1053. Spawn* LuaInterface::GetSpawn(lua_State* state, int8 arg_num) {
  1054. Spawn* ret = 0;
  1055. if (lua_islightuserdata(state, arg_num)){
  1056. LUAUserData* data = (LUAUserData*)lua_touserdata(state, arg_num);
  1057. if(!data || !data->IsCorrectlyInitialized()){
  1058. LogError("%s: GetSpawn error while processing %s", GetScriptName(state), lua_tostring(state, -1));
  1059. }
  1060. else if(!data->IsSpawn()){
  1061. lua_Debug ar;
  1062. lua_getstack (state, 1, &ar);
  1063. lua_getinfo(state, "Sln", &ar);
  1064. LogError("%s: Invalid data type used for GetSpawn in %s (line %d)", GetScriptName(state), ar.source, ar.currentline);
  1065. }
  1066. else
  1067. ret = data->spawn;
  1068. }
  1069. return ret;
  1070. }
  1071. vector<ConversationOption>* LuaInterface::GetConversation(lua_State* state, int8 arg_num) {
  1072. vector<ConversationOption>* ret = 0;
  1073. if(lua_islightuserdata(state, arg_num)){
  1074. LUAUserData* data = (LUAUserData*)lua_touserdata(state, arg_num);
  1075. if(!data || !data->IsCorrectlyInitialized()){
  1076. LogError("%s: GetConversation error while processing %s", GetScriptName(state), lua_tostring(state, -1));
  1077. }
  1078. else if(!data->IsConversationOption()){
  1079. lua_Debug ar;
  1080. lua_getstack (state, 1, &ar);
  1081. lua_getinfo(state, "Sln", &ar);
  1082. LogError("%s: Invalid data type used for GetConversation in %s (line %d)", GetScriptName(state), ar.source, ar.currentline);
  1083. }
  1084. else
  1085. ret = data->conversation_options;
  1086. }
  1087. return ret;
  1088. }
  1089. vector<OptionWindowOption>* LuaInterface::GetOptionWindow(lua_State* state, int8 arg_num) {
  1090. vector<OptionWindowOption>* ret = 0;
  1091. if(lua_islightuserdata(state, arg_num)){
  1092. LUAUserData* data = (LUAUserData*)lua_touserdata(state, arg_num);
  1093. if(!data || !data->IsCorrectlyInitialized()){
  1094. LogError("%s: GetOptionWindow error while processing %s", GetScriptName(state), lua_tostring(state, -1));
  1095. }
  1096. else if(!data->IsOptionWindow()){
  1097. lua_Debug ar;
  1098. lua_getstack (state, 1, &ar);
  1099. lua_getinfo(state, "Sln", &ar);
  1100. LogError("%s: Invalid data type used for GetOptionWindow in %s (line %d)", GetScriptName(state), ar.source, ar.currentline);
  1101. }
  1102. else
  1103. ret = data->option_window_option;
  1104. }
  1105. return ret;
  1106. }
  1107. Quest* LuaInterface::GetQuest(lua_State* state, int8 arg_num) {
  1108. Quest* ret = 0;
  1109. if(lua_islightuserdata(state, arg_num)){
  1110. LUAUserData* data = (LUAUserData*)lua_touserdata(state, arg_num);
  1111. if(!data || !data->IsCorrectlyInitialized()){
  1112. LogError("%s: GetQuest error while processing %s", GetScriptName(state), lua_tostring(state, 0));
  1113. }
  1114. else if(!data->IsQuest()){
  1115. lua_Debug ar;
  1116. lua_getstack (state, 1, &ar);
  1117. lua_getinfo(state, "Sln", &ar);
  1118. LogError("%s: Invalid data type used for GetQuest in %s (line %d)", GetScriptName(state), ar.source, ar.currentline);
  1119. }
  1120. else
  1121. ret = data->quest;
  1122. }
  1123. return ret;
  1124. }
  1125. Item* LuaInterface::GetItem(lua_State* state, int8 arg_num) {
  1126. Item* ret = 0;
  1127. if(lua_islightuserdata(state, arg_num)){
  1128. LUAUserData* data = (LUAUserData*)lua_touserdata(state, arg_num);
  1129. if(!data || !data->IsCorrectlyInitialized()){
  1130. LogError("%s: GetItem error while processing %s", GetScriptName(state), lua_tostring(state, 0));
  1131. }
  1132. else if(!data->IsItem()){
  1133. lua_Debug ar;
  1134. lua_getstack (state, 1, &ar);
  1135. lua_getinfo(state, "Sln", &ar);
  1136. LogError("%s: Invalid data type used for GetItem in %s (line %d)", GetScriptName(state), ar.source, ar.currentline);
  1137. }
  1138. else
  1139. ret = data->item;
  1140. }
  1141. return ret;
  1142. }
  1143. Skill* LuaInterface::GetSkill(lua_State* state, int8 arg_num) {
  1144. Skill* ret = 0;
  1145. if (lua_islightuserdata(state, arg_num)) {
  1146. LUAUserData* data = (LUAUserData*)lua_touserdata(state, arg_num);
  1147. if(!data || !data->IsCorrectlyInitialized()){
  1148. LogError("%s: GetSkill error while processing %s", GetScriptName(state), lua_tostring(state, 0));
  1149. }
  1150. else if(!data->IsSkill()){
  1151. lua_Debug ar;
  1152. lua_getstack (state, 1, &ar);
  1153. lua_getinfo(state, "Sln", &ar);
  1154. LogError("%s: Invalid data type used for GetSkill in %s (line %d)", GetScriptName(state), ar.source, ar.currentline);
  1155. }
  1156. else
  1157. ret = data->skill;
  1158. }
  1159. return ret;
  1160. }
  1161. ZoneServer* LuaInterface::GetZone(lua_State* state, int8 arg_num) {
  1162. ZoneServer* ret = 0;
  1163. if(lua_islightuserdata(state, arg_num)){
  1164. LUAUserData* data = (LUAUserData*)lua_touserdata(state, arg_num);
  1165. if(!data || !data->IsCorrectlyInitialized()){
  1166. LogError("%s: GetZone error while processing %s", GetScriptName(state), lua_tostring(state, -1));
  1167. }
  1168. else if(!data->IsZone()){
  1169. lua_Debug ar;
  1170. lua_getstack (state, 1, &ar);
  1171. lua_getinfo(state, "Sln", &ar);
  1172. LogError("%s: Invalid data type used for GetZone in %s (line %d)", GetScriptName(state), ar.source, ar.currentline);
  1173. }
  1174. else
  1175. ret = data->zone;
  1176. }
  1177. return ret;
  1178. }
  1179. sint32 LuaInterface::GetSInt32Value(lua_State* state, int8 arg_num) {
  1180. sint32 val = 0;
  1181. if(lua_isnumber(state, arg_num)){
  1182. val = lua_tointeger(state, arg_num);
  1183. }
  1184. return val;
  1185. }
  1186. int32 LuaInterface::GetInt32Value(lua_State* state, int8 arg_num) {
  1187. int32 val = 0;
  1188. if(lua_isnumber(state, arg_num)){
  1189. val = (int32)lua_tonumber(state, arg_num);
  1190. }
  1191. return val;
  1192. }
  1193. int16 LuaInterface::GetInt16Value(lua_State* state, int8 arg_num) {
  1194. int16 val = 0;
  1195. if(lua_isnumber(state, arg_num)){
  1196. val = lua_tointeger(state, arg_num);
  1197. }
  1198. return val;
  1199. }
  1200. int8 LuaInterface::GetInt8Value(lua_State* state, int8 arg_num) {
  1201. int8 val = 0;
  1202. if(lua_isnumber(state, arg_num)){
  1203. val = lua_tointeger(state, arg_num);
  1204. }
  1205. return val;
  1206. }
  1207. float LuaInterface::GetFloatValue(lua_State* state, int8 arg_num) {
  1208. float val = 0;
  1209. if(lua_isnumber(state, arg_num))
  1210. val = (float)lua_tonumber(state, arg_num);
  1211. return val;
  1212. }
  1213. string LuaInterface::GetStringValue(lua_State* state, int8 arg_num) {
  1214. string val;
  1215. if(lua_isstring(state, arg_num)){
  1216. size_t size = 0;
  1217. const char* str = lua_tolstring(state, arg_num, &size);
  1218. if(str)
  1219. val = string(str);
  1220. }
  1221. return val;
  1222. }
  1223. bool LuaInterface::GetBooleanValue(lua_State* state, int8 arg_num) {
  1224. return lua_toboolean(state, arg_num) == 1;
  1225. }
  1226. void LuaInterface::SetStringValue(lua_State* state, const char* value) {
  1227. lua_pushstring(state, value);
  1228. }
  1229. void LuaInterface::SetBooleanValue(lua_State* state, bool value) {
  1230. lua_pushboolean(state, value);
  1231. }
  1232. void LuaInterface::SetFloatValue(lua_State* state, float value) {
  1233. lua_pushnumber(state, value);
  1234. }
  1235. void LuaInterface::SetInt32Value(lua_State* state, int32 value) {
  1236. lua_pushinteger(state, value);
  1237. }
  1238. void LuaInterface::SetSInt32Value(lua_State* state, sint32 value) {
  1239. lua_pushinteger(state, value);
  1240. }
  1241. void LuaInterface::SetSpawnValue(lua_State* state, Spawn* spawn) {
  1242. LUASpawnWrapper* spawn_wrapper = new LUASpawnWrapper();
  1243. spawn_wrapper->spawn = spawn;
  1244. AddUserDataPtr(spawn_wrapper);
  1245. lua_pushlightuserdata(state, spawn_wrapper);
  1246. }
  1247. void LuaInterface::SetConversationValue(lua_State* state, vector<ConversationOption>* conversation) {
  1248. LUAConversationOptionWrapper* conv_wrapper = new LUAConversationOptionWrapper();
  1249. conv_wrapper->conversation_options = conversation;
  1250. AddUserDataPtr(conv_wrapper);
  1251. lua_pushlightuserdata(state, conv_wrapper);
  1252. }
  1253. void LuaInterface::SetOptionWindowValue(lua_State* state, vector<OptionWindowOption>* optionWindow) {
  1254. LUAOptionWindowWrapper* option_wrapper = new LUAOptionWindowWrapper();
  1255. option_wrapper->option_window_option = optionWindow;
  1256. AddUserDataPtr(option_wrapper);
  1257. lua_pushlightuserdata(state, option_wrapper);
  1258. }
  1259. void LuaInterface::SetItemValue(lua_State* state, Item* item) {
  1260. LUAItemWrapper* item_wrapper = new LUAItemWrapper();
  1261. item_wrapper->item = item;
  1262. AddUserDataPtr(item_wrapper);
  1263. lua_pushlightuserdata(state, item_wrapper);
  1264. }
  1265. void LuaInterface::SetSkillValue(lua_State* state, Skill* skill) {
  1266. LUASkillWrapper* skill_wrapper = new LUASkillWrapper();
  1267. skill_wrapper->skill = skill;
  1268. AddUserDataPtr(skill_wrapper);
  1269. lua_pushlightuserdata(state, skill_wrapper);
  1270. }
  1271. void LuaInterface::SetQuestValue(lua_State* state, Quest* quest) {
  1272. LUAQuestWrapper* quest_wrapper = new LUAQuestWrapper();
  1273. quest_wrapper->quest = quest;
  1274. AddUserDataPtr(quest_wrapper);
  1275. lua_pushlightuserdata(state, quest_wrapper);
  1276. }
  1277. void LuaInterface::SetZoneValue(lua_State* state, ZoneServer* zone) {
  1278. LUAZoneWrapper* zone_wrapper = new LUAZoneWrapper();
  1279. zone_wrapper->zone = zone;
  1280. AddUserDataPtr(zone_wrapper);
  1281. lua_pushlightuserdata(state, zone_wrapper);
  1282. }
  1283. LuaSpell* LuaInterface::GetSpell(const char* name) {
  1284. string lua_script = string(name);
  1285. if (lua_script.find(".lua") == string::npos)
  1286. lua_script.append(".lua");
  1287. if(spells.count(lua_script) > 0)
  1288. {
  1289. LogWrite(LUA__DEBUG, 0, "LUA", "Found LUA Spell Script: '%s'", lua_script.c_str());
  1290. LuaSpell* spell = spells[lua_script];
  1291. LuaSpell* new_spell = new LuaSpell;
  1292. new_spell->state = spell->state;
  1293. new_spell->file_name = spell->file_name;
  1294. new_spell->timer = spell->timer;
  1295. new_spell->timer.Disable();
  1296. new_spell->resisted = false;
  1297. new_spell->interrupted = false;
  1298. new_spell->crit = false;
  1299. new_spell->last_spellattack_hit = false;
  1300. new_spell->MSpellTargets.SetName("LuaSpell.MSpellTargets");
  1301. new_spell->cancel_after_all_triggers = false;
  1302. new_spell->num_triggers = 0;
  1303. new_spell->had_triggers = false;
  1304. new_spell->had_dmg_remaining = false;
  1305. new_spell->slot_pos = 0;
  1306. new_spell->damage_remaining = 0;
  1307. new_spell->effect_bitmask = 0;
  1308. new_spell->caster = 0;
  1309. new_spell->initial_target = 0;
  1310. new_spell->spell = 0;
  1311. return new_spell;
  1312. }
  1313. else{
  1314. LogWrite(LUA__ERROR, 0, "LUA", "Error LUA Spell Script: '%s'", name);
  1315. return 0;
  1316. }
  1317. }
  1318. Mutex* LuaInterface::GetItemScriptMutex(const char* name) {
  1319. Mutex* mutex = 0;
  1320. if(item_scripts_mutex.count(name) > 0)
  1321. mutex = item_scripts_mutex[name];
  1322. if(!mutex){
  1323. mutex = new Mutex();
  1324. item_scripts_mutex[name] = mutex;
  1325. }
  1326. return mutex;
  1327. }
  1328. Mutex* LuaInterface::GetSpawnScriptMutex(const char* name) {
  1329. Mutex* mutex = 0;
  1330. if(spawn_scripts_mutex.count(string(name)) > 0)
  1331. mutex = spawn_scripts_mutex[name];
  1332. if(!mutex){
  1333. mutex = new Mutex();
  1334. spawn_scripts_mutex[name] = mutex;
  1335. }
  1336. return mutex;
  1337. }
  1338. Mutex* LuaInterface::GetZoneScriptMutex(const char* name) {
  1339. Mutex* mutex = 0;
  1340. if(zone_scripts_mutex.count(name) > 0)
  1341. mutex = zone_scripts_mutex[name];
  1342. if(!mutex){
  1343. mutex = new Mutex();
  1344. zone_scripts_mutex[name] = mutex;
  1345. }
  1346. return mutex;
  1347. }
  1348. void LuaInterface::UseItemScript(const char* name, lua_State* state, bool val) {
  1349. MItemScripts.writelock(__FUNCTION__, __LINE__);
  1350. item_scripts[name][state] = val;
  1351. item_inverse_scripts[state] = name;
  1352. MItemScripts.releasewritelock(__FUNCTION__, __LINE__);
  1353. }
  1354. void LuaInterface::UseSpawnScript(const char* name, lua_State* state, bool val) {
  1355. MSpawnScripts.writelock(__FUNCTION__, __LINE__);
  1356. spawn_scripts[name][state] = val;
  1357. spawn_inverse_scripts[state] = name;
  1358. MSpawnScripts.releasewritelock(__FUNCTION__, __LINE__);
  1359. }
  1360. void LuaInterface::UseZoneScript(const char* name, lua_State* state, bool val) {
  1361. MZoneScripts.writelock(__FUNCTION__, __LINE__);
  1362. zone_scripts[name][state] = val;
  1363. zone_inverse_scripts[state] = name;
  1364. MZoneScripts.releasewritelock(__FUNCTION__, __LINE__);
  1365. }
  1366. lua_State* LuaInterface::GetItemScript(const char* name, bool create_new, bool use) {
  1367. map<string, map<lua_State*, bool> >::iterator itr;
  1368. map<lua_State*, bool>::iterator item_script_itr;
  1369. lua_State* ret = 0;
  1370. Mutex* mutex = 0;
  1371. itr = item_scripts.find(name);
  1372. if(itr != item_scripts.end()) {
  1373. mutex = GetItemScriptMutex(name);
  1374. mutex->readlock(__FUNCTION__, __LINE__);
  1375. for(item_script_itr = itr->second.begin(); item_script_itr != itr->second.end(); item_script_itr++){
  1376. if(!item_script_itr->second){ //not in use
  1377. ret = item_script_itr->first;
  1378. if (use)
  1379. {
  1380. item_script_itr->second = true;
  1381. break; // don't keep iterating, we already have our result
  1382. }
  1383. }
  1384. }
  1385. mutex->releasereadlock(__FUNCTION__, __LINE__);
  1386. }
  1387. if(!ret && create_new){
  1388. if(name && LoadItemScript(name))
  1389. ret = GetItemScript(name, create_new, use);
  1390. else{
  1391. LogError("Error LUA Item Script '%s'", name);
  1392. return 0;
  1393. }
  1394. }
  1395. return ret;
  1396. }
  1397. lua_State* LuaInterface::GetSpawnScript(const char* name, bool create_new, bool use) {
  1398. if (spawn_scripts_reloading)
  1399. return 0;
  1400. map<string, map<lua_State*, bool> >::iterator itr;
  1401. map<lua_State*, bool>::iterator spawn_script_itr;
  1402. lua_State* ret = 0;
  1403. Mutex* mutex = 0;
  1404. itr = spawn_scripts.find(name);
  1405. if(itr != spawn_scripts.end()) {
  1406. mutex = GetSpawnScriptMutex(name);
  1407. mutex->readlock(__FUNCTION__, __LINE__);
  1408. for(spawn_script_itr = itr->second.begin(); spawn_script_itr != itr->second.end(); spawn_script_itr++){
  1409. if(!spawn_script_itr->second){ //not in use
  1410. ret = spawn_script_itr->first;
  1411. if (use)
  1412. {
  1413. spawn_script_itr->second = true;
  1414. break; // don't keep iterating, we already have our result
  1415. }
  1416. }
  1417. }
  1418. mutex->releasereadlock(__FUNCTION__, __LINE__);
  1419. }
  1420. if(!ret && create_new){
  1421. if(name && LoadSpawnScript(name))
  1422. ret = GetSpawnScript(name, create_new, use);
  1423. else{
  1424. LogError("Error LUA Spawn Script '%s'", name);
  1425. return 0;
  1426. }
  1427. }
  1428. return ret;
  1429. }
  1430. lua_State* LuaInterface::GetZoneScript(const char* name, bool create_new, bool use) {
  1431. map<string, map<lua_State*, bool> >::iterator itr;
  1432. map<lua_State*, bool>::iterator zone_script_itr;
  1433. lua_State* ret = 0;
  1434. Mutex* mutex = 0;
  1435. itr = zone_scripts.find(name);
  1436. if(itr != zone_scripts.end()) {
  1437. mutex = GetZoneScriptMutex(name);
  1438. mutex->readlock(__FUNCTION__, __LINE__);
  1439. for(zone_script_itr = itr->second.begin(); zone_script_itr != itr->second.end(); zone_script_itr++){
  1440. if(!zone_script_itr->second){ //not in use
  1441. ret = zone_script_itr->first;
  1442. if (use)
  1443. {
  1444. zone_script_itr->second = true;
  1445. break; // don't keep iterating, we already have our result
  1446. }
  1447. }
  1448. }
  1449. mutex->releasereadlock(__FUNCTION__, __LINE__);
  1450. }
  1451. if(!ret && create_new){
  1452. if(name && LoadZoneScript(name))
  1453. ret = GetZoneScript(name);
  1454. else{
  1455. LogError("Error LUA Zone Script '%s'", name);
  1456. return 0;
  1457. }
  1458. }
  1459. return ret;
  1460. }
  1461. bool LuaInterface::RunItemScript(string script_name, const char* function_name, Item* item, Spawn* spawn) {
  1462. if(!item)
  1463. return false;
  1464. lua_State* state = GetItemScript(script_name.c_str(), true, true);
  1465. if(state){
  1466. Mutex* mutex = GetItemScriptMutex(script_name.c_str());
  1467. if(mutex)
  1468. mutex->readlock(__FUNCTION__, __LINE__);
  1469. else{
  1470. LogError("Error getting lock for '%s'", script_name.c_str());
  1471. UseItemScript(script_name.c_str(), state, false);
  1472. return false;
  1473. }
  1474. lua_getglobal(state, function_name);
  1475. lua_getglobal(state, function_name);
  1476. if (!lua_isfunction(state, lua_gettop(state))){
  1477. lua_pop(state, 1);
  1478. mutex->releasereadlock(__FUNCTION__);
  1479. UseItemScript(script_name.c_str(), state, false);
  1480. return false;
  1481. }
  1482. SetItemValue(state, item);
  1483. int8 num_parms = 1;
  1484. if(spawn){
  1485. SetSpawnValue(state, spawn);
  1486. num_parms++;
  1487. }
  1488. if(!CallItemScript(state, num_parms)){
  1489. if(mutex)
  1490. mutex->releasereadlock(__FUNCTION__, __LINE__);
  1491. UseItemScript(script_name.c_str(), state, false);
  1492. return false;
  1493. }
  1494. if(mutex)
  1495. mutex->releasereadlock(__FUNCTION__, __LINE__);
  1496. UseItemScript(script_name.c_str(), state, false);
  1497. return true;
  1498. }
  1499. else
  1500. return false;
  1501. }
  1502. bool LuaInterface::RunSpawnScript(string script_name, const char* function_name, Spawn* npc, Spawn* spawn, const char* message) {
  1503. if(!npc || spawn_scripts_reloading)
  1504. return false;
  1505. lua_State* state = GetSpawnScript(script_name.c_str(), true, true);
  1506. if(state){
  1507. Mutex* mutex = GetSpawnScriptMutex(script_name.c_str());
  1508. if(mutex)
  1509. mutex->readlock(__FUNCTION__, __LINE__);
  1510. else{
  1511. LogError("Error getting lock for '%s'", script_name.c_str());
  1512. UseSpawnScript(script_name.c_str(), state, false);
  1513. return false;
  1514. }
  1515. lua_getglobal(state, function_name);
  1516. if (!lua_isfunction(state, lua_gettop(state))){
  1517. lua_pop(state, 1);
  1518. mutex->releasereadlock(__FUNCTION__);
  1519. UseSpawnScript(script_name.c_str(), state, false);
  1520. return false;
  1521. }
  1522. SetSpawnValue(state, npc);
  1523. int8 num_parms = 1;
  1524. if(spawn){
  1525. SetSpawnValue(state, spawn);
  1526. num_parms++;
  1527. }
  1528. if(message){
  1529. SetStringValue(state, message);
  1530. num_parms++;
  1531. }
  1532. if(!CallSpawnScript(state, num_parms)){
  1533. if(mutex)
  1534. mutex->releasereadlock(__FUNCTION__, __LINE__);
  1535. UseSpawnScript(script_name.c_str(), state, false);
  1536. return false;
  1537. }
  1538. if(mutex)
  1539. mutex->releasereadlock(__FUNCTION__, __LINE__);
  1540. UseSpawnScript(script_name.c_str(), state, false);
  1541. return true;
  1542. }
  1543. else
  1544. return false;
  1545. }
  1546. bool LuaInterface::RunZoneScript(string script_name, const char* function_name, ZoneServer* zone, Spawn* spawn, int32 grid_id, const char* signal) {
  1547. if (!zone)
  1548. return false;
  1549. lua_State* state = GetZoneScript(script_name.c_str(), true, true);
  1550. if (state) {
  1551. Mutex* mutex = GetZoneScriptMutex(script_name.c_str());
  1552. if (mutex)
  1553. mutex->readlock(__FUNCTION__, __LINE__);
  1554. else {
  1555. LogError("Error getting lock for '%s'", script_name.c_str());
  1556. UseZoneScript(script_name.c_str(), state, false);
  1557. return false;
  1558. }
  1559. lua_getglobal(state, function_name);
  1560. if (!lua_isfunction(state, lua_gettop(state))) {
  1561. lua_pop(state, 1);
  1562. mutex->releasereadlock(__FUNCTION__);
  1563. UseZoneScript(script_name.c_str(), state, false);
  1564. return false;
  1565. }
  1566. SetZoneValue(state, zone);
  1567. int8 num_params = 1;
  1568. if (spawn) {
  1569. SetSpawnValue(state, spawn);
  1570. num_params++;
  1571. }
  1572. if (grid_id > 0) {
  1573. SetInt32Value(state, grid_id);
  1574. num_params++;
  1575. }
  1576. if (signal) {
  1577. SetStringValue(state, signal);
  1578. num_params++;
  1579. }
  1580. if (!CallZoneScript(state, num_params)) {
  1581. if (mutex)
  1582. mutex->releasereadlock(__FUNCTION__, __LINE__);
  1583. UseZoneScript(script_name.c_str(), state, false);
  1584. return false;
  1585. }
  1586. if (mutex)
  1587. mutex->releasereadlock(__FUNCTION__, __LINE__);
  1588. UseZoneScript(script_name.c_str(), state, false);
  1589. return true;
  1590. }
  1591. else
  1592. return false;
  1593. }
  1594. void LuaInterface::AddPendingSpellDelete(LuaSpell* spell) {
  1595. MSpellDelete.lock();
  1596. if ( spells_pending_delete.count(spell) == 0 )
  1597. spells_pending_delete[spell] = Timer::GetCurrentTime2() + 10000;
  1598. MSpellDelete.unlock();
  1599. }
  1600. LUAUserData::LUAUserData(){
  1601. correctly_initialized = false;
  1602. quest = 0;
  1603. conversation_options = 0;
  1604. spawn = 0;
  1605. zone = 0;
  1606. skill = 0;
  1607. option_window_option = 0;
  1608. item = 0;
  1609. }
  1610. bool LUAUserData::IsCorrectlyInitialized(){
  1611. return correctly_initialized;
  1612. }
  1613. bool LUAUserData::IsConversationOption(){
  1614. return false;
  1615. }
  1616. bool LUAUserData::IsOptionWindow() {
  1617. return false;
  1618. }
  1619. bool LUAUserData::IsSpawn(){
  1620. return false;
  1621. }
  1622. bool LUAUserData::IsQuest(){
  1623. return false;
  1624. }
  1625. bool LUAUserData::IsZone(){
  1626. return false;
  1627. }
  1628. bool LUAUserData::IsItem(){
  1629. return false;
  1630. }
  1631. bool LUAUserData::IsSkill() {
  1632. return false;
  1633. }
  1634. LUAConversationOptionWrapper::LUAConversationOptionWrapper(){
  1635. correctly_initialized = true;
  1636. }
  1637. bool LUAConversationOptionWrapper::IsConversationOption(){
  1638. return true;
  1639. }
  1640. LUAOptionWindowWrapper::LUAOptionWindowWrapper() {
  1641. correctly_initialized = true;
  1642. }
  1643. bool LUAOptionWindowWrapper::IsOptionWindow() {
  1644. return true;
  1645. }
  1646. LUASpawnWrapper::LUASpawnWrapper(){
  1647. correctly_initialized = true;
  1648. }
  1649. bool LUASpawnWrapper::IsSpawn(){
  1650. return true;
  1651. }
  1652. LUAZoneWrapper::LUAZoneWrapper(){
  1653. correctly_initialized = true;
  1654. }
  1655. bool LUAZoneWrapper::IsZone(){
  1656. return true;
  1657. }
  1658. LUAQuestWrapper::LUAQuestWrapper(){
  1659. correctly_initialized = true;
  1660. }
  1661. bool LUAQuestWrapper::IsQuest(){
  1662. return true;
  1663. }
  1664. LUAItemWrapper::LUAItemWrapper(){
  1665. correctly_initialized = true;
  1666. }
  1667. bool LUAItemWrapper::IsItem(){
  1668. return true;
  1669. }
  1670. LUASkillWrapper::LUASkillWrapper() {
  1671. correctly_initialized = true;
  1672. }
  1673. bool LUASkillWrapper::IsSkill() {
  1674. return true;
  1675. }