LuaInterface.cpp 65 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846
  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. spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
  579. for (int8 i = 0; i < spell->targets.size(); i++) {
  580. Spawn* target = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
  581. if (!target || !target->IsEntity())
  582. continue;
  583. ((Entity*)target)->RemoveProc(0, spell);
  584. }
  585. spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
  586. if (can_delete) {
  587. AddPendingSpellDelete(spell);
  588. }
  589. if (spell->caster)
  590. {
  591. spell->caster->GetZone()->GetSpellProcess()->RemoveSpellScriptTimerBySpell(spell, false);
  592. spell->caster->RemoveProc(0, spell);
  593. spell->caster->RemoveMaintainedSpell(spell);
  594. }
  595. }
  596. void LuaInterface::RegisterFunctions(lua_State* state) {
  597. lua_register(state, "SetHP", EQ2Emu_lua_SetCurrentHP);
  598. lua_register(state, "SetMaxHP", EQ2Emu_lua_SetMaxHP);
  599. lua_register(state, "SetMaxHPBase", EQ2Emu_lua_SetMaxHPBase);
  600. lua_register(state, "SetPower", EQ2Emu_lua_SetCurrentPower);
  601. lua_register(state, "SetMaxPower", EQ2Emu_lua_SetMaxPower);
  602. lua_register(state, "SetMaxPowerBase", EQ2Emu_lua_SetMaxPowerBase);
  603. lua_register(state, "SetPosition", EQ2Emu_lua_SetPosition);
  604. lua_register(state, "SetHeading", EQ2Emu_lua_SetHeading);
  605. lua_register(state, "SetModelType", EQ2Emu_lua_SetModelType);
  606. lua_register(state, "SetAdventureClass", EQ2Emu_lua_SetAdventureClass);
  607. lua_register(state, "SetTradeskillClass", EQ2Emu_lua_SetTradeskillClass);
  608. lua_register(state, "SetMount", EQ2Emu_lua_SetMount);
  609. lua_register(state, "SetMountColor", EQ2Emu_lua_SetMountColor);
  610. lua_register(state, "GetMount", EQ2Emu_lua_GetMount);
  611. lua_register(state, "GetRace", EQ2Emu_lua_GetRace);
  612. lua_register(state, "GetRaceName", EQ2Emu_lua_GetRaceName);
  613. lua_register(state, "GetClass", EQ2Emu_lua_GetClass);
  614. lua_register(state, "GetClassName", EQ2Emu_lua_GetClassName);
  615. lua_register(state, "GetArchetypeName", EQ2Emu_lua_GetArchetypeName);
  616. lua_register(state, "SetSpeed", EQ2Emu_lua_SetSpeed);
  617. lua_register(state, "ModifyPower", EQ2Emu_lua_ModifyPower);
  618. lua_register(state, "ModifyHP", EQ2Emu_lua_ModifyHP);
  619. lua_register(state, "GetDistance", EQ2Emu_lua_GetDistance);
  620. lua_register(state, "GetHeading", EQ2Emu_lua_GetHeading);
  621. lua_register(state, "GetLevel", EQ2Emu_lua_GetLevel);
  622. lua_register(state, "GetHP", EQ2Emu_lua_GetCurrentHP);
  623. lua_register(state, "GetMaxHP", EQ2Emu_lua_GetMaxHP);
  624. lua_register(state, "GetMaxHPBase", EQ2Emu_lua_GetMaxHPBase);
  625. lua_register(state, "GetMaxPower", EQ2Emu_lua_GetMaxPower);
  626. lua_register(state, "GetMaxPowerBase", EQ2Emu_lua_GetMaxPowerBase);
  627. lua_register(state, "GetName", EQ2Emu_lua_GetName);
  628. lua_register(state, "GetPower", EQ2Emu_lua_GetCurrentPower);
  629. lua_register(state, "GetX", EQ2Emu_lua_GetX);
  630. lua_register(state, "GetY", EQ2Emu_lua_GetY);
  631. lua_register(state, "GetZ", EQ2Emu_lua_GetZ);
  632. lua_register(state, "GetSpawnID", EQ2Emu_lua_GetSpawnID);
  633. lua_register(state, "GetSpawnGroupID", EQ2Emu_lua_GetSpawnGroupID);
  634. lua_register(state, "GetSpawnLocationID", EQ2Emu_lua_GetSpawnLocationID);
  635. lua_register(state, "GetSpawnLocationPlacementID", EQ2Emu_lua_GetSpawnLocationPlacementID);
  636. lua_register(state, "SetFactionID", EQ2Emu_lua_SetFactionID);
  637. lua_register(state, "GetFactionID", EQ2Emu_lua_GetFactionID);
  638. lua_register(state, "GetFactionAmount", EQ2Emu_lua_GetFactionAmount);
  639. lua_register(state, "GetGender", EQ2Emu_lua_GetGender);
  640. lua_register(state, "GetTarget", EQ2Emu_lua_GetTarget);
  641. lua_register(state, "HasFreeSlot", EQ2Emu_lua_HasFreeSlot);
  642. lua_register(state, "HasItemEquipped", EQ2Emu_lua_HasItemEquipped);
  643. lua_register(state, "GetEquippedItemByID", EQ2Emu_lua_GetEquippedItemByID);
  644. lua_register(state, "GetEquippedItemBySlot", EQ2Emu_lua_GetEquippedItemBySlot);
  645. lua_register(state, "GetItemByID", EQ2Emu_lua_GetItemByID);
  646. lua_register(state, "GetItemType", EQ2Emu_lua_GetItemType);
  647. lua_register(state, "GetSpellName", EQ2Emu_lua_GetSpellName);
  648. lua_register(state, "PerformCameraShake", EQ2Emu_lua_PerformCameraShake);
  649. lua_register(state, "GetModelType", EQ2Emu_lua_GetModelType);
  650. lua_register(state, "GetSpeed", EQ2Emu_lua_GetSpeed);
  651. lua_register(state, "HasMoved", EQ2Emu_lua_HasMoved);
  652. lua_register(state, "SpellDamage", EQ2Emu_lua_SpellDamage);
  653. lua_register(state, "CastSpell", EQ2Emu_lua_CastSpell);
  654. lua_register(state, "SpellHeal", EQ2Emu_lua_SpellHeal);
  655. lua_register(state, "AddItem", EQ2Emu_lua_AddItem);
  656. lua_register(state, "SummonItem", EQ2Emu_lua_SummonItem);
  657. lua_register(state, "RemoveItem", EQ2Emu_lua_RemoveItem);
  658. lua_register(state, "HasItem", EQ2Emu_lua_HasItem);
  659. lua_register(state, "SpawnMob", EQ2Emu_lua_Spawn);
  660. lua_register(state, "SummonPet", EQ2Emu_lua_SummonPet);
  661. lua_register(state, "AddSpawnAccess", EQ2Emu_lua_AddSpawnAccess);
  662. lua_register(state, "GetZone", EQ2Emu_lua_GetZone);
  663. lua_register(state, "GetZoneName", EQ2Emu_lua_GetZoneName);
  664. lua_register(state, "GetZoneID", EQ2Emu_lua_GetZoneID);
  665. lua_register(state, "Zone", EQ2Emu_lua_Zone);
  666. lua_register(state, "AddHate", EQ2Emu_lua_AddHate);
  667. lua_register(state, "IsAlive", EQ2Emu_lua_IsAlive);
  668. lua_register(state, "IsInCombat", EQ2Emu_lua_IsInCombat);
  669. lua_register(state, "Attack", EQ2Emu_lua_Attack);
  670. lua_register(state, "ApplySpellVisual", EQ2Emu_lua_ApplySpellVisual);
  671. lua_register(state, "IsPlayer", EQ2Emu_lua_IsPlayer);
  672. lua_register(state, "FaceTarget", EQ2Emu_lua_FaceTarget);
  673. lua_register(state, "MoveToLocation", EQ2Emu_lua_MoveToLocation);
  674. lua_register(state, "Shout", EQ2Emu_lua_Shout);
  675. lua_register(state, "Say", EQ2Emu_lua_Say);
  676. lua_register(state, "SayOOC", EQ2Emu_lua_SayOOC);
  677. lua_register(state, "Emote", EQ2Emu_lua_Emote);
  678. lua_register(state, "MovementLoopAddLocation", EQ2Emu_lua_MovementLoopAdd);
  679. lua_register(state, "GetCurrentZoneSafeLocation", EQ2Emu_lua_GetCurrentZoneSafeLocation);
  680. lua_register(state, "AddTimer", EQ2Emu_lua_AddTimer);
  681. lua_register(state, "Harvest", EQ2Emu_lua_Harvest);
  682. lua_register(state, "AddSpellBonus", EQ2Emu_lua_AddSpellBonus);
  683. lua_register(state, "RemoveSpellBonus", EQ2Emu_lua_RemoveSpellBonus);
  684. lua_register(state, "AddSkillBonus", EQ2Emu_lua_AddSkillBonus);
  685. lua_register(state, "RemoveSkillBonus", EQ2Emu_lua_RemoveSkillBonus);
  686. lua_register(state, "AddControlEffect", EQ2Emu_lua_AddControlEffect);
  687. lua_register(state, "RemoveControlEffect", EQ2Emu_lua_RemoveControlEffect);
  688. lua_register(state, "GetCurrentZoneSafeLocation", EQ2Emu_lua_GetCurrentZoneSafeLocation);
  689. lua_register(state, "GetInt", EQ2Emu_lua_GetInt);
  690. lua_register(state, "GetWis", EQ2Emu_lua_GetWis);
  691. lua_register(state, "GetSta", EQ2Emu_lua_GetSta);
  692. lua_register(state, "GetStr", EQ2Emu_lua_GetStr);
  693. lua_register(state, "GetAgi", EQ2Emu_lua_GetAgi);
  694. lua_register(state, "SetInt", EQ2Emu_lua_SetInt);
  695. lua_register(state, "SetWis", EQ2Emu_lua_SetWis);
  696. lua_register(state, "SetSta", EQ2Emu_lua_SetSta);
  697. lua_register(state, "SetStr", EQ2Emu_lua_SetStr);
  698. lua_register(state, "SetAgi", EQ2Emu_lua_SetAgi);
  699. lua_register(state, "GetIntBase", EQ2Emu_lua_GetIntBase);
  700. lua_register(state, "GetWisBase", EQ2Emu_lua_GetWisBase);
  701. lua_register(state, "GetStaBase", EQ2Emu_lua_GetStaBase);
  702. lua_register(state, "GetStrBase", EQ2Emu_lua_GetStrBase);
  703. lua_register(state, "GetAgiBase", EQ2Emu_lua_GetAgiBase);
  704. lua_register(state, "SetIntBase", EQ2Emu_lua_SetIntBase);
  705. lua_register(state, "SetWisBase", EQ2Emu_lua_SetWisBase);
  706. lua_register(state, "SetStaBase", EQ2Emu_lua_SetStaBase);
  707. lua_register(state, "SetStrBase", EQ2Emu_lua_SetStrBase);
  708. lua_register(state, "SetAgiBase", EQ2Emu_lua_SetAgiBase);
  709. lua_register(state, "GetSpawn", EQ2Emu_lua_GetSpawn);
  710. lua_register(state, "GetVariableValue", EQ2Emu_lua_GetVariableValue);
  711. lua_register(state, "GetCoinMessage", EQ2Emu_lua_GetCoinMessage);
  712. lua_register(state, "GetSpawnByGroupID", EQ2Emu_lua_GetSpawnByGroupID);
  713. lua_register(state, "GetSpawnByLocationID", EQ2Emu_lua_GetSpawnByLocationID);
  714. lua_register(state, "PlayFlavor", EQ2Emu_lua_PlayFlavor);
  715. lua_register(state, "PlaySound", EQ2Emu_lua_PlaySound);
  716. lua_register(state, "PlayVoice", EQ2Emu_lua_PlayVoice);
  717. lua_register(state, "PlayAnimation", EQ2Emu_lua_PlayAnimation);
  718. lua_register(state, "AddLootItem", EQ2Emu_lua_AddLootItem);
  719. lua_register(state, "RemoveLootItem", EQ2Emu_lua_RemoveLootItem);
  720. lua_register(state, "AddLootCoin", EQ2Emu_lua_AddLootCoin);
  721. lua_register(state, "GiveLoot", EQ2Emu_lua_GiveLoot);
  722. lua_register(state, "HasPendingLootItem", EQ2Emu_lua_HasPendingLootItem);
  723. lua_register(state, "HasPendingLoot", EQ2Emu_lua_HasPendingLoot);
  724. lua_register(state, "SetLootCoin", EQ2Emu_lua_SetLootCoin);
  725. lua_register(state, "GetLootCoin", EQ2Emu_lua_GetLootCoin);
  726. lua_register(state, "SetPlayerProximityFunction", EQ2Emu_lua_SetPlayerProximityFunction);
  727. lua_register(state, "SetLocationProximityFunction", EQ2Emu_lua_SetLocationProximityFunction);
  728. lua_register(state, "CreateConversation", EQ2Emu_lua_CreateConversation);
  729. lua_register(state, "AddConversationOption", EQ2Emu_lua_AddConversationOption);
  730. lua_register(state, "StartConversation", EQ2Emu_lua_StartConversation);
  731. lua_register(state, "CloseConversation", EQ2Emu_lua_CloseConversation);
  732. lua_register(state, "CloseItemConversation", EQ2Emu_lua_CloseItemConversation);
  733. //lua_register(state, "StartItemConversation", EQ2Emu_lua_StartItemConversation);
  734. lua_register(state, "StartDialogConversation", EQ2Emu_lua_StartDialogConversation);
  735. lua_register(state, "SpawnSet", EQ2Emu_lua_SpawnSet);
  736. lua_register(state, "SpawnSetByDistance", EQ2Emu_lua_SpawnSetByDistance);
  737. lua_register(state, "SpawnMove", EQ2Emu_lua_SpawnMove);
  738. lua_register(state, "KillSpawn", EQ2Emu_lua_KillSpawn);
  739. lua_register(state, "KillSpawnByDistance", EQ2Emu_lua_KillSpawnByDistance);
  740. lua_register(state, "Despawn", EQ2Emu_lua_Despawn);
  741. lua_register(state, "IsBindAllowed", EQ2Emu_lua_IsBindAllowed);
  742. lua_register(state, "IsGateAllowed", EQ2Emu_lua_IsGateAllowed);
  743. lua_register(state, "Bind", EQ2Emu_lua_Bind);
  744. lua_register(state, "Gate", EQ2Emu_lua_Gate);
  745. lua_register(state, "SendMessage", EQ2Emu_lua_SendMessage);
  746. lua_register(state, "SendPopUpMessage", EQ2Emu_lua_SendPopUpMessage);
  747. lua_register(state, "SetServerControlFlag", EQ2Emu_lua_SetServerControlFlag);
  748. lua_register(state, "ToggleTracking", EQ2Emu_lua_ToggleTracking);
  749. lua_register(state, "AddPrimaryEntityCommand", EQ2Emu_lua_AddPrimaryEntityCommand);
  750. lua_register(state, "AddSpellBookEntry", EQ2Emu_lua_AddSpellBookEntry);
  751. lua_register(state, "Interrupt", EQ2Emu_lua_Interrupt);
  752. lua_register(state, "Stealth", EQ2Emu_lua_Stealth);
  753. lua_register(state, "IsInvis", EQ2Emu_lua_IsInvis);
  754. lua_register(state, "IsStealthed", EQ2Emu_lua_IsStealthed);
  755. lua_register(state, "AddSpawnIDAccess", EQ2Emu_lua_AddSpawnIDAccess);
  756. lua_register(state, "RemoveSpawnIDAccess", EQ2Emu_lua_RemoveSpawnIDAccess);
  757. lua_register(state, "HasRecipeBook", EQ2Emu_lua_HasRecipeBook);
  758. lua_register(state, "SetRequiredQuest", EQ2Emu_lua_SetRequiredQuest);
  759. lua_register(state, "SetRequiredHistory", EQ2Emu_lua_SetRequiredHistory);
  760. lua_register(state, "SetStepComplete", EQ2Emu_lua_SetStepComplete);
  761. lua_register(state, "AddStepProgress", EQ2Emu_lua_AddStepProgress);
  762. lua_register(state, "UpdateQuestTaskGroupDescription", EQ2Emu_lua_UpdateQuestTaskGroupDescription);
  763. lua_register(state, "GetTaskGroupStep", EQ2Emu_lua_GetTaskGroupStep);
  764. lua_register(state, "GetQuestStep", EQ2Emu_lua_GetQuestStep);
  765. lua_register(state, "QuestStepIsComplete", EQ2Emu_lua_QuestStepIsComplete);
  766. lua_register(state, "RegisterQuest", EQ2Emu_lua_RegisterQuest);
  767. lua_register(state, "SetQuestPrereqLevel", EQ2Emu_lua_SetQuestPrereqLevel);
  768. lua_register(state, "AddQuestPrereqQuest", EQ2Emu_lua_AddQuestPrereqQuest);
  769. lua_register(state, "AddQuestPrereqItem", EQ2Emu_lua_AddQuestPrereqItem);
  770. lua_register(state, "AddQuestPrereqFaction", EQ2Emu_lua_AddQuestPrereqFaction);
  771. lua_register(state, "AddQuestPrereqRace", EQ2Emu_lua_AddQuestPrereqRace);
  772. lua_register(state, "AddQuestPrereqModelType", EQ2Emu_lua_AddQuestPrereqModelType);
  773. lua_register(state, "AddQuestPrereqClass", EQ2Emu_lua_AddQuestPrereqClass);
  774. lua_register(state, "AddQuestPrereqTradeskillLevel", EQ2Emu_lua_AddQuestPrereqTradeskillLevel);
  775. lua_register(state, "AddQuestPrereqTradeskillClass", EQ2Emu_lua_AddQuestPrereqTradeskillClass);
  776. lua_register(state, "AddQuestSelectableRewardItem", EQ2Emu_lua_AddQuestSelectableRewardItem);
  777. lua_register(state, "AddQuestRewardItem", EQ2Emu_lua_AddQuestRewardItem);
  778. lua_register(state, "AddQuestRewardCoin", EQ2Emu_lua_AddQuestRewardCoin);
  779. lua_register(state, "AddQuestRewardFaction", EQ2Emu_lua_AddQuestRewardFaction);
  780. lua_register(state, "SetQuestRewardStatus", EQ2Emu_lua_SetQuestRewardStatus);
  781. lua_register(state, "SetQuestRewardComment", EQ2Emu_lua_SetQuestRewardComment);
  782. lua_register(state, "SetQuestRewardExp", EQ2Emu_lua_SetQuestRewardExp);
  783. lua_register(state, "AddQuestStepKill", EQ2Emu_lua_AddQuestStepKill);
  784. lua_register(state, "AddQuestStep", EQ2Emu_lua_AddQuestStep);
  785. lua_register(state, "AddQuestStepChat", EQ2Emu_lua_AddQuestStepChat);
  786. lua_register(state, "AddQuestStepObtainItem", EQ2Emu_lua_AddQuestStepObtainItem);
  787. lua_register(state, "AddQuestStepLocation", EQ2Emu_lua_AddQuestStepLocation);
  788. lua_register(state, "AddQuestStepSpell", EQ2Emu_lua_AddQuestStepSpell);
  789. lua_register(state, "AddQuestStepCraft", EQ2Emu_lua_AddQuestStepCraft);
  790. lua_register(state, "AddQuestStepHarvest", EQ2Emu_lua_AddQuestStepHarvest);
  791. lua_register(state, "AddQuestStepCompleteAction", EQ2Emu_lua_AddQuestStepCompleteAction);
  792. lua_register(state, "AddQuestStepProgressAction", EQ2Emu_lua_AddQuestStepProgressAction);
  793. lua_register(state, "SetQuestCompleteAction", EQ2Emu_lua_SetQuestCompleteAction);
  794. lua_register(state, "GiveQuestReward", EQ2Emu_lua_GiveQuestReward);
  795. lua_register(state, "UpdateQuestStepDescription", EQ2Emu_lua_UpdateQuestStepDescription);
  796. lua_register(state, "UpdateQuestDescription", EQ2Emu_lua_UpdateQuestDescription);
  797. lua_register(state, "UpdateQuestZone", EQ2Emu_lua_UpdateQuestZone);
  798. lua_register(state, "SetCompletedDescription", EQ2Emu_lua_SetCompletedDescription);
  799. lua_register(state, "OfferQuest", EQ2Emu_lua_OfferQuest);
  800. lua_register(state, "ProvidesQuest", EQ2Emu_lua_ProvidesQuest);
  801. lua_register(state, "HasQuest", EQ2Emu_lua_HasQuest);
  802. lua_register(state, "HasCompletedQuest", EQ2Emu_lua_HasCompletedQuest);
  803. lua_register(state, "QuestIsComplete", EQ2Emu_lua_QuestIsComplete);
  804. lua_register(state, "QuestReturnNPC", EQ2Emu_lua_QuestReturnNPC);
  805. lua_register(state, "GetQuest", EQ2Emu_lua_GetQuest);
  806. lua_register(state, "HasCollectionsToHandIn", EQ2Emu_lua_HasCollectionsToHandIn);
  807. lua_register(state, "HandInCollections", EQ2Emu_lua_HandInCollections);
  808. lua_register(state, "UseWidget", EQ2Emu_lua_UseWidget);
  809. lua_register(state, "SetSpellList", EQ2Emu_lua_SetSpellList);
  810. lua_register(state, "GetPet", EQ2Emu_lua_GetPet);
  811. lua_register(state, "Charm", EQ2Emu_lua_Charm);
  812. lua_register(state, "GetGroup", EQ2Emu_lua_GetGroup);
  813. lua_register(state, "SetCompleteFlag", EQ2Emu_lua_SetCompleteFlag);
  814. lua_register(state, "SetQuestYellow", EQ2Emu_lua_SetQuestYellow);
  815. lua_register(state, "CanReceiveQuest", EQ2Emu_lua_CanReceiveQuest);
  816. lua_register(state, "AddTransportSpawn", EQ2Emu_lua_AddTransportSpawn);
  817. // Option window
  818. lua_register(state, "CreateOptionWindow", EQ2Emu_lua_CreateOptionWindow);
  819. lua_register(state, "AddOptionWindowOption", EQ2Emu_lua_AddOptionWindowOption);
  820. lua_register(state, "SendOptionWindow", EQ2Emu_lua_SendOptionWindow);
  821. lua_register(state, "GetTradeskillClass", EQ2Emu_lua_GetTradeskillClass);
  822. lua_register(state, "GetTradeskillLevel", EQ2Emu_lua_GetTradeskillLevel);
  823. lua_register(state, "GetTradeskillClassName", EQ2Emu_lua_GetTradeskillClassName);
  824. lua_register(state, "SetTradeskillLevel", EQ2Emu_lua_SetTradeskillLevel);
  825. lua_register(state, "SummonDeityPet", EQ2Emu_lua_SummonDeityPet);
  826. lua_register(state, "SummonCosmeticPet", EQ2Emu_lua_SummonCosmeticPet);
  827. lua_register(state, "DismissPet", EQ2Emu_lua_DismissPet);
  828. lua_register(state, "GetCharmedPet", EQ2Emu_lua_GetCharmedPet);
  829. lua_register(state, "GetDeityPet", EQ2Emu_lua_GetDeityPet);
  830. lua_register(state, "GetCosmeticPet", EQ2Emu_lua_GetCosmeticPet);
  831. lua_register(state, "SetQuestFeatherColor", EQ2Emu_lua_SetQuestFeatherColor);
  832. lua_register(state, "RemoveSpawnAccess", EQ2Emu_lua_RemoveSpawnAccess);
  833. lua_register(state, "SpawnByLocationID", EQ2Emu_lua_SpawnByLocationID);
  834. lua_register(state, "CastEntityCommand", EQ2Emu_lua_CastEntityCommand);
  835. lua_register(state, "SetLuaBrain", EQ2Emu_lua_SetLuaBrain);
  836. lua_register(state, "SetBrainTick", EQ2Emu_lua_SetBrainTick);
  837. lua_register(state, "SetFollowTarget", EQ2Emu_lua_SetFollowTarget);
  838. lua_register(state, "GetFollowTarget", EQ2Emu_lua_GetFollowTarget);
  839. lua_register(state, "ToggleFollow", EQ2Emu_lua_ToggleFollow);
  840. lua_register(state, "IsFollowing", EQ2Emu_lua_IsFollowing);
  841. lua_register(state, "SetTempVariable", EQ2Emu_lua_SetTempVariable);
  842. lua_register(state, "GetTempVariable", EQ2Emu_lua_GetTempVariable);
  843. lua_register(state, "GiveQuestItem", EQ2Emu_lua_GiveQuestItem);
  844. lua_register(state, "SetQuestRepeatable", EQ2Emu_lua_SetQuestRepeatable);
  845. lua_register(state, "AddWard", EQ2Emu_lua_AddWard);
  846. lua_register(state, "AddToWard", EQ2Emu_lua_AddToWard);
  847. lua_register(state, "RemoveWard", EQ2Emu_lua_RemoveWard);
  848. lua_register(state, "GetWardAmountLeft", EQ2Emu_lua_GetWardAmountLeft);
  849. lua_register(state, "GetWardValue", EQ2Emu_lua_GetWardValue);
  850. lua_register(state, "SetTarget", EQ2Emu_lua_SetTarget);
  851. lua_register(state, "IsPet", EQ2Emu_lua_IsPet);
  852. lua_register(state, "GetOwner", EQ2Emu_lua_GetOwner);
  853. lua_register(state, "SetInCombat", EQ2Emu_lua_SetInCombat);
  854. lua_register(state, "CompareSpawns", EQ2Emu_lua_CompareSpawns);
  855. lua_register(state, "Runback", EQ2Emu_lua_Runback);
  856. lua_register(state, "GetRunbackDistance", EQ2Emu_lua_GetRunbackDistance);
  857. lua_register(state, "IsCasting", EQ2Emu_lua_IsCasting);
  858. lua_register(state, "IsMezzed", EQ2Emu_lua_IsMezzed);
  859. lua_register(state, "IsStunned", EQ2Emu_lua_IsStunned);
  860. lua_register(state, "IsMezzedOrStunned", EQ2Emu_lua_IsMezzedOrStunned);
  861. lua_register(state, "ProcessSpell", EQ2Emu_lua_ProcessSpell);
  862. lua_register(state, "ProcessMelee", EQ2Emu_lua_ProcessMelee);
  863. lua_register(state, "HasRecovered", EQ2Emu_lua_HasRecovered);
  864. lua_register(state, "GetEncounterSize", EQ2Emu_lua_GetEncounterSize);
  865. lua_register(state, "GetMostHated", EQ2Emu_lua_GetMostHated);
  866. lua_register(state, "ClearHate", EQ2Emu_lua_ClearHate);
  867. lua_register(state, "ClearEncounter", EQ2Emu_lua_ClearEncounter);
  868. lua_register(state, "GetEncounter", EQ2Emu_lua_GetEncounter);
  869. lua_register(state, "GetHateList", EQ2Emu_lua_GetHateList);
  870. lua_register(state, "HasGroup", EQ2Emu_lua_HasGroup);
  871. lua_register(state, "HasSpellEffect", EQ2Emu_lua_HasSpellEffect);
  872. lua_register(state, "SetSuccessTimer", EQ2Emu_lua_SetSuccessTimer);
  873. lua_register(state, "SetFailureTimer", EQ2Emu_lua_SetFailureTimer);
  874. lua_register(state, "IsGroundSpawn", EQ2Emu_lua_IsGroundSpawn);
  875. lua_register(state, "CanHarvest", EQ2Emu_lua_CanHarvest);
  876. lua_register(state, "SummonDumbFirePet", EQ2Emu_lua_SummonDumbFirePet);
  877. lua_register(state, "GetSkillValue", EQ2Emu_lua_GetSkillValue);
  878. lua_register(state, "GetSkillMaxValue", EQ2Emu_lua_GetSkillMaxValue);
  879. lua_register(state, "GetSkillName", EQ2Emu_lua_GetSkillName);
  880. lua_register(state, "SetSkillMaxValue", EQ2Emu_lua_SetSkillMaxValue);
  881. lua_register(state, "SetSkillValue", EQ2Emu_lua_SetSkillValue);
  882. lua_register(state, "GetSkill", EQ2Emu_lua_GetSkill);
  883. lua_register(state, "GetSkillIDByName", EQ2Emu_lua_GetSkillIDByName);
  884. lua_register(state, "AddProc", EQ2Emu_lua_AddProc);
  885. lua_register(state, "RemoveProc", EQ2Emu_lua_RemoveProc);
  886. lua_register(state, "Knockback", EQ2Emu_lua_Knockback);
  887. lua_register(state, "IsEpic", EQ2Emu_lua_IsEpic);
  888. lua_register(state, "IsHeroic", EQ2Emu_lua_IsHeroic);
  889. lua_register(state, "ProcDamage", EQ2Emu_lua_ProcDamage);
  890. lua_register(state, "LastSpellAttackHit", EQ2Emu_lua_LastSpellAttackHit);
  891. lua_register(state, "IsBehind", EQ2Emu_lua_IsBehind);
  892. lua_register(state, "IsFlanking", EQ2Emu_lua_IsFlanking);
  893. lua_register(state, "AddSpellTimer", EQ2Emu_lua_AddSpellTimer);
  894. lua_register(state, "GetItemCount", EQ2Emu_lua_GetItemCount);
  895. lua_register(state, "SetItemCount", EQ2Emu_lua_SetItemCount);
  896. lua_register(state, "Resurrect", EQ2Emu_lua_Resurrect);
  897. lua_register(state, "BreatheUnderwater", EQ2Emu_lua_BreatheUnderwater);
  898. lua_register(state, "BlurVision", EQ2Emu_lua_BlurVision);
  899. lua_register(state, "SetVision", EQ2Emu_lua_SetVision);
  900. lua_register(state, "GetItemSkillReq", EQ2Emu_lua_GetItemSkillReq);
  901. lua_register(state, "SetSpeedMultiplier", EQ2Emu_lua_SetSpeedMultiplier);
  902. lua_register(state, "SetIllusion", EQ2Emu_lua_SetIllusion);
  903. lua_register(state, "ResetIllusion", EQ2Emu_lua_ResetIllusion);
  904. lua_register(state, "AddThreatTransfer", EQ2Emu_lua_AddThreatTransfer);
  905. lua_register(state, "RemoveThreatTransfer", EQ2Emu_lua_RemoveThreatTransfer);
  906. lua_register(state, "CureByType", EQ2Emu_lua_CureByType);
  907. lua_register(state, "CureByControlEffect", EQ2Emu_lua_CureByControlEffect);
  908. lua_register(state, "AddSpawnSpellBonus", EQ2Emu_lua_AddSpawnSpellBonus);
  909. lua_register(state, "CancelSpell", EQ2Emu_lua_CancelSpell);
  910. lua_register(state, "RemoveStealth", EQ2Emu_lua_RemoveStealth);
  911. lua_register(state, "RemoveInvis", EQ2Emu_lua_RemoveInvis);
  912. lua_register(state, "StartHeroicOpportunity", EQ2Emu_lua_StartHeroicOpportunity);
  913. lua_register(state, "CopySpawnAppearance", EQ2Emu_lua_CopySpawnAppearance);
  914. lua_register(state, "SetSpellTriggerCount", EQ2Emu_lua_SetSpellTriggerCount);
  915. lua_register(state, "GetSpellTriggerCount", EQ2Emu_lua_GetSpellTriggerCount);
  916. lua_register(state, "RemoveTriggerFromSpell", EQ2Emu_lua_RemoveTriggerFromSpell);
  917. lua_register(state, "AddImmunitySpell", EQ2Emu_lua_AddImmunitySpell);
  918. lua_register(state, "RemoveImmunitySpell", EQ2Emu_lua_RemoveImmunitySpell);
  919. lua_register(state, "SetSpellSnareValue", EQ2Emu_lua_SetSpellSnareValue);
  920. lua_register(state, "CheckRaceType", EQ2Emu_lua_CheckRaceType);
  921. lua_register(state, "GetRaceType", EQ2Emu_lua_GetRaceType);
  922. lua_register(state, "GetRaceBaseType", EQ2Emu_lua_GetRaceBaseType);
  923. lua_register(state, "GetQuestFlags", EQ2Emu_lua_GetQuestFlags);
  924. lua_register(state, "SetQuestFlags", EQ2Emu_lua_SetQuestFlags);
  925. lua_register(state, "SetQuestTimer", EQ2Emu_lua_SetQuestTimer);
  926. lua_register(state, "RemoveQuestStep", EQ2Emu_lua_RemoveQuestStep);
  927. lua_register(state, "ResetQuestStep", EQ2Emu_lua_ResetQuestStep);
  928. lua_register(state, "SetQuestTimerComplete", EQ2Emu_lua_SetQuestTimerComplete);
  929. lua_register(state, "AddQuestStepFailureAction", EQ2Emu_lua_AddQuestStepFailureAction);
  930. lua_register(state, "SetStepFailed", EQ2Emu_lua_SetStepFailed);
  931. lua_register(state, "GetQuestCompleteCount", EQ2Emu_lua_GetQuestCompleteCount);
  932. lua_register(state, "SetServerVariable", EQ2Emu_lua_SetServerVariable);
  933. lua_register(state, "GetServerVariable", EQ2Emu_lua_GetServerVariable);
  934. lua_register(state, "HasLanguage", EQ2Emu_lua_HasLanguage);
  935. lua_register(state, "AddLanguage", EQ2Emu_lua_AddLanguage);
  936. lua_register(state, "IsNight", EQ2Emu_lua_IsNight);
  937. lua_register(state, "AddMultiFloorLift", EQ2Emu_lua_AddMultiFloorLift);
  938. lua_register(state, "StartAutoMount", EQ2Emu_lua_StartAutoMount);
  939. lua_register(state, "EndAutoMount", EQ2Emu_lua_EndAutoMount);
  940. lua_register(state, "IsOnAutoMount", EQ2Emu_lua_IsOnAutoMount);
  941. lua_register(state, "SetPlayerHistory", EQ2Emu_lua_SetPlayerHistory);
  942. lua_register(state, "GetPlayerHistory", EQ2Emu_lua_GetPlayerHistory);
  943. lua_register(state, "SetGridID", EQ2Emu_lua_SetGridID);
  944. lua_register(state, "GetQuestStepProgress", EQ2Emu_lua_GetQuestStepProgress);
  945. lua_register(state, "SetPlayerLevel", EQ2Emu_lua_SetPlayerLevel);
  946. lua_register(state, "AddCoin", EQ2Emu_lua_AddCoin);
  947. lua_register(state, "RemoveCoin", EQ2Emu_lua_RemoveCoin);
  948. lua_register(state, "GetPlayersInZone", EQ2Emu_lua_GetPlayersInZone);
  949. lua_register(state, "SpawnGroupByID", EQ2Emu_lua_SpawnGroupByID);
  950. lua_register(state, "SetSpawnAnimation", EQ2Emu_lua_SetSpawnAnimation);
  951. lua_register(state, "GetClientVersion", EQ2Emu_lua_GetClientVersion);
  952. lua_register(state, "GetItemID", EQ2Emu_lua_GetItemID);
  953. lua_register(state, "IsEntity", EQ2Emu_lua_IsEntity);
  954. lua_register(state, "GetOrigX", EQ2Emu_lua_GetOrigX);
  955. lua_register(state, "GetOrigY", EQ2Emu_lua_GetOrigY);
  956. lua_register(state, "GetOrigZ", EQ2Emu_lua_GetOrigZ);
  957. lua_register(state, "GetPCTOfHP", EQ2Emu_lua_GetPCTOfHP);
  958. lua_register(state, "GetPCTOfPower", EQ2Emu_lua_GetPCTOfPower);
  959. lua_register(state, "GetBoundZoneID", EQ2Emu_lua_GetBoundZoneID);
  960. lua_register(state, "Evac", EQ2Emu_lua_Evac);
  961. lua_register(state, "GetSpellTier", EQ2Emu_lua_GetSpellTier);
  962. lua_register(state, "GetSpellID", EQ2Emu_lua_GetSpellID);
  963. lua_register(state, "StartTransmute", EQ2Emu_lua_StartTransmute);
  964. lua_register(state, "CompleteTransmute", EQ2Emu_lua_CompleteTransmute);
  965. lua_register(state, "ProcHate", EQ2Emu_lua_ProcHate);
  966. lua_register(state, "GetRandomSpawnByID", EQ2Emu_lua_GetRandomSpawnByID);
  967. lua_register(state, "AddLootToObject", EQ2Emu_lua_AddLootToObject);
  968. lua_register(state, "ShowLootWindow", EQ2Emu_lua_ShowLootWindow);
  969. lua_register(state, "AddPrimaryEntityCommandAllSpawns", EQ2Emu_lua_AddPrimaryEntityCommandAllSpawns);
  970. lua_register(state, "InstructionWindow", EQ2Emu_lua_InstructionWindow);
  971. lua_register(state, "ShowWindow", EQ2Emu_lua_ShowWindow);
  972. lua_register(state, "FlashWindow", EQ2Emu_lua_FlashWindow);
  973. lua_register(state, "EnableGameEvent", EQ2Emu_lua_EnableGameEvent);
  974. lua_register(state, "DisplayText", EQ2Emu_lua_DisplayText);
  975. lua_register(state, "CheckLOS", EQ2Emu_lua_CheckLOS);
  976. lua_register(state, "CheckLOSByCoordinates", EQ2Emu_lua_CheckLOSByCoordinates);
  977. lua_register(state, "SetZoneExpansionFlag", EQ2Emu_lua_SetZoneExpansionFlag);
  978. lua_register(state, "GetZoneExpansionFlag", EQ2Emu_lua_GetZoneExpansionFlag);
  979. lua_register(state, "SetZoneHolidayFlag", EQ2Emu_lua_SetZoneHolidayFlag);
  980. lua_register(state, "GetZoneHolidayFlag", EQ2Emu_lua_GetZoneHolidayFlag);
  981. lua_register(state, "AddSpawnProximity", EQ2Emu_lua_AddSpawnProximity);
  982. lua_register(state, "CanSeeInvis", EQ2Emu_lua_CanSeeInvis);
  983. lua_register(state, "SetSeeInvis", EQ2Emu_lua_SetSeeInvis);
  984. lua_register(state, "SetSeeHide", EQ2Emu_lua_SetSeeHide);
  985. lua_register(state, "SetAccessToEntityCommand", EQ2Emu_lua_SetAccessToEntityCommand);
  986. lua_register(state, "RemovePrimaryEntityCommand", EQ2Emu_lua_RemovePrimaryEntityCommand);
  987. lua_register(state, "SendUpdateDefaultCommand", EQ2Emu_lua_SendUpdateDefaultCommand);
  988. lua_register(state, "SendTransporters", EQ2Emu_lua_SendTransporters);
  989. lua_register(state, "SetTemporaryTransportID", EQ2Emu_lua_SetTemporaryTransportID);
  990. lua_register(state, "GetTemporaryTransportID", EQ2Emu_lua_GetTemporaryTransportID);
  991. }
  992. void LuaInterface::LogError(const char* error, ...) {
  993. va_list argptr;
  994. char buffer[4096];
  995. va_start(argptr, error);
  996. vsnprintf(buffer, sizeof(buffer), error, argptr);
  997. va_end(argptr);
  998. SimpleLogError(buffer);
  999. }
  1000. void LuaInterface::SimpleLogError(const char* error) {
  1001. ProcessErrorMessage(error);
  1002. LogWrite(LUA__ERROR, 0, "LUA", "%s", error);
  1003. }
  1004. void LuaInterface::ResetFunctionStack(lua_State* state) {
  1005. lua_settop(state, 0);
  1006. }
  1007. void LuaInterface::AddUserDataPtr(LUAUserData* data) {
  1008. MLUAUserData.lock();
  1009. user_data[data] = Timer::GetCurrentTime2() + 300000; //allow a function to use this pointer for 5 minutes
  1010. MLUAUserData.unlock();
  1011. }
  1012. void LuaInterface::DeletePendingSpells(bool all) {
  1013. MSpellDelete.lock();
  1014. if (spells_pending_delete.size() > 0) {
  1015. int32 time = Timer::GetCurrentTime2();
  1016. map<LuaSpell*, int32>::iterator itr;
  1017. vector<LuaSpell*> tmp_deletes;
  1018. vector<LuaSpell*>::iterator del_itr;
  1019. for (itr = spells_pending_delete.begin(); itr != spells_pending_delete.end(); itr++) {
  1020. if (all || time >= itr->second)
  1021. tmp_deletes.push_back(itr->first);
  1022. }
  1023. LuaSpell* spell = 0;
  1024. for (del_itr = tmp_deletes.begin(); del_itr != tmp_deletes.end(); del_itr++) {
  1025. spell = *del_itr;
  1026. spells_pending_delete.erase(spell);
  1027. safe_delete(spell);
  1028. }
  1029. }
  1030. MSpellDelete.unlock();
  1031. }
  1032. void LuaInterface::DeletePendingSpell(LuaSpell* spell) {
  1033. MSpellDelete.lock();
  1034. if (spells_pending_delete.size() > 0) {
  1035. map<LuaSpell*, int32>::iterator itr = spells_pending_delete.find(spell);
  1036. if (itr != spells_pending_delete.end())
  1037. spells_pending_delete.erase(itr);
  1038. }
  1039. MSpellDelete.unlock();
  1040. }
  1041. void LuaInterface::DeleteUserDataPtrs(bool all) {
  1042. MLUAUserData.lock();
  1043. if(user_data.size() > 0){
  1044. map<LUAUserData*, int32>::iterator itr;
  1045. int32 time = Timer::GetCurrentTime2();
  1046. vector<LUAUserData*> tmp_deletes;
  1047. vector<LUAUserData*>::iterator del_itr;
  1048. for(itr = user_data.begin(); itr != user_data.end(); itr++){
  1049. if(all || time >= itr->second)
  1050. tmp_deletes.push_back(itr->first);
  1051. }
  1052. LUAUserData* data = 0;
  1053. for(del_itr = tmp_deletes.begin(); del_itr != tmp_deletes.end(); del_itr++){
  1054. data = *del_itr;
  1055. user_data.erase(data);
  1056. safe_delete(data);
  1057. }
  1058. }
  1059. MLUAUserData.unlock();
  1060. }
  1061. Spawn* LuaInterface::GetSpawn(lua_State* state, int8 arg_num) {
  1062. Spawn* ret = 0;
  1063. if (lua_islightuserdata(state, arg_num)){
  1064. LUAUserData* data = (LUAUserData*)lua_touserdata(state, arg_num);
  1065. if(!data || !data->IsCorrectlyInitialized()){
  1066. LogError("%s: GetSpawn error while processing %s", GetScriptName(state), lua_tostring(state, -1));
  1067. }
  1068. else if(!data->IsSpawn()){
  1069. lua_Debug ar;
  1070. lua_getstack (state, 1, &ar);
  1071. lua_getinfo(state, "Sln", &ar);
  1072. LogError("%s: Invalid data type used for GetSpawn in %s (line %d)", GetScriptName(state), ar.source, ar.currentline);
  1073. }
  1074. else
  1075. ret = data->spawn;
  1076. }
  1077. return ret;
  1078. }
  1079. vector<ConversationOption>* LuaInterface::GetConversation(lua_State* state, int8 arg_num) {
  1080. vector<ConversationOption>* ret = 0;
  1081. if(lua_islightuserdata(state, arg_num)){
  1082. LUAUserData* data = (LUAUserData*)lua_touserdata(state, arg_num);
  1083. if(!data || !data->IsCorrectlyInitialized()){
  1084. LogError("%s: GetConversation error while processing %s", GetScriptName(state), lua_tostring(state, -1));
  1085. }
  1086. else if(!data->IsConversationOption()){
  1087. lua_Debug ar;
  1088. lua_getstack (state, 1, &ar);
  1089. lua_getinfo(state, "Sln", &ar);
  1090. LogError("%s: Invalid data type used for GetConversation in %s (line %d)", GetScriptName(state), ar.source, ar.currentline);
  1091. }
  1092. else
  1093. ret = data->conversation_options;
  1094. }
  1095. return ret;
  1096. }
  1097. vector<OptionWindowOption>* LuaInterface::GetOptionWindow(lua_State* state, int8 arg_num) {
  1098. vector<OptionWindowOption>* ret = 0;
  1099. if(lua_islightuserdata(state, arg_num)){
  1100. LUAUserData* data = (LUAUserData*)lua_touserdata(state, arg_num);
  1101. if(!data || !data->IsCorrectlyInitialized()){
  1102. LogError("%s: GetOptionWindow error while processing %s", GetScriptName(state), lua_tostring(state, -1));
  1103. }
  1104. else if(!data->IsOptionWindow()){
  1105. lua_Debug ar;
  1106. lua_getstack (state, 1, &ar);
  1107. lua_getinfo(state, "Sln", &ar);
  1108. LogError("%s: Invalid data type used for GetOptionWindow in %s (line %d)", GetScriptName(state), ar.source, ar.currentline);
  1109. }
  1110. else
  1111. ret = data->option_window_option;
  1112. }
  1113. return ret;
  1114. }
  1115. Quest* LuaInterface::GetQuest(lua_State* state, int8 arg_num) {
  1116. Quest* ret = 0;
  1117. if(lua_islightuserdata(state, arg_num)){
  1118. LUAUserData* data = (LUAUserData*)lua_touserdata(state, arg_num);
  1119. if(!data || !data->IsCorrectlyInitialized()){
  1120. LogError("%s: GetQuest error while processing %s", GetScriptName(state), lua_tostring(state, 0));
  1121. }
  1122. else if(!data->IsQuest()){
  1123. lua_Debug ar;
  1124. lua_getstack (state, 1, &ar);
  1125. lua_getinfo(state, "Sln", &ar);
  1126. LogError("%s: Invalid data type used for GetQuest in %s (line %d)", GetScriptName(state), ar.source, ar.currentline);
  1127. }
  1128. else
  1129. ret = data->quest;
  1130. }
  1131. return ret;
  1132. }
  1133. Item* LuaInterface::GetItem(lua_State* state, int8 arg_num) {
  1134. Item* ret = 0;
  1135. if(lua_islightuserdata(state, arg_num)){
  1136. LUAUserData* data = (LUAUserData*)lua_touserdata(state, arg_num);
  1137. if(!data || !data->IsCorrectlyInitialized()){
  1138. LogError("%s: GetItem error while processing %s", GetScriptName(state), lua_tostring(state, 0));
  1139. }
  1140. else if(!data->IsItem()){
  1141. lua_Debug ar;
  1142. lua_getstack (state, 1, &ar);
  1143. lua_getinfo(state, "Sln", &ar);
  1144. LogError("%s: Invalid data type used for GetItem in %s (line %d)", GetScriptName(state), ar.source, ar.currentline);
  1145. }
  1146. else
  1147. ret = data->item;
  1148. }
  1149. return ret;
  1150. }
  1151. Skill* LuaInterface::GetSkill(lua_State* state, int8 arg_num) {
  1152. Skill* ret = 0;
  1153. if (lua_islightuserdata(state, arg_num)) {
  1154. LUAUserData* data = (LUAUserData*)lua_touserdata(state, arg_num);
  1155. if(!data || !data->IsCorrectlyInitialized()){
  1156. LogError("%s: GetSkill error while processing %s", GetScriptName(state), lua_tostring(state, 0));
  1157. }
  1158. else if(!data->IsSkill()){
  1159. lua_Debug ar;
  1160. lua_getstack (state, 1, &ar);
  1161. lua_getinfo(state, "Sln", &ar);
  1162. LogError("%s: Invalid data type used for GetSkill in %s (line %d)", GetScriptName(state), ar.source, ar.currentline);
  1163. }
  1164. else
  1165. ret = data->skill;
  1166. }
  1167. return ret;
  1168. }
  1169. ZoneServer* LuaInterface::GetZone(lua_State* state, int8 arg_num) {
  1170. ZoneServer* ret = 0;
  1171. if(lua_islightuserdata(state, arg_num)){
  1172. LUAUserData* data = (LUAUserData*)lua_touserdata(state, arg_num);
  1173. if(!data || !data->IsCorrectlyInitialized()){
  1174. LogError("%s: GetZone error while processing %s", GetScriptName(state), lua_tostring(state, -1));
  1175. }
  1176. else if(!data->IsZone()){
  1177. lua_Debug ar;
  1178. lua_getstack (state, 1, &ar);
  1179. lua_getinfo(state, "Sln", &ar);
  1180. LogError("%s: Invalid data type used for GetZone in %s (line %d)", GetScriptName(state), ar.source, ar.currentline);
  1181. }
  1182. else
  1183. ret = data->zone;
  1184. }
  1185. return ret;
  1186. }
  1187. sint32 LuaInterface::GetSInt32Value(lua_State* state, int8 arg_num) {
  1188. sint32 val = 0;
  1189. if(lua_isnumber(state, arg_num)){
  1190. val = lua_tointeger(state, arg_num);
  1191. }
  1192. return val;
  1193. }
  1194. int32 LuaInterface::GetInt32Value(lua_State* state, int8 arg_num) {
  1195. int32 val = 0;
  1196. if(lua_isnumber(state, arg_num)){
  1197. val = (int32)lua_tonumber(state, arg_num);
  1198. }
  1199. return val;
  1200. }
  1201. int16 LuaInterface::GetInt16Value(lua_State* state, int8 arg_num) {
  1202. int16 val = 0;
  1203. if(lua_isnumber(state, arg_num)){
  1204. val = lua_tointeger(state, arg_num);
  1205. }
  1206. return val;
  1207. }
  1208. int8 LuaInterface::GetInt8Value(lua_State* state, int8 arg_num) {
  1209. int8 val = 0;
  1210. if(lua_isnumber(state, arg_num)){
  1211. val = lua_tointeger(state, arg_num);
  1212. }
  1213. return val;
  1214. }
  1215. float LuaInterface::GetFloatValue(lua_State* state, int8 arg_num) {
  1216. float val = 0;
  1217. if(lua_isnumber(state, arg_num))
  1218. val = (float)lua_tonumber(state, arg_num);
  1219. return val;
  1220. }
  1221. string LuaInterface::GetStringValue(lua_State* state, int8 arg_num) {
  1222. string val;
  1223. if(lua_isstring(state, arg_num)){
  1224. size_t size = 0;
  1225. const char* str = lua_tolstring(state, arg_num, &size);
  1226. if(str)
  1227. val = string(str);
  1228. }
  1229. return val;
  1230. }
  1231. bool LuaInterface::GetBooleanValue(lua_State* state, int8 arg_num) {
  1232. return lua_toboolean(state, arg_num) == 1;
  1233. }
  1234. void LuaInterface::SetStringValue(lua_State* state, const char* value) {
  1235. lua_pushstring(state, value);
  1236. }
  1237. void LuaInterface::SetBooleanValue(lua_State* state, bool value) {
  1238. lua_pushboolean(state, value);
  1239. }
  1240. void LuaInterface::SetFloatValue(lua_State* state, float value) {
  1241. lua_pushnumber(state, value);
  1242. }
  1243. void LuaInterface::SetInt32Value(lua_State* state, int32 value) {
  1244. lua_pushinteger(state, value);
  1245. }
  1246. void LuaInterface::SetSInt32Value(lua_State* state, sint32 value) {
  1247. lua_pushinteger(state, value);
  1248. }
  1249. void LuaInterface::SetSpawnValue(lua_State* state, Spawn* spawn) {
  1250. LUASpawnWrapper* spawn_wrapper = new LUASpawnWrapper();
  1251. spawn_wrapper->spawn = spawn;
  1252. AddUserDataPtr(spawn_wrapper);
  1253. lua_pushlightuserdata(state, spawn_wrapper);
  1254. }
  1255. void LuaInterface::SetConversationValue(lua_State* state, vector<ConversationOption>* conversation) {
  1256. LUAConversationOptionWrapper* conv_wrapper = new LUAConversationOptionWrapper();
  1257. conv_wrapper->conversation_options = conversation;
  1258. AddUserDataPtr(conv_wrapper);
  1259. lua_pushlightuserdata(state, conv_wrapper);
  1260. }
  1261. void LuaInterface::SetOptionWindowValue(lua_State* state, vector<OptionWindowOption>* optionWindow) {
  1262. LUAOptionWindowWrapper* option_wrapper = new LUAOptionWindowWrapper();
  1263. option_wrapper->option_window_option = optionWindow;
  1264. AddUserDataPtr(option_wrapper);
  1265. lua_pushlightuserdata(state, option_wrapper);
  1266. }
  1267. void LuaInterface::SetItemValue(lua_State* state, Item* item) {
  1268. LUAItemWrapper* item_wrapper = new LUAItemWrapper();
  1269. item_wrapper->item = item;
  1270. AddUserDataPtr(item_wrapper);
  1271. lua_pushlightuserdata(state, item_wrapper);
  1272. }
  1273. void LuaInterface::SetSkillValue(lua_State* state, Skill* skill) {
  1274. LUASkillWrapper* skill_wrapper = new LUASkillWrapper();
  1275. skill_wrapper->skill = skill;
  1276. AddUserDataPtr(skill_wrapper);
  1277. lua_pushlightuserdata(state, skill_wrapper);
  1278. }
  1279. void LuaInterface::SetQuestValue(lua_State* state, Quest* quest) {
  1280. LUAQuestWrapper* quest_wrapper = new LUAQuestWrapper();
  1281. quest_wrapper->quest = quest;
  1282. AddUserDataPtr(quest_wrapper);
  1283. lua_pushlightuserdata(state, quest_wrapper);
  1284. }
  1285. void LuaInterface::SetZoneValue(lua_State* state, ZoneServer* zone) {
  1286. LUAZoneWrapper* zone_wrapper = new LUAZoneWrapper();
  1287. zone_wrapper->zone = zone;
  1288. AddUserDataPtr(zone_wrapper);
  1289. lua_pushlightuserdata(state, zone_wrapper);
  1290. }
  1291. LuaSpell* LuaInterface::GetSpell(const char* name) {
  1292. string lua_script = string(name);
  1293. if (lua_script.find(".lua") == string::npos)
  1294. lua_script.append(".lua");
  1295. if(spells.count(lua_script) > 0)
  1296. {
  1297. LogWrite(LUA__DEBUG, 0, "LUA", "Found LUA Spell Script: '%s'", lua_script.c_str());
  1298. LuaSpell* spell = spells[lua_script];
  1299. LuaSpell* new_spell = new LuaSpell;
  1300. new_spell->state = spell->state;
  1301. new_spell->file_name = spell->file_name;
  1302. new_spell->timer = spell->timer;
  1303. new_spell->timer.Disable();
  1304. new_spell->resisted = false;
  1305. new_spell->interrupted = false;
  1306. new_spell->crit = false;
  1307. new_spell->last_spellattack_hit = false;
  1308. new_spell->MSpellTargets.SetName("LuaSpell.MSpellTargets");
  1309. new_spell->cancel_after_all_triggers = false;
  1310. new_spell->num_triggers = 0;
  1311. new_spell->had_triggers = false;
  1312. new_spell->had_dmg_remaining = false;
  1313. new_spell->slot_pos = 0;
  1314. new_spell->damage_remaining = 0;
  1315. new_spell->effect_bitmask = 0;
  1316. new_spell->caster = 0;
  1317. new_spell->initial_target = 0;
  1318. new_spell->spell = 0;
  1319. return new_spell;
  1320. }
  1321. else{
  1322. LogWrite(LUA__ERROR, 0, "LUA", "Error LUA Spell Script: '%s'", name);
  1323. return 0;
  1324. }
  1325. }
  1326. Mutex* LuaInterface::GetItemScriptMutex(const char* name) {
  1327. Mutex* mutex = 0;
  1328. if(item_scripts_mutex.count(name) > 0)
  1329. mutex = item_scripts_mutex[name];
  1330. if(!mutex){
  1331. mutex = new Mutex();
  1332. item_scripts_mutex[name] = mutex;
  1333. }
  1334. return mutex;
  1335. }
  1336. Mutex* LuaInterface::GetSpawnScriptMutex(const char* name) {
  1337. Mutex* mutex = 0;
  1338. if(spawn_scripts_mutex.count(string(name)) > 0)
  1339. mutex = spawn_scripts_mutex[name];
  1340. if(!mutex){
  1341. mutex = new Mutex();
  1342. spawn_scripts_mutex[name] = mutex;
  1343. }
  1344. return mutex;
  1345. }
  1346. Mutex* LuaInterface::GetZoneScriptMutex(const char* name) {
  1347. Mutex* mutex = 0;
  1348. if(zone_scripts_mutex.count(name) > 0)
  1349. mutex = zone_scripts_mutex[name];
  1350. if(!mutex){
  1351. mutex = new Mutex();
  1352. zone_scripts_mutex[name] = mutex;
  1353. }
  1354. return mutex;
  1355. }
  1356. void LuaInterface::UseItemScript(const char* name, lua_State* state, bool val) {
  1357. MItemScripts.writelock(__FUNCTION__, __LINE__);
  1358. item_scripts[name][state] = val;
  1359. item_inverse_scripts[state] = name;
  1360. MItemScripts.releasewritelock(__FUNCTION__, __LINE__);
  1361. }
  1362. void LuaInterface::UseSpawnScript(const char* name, lua_State* state, bool val) {
  1363. MSpawnScripts.writelock(__FUNCTION__, __LINE__);
  1364. spawn_scripts[name][state] = val;
  1365. spawn_inverse_scripts[state] = name;
  1366. MSpawnScripts.releasewritelock(__FUNCTION__, __LINE__);
  1367. }
  1368. void LuaInterface::UseZoneScript(const char* name, lua_State* state, bool val) {
  1369. MZoneScripts.writelock(__FUNCTION__, __LINE__);
  1370. zone_scripts[name][state] = val;
  1371. zone_inverse_scripts[state] = name;
  1372. MZoneScripts.releasewritelock(__FUNCTION__, __LINE__);
  1373. }
  1374. lua_State* LuaInterface::GetItemScript(const char* name, bool create_new, bool use) {
  1375. map<string, map<lua_State*, bool> >::iterator itr;
  1376. map<lua_State*, bool>::iterator item_script_itr;
  1377. lua_State* ret = 0;
  1378. Mutex* mutex = 0;
  1379. itr = item_scripts.find(name);
  1380. if(itr != item_scripts.end()) {
  1381. mutex = GetItemScriptMutex(name);
  1382. mutex->readlock(__FUNCTION__, __LINE__);
  1383. for(item_script_itr = itr->second.begin(); item_script_itr != itr->second.end(); item_script_itr++){
  1384. if(!item_script_itr->second){ //not in use
  1385. ret = item_script_itr->first;
  1386. if (use)
  1387. {
  1388. item_script_itr->second = true;
  1389. break; // don't keep iterating, we already have our result
  1390. }
  1391. }
  1392. }
  1393. mutex->releasereadlock(__FUNCTION__, __LINE__);
  1394. }
  1395. if(!ret && create_new){
  1396. if(name && LoadItemScript(name))
  1397. ret = GetItemScript(name, create_new, use);
  1398. else{
  1399. LogError("Error LUA Item Script '%s'", name);
  1400. return 0;
  1401. }
  1402. }
  1403. return ret;
  1404. }
  1405. lua_State* LuaInterface::GetSpawnScript(const char* name, bool create_new, bool use) {
  1406. if (spawn_scripts_reloading)
  1407. return 0;
  1408. map<string, map<lua_State*, bool> >::iterator itr;
  1409. map<lua_State*, bool>::iterator spawn_script_itr;
  1410. lua_State* ret = 0;
  1411. Mutex* mutex = 0;
  1412. itr = spawn_scripts.find(name);
  1413. if(itr != spawn_scripts.end()) {
  1414. mutex = GetSpawnScriptMutex(name);
  1415. mutex->readlock(__FUNCTION__, __LINE__);
  1416. for(spawn_script_itr = itr->second.begin(); spawn_script_itr != itr->second.end(); spawn_script_itr++){
  1417. if(!spawn_script_itr->second){ //not in use
  1418. ret = spawn_script_itr->first;
  1419. if (use)
  1420. {
  1421. spawn_script_itr->second = true;
  1422. break; // don't keep iterating, we already have our result
  1423. }
  1424. }
  1425. }
  1426. mutex->releasereadlock(__FUNCTION__, __LINE__);
  1427. }
  1428. if(!ret && create_new){
  1429. if(name && LoadSpawnScript(name))
  1430. ret = GetSpawnScript(name, create_new, use);
  1431. else{
  1432. LogError("Error LUA Spawn Script '%s'", name);
  1433. return 0;
  1434. }
  1435. }
  1436. return ret;
  1437. }
  1438. lua_State* LuaInterface::GetZoneScript(const char* name, bool create_new, bool use) {
  1439. map<string, map<lua_State*, bool> >::iterator itr;
  1440. map<lua_State*, bool>::iterator zone_script_itr;
  1441. lua_State* ret = 0;
  1442. Mutex* mutex = 0;
  1443. itr = zone_scripts.find(name);
  1444. if(itr != zone_scripts.end()) {
  1445. mutex = GetZoneScriptMutex(name);
  1446. mutex->readlock(__FUNCTION__, __LINE__);
  1447. for(zone_script_itr = itr->second.begin(); zone_script_itr != itr->second.end(); zone_script_itr++){
  1448. if(!zone_script_itr->second){ //not in use
  1449. ret = zone_script_itr->first;
  1450. if (use)
  1451. {
  1452. zone_script_itr->second = true;
  1453. break; // don't keep iterating, we already have our result
  1454. }
  1455. }
  1456. }
  1457. mutex->releasereadlock(__FUNCTION__, __LINE__);
  1458. }
  1459. if(!ret && create_new){
  1460. if(name && LoadZoneScript(name))
  1461. ret = GetZoneScript(name);
  1462. else{
  1463. LogError("Error LUA Zone Script '%s'", name);
  1464. return 0;
  1465. }
  1466. }
  1467. return ret;
  1468. }
  1469. bool LuaInterface::RunItemScript(string script_name, const char* function_name, Item* item, Spawn* spawn) {
  1470. if(!item)
  1471. return false;
  1472. lua_State* state = GetItemScript(script_name.c_str(), true, true);
  1473. if(state){
  1474. Mutex* mutex = GetItemScriptMutex(script_name.c_str());
  1475. if(mutex)
  1476. mutex->readlock(__FUNCTION__, __LINE__);
  1477. else{
  1478. LogError("Error getting lock for '%s'", script_name.c_str());
  1479. UseItemScript(script_name.c_str(), state, false);
  1480. return false;
  1481. }
  1482. lua_getglobal(state, function_name);
  1483. lua_getglobal(state, function_name);
  1484. if (!lua_isfunction(state, lua_gettop(state))){
  1485. lua_pop(state, 1);
  1486. mutex->releasereadlock(__FUNCTION__);
  1487. UseItemScript(script_name.c_str(), state, false);
  1488. return false;
  1489. }
  1490. SetItemValue(state, item);
  1491. int8 num_parms = 1;
  1492. if(spawn){
  1493. SetSpawnValue(state, spawn);
  1494. num_parms++;
  1495. }
  1496. if(!CallItemScript(state, num_parms)){
  1497. if(mutex)
  1498. mutex->releasereadlock(__FUNCTION__, __LINE__);
  1499. UseItemScript(script_name.c_str(), state, false);
  1500. return false;
  1501. }
  1502. if(mutex)
  1503. mutex->releasereadlock(__FUNCTION__, __LINE__);
  1504. UseItemScript(script_name.c_str(), state, false);
  1505. return true;
  1506. }
  1507. else
  1508. return false;
  1509. }
  1510. bool LuaInterface::RunSpawnScript(string script_name, const char* function_name, Spawn* npc, Spawn* spawn, const char* message) {
  1511. if(!npc || spawn_scripts_reloading)
  1512. return false;
  1513. lua_State* state = GetSpawnScript(script_name.c_str(), true, true);
  1514. if(state){
  1515. Mutex* mutex = GetSpawnScriptMutex(script_name.c_str());
  1516. if(mutex)
  1517. mutex->readlock(__FUNCTION__, __LINE__);
  1518. else{
  1519. LogError("Error getting lock for '%s'", script_name.c_str());
  1520. UseSpawnScript(script_name.c_str(), state, false);
  1521. return false;
  1522. }
  1523. lua_getglobal(state, function_name);
  1524. if (!lua_isfunction(state, lua_gettop(state))){
  1525. lua_pop(state, 1);
  1526. mutex->releasereadlock(__FUNCTION__);
  1527. UseSpawnScript(script_name.c_str(), state, false);
  1528. return false;
  1529. }
  1530. SetSpawnValue(state, npc);
  1531. int8 num_parms = 1;
  1532. if(spawn){
  1533. SetSpawnValue(state, spawn);
  1534. num_parms++;
  1535. }
  1536. if(message){
  1537. SetStringValue(state, message);
  1538. num_parms++;
  1539. }
  1540. if(!CallSpawnScript(state, num_parms)){
  1541. if(mutex)
  1542. mutex->releasereadlock(__FUNCTION__, __LINE__);
  1543. UseSpawnScript(script_name.c_str(), state, false);
  1544. return false;
  1545. }
  1546. if(mutex)
  1547. mutex->releasereadlock(__FUNCTION__, __LINE__);
  1548. UseSpawnScript(script_name.c_str(), state, false);
  1549. return true;
  1550. }
  1551. else
  1552. return false;
  1553. }
  1554. bool LuaInterface::RunZoneScript(string script_name, const char* function_name, ZoneServer* zone, Spawn* spawn, int32 grid_id, const char* signal) {
  1555. if (!zone)
  1556. return false;
  1557. lua_State* state = GetZoneScript(script_name.c_str(), true, true);
  1558. if (state) {
  1559. Mutex* mutex = GetZoneScriptMutex(script_name.c_str());
  1560. if (mutex)
  1561. mutex->readlock(__FUNCTION__, __LINE__);
  1562. else {
  1563. LogError("Error getting lock for '%s'", script_name.c_str());
  1564. UseZoneScript(script_name.c_str(), state, false);
  1565. return false;
  1566. }
  1567. lua_getglobal(state, function_name);
  1568. if (!lua_isfunction(state, lua_gettop(state))) {
  1569. lua_pop(state, 1);
  1570. mutex->releasereadlock(__FUNCTION__);
  1571. UseZoneScript(script_name.c_str(), state, false);
  1572. return false;
  1573. }
  1574. SetZoneValue(state, zone);
  1575. int8 num_params = 1;
  1576. if (spawn) {
  1577. SetSpawnValue(state, spawn);
  1578. num_params++;
  1579. }
  1580. if (grid_id > 0) {
  1581. SetInt32Value(state, grid_id);
  1582. num_params++;
  1583. }
  1584. if (signal) {
  1585. SetStringValue(state, signal);
  1586. num_params++;
  1587. }
  1588. if (!CallZoneScript(state, num_params)) {
  1589. if (mutex)
  1590. mutex->releasereadlock(__FUNCTION__, __LINE__);
  1591. UseZoneScript(script_name.c_str(), state, false);
  1592. return false;
  1593. }
  1594. if (mutex)
  1595. mutex->releasereadlock(__FUNCTION__, __LINE__);
  1596. UseZoneScript(script_name.c_str(), state, false);
  1597. return true;
  1598. }
  1599. else
  1600. return false;
  1601. }
  1602. void LuaInterface::AddPendingSpellDelete(LuaSpell* spell) {
  1603. MSpellDelete.lock();
  1604. if ( spells_pending_delete.count(spell) == 0 )
  1605. spells_pending_delete[spell] = Timer::GetCurrentTime2() + 10000;
  1606. MSpellDelete.unlock();
  1607. }
  1608. LUAUserData::LUAUserData(){
  1609. correctly_initialized = false;
  1610. quest = 0;
  1611. conversation_options = 0;
  1612. spawn = 0;
  1613. zone = 0;
  1614. skill = 0;
  1615. option_window_option = 0;
  1616. item = 0;
  1617. }
  1618. bool LUAUserData::IsCorrectlyInitialized(){
  1619. return correctly_initialized;
  1620. }
  1621. bool LUAUserData::IsConversationOption(){
  1622. return false;
  1623. }
  1624. bool LUAUserData::IsOptionWindow() {
  1625. return false;
  1626. }
  1627. bool LUAUserData::IsSpawn(){
  1628. return false;
  1629. }
  1630. bool LUAUserData::IsQuest(){
  1631. return false;
  1632. }
  1633. bool LUAUserData::IsZone(){
  1634. return false;
  1635. }
  1636. bool LUAUserData::IsItem(){
  1637. return false;
  1638. }
  1639. bool LUAUserData::IsSkill() {
  1640. return false;
  1641. }
  1642. LUAConversationOptionWrapper::LUAConversationOptionWrapper(){
  1643. correctly_initialized = true;
  1644. }
  1645. bool LUAConversationOptionWrapper::IsConversationOption(){
  1646. return true;
  1647. }
  1648. LUAOptionWindowWrapper::LUAOptionWindowWrapper() {
  1649. correctly_initialized = true;
  1650. }
  1651. bool LUAOptionWindowWrapper::IsOptionWindow() {
  1652. return true;
  1653. }
  1654. LUASpawnWrapper::LUASpawnWrapper(){
  1655. correctly_initialized = true;
  1656. }
  1657. bool LUASpawnWrapper::IsSpawn(){
  1658. return true;
  1659. }
  1660. LUAZoneWrapper::LUAZoneWrapper(){
  1661. correctly_initialized = true;
  1662. }
  1663. bool LUAZoneWrapper::IsZone(){
  1664. return true;
  1665. }
  1666. LUAQuestWrapper::LUAQuestWrapper(){
  1667. correctly_initialized = true;
  1668. }
  1669. bool LUAQuestWrapper::IsQuest(){
  1670. return true;
  1671. }
  1672. LUAItemWrapper::LUAItemWrapper(){
  1673. correctly_initialized = true;
  1674. }
  1675. bool LUAItemWrapper::IsItem(){
  1676. return true;
  1677. }
  1678. LUASkillWrapper::LUASkillWrapper() {
  1679. correctly_initialized = true;
  1680. }
  1681. bool LUASkillWrapper::IsSkill() {
  1682. return true;
  1683. }