1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719 |
- /*
- EQ2Emulator: Everquest II Server Emulator
- Copyright (C) 2007 EQ2EMulator Development Team (http://www.eq2emulator.net)
- This file is part of EQ2Emulator.
- EQ2Emulator is free software: you can redistribute it and/or modify
- it under the terms of the GNU General Public License as published by
- the Free Software Foundation, either version 3 of the License, or
- (at your option) any later version.
- EQ2Emulator is distributed in the hope that it will be useful,
- but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU General Public License for more details.
- You should have received a copy of the GNU General Public License
- along with EQ2Emulator. If not, see <http://www.gnu.org/licenses/>.
- */
- #include "LuaInterface.h"
- #include "LuaFunctions.h"
- #include "WorldDatabase.h"
- #include "SpellProcess.h"
- #include "../common/Log.h"
- #include "World.h"
- #ifndef WIN32
- #include <stdio.h>
- #include <sys/types.h>
- #include <sys/stat.h>
- #include <dirent.h>
- #include <pthread.h>
- #else
- #include <process.h>
- #endif
- extern WorldDatabase database;
- extern ZoneList zone_list;
- LuaInterface::LuaInterface() {
- shutting_down = false;
- lua_system_reloading = false;
- MDebugClients.SetName("LuaInterface::MDebugClients");
- MSpells.SetName("LuaInterface::MSpells");
- MSpawnScripts.SetName("LuaInterface::MSpawnScripts");
- MZoneScripts.SetName("LuaInterface::MZoneScripts");
- MQuests.SetName("LuaInterface::MQuests");
- MLUAMain.SetName("LuaInterface::MLUAMain");
- MItemScripts.SetName("LuaInterface::MItemScripts");
- MSpellDelete.SetName("LuaInterface::MSpellDelete");
- MCustomSpell.SetName("LuaInterface::MCustomSpell");
- MRegionScripts.SetName("LuaInterface::MRegionScripts");
- user_data_timer = new Timer(20000);
- user_data_timer->Start();
- spell_delete_timer = new Timer(5000);
- spell_delete_timer->Start();
- }
- #ifdef WIN32
- vector<string>* LuaInterface::GetDirectoryListing(const char* directory) {
- vector<string>* ret = new vector<string>;
- WIN32_FIND_DATA fdata;
- HANDLE dhandle;
- char buf[MAX_PATH];
- snprintf(buf, sizeof(buf), "%s\\*", directory);
- if((dhandle = FindFirstFile(buf, &fdata)) == INVALID_HANDLE_VALUE) {
- safe_delete(ret);
- return 0;
- }
- ret->push_back(string(fdata.cFileName));
- while(1) {
- if(FindNextFile(dhandle, &fdata)) {
- ret->push_back(string(fdata.cFileName));
- }
- else{
- if(GetLastError() == ERROR_NO_MORE_FILES) {
- break;
- } else {
- safe_delete(ret);
- FindClose(dhandle);
- return 0;
- }
- }
- }
- if(FindClose(dhandle) == 0) {
- safe_delete(ret);
- return 0;
- }
- return ret;
- }
- #else
- vector<string>* LuaInterface::GetDirectoryListing(const char* directory) {
- vector<string>* ret = new vector<string>;
- DIR *dp;
- struct dirent *ep;
- dp = opendir (directory);
- if (dp != NULL){
- while ((ep = readdir (dp)))
- ret->push_back(string(ep->d_name));
- (void) closedir (dp);
- }
- else {
- safe_delete(ret);
- return 0;
- }
- return ret;
- }
- #endif
- LuaInterface::~LuaInterface() {
- shutting_down = true;
- MLUAMain.lock();
- DestroySpells();
- DestroySpawnScripts();
- DestroyQuests();
- DestroyItemScripts();
- DestroyZoneScripts();
- DestroyRegionScripts();
- DeleteUserDataPtrs(true);
- DeletePendingSpells(true);
- safe_delete(user_data_timer);
- safe_delete(spell_delete_timer);
- MLUAMain.unlock();
- }
- int LuaInterface::GetNumberOfArgs(lua_State* state) {
- return lua_gettop(state);
- }
- void LuaInterface::Process() {
- if(shutting_down)
- return;
- MLUAMain.lock();
- if(user_data_timer && user_data_timer->Check())
- DeleteUserDataPtrs(false);
- if(spell_delete_timer && spell_delete_timer->Check())
- DeletePendingSpells(false);
- MLUAMain.unlock();
- }
- void LuaInterface::DestroySpells() {
- map<string, LuaSpell*>::iterator itr;
- MSpells.lock();
- for(itr = spells.begin(); itr != spells.end(); itr++){
- lua_close(itr->second->state);
- safe_delete(itr->second);
- }
- spells.clear();
- MSpells.unlock();
- }
- void LuaInterface::DestroyQuests(bool reload) {
- map<int32, lua_State*>::iterator itr;
- MQuests.lock();
- for(itr = quest_states.begin(); itr != quest_states.end(); itr++){
- safe_delete(quests[itr->first]);
- lua_close(itr->second);
- }
- quests.clear();
- quest_states.clear();
- map<int32, Mutex*>::iterator mutex_itr;
- for(mutex_itr = quests_mutex.begin(); mutex_itr != quests_mutex.end(); mutex_itr++){
- safe_delete(mutex_itr->second);
- }
- quests_mutex.clear();
- if(reload)
- database.LoadQuests();
- MQuests.unlock();
- }
- void LuaInterface::DestroyItemScripts() {
- map<string, map<lua_State*, bool> >::iterator itr;
- map<lua_State*, bool>::iterator state_itr;
- Mutex* mutex = 0;
- MItemScripts.writelock(__FUNCTION__, __LINE__);
- for(itr = item_scripts.begin(); itr != item_scripts.end(); itr++){
- mutex = GetItemScriptMutex(itr->first.c_str());
- mutex->writelock(__FUNCTION__, __LINE__);
- for(state_itr = itr->second.begin(); state_itr != itr->second.end(); state_itr++)
- lua_close(state_itr->first);
- mutex->releasewritelock(__FUNCTION__, __LINE__);
- safe_delete(mutex);
- }
- item_scripts.clear();
- item_inverse_scripts.clear();
- item_scripts_mutex.clear();
- MItemScripts.releasewritelock(__FUNCTION__, __LINE__);
- }
- void LuaInterface::DestroySpawnScripts() {
- map<string, map<lua_State*, bool> >::iterator itr;
- map<lua_State*, bool>::iterator state_itr;
- Mutex* mutex = 0;
- MSpawnScripts.writelock(__FUNCTION__, __LINE__);
- for(itr = spawn_scripts.begin(); itr != spawn_scripts.end(); itr++){
- mutex = GetSpawnScriptMutex(itr->first.c_str());
- mutex->writelock(__FUNCTION__, __LINE__);
- for(state_itr = itr->second.begin(); state_itr != itr->second.end(); state_itr++)
- lua_close(state_itr->first);
- mutex->releasewritelock(__FUNCTION__, __LINE__);
- safe_delete(mutex);
- }
- spawn_scripts.clear();
- spawn_inverse_scripts.clear();
- spawn_scripts_mutex.clear();
- MSpawnScripts.releasewritelock(__FUNCTION__, __LINE__);
- }
- void LuaInterface::DestroyZoneScripts() {
- map<string, map<lua_State*, bool> >::iterator itr;
- map<lua_State*, bool>::iterator state_itr;
- Mutex* mutex = 0;
- MZoneScripts.writelock(__FUNCTION__, __LINE__);
- for (itr = zone_scripts.begin(); itr != zone_scripts.end(); itr++){
- mutex = GetZoneScriptMutex(itr->first.c_str());
- mutex->writelock(__FUNCTION__, __LINE__);
- for(state_itr = itr->second.begin(); state_itr != itr->second.end(); state_itr++)
- lua_close(state_itr->first);
- mutex->releasewritelock(__FUNCTION__, __LINE__);
- safe_delete(mutex);
- }
- zone_scripts.clear();
- zone_inverse_scripts.clear();
- zone_scripts_mutex.clear();
- MZoneScripts.releasewritelock(__FUNCTION__, __LINE__);
- }
- void LuaInterface::DestroyRegionScripts() {
- map<string, map<lua_State*, bool> >::iterator itr;
- map<lua_State*, bool>::iterator state_itr;
- Mutex* mutex = 0;
- MRegionScripts.writelock(__FUNCTION__, __LINE__);
- for (itr = region_scripts.begin(); itr != region_scripts.end(); itr++){
- mutex = GetRegionScriptMutex(itr->first.c_str());
- mutex->writelock(__FUNCTION__, __LINE__);
- for(state_itr = itr->second.begin(); state_itr != itr->second.end(); state_itr++)
- lua_close(state_itr->first);
- mutex->releasewritelock(__FUNCTION__, __LINE__);
- safe_delete(mutex);
- }
- region_scripts.clear();
- region_inverse_scripts.clear();
- region_scripts_mutex.clear();
- MRegionScripts.releasewritelock(__FUNCTION__, __LINE__);
- }
- void LuaInterface::ReloadSpells() {
- DestroySpells();
- database.LoadSpellScriptData();
- }
- bool LuaInterface::LoadLuaSpell(const char* name) {
- LuaSpell* spell = 0;
- string lua_script = string(name);
- if (lua_script.find(".lua") == string::npos)
- lua_script.append(".lua");
- lua_State* state = LoadLuaFile(lua_script.c_str());
- if(state){
- spell = new LuaSpell;
- spell->file_name = lua_script;
- spell->state = state;
- spell->spell = 0;
- spell->caster = 0;
- spell->initial_target = 0;
- spell->resisted = false;
- spell->interrupted = false;
- spell->last_spellattack_hit = false;
- spell->crit = false;
- spell->MSpellTargets.SetName("LuaSpell.MSpellTargets");
- spell->cancel_after_all_triggers = false;
- spell->num_triggers = 0;
- spell->num_calls = 0;
- spell->is_recast_timer = false;
- spell->had_triggers = false;
- spell->had_dmg_remaining = false;
- spell->slot_pos = 0;
- spell->damage_remaining = 0;
- spell->effect_bitmask = 0;
- spell->restored = false;
- spell->initial_caster_char_id = 0;
- spell->initial_target_char_id = 0;
- MSpells.lock();
- if (spells.count(lua_script) > 0) {
- lua_close(spells[lua_script]->state);
- safe_delete(spells[lua_script]);
- }
- spells[lua_script] = spell;
- MSpells.unlock();
- return true;
- }
- return false;
- }
- bool LuaInterface::LoadLuaSpell(string name) {
- return LoadLuaSpell(name.c_str());
- }
- bool LuaInterface::LoadItemScript(string name) {
- return LoadItemScript(name.c_str());
- }
- bool LuaInterface::LoadItemScript(const char* name) {
- bool ret = false;
- if(name){
- lua_State* state = LoadLuaFile(name);
- if(state){
- MItemScripts.writelock(__FUNCTION__, __LINE__);
- item_scripts[name][state] = false;
- MItemScripts.releasewritelock(__FUNCTION__, __LINE__);
- ret = true;
- }
- }
- return ret;
- }
- bool LuaInterface::LoadSpawnScript(const char* name) {
- bool ret = false;
- if(name){
- lua_State* state = LoadLuaFile(name);
- if(state){
- MSpawnScripts.writelock(__FUNCTION__, __LINE__);
- spawn_scripts[name][state] = false;
- MSpawnScripts.releasewritelock(__FUNCTION__, __LINE__);
- ret = true;
- }
- }
- return ret;
- }
- bool LuaInterface::LoadZoneScript(const char* name) {
- bool ret = false;
- if (name) {
- lua_State* state = LoadLuaFile(name);
- if (state) {
- MZoneScripts.writelock(__FUNCTION__, __LINE__);
- zone_scripts[name][state] = false;
- MZoneScripts.releasewritelock(__FUNCTION__, __LINE__);
- ret = true;
- }
- }
- return ret;
- }
- bool LuaInterface::LoadRegionScript(const char* name) {
- bool ret = false;
- if (name) {
- lua_State* state = LoadLuaFile(name);
- if (state) {
- MRegionScripts.writelock(__FUNCTION__, __LINE__);
- region_scripts[name][state] = false;
- MRegionScripts.releasewritelock(__FUNCTION__, __LINE__);
- ret = true;
- }
- }
- return ret;
- }
- void LuaInterface::ProcessErrorMessage(const char* message) {
- MDebugClients.lock();
- vector<Client*> delete_clients;
- map<Client*, int32>::iterator itr;
- for(itr = debug_clients.begin(); itr != debug_clients.end(); itr++){
- if((Timer::GetCurrentTime2() - itr->second) > 60000)
- delete_clients.push_back(itr->first);
- else
- itr->first->Message(CHANNEL_COLOR_RED, "LUA Error: %s", message);
- }
- for(int32 i=0;i<delete_clients.size();i++)
- debug_clients.erase(delete_clients[i]);
- MDebugClients.unlock();
- }
- void LuaInterface::RemoveDebugClients(Client* client) {
- MDebugClients.lock();
- debug_clients.erase(client);
- MDebugClients.unlock();
- }
- void LuaInterface::UpdateDebugClients(Client* client) {
- MDebugClients.lock();
- debug_clients[client] = Timer::GetCurrentTime2();
- MDebugClients.unlock();
- }
- Mutex* LuaInterface::GetQuestMutex(Quest* quest) {
- Mutex* ret = 0;
- MQuests.lock();
- if(quests_mutex.count(quest->GetQuestID()) == 0){
- ret = new Mutex();
- quests_mutex[quest->GetQuestID()] = ret;
- ret->SetName(string("Quest::").append(quest->GetName()));
- }
- else
- ret = quests_mutex[quest->GetQuestID()];
- MQuests.unlock();
- return ret;
- }
- bool LuaInterface::CallQuestFunction(Quest* quest, const char* function, Spawn* player, int32 step_id, int32* returnValue) {
- if(shutting_down)
- return false;
- lua_State* state = 0;
- if(quest){
- LogWrite(LUA__DEBUG, 0, "LUA", "Quest: %s, function: %s", quest->GetName(), function);
- Mutex* mutex = GetQuestMutex(quest);
- mutex->readlock(__FUNCTION__, __LINE__);
- if(quest_states.count(quest->GetQuestID()) > 0)
- state = quest_states[quest->GetQuestID()];
- bool success = false; // if no state then we return false
- if(state){
- int8 arg_count = 3;
- lua_getglobal(state, function);
-
- if (!lua_isfunction(state, lua_gettop(state))){
- lua_pop(state, 1);
- mutex->releasereadlock(__FUNCTION__);
- return false;
- }
-
- SetQuestValue(state, quest);
- Spawn* spawn = player->GetZone()->GetSpawnByDatabaseID(quest->GetQuestGiver());
- SetSpawnValue(state, spawn);
- SetSpawnValue(state, player);
- if(step_id != 0xFFFFFFFF){
- SetInt32Value(state, step_id);
- arg_count++;
- }
-
- success = CallScriptInt32(state, arg_count, returnValue);
- }
- mutex->releasereadlock(__FUNCTION__, __LINE__);
- LogWrite(LUA__DEBUG, 0, "LUA", "Done!");
- return success;
- }
- return false;
- }
- Quest* LuaInterface::LoadQuest(int32 id, const char* name, const char* type, const char* zone, int8 level, const char* description, char* script_name) {
- if(shutting_down)
- return 0;
- lua_State* state = LoadLuaFile(script_name);
- Quest* quest = 0;
- if(state){
- quest = new Quest(id);
- if (name)
- quest->SetName(string(name));
- if (type)
- quest->SetType(string(type));
- if (zone)
- quest->SetZone(string(zone));
- quest->SetLevel(level);
- if (description)
- quest->SetDescription(string(description));
- lua_getglobal(state, "Init");
- SetQuestValue(state, quest);
- if(lua_pcall(state, 1, 0, 0) != 0){
- LogError("Error processing Quest \"%s\" (%u): %s", name ? name : "unknown", id, lua_tostring(state, -1));
- lua_pop(state, 1);
- SetLuaUserDataStale(quest);
- safe_delete(quest);
- return 0;
- }
- if(!quest->GetName()){
- SetLuaUserDataStale(quest);
- safe_delete(quest);
- return 0;
- }
- quest_states[id] = state;
- quests[id] = quest;
- }
- return quest;
- }
- const char* LuaInterface::GetScriptName(lua_State* state)
- {
- map<lua_State*, string>::iterator itr;
- MItemScripts.writelock(__FUNCTION__, __LINE__);
- itr = item_inverse_scripts.find(state);
- if (itr != item_inverse_scripts.end())
- {
- const char* scriptName = itr->second.c_str();
- MItemScripts.releasewritelock(__FUNCTION__, __LINE__);
- return scriptName;
- }
- MItemScripts.releasewritelock(__FUNCTION__, __LINE__);
- MSpawnScripts.writelock(__FUNCTION__, __LINE__);
- itr = spawn_inverse_scripts.find(state);
- if (itr != spawn_inverse_scripts.end())
- {
- const char* scriptName = itr->second.c_str();
- MSpawnScripts.releasewritelock(__FUNCTION__, __LINE__);
- return scriptName;
- }
- MSpawnScripts.releasewritelock(__FUNCTION__, __LINE__);
- MZoneScripts.writelock(__FUNCTION__, __LINE__);
- itr = zone_inverse_scripts.find(state);
- if (itr != zone_inverse_scripts.end())
- {
- const char* scriptName = itr->second.c_str();
- MZoneScripts.releasewritelock(__FUNCTION__, __LINE__);
- return scriptName;
- }
- MZoneScripts.releasewritelock(__FUNCTION__, __LINE__);
-
- MRegionScripts.writelock(__FUNCTION__, __LINE__);
- itr = region_inverse_scripts.find(state);
- if (itr != region_inverse_scripts.end())
- {
- const char* scriptName = itr->second.c_str();
- MRegionScripts.releasewritelock(__FUNCTION__, __LINE__);
- return scriptName;
- }
- MRegionScripts.releasewritelock(__FUNCTION__, __LINE__);
- MSpells.lock();
- LuaSpell* spell = GetCurrentSpell(state);
- if (spell)
- {
- const char* fileName = (spell->file_name.length() > 0) ? spell->file_name.c_str() : "";
- MSpells.unlock();
- return fileName;
- }
- MSpells.unlock();
- return "";
- }
- bool LuaInterface::LoadSpawnScript(string name) {
- return LoadSpawnScript(name.c_str());
- }
- bool LuaInterface::LoadZoneScript(string name) {
- return LoadZoneScript(name.c_str());
- }
- bool LuaInterface::LoadRegionScript(string name) {
- return LoadRegionScript(name.c_str());
- }
- std::string LuaInterface::AddSpawnPointers(LuaSpell* spell, bool first_cast, bool precast, const char* function, SpellScriptTimer* timer, bool passLuaSpell, Spawn* altTarget) {
- std::string functionCalled = string("");
- if (function)
- {
- functionCalled = string(function);
- lua_getglobal(spell->state, function);
- }
- else if (precast)
- {
- functionCalled = "precast";
- lua_getglobal(spell->state, "precast");
- }
- else if(first_cast)
- {
- functionCalled = "cast";
- lua_getglobal(spell->state, "cast");
- }
- else
- {
- functionCalled = "tick";
- lua_getglobal(spell->state, "tick");
- }
- if(passLuaSpell)
- SetSpellValue(spell->state, spell);
- Spawn* temp_spawn = 0;
- if (timer && timer->caster && spell->caster)
- temp_spawn = spell->caster->GetZone()->GetSpawnByID(timer->caster);
- if (temp_spawn)
- SetSpawnValue(spell->state, temp_spawn);
- else if (spell->caster)
- SetSpawnValue(spell->state, spell->caster);
- temp_spawn = 0;
- if (timer && timer->target && spell->caster)
- temp_spawn = spell->caster->GetZone()->GetSpawnByID(timer->target);
- if (temp_spawn)
- SetSpawnValue(spell->state, temp_spawn);
- else {
- if(altTarget)
- {
- SetSpawnValue(spell->state, altTarget);
- }
- else if(spell->caster && spell->caster->GetZone() != nullptr && spell->initial_target)
- {
- // easier to debug target id as ptr
- Spawn* new_target = spell->caster->GetZone()->GetSpawnByID(spell->initial_target);
- SetSpawnValue(spell->state, new_target);
- }
- else if(spell->caster && spell->caster->GetTarget())
- SetSpawnValue(spell->state, spell->caster->GetTarget());
- else
- SetSpawnValue(spell->state, 0);
- }
- return functionCalled;
- }
- LuaSpell* LuaInterface::GetCurrentSpell(lua_State* state) {
- if(current_spells.count(state) > 0)
- return current_spells[state];
- return 0;
- }
- bool LuaInterface::CallSpellProcess(LuaSpell* spell, int8 num_parameters, std::string customFunction) {
- if(shutting_down || !spell || !spell->caster)
- return false;
- MSpells.lock();
- current_spells[spell->state] = spell;
- MSpells.unlock();
- if(lua_pcall(spell->state, num_parameters, 0, 0) != 0){
- LogError("Error running function '%s' in %s: %s", customFunction.c_str(), spell->spell->GetName(), lua_tostring(spell->state, -1));
- lua_pop(spell->state, 1);
- RemoveSpell(spell, false); // may be in a lock
- return false;
- }
- return true;
- }
- void LuaInterface::RemoveSpawnScript(const char* name) {
- lua_State* state = 0;
- Mutex* mutex = GetSpawnScriptMutex(name);
- while((state = GetSpawnScript(name, false))){
- mutex->writelock(__FUNCTION__, __LINE__);
- lua_close(state);
- spawn_scripts[name].erase(state);
- mutex->releasewritelock(__FUNCTION__, __LINE__);
- }
- MSpawnScripts.writelock(__FUNCTION__, __LINE__);
- spawn_scripts.erase(name);
- MSpawnScripts.releasewritelock(__FUNCTION__, __LINE__);
- }
- bool LuaInterface::CallItemScript(lua_State* state, int8 num_parameters, std::string* returnValue) {
- if(shutting_down)
- return false;
- if(!state || lua_pcall(state, num_parameters, 1, 0) != 0){
- if (state){
- const char* err = lua_tostring(state, -1);
- LogError("%s: %s", GetScriptName(state), err);
- lua_pop(state, 1);
- }
- return false;
- }
- std::string result = std::string("");
-
- if(lua_isstring(state, -1)){
- size_t size = 0;
- const char* str = lua_tolstring(state, -1, &size);
- if(str)
- result = string(str);
- }
-
- if(returnValue)
- *returnValue = std::string(result);
-
- return true;
- }
- bool LuaInterface::CallItemScript(lua_State* state, int8 num_parameters, sint64* returnValue) {
- if(shutting_down)
- return false;
- if(!state || lua_pcall(state, num_parameters, 1, 0) != 0){
- if (state){
- const char* err = lua_tostring(state, -1);
- LogError("%s: %s", GetScriptName(state), err);
- lua_pop(state, 1);
- }
- return false;
- }
- sint64 result = 0;
-
- if (lua_isnumber(state, -1))
- {
- result = (sint64)lua_tonumber(state, -1);
- lua_pop(state, 1);
- }
-
- if(returnValue)
- *returnValue = result;
-
- return true;
- }
- bool LuaInterface::CallSpawnScript(lua_State* state, int8 num_parameters) {
- if(shutting_down || lua_system_reloading)
- return false;
- if(!state || lua_pcall(state, num_parameters, 0, 0) != 0){
- if (state){
- const char* err = lua_tostring(state, -1);
- LogError("%s: %s", GetScriptName(state), err);
- lua_pop(state, 1);
- }
- return false;
- }
- return true;
- }
- bool LuaInterface::CallScriptInt32(lua_State* state, int8 num_parameters, int32* returnValue) {
- if(shutting_down)
- return false;
- if (!state || lua_pcall(state, num_parameters, 1, 0) != 0) {
- if (state){
- const char* err = lua_tostring(state, -1);
- LogError("%s: %s", GetScriptName(state), err);
- lua_pop(state, 1);
- }
- return false;
- }
-
- int32 result = 0;
-
- if (lua_isnumber(state, -1))
- {
- result = (int32)lua_tonumber(state, -1);
- lua_pop(state, 1);
- }
-
- if(returnValue)
- *returnValue = result;
-
- return true;
- }
- bool LuaInterface::CallScriptSInt32(lua_State* state, int8 num_parameters, sint32* returnValue) {
- if(shutting_down)
- return false;
- if (!state || lua_pcall(state, num_parameters, 1, 0) != 0) {
- if (state){
- const char* err = lua_tostring(state, -1);
- LogError("%s: %s", GetScriptName(state), err);
- lua_pop(state, 1);
- }
- return false;
- }
-
- sint32 result = 0;
-
- if (lua_isnumber(state, -1))
- {
- result = (sint32)lua_tointeger(state, -1);
- lua_pop(state, 1);
- }
-
- if(returnValue)
- *returnValue = result;
-
- return true;
- }
- bool LuaInterface::CallRegionScript(lua_State* state, int8 num_parameters, int32* returnValue) {
- if(shutting_down)
- return false;
- if (!state || lua_pcall(state, num_parameters, 1, 0) != 0) {
- if (state){
- const char* err = lua_tostring(state, -1);
- LogError("%s: %s", GetScriptName(state), err);
- lua_pop(state, 1);
- }
- return false;
- }
-
- int32 result = 0;
-
- if (lua_isnumber(state, -1))
- {
- result = (int32)lua_tonumber(state, -1);
- lua_pop(state, 1);
- }
-
- if(returnValue)
- *returnValue = result;
-
- return true;
- }
- lua_State* LuaInterface::LoadLuaFile(const char* name) {
- if(shutting_down)
- return 0;
- lua_State* state = luaL_newstate();
- luaL_openlibs(state);
- if(luaL_dofile(state, name) == 0){
- RegisterFunctions(state);
- return state;
- }
- else{
- LogError("Error loading %s (file name: '%s')", lua_tostring(state, -1), name);
- lua_pop(state, 1);
- lua_close(state);
- }
- return 0;
- }
- void LuaInterface::RemoveSpell(LuaSpell* spell, bool call_remove_function, bool can_delete, string reason, bool removing_all_spells) {
- if(shutting_down)
- return;
- if(call_remove_function){
- lua_getglobal(spell->state, "remove");
- LUASpawnWrapper* spawn_wrapper = new LUASpawnWrapper();
- spawn_wrapper->spawn = spell->caster;
- AddUserDataPtr(spawn_wrapper, spawn_wrapper->spawn);
- lua_pushlightuserdata(spell->state, spawn_wrapper);
- if(spell->caster && (spell->initial_target || spell->caster->GetTarget())){
- spawn_wrapper = new LUASpawnWrapper();
- if(!spell->initial_target)
- spawn_wrapper->spawn = spell->caster->GetTarget();
- else
- spawn_wrapper->spawn = spell->caster->GetZone()->GetSpawnByID(spell->initial_target);
- AddUserDataPtr(spawn_wrapper, spawn_wrapper->spawn);
- lua_pushlightuserdata(spell->state, spawn_wrapper);
- }
- else
- lua_pushlightuserdata(spell->state, 0);
- if (spell->caster && !spell->caster->Alive())
- reason = "dead";
- lua_pushstring(spell->state, (char*)reason.c_str());
- MSpells.lock();
- current_spells[spell->state] = spell;
- MSpells.unlock();
- lua_pcall(spell->state, 3, 0, 0);
- ResetFunctionStack(spell->state);
- }
-
- spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
- if(spell->caster) {
- for (int8 i = 0; i < spell->targets.size(); i++) {
- Spawn* target = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
- if (!target || !target->IsEntity())
- continue;
- ((Entity*)target)->RemoveProc(0, spell);
- ((Entity*)target)->RemoveSpellEffect(spell);
- ((Entity*)target)->RemoveSpellBonus(spell);
- }
- }
- multimap<int32,int8>::iterator entries;
- for(entries = spell->char_id_targets.begin(); entries != spell->char_id_targets.end(); entries++)
- {
- Client* tmpClient = zone_list.GetClientByCharID(entries->first);
- if(tmpClient && tmpClient->GetPlayer())
- {
- tmpClient->GetPlayer()->RemoveProc(0, spell);
- tmpClient->GetPlayer()->RemoveSpellEffect(spell);
- tmpClient->GetPlayer()->RemoveSpellBonus(spell);
- }
- }
- spell->char_id_targets.clear(); // TODO: reach out to those clients in different
- spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
- // we need to make sure all memory is purged for a copied spell, its only used once
- if (spell->spell->IsCopiedSpell())
- can_delete = true;
- if (can_delete) {
- AddPendingSpellDelete(spell);
- }
- if (spell->caster)
- {
- spell->caster->GetZone()->GetSpellProcess()->RemoveSpellScriptTimerBySpell(spell);
- spell->caster->RemoveProc(0, spell);
- spell->caster->RemoveMaintainedSpell(spell);
- int8 spell_type = spell->spell->GetSpellData()->spell_type;
- if(spell->caster->IsPlayer() && !removing_all_spells)
- {
- Player* player = (Player*)spell->caster;
- switch(spell_type)
- {
- case SPELL_TYPE_FOOD:
- if(player->get_character_flag(CF_FOOD_AUTO_CONSUME))
- {
- Item* item = player->GetEquipmentList()->GetItem(EQ2_FOOD_SLOT);
- if(item && player->GetClient())
- player->GetClient()->ConsumeFoodDrink(item, EQ2_FOOD_SLOT);
- }
- break;
- case SPELL_TYPE_DRINK:
- if(player->get_character_flag(CF_DRINK_AUTO_CONSUME))
- {
- Item* item = player->GetEquipmentList()->GetItem(EQ2_DRINK_SLOT);
- if(item && player->GetClient())
- player->GetClient()->ConsumeFoodDrink(item, EQ2_DRINK_SLOT);
- }
- break;
- }
- }
- }
- }
- void LuaInterface::RegisterFunctions(lua_State* state) {
- lua_register(state, "SetHP", EQ2Emu_lua_SetCurrentHP);
- lua_register(state, "SetMaxHP", EQ2Emu_lua_SetMaxHP);
- lua_register(state, "SetMaxHPBase", EQ2Emu_lua_SetMaxHPBase);
- lua_register(state, "SetPower", EQ2Emu_lua_SetCurrentPower);
- lua_register(state, "SetMaxPower", EQ2Emu_lua_SetMaxPower);
- lua_register(state, "SetMaxPowerBase", EQ2Emu_lua_SetMaxPowerBase);
- lua_register(state, "SetPosition", EQ2Emu_lua_SetPosition);
- lua_register(state, "SetHeading", EQ2Emu_lua_SetHeading);
- lua_register(state, "SetModelType", EQ2Emu_lua_SetModelType);
- lua_register(state, "SetAdventureClass", EQ2Emu_lua_SetAdventureClass);
- lua_register(state, "SetTradeskillClass", EQ2Emu_lua_SetTradeskillClass);
- lua_register(state, "SetMount", EQ2Emu_lua_SetMount);
- lua_register(state, "SetMountColor", EQ2Emu_lua_SetMountColor);
- lua_register(state, "GetMount", EQ2Emu_lua_GetMount);
- lua_register(state, "GetRace", EQ2Emu_lua_GetRace);
- lua_register(state, "GetRaceName", EQ2Emu_lua_GetRaceName);
- lua_register(state, "GetClass", EQ2Emu_lua_GetClass);
- lua_register(state, "GetClassName", EQ2Emu_lua_GetClassName);
- lua_register(state, "GetArchetypeName", EQ2Emu_lua_GetArchetypeName);
- lua_register(state, "SetSpeed", EQ2Emu_lua_SetSpeed);
- lua_register(state, "ModifyPower", EQ2Emu_lua_ModifyPower);
- lua_register(state, "ModifyHP", EQ2Emu_lua_ModifyHP);
- lua_register(state, "GetDistance", EQ2Emu_lua_GetDistance);
- lua_register(state, "GetHeading", EQ2Emu_lua_GetHeading);
- lua_register(state, "GetLevel", EQ2Emu_lua_GetLevel);
- lua_register(state, "GetHP", EQ2Emu_lua_GetCurrentHP);
- lua_register(state, "GetMaxHP", EQ2Emu_lua_GetMaxHP);
- lua_register(state, "GetMaxHPBase", EQ2Emu_lua_GetMaxHPBase);
- lua_register(state, "GetMaxPower", EQ2Emu_lua_GetMaxPower);
- lua_register(state, "GetMaxPowerBase", EQ2Emu_lua_GetMaxPowerBase);
- lua_register(state, "GetName", EQ2Emu_lua_GetName);
- lua_register(state, "GetPower", EQ2Emu_lua_GetCurrentPower);
- lua_register(state, "GetX", EQ2Emu_lua_GetX);
- lua_register(state, "GetY", EQ2Emu_lua_GetY);
- lua_register(state, "GetZ", EQ2Emu_lua_GetZ);
- lua_register(state, "GetSpawnID", EQ2Emu_lua_GetSpawnID);
- lua_register(state, "GetSpawnGroupID", EQ2Emu_lua_GetSpawnGroupID);
- lua_register(state, "SetSpawnGroupID", EQ2Emu_lua_SetSpawnGroupID);
- lua_register(state, "AddSpawnToGroup", EQ2Emu_lua_AddSpawnToGroup);
- lua_register(state, "GetSpawnLocationID", EQ2Emu_lua_GetSpawnLocationID);
- lua_register(state, "GetSpawnLocationPlacementID", EQ2Emu_lua_GetSpawnLocationPlacementID);
- lua_register(state, "CreateSpawnList", EQ2Emu_lua_CreateSpawnList);
- lua_register(state, "AddSpawnToSpawnList", EQ2Emu_lua_AddSpawnToSpawnList);
- lua_register(state, "RemoveSpawnFromSpawnList", EQ2Emu_lua_RemoveSpawnFromSpawnList);
- lua_register(state, "GetSpawnListBySpawnID", EQ2Emu_lua_GetSpawnListBySpawnID);
- lua_register(state, "GetSpawnListByRailID", EQ2Emu_lua_GetSpawnListByRailID);
- lua_register(state, "GetPassengerSpawnList", EQ2Emu_lua_GetPassengerSpawnList);
- lua_register(state, "GetSpawnFromList", EQ2Emu_lua_GetSpawnFromList);
- lua_register(state, "GetSpawnListSize", EQ2Emu_lua_GetSpawnListSize);
- lua_register(state, "SetFactionID", EQ2Emu_lua_SetFactionID);
- lua_register(state, "GetFactionID", EQ2Emu_lua_GetFactionID);
- lua_register(state, "GetFactionAmount", EQ2Emu_lua_GetFactionAmount);
- lua_register(state, "ChangeFaction", EQ2Emu_lua_ChangeFaction);
- lua_register(state, "GetGender", EQ2Emu_lua_GetGender);
- lua_register(state, "GetTarget", EQ2Emu_lua_GetTarget);
- lua_register(state, "HasFreeSlot", EQ2Emu_lua_HasFreeSlot);
- lua_register(state, "HasItemEquipped", EQ2Emu_lua_HasItemEquipped);
- lua_register(state, "GetEquippedItemByID", EQ2Emu_lua_GetEquippedItemByID);
- lua_register(state, "SetEquippedItemByID", EQ2Emu_lua_SetEquippedItemByID);
- lua_register(state, "SetEquippedItem", EQ2Emu_lua_SetEquippedItem);
- lua_register(state, "UnequipSlot", EQ2Emu_lua_UnequipSlot);
- lua_register(state, "SetEquipment", EQ2Emu_lua_SetEquipment);
- lua_register(state, "GetEquippedItemBySlot", EQ2Emu_lua_GetEquippedItemBySlot);
- lua_register(state, "GetItemByID", EQ2Emu_lua_GetItemByID);
- lua_register(state, "GetItemType", EQ2Emu_lua_GetItemType);
- lua_register(state, "GetItemEffectType", EQ2Emu_lua_GetItemEffectType);
- lua_register(state, "GetSpellName", EQ2Emu_lua_GetSpellName);
- lua_register(state, "PerformCameraShake", EQ2Emu_lua_PerformCameraShake);
- lua_register(state, "GetModelType", EQ2Emu_lua_GetModelType);
- lua_register(state, "GetSpeed", EQ2Emu_lua_GetSpeed);
- lua_register(state, "HasMoved", EQ2Emu_lua_HasMoved);
- lua_register(state, "SpellDamage", EQ2Emu_lua_SpellDamage);
- lua_register(state, "CastSpell", EQ2Emu_lua_CastSpell);
- lua_register(state, "SpellHeal", EQ2Emu_lua_SpellHeal);
- lua_register(state, "SpellHealPct", EQ2Emu_lua_SpellHealPct);
- lua_register(state, "AddItem", EQ2Emu_lua_AddItem);
- lua_register(state, "SummonItem", EQ2Emu_lua_SummonItem);
- lua_register(state, "RemoveItem", EQ2Emu_lua_RemoveItem);
- lua_register(state, "HasItem", EQ2Emu_lua_HasItem);
- lua_register(state, "SpawnMob", EQ2Emu_lua_Spawn);
- lua_register(state, "SummonPet", EQ2Emu_lua_SummonPet);
- lua_register(state, "AddSpawnAccess", EQ2Emu_lua_AddSpawnAccess);
- lua_register(state, "GetZone", EQ2Emu_lua_GetZone);
- lua_register(state, "GetZoneName", EQ2Emu_lua_GetZoneName);
- lua_register(state, "GetZoneID", EQ2Emu_lua_GetZoneID);
- lua_register(state, "Zone", EQ2Emu_lua_Zone);
- lua_register(state, "AddHate", EQ2Emu_lua_AddHate);
- lua_register(state, "IsAlive", EQ2Emu_lua_IsAlive);
- lua_register(state, "IsInCombat", EQ2Emu_lua_IsInCombat);
- lua_register(state, "Attack", EQ2Emu_lua_Attack);
- lua_register(state, "ApplySpellVisual", EQ2Emu_lua_ApplySpellVisual);
-
-
- lua_register(state, "IsPlayer", EQ2Emu_lua_IsPlayer);
- lua_register(state, "GetCharacterID", EQ2Emu_lua_GetCharacterID);
- lua_register(state, "FaceTarget", EQ2Emu_lua_FaceTarget);
- lua_register(state, "MoveToLocation", EQ2Emu_lua_MoveToLocation);
- lua_register(state, "ClearRunningLocations", EQ2Emu_lua_ClearRunningLocations);
- lua_register(state, "Shout", EQ2Emu_lua_Shout);
- lua_register(state, "Say", EQ2Emu_lua_Say);
- lua_register(state, "SayOOC", EQ2Emu_lua_SayOOC);
- lua_register(state, "Emote", EQ2Emu_lua_Emote);
- lua_register(state, "MovementLoopAddLocation", EQ2Emu_lua_MovementLoopAdd); // do not remove this function, it is already heavily used by the content team
- lua_register(state, "MovementLoopAdd", EQ2Emu_lua_MovementLoopAdd);
- // lua_register(state, "GetCurrentZoneSafeLocation", EQ2Emu_lua_GetCurrentZoneSafeLocation); // This is already added below.
- lua_register(state, "AddTimer", EQ2Emu_lua_AddTimer);
- lua_register(state, "StopTimer", EQ2Emu_lua_StopTimer);
- lua_register(state, "Harvest", EQ2Emu_lua_Harvest);
- lua_register(state, "SetAttackable", EQ2Emu_lua_SetAttackable);
-
- lua_register(state, "AddSpellBonus", EQ2Emu_lua_AddSpellBonus);
- lua_register(state, "RemoveSpellBonus", EQ2Emu_lua_RemoveSpellBonus);
- lua_register(state, "AddSkillBonus", EQ2Emu_lua_AddSkillBonus);
- lua_register(state, "RemoveSkillBonus", EQ2Emu_lua_RemoveSkillBonus);
- lua_register(state, "AddControlEffect", EQ2Emu_lua_AddControlEffect);
- lua_register(state, "RemoveControlEffect", EQ2Emu_lua_RemoveControlEffect);
- lua_register(state, "HasControlEffect", EQ2Emu_lua_HasControlEffect);
- lua_register(state, "GetBaseAggroRadius", EQ2Emu_lua_GetBaseAggroRadius);
- lua_register(state, "GetAggroRadius", EQ2Emu_lua_GetAggroRadius);
- lua_register(state, "SetAggroRadius", EQ2Emu_lua_SetAggroRadius);
- lua_register(state, "GetCurrentZoneSafeLocation", EQ2Emu_lua_GetCurrentZoneSafeLocation);
- lua_register(state, "SetDeity", EQ2Emu_lua_SetDeity);
- lua_register(state, "GetDeity", EQ2Emu_lua_GetDeity);
- lua_register(state, "GetInt", EQ2Emu_lua_GetInt);
- lua_register(state, "GetWis", EQ2Emu_lua_GetWis);
- lua_register(state, "GetSta", EQ2Emu_lua_GetSta);
- lua_register(state, "GetStr", EQ2Emu_lua_GetStr);
- lua_register(state, "GetAgi", EQ2Emu_lua_GetAgi);
- lua_register(state, "SetInt", EQ2Emu_lua_SetInt);
- lua_register(state, "SetWis", EQ2Emu_lua_SetWis);
- lua_register(state, "SetSta", EQ2Emu_lua_SetSta);
- lua_register(state, "SetStr", EQ2Emu_lua_SetStr);
- lua_register(state, "SetAgi", EQ2Emu_lua_SetAgi);
- lua_register(state, "GetIntBase", EQ2Emu_lua_GetIntBase);
- lua_register(state, "GetWisBase", EQ2Emu_lua_GetWisBase);
- lua_register(state, "GetStaBase", EQ2Emu_lua_GetStaBase);
- lua_register(state, "GetStrBase", EQ2Emu_lua_GetStrBase);
- lua_register(state, "GetAgiBase", EQ2Emu_lua_GetAgiBase);
- lua_register(state, "SetIntBase", EQ2Emu_lua_SetIntBase);
- lua_register(state, "SetWisBase", EQ2Emu_lua_SetWisBase);
- lua_register(state, "SetStaBase", EQ2Emu_lua_SetStaBase);
- lua_register(state, "SetStrBase", EQ2Emu_lua_SetStrBase);
- lua_register(state, "SetAgiBase", EQ2Emu_lua_SetAgiBase);
- lua_register(state, "GetSpawn", EQ2Emu_lua_GetSpawn);
- lua_register(state, "GetVariableValue", EQ2Emu_lua_GetVariableValue);
- lua_register(state, "GetCoinMessage", EQ2Emu_lua_GetCoinMessage);
- lua_register(state, "GetSpawnByGroupID", EQ2Emu_lua_GetSpawnByGroupID);
- lua_register(state, "GetSpawnByLocationID", EQ2Emu_lua_GetSpawnByLocationID);
- lua_register(state, "PlayFlavor", EQ2Emu_lua_PlayFlavor);
- lua_register(state, "PlayFlavorID", EQ2Emu_lua_PlayFlavorID);
- lua_register(state, "PlaySound", EQ2Emu_lua_PlaySound);
- lua_register(state, "PlayVoice", EQ2Emu_lua_PlayVoice);
- lua_register(state, "PlayAnimation", EQ2Emu_lua_PlayAnimation);
- lua_register(state, "AddLootItem", EQ2Emu_lua_AddLootItem);
- lua_register(state, "HasLootItem", EQ2Emu_lua_HasLootItem);
- lua_register(state, "RemoveLootItem", EQ2Emu_lua_RemoveLootItem);
- lua_register(state, "AddLootCoin", EQ2Emu_lua_AddLootCoin);
- lua_register(state, "GiveLoot", EQ2Emu_lua_GiveLoot);
- lua_register(state, "HasPendingLootItem", EQ2Emu_lua_HasPendingLootItem);
- lua_register(state, "HasPendingLoot", EQ2Emu_lua_HasPendingLoot);
- lua_register(state, "SetLootCoin", EQ2Emu_lua_SetLootCoin);
- lua_register(state, "HasCoin", EQ2Emu_lua_HasCoin);
- lua_register(state, "GetLootCoin", EQ2Emu_lua_GetLootCoin);
- lua_register(state, "SetPlayerProximityFunction", EQ2Emu_lua_SetPlayerProximityFunction);
- lua_register(state, "SetLocationProximityFunction", EQ2Emu_lua_SetLocationProximityFunction);
- lua_register(state, "CreateConversation", EQ2Emu_lua_CreateConversation);
- lua_register(state, "AddConversationOption", EQ2Emu_lua_AddConversationOption);
- lua_register(state, "StartConversation", EQ2Emu_lua_StartConversation);
- lua_register(state, "CloseConversation", EQ2Emu_lua_CloseConversation);
- lua_register(state, "CloseItemConversation", EQ2Emu_lua_CloseItemConversation);
- //lua_register(state, "StartItemConversation", EQ2Emu_lua_StartItemConversation);
- lua_register(state, "StartDialogConversation", EQ2Emu_lua_StartDialogConversation);
- lua_register(state, "SendStateCommand", EQ2Emu_lua_SendStateCommand);
- lua_register(state, "SpawnSet", EQ2Emu_lua_SpawnSet);
- lua_register(state, "SpawnSetByDistance", EQ2Emu_lua_SpawnSetByDistance);
- lua_register(state, "SpawnMove", EQ2Emu_lua_SpawnMove);
- lua_register(state, "KillSpawn", EQ2Emu_lua_KillSpawn);
- lua_register(state, "KillSpawnByDistance", EQ2Emu_lua_KillSpawnByDistance);
- lua_register(state, "Despawn", EQ2Emu_lua_Despawn);
- lua_register(state, "ChangeHandIcon", EQ2Emu_lua_ChangeHandIcon);
- lua_register(state, "SetVisualFlag", EQ2Emu_lua_SetVisualFlag);
- lua_register(state, "SetInfoFlag", EQ2Emu_lua_SetInfoFlag);
- lua_register(state, "IsBindAllowed", EQ2Emu_lua_IsBindAllowed);
- lua_register(state, "IsGateAllowed", EQ2Emu_lua_IsGateAllowed);
- lua_register(state, "Bind", EQ2Emu_lua_Bind);
- lua_register(state, "Gate", EQ2Emu_lua_Gate);
- lua_register(state, "SendMessage", EQ2Emu_lua_SendMessage);
- lua_register(state, "SendPopUpMessage", EQ2Emu_lua_SendPopUpMessage);
- lua_register(state, "SetServerControlFlag", EQ2Emu_lua_SetServerControlFlag);
- lua_register(state, "ToggleTracking", EQ2Emu_lua_ToggleTracking);
- lua_register(state, "AddPrimaryEntityCommand", EQ2Emu_lua_AddPrimaryEntityCommand);
- lua_register(state, "AddSpellBookEntry", EQ2Emu_lua_AddSpellBookEntry);
- lua_register(state, "HasSpell", EQ2Emu_lua_HasSpell);
- lua_register(state, "Interrupt", EQ2Emu_lua_Interrupt);
- lua_register(state, "Stealth", EQ2Emu_lua_Stealth);
- lua_register(state, "IsInvis", EQ2Emu_lua_IsInvis);
- lua_register(state, "IsStealthed", EQ2Emu_lua_IsStealthed);
- lua_register(state, "AddSpawnIDAccess", EQ2Emu_lua_AddSpawnIDAccess);
- lua_register(state, "RemoveSpawnIDAccess", EQ2Emu_lua_RemoveSpawnIDAccess);
- lua_register(state, "HasRecipeBook", EQ2Emu_lua_HasRecipeBook);
- lua_register(state, "SetRequiredQuest", EQ2Emu_lua_SetRequiredQuest);
- lua_register(state, "SetRequiredHistory", EQ2Emu_lua_SetRequiredHistory);
- lua_register(state, "SetStepComplete", EQ2Emu_lua_SetStepComplete);
- lua_register(state, "AddStepProgress", EQ2Emu_lua_AddStepProgress);
- lua_register(state, "UpdateQuestTaskGroupDescription", EQ2Emu_lua_UpdateQuestTaskGroupDescription);
- lua_register(state, "GetTaskGroupStep", EQ2Emu_lua_GetTaskGroupStep);
- lua_register(state, "GetQuestStep", EQ2Emu_lua_GetQuestStep);
- lua_register(state, "QuestStepIsComplete", EQ2Emu_lua_QuestStepIsComplete);
- lua_register(state, "RegisterQuest", EQ2Emu_lua_RegisterQuest);
- lua_register(state, "SetQuestPrereqLevel", EQ2Emu_lua_SetQuestPrereqLevel);
- lua_register(state, "AddQuestPrereqQuest", EQ2Emu_lua_AddQuestPrereqQuest);
- lua_register(state, "AddQuestPrereqItem", EQ2Emu_lua_AddQuestPrereqItem);
- lua_register(state, "AddQuestPrereqFaction", EQ2Emu_lua_AddQuestPrereqFaction);
- lua_register(state, "AddQuestPrereqRace", EQ2Emu_lua_AddQuestPrereqRace);
- lua_register(state, "AddQuestPrereqModelType", EQ2Emu_lua_AddQuestPrereqModelType);
- lua_register(state, "AddQuestPrereqClass", EQ2Emu_lua_AddQuestPrereqClass);
- lua_register(state, "AddQuestPrereqTradeskillLevel", EQ2Emu_lua_AddQuestPrereqTradeskillLevel);
- lua_register(state, "AddQuestPrereqTradeskillClass", EQ2Emu_lua_AddQuestPrereqTradeskillClass);
- lua_register(state, "AddQuestSelectableRewardItem", EQ2Emu_lua_AddQuestSelectableRewardItem);
- lua_register(state, "HasQuestRewardItem", EQ2Emu_lua_HasQuestRewardItem);
- lua_register(state, "AddQuestRewardItem", EQ2Emu_lua_AddQuestRewardItem);
- lua_register(state, "AddQuestRewardCoin", EQ2Emu_lua_AddQuestRewardCoin);
- lua_register(state, "AddQuestRewardFaction", EQ2Emu_lua_AddQuestRewardFaction);
- lua_register(state, "SetQuestRewardStatus", EQ2Emu_lua_SetQuestRewardStatus);
- lua_register(state, "SetStatusTmpReward", EQ2Emu_lua_SetStatusTmpReward);
- lua_register(state, "SetCoinTmpReward", EQ2Emu_lua_SetCoinTmpReward);
- lua_register(state, "SetQuestRewardComment", EQ2Emu_lua_SetQuestRewardComment);
- lua_register(state, "SetQuestRewardExp", EQ2Emu_lua_SetQuestRewardExp);
- lua_register(state, "AddQuestStepKill", EQ2Emu_lua_AddQuestStepKill);
- lua_register(state, "AddQuestStepKillByRace", EQ2Emu_lua_AddQuestStepKillByRace);
- lua_register(state, "AddQuestStep", EQ2Emu_lua_AddQuestStep);
- lua_register(state, "AddQuestStepChat", EQ2Emu_lua_AddQuestStepChat);
- lua_register(state, "AddQuestStepObtainItem", EQ2Emu_lua_AddQuestStepObtainItem);
- lua_register(state, "AddQuestStepZoneLoc", EQ2Emu_lua_AddQuestStepZoneLoc);
- lua_register(state, "AddQuestStepLocation", EQ2Emu_lua_AddQuestStepLocation);
- lua_register(state, "AddQuestStepSpell", EQ2Emu_lua_AddQuestStepSpell);
- lua_register(state, "AddQuestStepCraft", EQ2Emu_lua_AddQuestStepCraft);
- lua_register(state, "AddQuestStepHarvest", EQ2Emu_lua_AddQuestStepHarvest);
- lua_register(state, "AddQuestStepCompleteAction", EQ2Emu_lua_AddQuestStepCompleteAction);
- lua_register(state, "AddQuestStepProgressAction", EQ2Emu_lua_AddQuestStepProgressAction);
- lua_register(state, "SetQuestCompleteAction", EQ2Emu_lua_SetQuestCompleteAction);
- lua_register(state, "GiveQuestReward", EQ2Emu_lua_GiveQuestReward);
- lua_register(state, "UpdateQuestStepDescription", EQ2Emu_lua_UpdateQuestStepDescription);
- lua_register(state, "UpdateQuestDescription", EQ2Emu_lua_UpdateQuestDescription);
- lua_register(state, "UpdateQuestZone", EQ2Emu_lua_UpdateQuestZone);
- lua_register(state, "SetCompletedDescription", EQ2Emu_lua_SetCompletedDescription);
- lua_register(state, "OfferQuest", EQ2Emu_lua_OfferQuest);
- lua_register(state, "ProvidesQuest", EQ2Emu_lua_ProvidesQuest);
- lua_register(state, "HasQuest", EQ2Emu_lua_HasQuest);
- lua_register(state, "HasCompletedQuest", EQ2Emu_lua_HasCompletedQuest);
- lua_register(state, "QuestIsComplete", EQ2Emu_lua_QuestIsComplete);
- lua_register(state, "QuestReturnNPC", EQ2Emu_lua_QuestReturnNPC);
- lua_register(state, "GetQuest", EQ2Emu_lua_GetQuest);
- lua_register(state, "HasCollectionsToHandIn", EQ2Emu_lua_HasCollectionsToHandIn);
- lua_register(state, "HandInCollections", EQ2Emu_lua_HandInCollections);
- lua_register(state, "UseWidget", EQ2Emu_lua_UseWidget);
- lua_register(state, "SetSpellList", EQ2Emu_lua_SetSpellList);
- lua_register(state, "GetPet", EQ2Emu_lua_GetPet);
- lua_register(state, "Charm", EQ2Emu_lua_Charm);
- lua_register(state, "GetGroup", EQ2Emu_lua_GetGroup);
- lua_register(state, "SetCompleteFlag", EQ2Emu_lua_SetCompleteFlag);
- lua_register(state, "SetQuestYellow", EQ2Emu_lua_SetQuestYellow);
- lua_register(state, "CanReceiveQuest", EQ2Emu_lua_CanReceiveQuest);
- lua_register(state, "AddTransportSpawn", EQ2Emu_lua_AddTransportSpawn);
- lua_register(state, "IsTransportSpawn", EQ2Emu_lua_IsTransportSpawn);
- // Option window
- lua_register(state, "CreateOptionWindow", EQ2Emu_lua_CreateOptionWindow);
- lua_register(state, "AddOptionWindowOption", EQ2Emu_lua_AddOptionWindowOption);
- lua_register(state, "SendOptionWindow", EQ2Emu_lua_SendOptionWindow);
- lua_register(state, "GetTradeskillClass", EQ2Emu_lua_GetTradeskillClass);
- lua_register(state, "GetTradeskillLevel", EQ2Emu_lua_GetTradeskillLevel);
- lua_register(state, "GetTradeskillClassName", EQ2Emu_lua_GetTradeskillClassName);
- lua_register(state, "SetTradeskillLevel", EQ2Emu_lua_SetTradeskillLevel);
- lua_register(state, "SummonDeityPet", EQ2Emu_lua_SummonDeityPet);
- lua_register(state, "SummonCosmeticPet", EQ2Emu_lua_SummonCosmeticPet);
- lua_register(state, "DismissPet", EQ2Emu_lua_DismissPet);
- lua_register(state, "GetCharmedPet", EQ2Emu_lua_GetCharmedPet);
- lua_register(state, "GetDeityPet", EQ2Emu_lua_GetDeityPet);
- lua_register(state, "GetCosmeticPet", EQ2Emu_lua_GetCosmeticPet);
- lua_register(state, "SetQuestFeatherColor", EQ2Emu_lua_SetQuestFeatherColor);
- lua_register(state, "RemoveSpawnAccess", EQ2Emu_lua_RemoveSpawnAccess);
- lua_register(state, "SpawnByLocationID", EQ2Emu_lua_SpawnByLocationID);
- lua_register(state, "CastEntityCommand", EQ2Emu_lua_CastEntityCommand);
- lua_register(state, "SetLuaBrain", EQ2Emu_lua_SetLuaBrain);
- lua_register(state, "SetBrainTick", EQ2Emu_lua_SetBrainTick);
- lua_register(state, "SetFollowTarget", EQ2Emu_lua_SetFollowTarget);
- lua_register(state, "GetFollowTarget", EQ2Emu_lua_GetFollowTarget);
- lua_register(state, "ToggleFollow", EQ2Emu_lua_ToggleFollow);
- lua_register(state, "IsFollowing", EQ2Emu_lua_IsFollowing);
- lua_register(state, "SetTempVariable", EQ2Emu_lua_SetTempVariable);
- lua_register(state, "GetTempVariable", EQ2Emu_lua_GetTempVariable);
- lua_register(state, "GiveQuestItem", EQ2Emu_lua_GiveQuestItem);
- lua_register(state, "SetQuestRepeatable", EQ2Emu_lua_SetQuestRepeatable);
- lua_register(state, "AddWaypoint", EQ2Emu_lua_AddWaypoint);
- lua_register(state, "RemoveWaypoint", EQ2Emu_lua_RemoveWaypoint);
- lua_register(state, "SendWaypoints", EQ2Emu_lua_SendWaypoints);
- lua_register(state, "AddWard", EQ2Emu_lua_AddWard);
- lua_register(state, "AddToWard", EQ2Emu_lua_AddToWard);
- lua_register(state, "RemoveWard", EQ2Emu_lua_RemoveWard);
- lua_register(state, "GetWardAmountLeft", EQ2Emu_lua_GetWardAmountLeft);
- lua_register(state, "GetWardValue", EQ2Emu_lua_GetWardValue);
- lua_register(state, "SetTarget", EQ2Emu_lua_SetTarget);
- lua_register(state, "IsPet", EQ2Emu_lua_IsPet);
- lua_register(state, "GetOwner", EQ2Emu_lua_GetOwner);
- lua_register(state, "SetInCombat", EQ2Emu_lua_SetInCombat);
- lua_register(state, "CompareSpawns", EQ2Emu_lua_CompareSpawns);
- lua_register(state, "ClearRunback", EQ2Emu_lua_ClearRunback);
- lua_register(state, "Runback", EQ2Emu_lua_Runback);
- lua_register(state, "GetRunbackDistance", EQ2Emu_lua_GetRunbackDistance);
- lua_register(state, "IsCasting", EQ2Emu_lua_IsCasting);
- lua_register(state, "IsMezzed", EQ2Emu_lua_IsMezzed);
- lua_register(state, "IsStunned", EQ2Emu_lua_IsStunned);
- lua_register(state, "IsMezzedOrStunned", EQ2Emu_lua_IsMezzedOrStunned);
- lua_register(state, "ProcessSpell", EQ2Emu_lua_ProcessSpell);
- lua_register(state, "ProcessMelee", EQ2Emu_lua_ProcessMelee);
- lua_register(state, "HasRecovered", EQ2Emu_lua_HasRecovered);
- lua_register(state, "GetEncounterSize", EQ2Emu_lua_GetEncounterSize);
- lua_register(state, "GetMostHated", EQ2Emu_lua_GetMostHated);
- lua_register(state, "ClearHate", EQ2Emu_lua_ClearHate);
- lua_register(state, "ClearEncounter", EQ2Emu_lua_ClearEncounter);
- lua_register(state, "GetEncounter", EQ2Emu_lua_GetEncounter);
- lua_register(state, "GetHateList", EQ2Emu_lua_GetHateList);
- lua_register(state, "HasGroup", EQ2Emu_lua_HasGroup);
- lua_register(state, "HasSpellEffect", EQ2Emu_lua_HasSpellEffect);
- lua_register(state, "SetSuccessTimer", EQ2Emu_lua_SetSuccessTimer);
- lua_register(state, "SetFailureTimer", EQ2Emu_lua_SetFailureTimer);
- lua_register(state, "IsGroundSpawn", EQ2Emu_lua_IsGroundSpawn);
- lua_register(state, "CanHarvest", EQ2Emu_lua_CanHarvest);
- lua_register(state, "SummonDumbFirePet", EQ2Emu_lua_SummonDumbFirePet);
- lua_register(state, "GetSkillValue", EQ2Emu_lua_GetSkillValue);
- lua_register(state, "GetSkillMaxValue", EQ2Emu_lua_GetSkillMaxValue);
- lua_register(state, "GetSkillName", EQ2Emu_lua_GetSkillName);
- lua_register(state, "SetSkillMaxValue", EQ2Emu_lua_SetSkillMaxValue);
- lua_register(state, "SetSkillValue", EQ2Emu_lua_SetSkillValue);
- lua_register(state, "GetSkill", EQ2Emu_lua_GetSkill);
- lua_register(state, "GetSkillIDByName", EQ2Emu_lua_GetSkillIDByName);
- lua_register(state, "HasSkill", EQ2Emu_lua_HasSkill);
- lua_register(state, "AddSkill", EQ2Emu_lua_AddSkill);
- lua_register(state, "IncreaseSkillCapsByType", EQ2Emu_lua_IncreaseSkillCapsByType);
- lua_register(state, "RemoveSkill", EQ2Emu_lua_RemoveSkill);
- lua_register(state, "AddProc", EQ2Emu_lua_AddProc);
- lua_register(state, "RemoveProc", EQ2Emu_lua_RemoveProc);
- lua_register(state, "Knockback", EQ2Emu_lua_Knockback);
- lua_register(state, "IsEpic", EQ2Emu_lua_IsEpic);
- lua_register(state, "IsHeroic", EQ2Emu_lua_IsHeroic);
- lua_register(state, "ProcDamage", EQ2Emu_lua_ProcDamage);
- lua_register(state, "LastSpellAttackHit", EQ2Emu_lua_LastSpellAttackHit);
- lua_register(state, "IsBehind", EQ2Emu_lua_IsBehind);
- lua_register(state, "IsFlanking", EQ2Emu_lua_IsFlanking);
- lua_register(state, "AddSpellTimer", EQ2Emu_lua_AddSpellTimer);
- lua_register(state, "GetItemCount", EQ2Emu_lua_GetItemCount);
- lua_register(state, "SetItemCount", EQ2Emu_lua_SetItemCount);
- lua_register(state, "Resurrect", EQ2Emu_lua_Resurrect);
- lua_register(state, "BreatheUnderwater", EQ2Emu_lua_BreatheUnderwater);
- lua_register(state, "BlurVision", EQ2Emu_lua_BlurVision);
- lua_register(state, "SetVision", EQ2Emu_lua_SetVision);
- lua_register(state, "GetItemSkillReq", EQ2Emu_lua_GetItemSkillReq);
- lua_register(state, "SetSpeedMultiplier", EQ2Emu_lua_SetSpeedMultiplier);
- lua_register(state, "SetIllusion", EQ2Emu_lua_SetIllusion);
- lua_register(state, "ResetIllusion", EQ2Emu_lua_ResetIllusion);
- lua_register(state, "AddThreatTransfer", EQ2Emu_lua_AddThreatTransfer);
- lua_register(state, "RemoveThreatTransfer", EQ2Emu_lua_RemoveThreatTransfer);
- lua_register(state, "CureByType", EQ2Emu_lua_CureByType);
- lua_register(state, "CureByControlEffect", EQ2Emu_lua_CureByControlEffect);
- lua_register(state, "AddSpawnSpellBonus", EQ2Emu_lua_AddSpawnSpellBonus);
- lua_register(state, "RemoveSpawnSpellBonus", EQ2Emu_lua_RemoveSpawnSpellBonus);
- lua_register(state, "CancelSpell", EQ2Emu_lua_CancelSpell);
- lua_register(state, "RemoveStealth", EQ2Emu_lua_RemoveStealth);
- lua_register(state, "RemoveInvis", EQ2Emu_lua_RemoveInvis);
- lua_register(state, "StartHeroicOpportunity", EQ2Emu_lua_StartHeroicOpportunity);
- lua_register(state, "CopySpawnAppearance", EQ2Emu_lua_CopySpawnAppearance);
- lua_register(state, "SetSpellTriggerCount", EQ2Emu_lua_SetSpellTriggerCount);
- lua_register(state, "GetSpellTriggerCount", EQ2Emu_lua_GetSpellTriggerCount);
- lua_register(state, "RemoveTriggerFromSpell", EQ2Emu_lua_RemoveTriggerFromSpell);
- lua_register(state, "HasSpellImmunity", EQ2Emu_lua_HasSpellImmunity);
- lua_register(state, "AddImmunitySpell", EQ2Emu_lua_AddImmunitySpell);
- lua_register(state, "RemoveImmunitySpell", EQ2Emu_lua_RemoveImmunitySpell);
- lua_register(state, "SetSpellSnareValue", EQ2Emu_lua_SetSpellSnareValue);
- lua_register(state, "CheckRaceType", EQ2Emu_lua_CheckRaceType);
- lua_register(state, "GetRaceType", EQ2Emu_lua_GetRaceType);
- lua_register(state, "GetRaceBaseType", EQ2Emu_lua_GetRaceBaseType);
- lua_register(state, "GetQuestFlags", EQ2Emu_lua_GetQuestFlags);
- lua_register(state, "SetQuestFlags", EQ2Emu_lua_SetQuestFlags);
- lua_register(state, "SetQuestTimer", EQ2Emu_lua_SetQuestTimer);
- lua_register(state, "RemoveQuestStep", EQ2Emu_lua_RemoveQuestStep);
- lua_register(state, "ResetQuestStep", EQ2Emu_lua_ResetQuestStep);
- lua_register(state, "SetQuestTimerComplete", EQ2Emu_lua_SetQuestTimerComplete);
- lua_register(state, "AddQuestStepFailureAction", EQ2Emu_lua_AddQuestStepFailureAction);
- lua_register(state, "SetStepFailed", EQ2Emu_lua_SetStepFailed);
- lua_register(state, "GetQuestCompleteCount", EQ2Emu_lua_GetQuestCompleteCount);
- lua_register(state, "SetServerVariable", EQ2Emu_lua_SetServerVariable);
- lua_register(state, "GetServerVariable", EQ2Emu_lua_GetServerVariable);
- lua_register(state, "HasLanguage", EQ2Emu_lua_HasLanguage);
- lua_register(state, "AddLanguage", EQ2Emu_lua_AddLanguage);
- lua_register(state, "IsNight", EQ2Emu_lua_IsNight);
- lua_register(state, "AddMultiFloorLift", EQ2Emu_lua_AddMultiFloorLift);
- lua_register(state, "StartAutoMount", EQ2Emu_lua_StartAutoMount);
- lua_register(state, "EndAutoMount", EQ2Emu_lua_EndAutoMount);
- lua_register(state, "IsOnAutoMount", EQ2Emu_lua_IsOnAutoMount);
- lua_register(state, "SetPlayerHistory", EQ2Emu_lua_SetPlayerHistory);
- lua_register(state, "GetPlayerHistory", EQ2Emu_lua_GetPlayerHistory);
- lua_register(state, "SetGridID", EQ2Emu_lua_SetGridID);
- lua_register(state, "GetQuestStepProgress", EQ2Emu_lua_GetQuestStepProgress);
- lua_register(state, "SetPlayerLevel", EQ2Emu_lua_SetPlayerLevel);
- lua_register(state, "AddCoin", EQ2Emu_lua_AddCoin);
- lua_register(state, "RemoveCoin", EQ2Emu_lua_RemoveCoin);
- lua_register(state, "GetPlayersInZone", EQ2Emu_lua_GetPlayersInZone);
- lua_register(state, "SpawnGroupByID", EQ2Emu_lua_SpawnGroupByID);
- lua_register(state, "SetSpawnAnimation", EQ2Emu_lua_SetSpawnAnimation);
- lua_register(state, "GetClientVersion", EQ2Emu_lua_GetClientVersion);
- lua_register(state, "GetItemID", EQ2Emu_lua_GetItemID);
- lua_register(state, "IsEntity", EQ2Emu_lua_IsEntity);
- lua_register(state, "GetOrigX", EQ2Emu_lua_GetOrigX);
- lua_register(state, "GetOrigY", EQ2Emu_lua_GetOrigY);
- lua_register(state, "GetOrigZ", EQ2Emu_lua_GetOrigZ);
- lua_register(state, "GetPCTOfHP", EQ2Emu_lua_GetPCTOfHP);
- lua_register(state, "GetPCTOfPower", EQ2Emu_lua_GetPCTOfPower);
- lua_register(state, "GetBoundZoneID", EQ2Emu_lua_GetBoundZoneID);
- lua_register(state, "Evac", EQ2Emu_lua_Evac);
- lua_register(state, "GetSpellTier", EQ2Emu_lua_GetSpellTier);
- lua_register(state, "GetSpellID", EQ2Emu_lua_GetSpellID);
- lua_register(state, "StartTransmute", EQ2Emu_lua_StartTransmute);
- lua_register(state, "CompleteTransmute", EQ2Emu_lua_CompleteTransmute);
- lua_register(state, "ProcHate", EQ2Emu_lua_ProcHate);
- lua_register(state, "GetRandomSpawnByID", EQ2Emu_lua_GetRandomSpawnByID);
- lua_register(state, "ShowLootWindow", EQ2Emu_lua_ShowLootWindow);
- lua_register(state, "AddPrimaryEntityCommandAllSpawns", EQ2Emu_lua_AddPrimaryEntityCommandAllSpawns);
- lua_register(state, "InstructionWindow", EQ2Emu_lua_InstructionWindow);
- lua_register(state, "InstructionWindowClose", EQ2Emu_lua_InstructionWindowClose);
- lua_register(state, "InstructionWindowGoal", EQ2Emu_lua_InstructionWindowGoal);
- lua_register(state, "ShowWindow", EQ2Emu_lua_ShowWindow);
- lua_register(state, "FlashWindow", EQ2Emu_lua_FlashWindow);
- lua_register(state, "EnableGameEvent", EQ2Emu_lua_EnableGameEvent);
- lua_register(state, "GetTutorialStep", EQ2Emu_lua_GetTutorialStep);
- lua_register(state, "SetTutorialStep", EQ2Emu_lua_SetTutorialStep);
- lua_register(state, "DisplayText", EQ2Emu_lua_DisplayText);
- lua_register(state, "GiveExp", EQ2Emu_lua_GiveExp);
- lua_register(state, "CheckLOS", EQ2Emu_lua_CheckLOS);
- lua_register(state, "CheckLOSByCoordinates", EQ2Emu_lua_CheckLOSByCoordinates);
- lua_register(state, "SetZoneExpansionFlag", EQ2Emu_lua_SetZoneExpansionFlag);
- lua_register(state, "GetZoneExpansionFlag", EQ2Emu_lua_GetZoneExpansionFlag);
- lua_register(state, "SetZoneHolidayFlag", EQ2Emu_lua_SetZoneHolidayFlag);
- lua_register(state, "GetZoneHolidayFlag", EQ2Emu_lua_GetZoneHolidayFlag);
-
- lua_register(state, "SetCanBind", EQ2Emu_lua_SetCanBind);
- lua_register(state, "GetCanBind", EQ2Emu_lua_GetCanBind);
- lua_register(state, "GetCanGate", EQ2Emu_lua_GetCanGate);
- lua_register(state, "SetCanGate", EQ2Emu_lua_SetCanGate);
- lua_register(state, "AddSpawnProximity", EQ2Emu_lua_AddSpawnProximity);
- lua_register(state, "CanSeeInvis", EQ2Emu_lua_CanSeeInvis);
- lua_register(state, "SetSeeInvis", EQ2Emu_lua_SetSeeInvis);
- lua_register(state, "SetSeeHide", EQ2Emu_lua_SetSeeHide);
- lua_register(state, "SetAccessToEntityCommand", EQ2Emu_lua_SetAccessToEntityCommand);
- lua_register(state, "SetAccessToEntityCommandByCharID", EQ2Emu_lua_SetAccessToEntityCommandByCharID);
- lua_register(state, "RemovePrimaryEntityCommand", EQ2Emu_lua_RemovePrimaryEntityCommand);
- lua_register(state, "SendUpdateDefaultCommand", EQ2Emu_lua_SendUpdateDefaultCommand);
- lua_register(state, "SendTransporters", EQ2Emu_lua_SendTransporters);
- lua_register(state, "SetTemporaryTransportID", EQ2Emu_lua_SetTemporaryTransportID);
- lua_register(state, "GetTemporaryTransportID", EQ2Emu_lua_GetTemporaryTransportID);
- lua_register(state, "SetAlignment", EQ2Emu_lua_SetAlignment);
- lua_register(state, "GetAlignment", EQ2Emu_lua_GetAlignment);
- lua_register(state, "GetSpell", EQ2Emu_lua_GetSpell);
- lua_register(state, "GetSpellData", EQ2Emu_lua_GetSpellData);
- lua_register(state, "SetSpellData", EQ2Emu_lua_SetSpellData);
- lua_register(state, "CastCustomSpell", EQ2Emu_lua_CastCustomSpell);
- lua_register(state, "SetSpellDataIndex", EQ2Emu_lua_SetSpellDataIndex);
- lua_register(state, "GetSpellDataIndex", EQ2Emu_lua_GetSpellDataIndex);
- lua_register(state, "SetSpellDisplayEffect", EQ2Emu_lua_SetSpellDisplayEffect);
- lua_register(state, "GetSpellDisplayEffect", EQ2Emu_lua_GetSpellDisplayEffect);
- lua_register(state, "InWater", EQ2Emu_lua_InWater);
- lua_register(state, "InLava", EQ2Emu_lua_InLava);
-
- lua_register(state, "DamageSpawn", EQ2Emu_lua_DamageSpawn);
- lua_register(state, "IsInvulnerable", EQ2Emu_lua_IsInvulnerable);
- lua_register(state, "SetInvulnerable", EQ2Emu_lua_SetInvulnerable);
-
- lua_register(state, "GetRuleFlagBool", EQ2Emu_lua_GetRuleFlagBool);
- lua_register(state, "GetRuleFlagInt32", EQ2Emu_lua_GetRuleFlagInt32);
- lua_register(state, "GetRuleFlagFloat", EQ2Emu_lua_GetRuleFlagFloat);
-
- lua_register(state, "GetAAInfo", EQ2Emu_lua_GetAAInfo);
- lua_register(state, "SetAAInfo", EQ2Emu_lua_SetAAInfo);
-
- lua_register(state, "AddMasterTitle", EQ2Emu_lua_AddMasterTitle);
- lua_register(state, "AddCharacterTitle", EQ2Emu_lua_AddCharacterTitle);
- lua_register(state, "SetCharacterTitleSuffix", EQ2Emu_lua_SetCharacterTitleSuffix);
- lua_register(state, "SetCharacterTitlePrefix", EQ2Emu_lua_SetCharacterTitlePrefix);
- lua_register(state, "ResetCharacterTitleSuffix", EQ2Emu_lua_ResetCharacterTitleSuffix);
- lua_register(state, "ResetCharacterTitlePrefix", EQ2Emu_lua_ResetCharacterTitlePrefix);
-
- lua_register(state, "GetInfoStructString", EQ2Emu_lua_GetInfoStructString);
- lua_register(state, "GetInfoStructUInt", EQ2Emu_lua_GetInfoStructUInt);
- lua_register(state, "GetInfoStructSInt", EQ2Emu_lua_GetInfoStructSInt);
- lua_register(state, "GetInfoStructFloat", EQ2Emu_lua_GetInfoStructFloat);
-
- lua_register(state, "SetInfoStructString", EQ2Emu_lua_SetInfoStructString);
- lua_register(state, "SetInfoStructUInt", EQ2Emu_lua_SetInfoStructUInt);
- lua_register(state, "SetInfoStructSInt", EQ2Emu_lua_SetInfoStructSInt);
- lua_register(state, "SetInfoStructFloat", EQ2Emu_lua_SetInfoStructFloat);
-
- lua_register(state, "SetCharSheetChanged", EQ2Emu_lua_SetCharSheetChanged);
-
- lua_register(state, "AddPlayerMail", EQ2Emu_lua_AddPlayerMail);
- lua_register(state, "AddPlayerMailByCharID", EQ2Emu_lua_AddPlayerMailByCharID);
-
- lua_register(state, "OpenDoor", EQ2Emu_lua_OpenDoor);
- lua_register(state, "CloseDoor", EQ2Emu_lua_CloseDoor);
- lua_register(state, "IsOpen", EQ2Emu_lua_IsOpen);
-
- lua_register(state, "MakeRandomInt", EQ2Emu_lua_MakeRandomInt);
- lua_register(state, "MakeRandomFloat", EQ2Emu_lua_MakeRandomFloat);
-
- lua_register(state, "AddIconValue", EQ2Emu_lua_AddIconValue);
- lua_register(state, "RemoveIconValue", EQ2Emu_lua_RemoveIconValue);
-
- lua_register(state, "GetShardID", EQ2Emu_lua_GetShardID);
- lua_register(state, "GetShardCharID", EQ2Emu_lua_GetShardCharID);
- lua_register(state, "GetShardCreatedTimestamp", EQ2Emu_lua_GetShardCreatedTimestamp);
- lua_register(state, "DeleteDBShardID", EQ2Emu_lua_DeleteDBShardID);
-
- lua_register(state, "PauseMovement", EQ2Emu_lua_PauseMovement);
- lua_register(state, "StopMovement", EQ2Emu_lua_StopMovement);
-
- lua_register(state, "GetArrowColor", EQ2Emu_lua_GetArrowColor);
- lua_register(state, "GetTSArrowColor", EQ2Emu_lua_GetTSArrowColor);
-
- lua_register(state, "GetSpawnByRailID", EQ2Emu_lua_GetSpawnByRailID);
- lua_register(state, "SetRailID", EQ2Emu_lua_SetRailID);
- lua_register(state, "IsZoneLoading", EQ2Emu_lua_IsZoneLoading);
- lua_register(state, "IsRunning", EQ2Emu_lua_IsRunning);
-
- lua_register(state, "GetZoneLockoutTimer", EQ2Emu_lua_GetZoneLockoutTimer);
-
- lua_register(state, "SetWorldTime", EQ2Emu_lua_SetWorldTime);
- lua_register(state, "GetWorldTimeYear", EQ2Emu_lua_GetWorldTimeYear);
- lua_register(state, "GetWorldTimeMonth", EQ2Emu_lua_GetWorldTimeMonth);
- lua_register(state, "GetWorldTimeHour", EQ2Emu_lua_GetWorldTimeHour);
- lua_register(state, "GetWorldTimeMinute", EQ2Emu_lua_GetWorldTimeMinute);
- lua_register(state, "SendTimeUpdate", EQ2Emu_lua_SendTimeUpdate);
-
- lua_register(state, "GetLootTier", EQ2Emu_lua_GetLootTier);
- lua_register(state, "SetLootTier", EQ2Emu_lua_SetLootTier);
- lua_register(state, "GetLootDropType", EQ2Emu_lua_GetLootDropType);
- lua_register(state, "SetLootDropType", EQ2Emu_lua_SetLootDropType);
-
- lua_register(state, "DamageEquippedItems", EQ2Emu_lua_DamageEquippedItems);
-
- lua_register(state, "CreateWidgetRegion", EQ2Emu_lua_CreateWidgetRegion);
- lua_register(state, "RemoveRegion", EQ2Emu_lua_RemoveRegion);
-
- lua_register(state, "SetPlayerPOVGhost", EQ2Emu_lua_SetPlayerPOVGhost);
-
- lua_register(state, "SetCastOnAggroComplete", EQ2Emu_lua_SetCastOnAggroComplete);
- lua_register(state, "IsCastOnAggroComplete", EQ2Emu_lua_IsCastOnAggroComplete);
- }
- void LuaInterface::LogError(const char* error, ...) {
- va_list argptr;
- char buffer[4096];
- va_start(argptr, error);
- vsnprintf(buffer, sizeof(buffer), error, argptr);
- va_end(argptr);
- SimpleLogError(buffer);
- }
- void LuaInterface::SimpleLogError(const char* error) {
- ProcessErrorMessage(error);
- LogWrite(LUA__ERROR, 0, "LUA", "%s", error);
- }
- void LuaInterface::ResetFunctionStack(lua_State* state) {
- lua_settop(state, 0);
- }
- void LuaInterface::AddUserDataPtr(LUAUserData* data, void* data_ptr) {
- std::unique_lock lock(MLUAUserData);
- if(data_ptr) {
- user_data_ptr[data_ptr] = data;
- }
- user_data[data] = Timer::GetCurrentTime2() + 300000; //allow a function to use this pointer for 5 minutes
- }
- void LuaInterface::DeletePendingSpells(bool all) {
- MSpellDelete.lock();
- if (spells_pending_delete.size() > 0) {
- int32 time = Timer::GetCurrentTime2();
- map<LuaSpell*, int32>::iterator itr;
- vector<LuaSpell*> tmp_deletes;
- vector<LuaSpell*>::iterator del_itr;
- for (itr = spells_pending_delete.begin(); itr != spells_pending_delete.end(); itr++) {
- if (all || time >= itr->second)
- tmp_deletes.push_back(itr->first);
- }
- LuaSpell* spell = 0;
- for (del_itr = tmp_deletes.begin(); del_itr != tmp_deletes.end(); del_itr++) {
- spell = *del_itr;
-
-
- if (spell->caster) {
- spell->caster->GetZone()->GetSpellProcess()->DeleteActiveSpell(spell);
- }
- else if(spell->targets.size() > 0) {
- spell->MSpellTargets.readlock(__FUNCTION__, __LINE__);
- for (int8 i = 0; i < spell->targets.size(); i++) {
- Spawn* target = spell->caster->GetZone()->GetSpawnByID(spell->targets.at(i));
- if (!target || !target->IsEntity())
- continue;
- target->GetZone()->GetSpellProcess()->DeleteActiveSpell(spell);
- }
- spell->MSpellTargets.releasereadlock(__FUNCTION__, __LINE__);
- }
- spells_pending_delete.erase(spell);
- if (spell->spell->IsCopiedSpell())
- {
- RemoveCustomSpell(spell->spell->GetSpellID());
- safe_delete(spell->spell);
- }
- SetLuaUserDataStale(spell);
- safe_delete(spell);
- }
- }
- MSpellDelete.unlock();
- }
- void LuaInterface::DeletePendingSpell(LuaSpell* spell) {
- MSpellDelete.lock();
- if (spells_pending_delete.size() > 0) {
- map<LuaSpell*, int32>::iterator itr = spells_pending_delete.find(spell);
- if (itr != spells_pending_delete.end())
- spells_pending_delete.erase(itr);
- }
- MSpellDelete.unlock();
- }
- void LuaInterface::DeleteUserDataPtrs(bool all) {
- std::unique_lock lock(MLUAUserData);
- if(user_data.size() > 0){
- map<LUAUserData*, int32>::iterator itr;
- int32 time = Timer::GetCurrentTime2();
- vector<LUAUserData*> tmp_deletes;
- vector<LUAUserData*>::iterator del_itr;
- for(itr = user_data.begin(); itr != user_data.end(); itr++){
- if(all || time >= itr->second)
- tmp_deletes.push_back(itr->first);
- }
- LUAUserData* data = 0;
- for(del_itr = tmp_deletes.begin(); del_itr != tmp_deletes.end(); del_itr++){
- data = *del_itr;
-
- void* target = 0;
- if(data->IsConversationOption()) {
- target = data->conversation_options;
- }
- else if(data->IsSpawnList()) {
- target = data->spawn_list;
- }
- else if(data->IsOptionWindow()) {
- target = data->option_window_option;
- }
- else if(data->IsSpawn()) {
- target = data->spawn;
- }
- else if(data->IsQuest()) {
- target = data->quest;
- }
- else if(data->IsZone()) {
- target = data->zone;
- }
- else if(data->IsItem()) {
- target = data->item;
- }
- else if(data->IsSkill()) {
- target = data->skill;
- }
- else if(data->IsSpell()) {
- target = data->spell;
- }
- if(target) {
- std::map<void*, LUAUserData*>::iterator itr = user_data_ptr.find(target);
- if(itr != user_data_ptr.end()) {
- user_data_ptr.erase(itr);
- }
- }
- user_data.erase(data);
- safe_delete(data);
- }
- }
- }
- Spawn* LuaInterface::GetSpawn(lua_State* state, int8 arg_num) {
- std::shared_lock lock(MLUAUserData);
- Spawn* ret = 0;
- if (lua_islightuserdata(state, arg_num)){
- LUAUserData* data = (LUAUserData*)lua_touserdata(state, arg_num);
- if(!data || !data->IsCorrectlyInitialized()){
- LogError("%s: GetSpawn error while processing %s", GetScriptName(state), lua_tostring(state, -1));
- }
- else if(!data->IsSpawn()){
- lua_Debug ar;
- lua_getstack (state, 1, &ar);
- lua_getinfo(state, "Sln", &ar);
- LogError("%s: Invalid data type used for GetSpawn in %s (line %d)", GetScriptName(state), ar.source, ar.currentline);
- }
- else
- ret = data->spawn;
- }
- return ret;
- }
- vector<ConversationOption>* LuaInterface::GetConversation(lua_State* state, int8 arg_num) {
- std::shared_lock lock(MLUAUserData);
- vector<ConversationOption>* ret = 0;
- if(lua_islightuserdata(state, arg_num)){
- LUAUserData* data = (LUAUserData*)lua_touserdata(state, arg_num);
- if(!data || !data->IsCorrectlyInitialized()){
- LogError("%s: GetConversation error while processing %s", GetScriptName(state), lua_tostring(state, -1));
- }
- else if(!data->IsConversationOption()){
- lua_Debug ar;
- lua_getstack (state, 1, &ar);
- lua_getinfo(state, "Sln", &ar);
- LogError("%s: Invalid data type used for GetConversation in %s (line %d)", GetScriptName(state), ar.source, ar.currentline);
- }
- else
- ret = data->conversation_options;
- }
- return ret;
- }
- vector<Spawn*>* LuaInterface::GetSpawnList(lua_State* state, int8 arg_num) {
- std::shared_lock lock(MLUAUserData);
- vector<Spawn*>* ret = 0;
- if (lua_islightuserdata(state, arg_num)) {
- LUAUserData* data = (LUAUserData*)lua_touserdata(state, arg_num);
- if (!data || !data->IsCorrectlyInitialized()) {
- LogError("%s: GetSpawnList error while processing %s", GetScriptName(state), lua_tostring(state, -1));
- }
- else if (!data->IsSpawnList()) {
- lua_Debug ar;
- lua_getstack(state, 1, &ar);
- lua_getinfo(state, "Sln", &ar);
- LogError("%s: Invalid data type used for GetSpawnList in %s (line %d)", GetScriptName(state), ar.source, ar.currentline);
- }
- else
- ret = data->spawn_list;
- }
- return ret;
- }
- vector<OptionWindowOption>* LuaInterface::GetOptionWindow(lua_State* state, int8 arg_num) {
- std::shared_lock lock(MLUAUserData);
- vector<OptionWindowOption>* ret = 0;
- if(lua_islightuserdata(state, arg_num)){
- LUAUserData* data = (LUAUserData*)lua_touserdata(state, arg_num);
- if(!data || !data->IsCorrectlyInitialized()){
- LogError("%s: GetOptionWindow error while processing %s", GetScriptName(state), lua_tostring(state, -1));
- }
- else if(!data->IsOptionWindow()){
- lua_Debug ar;
- lua_getstack (state, 1, &ar);
- lua_getinfo(state, "Sln", &ar);
- LogError("%s: Invalid data type used for GetOptionWindow in %s (line %d)", GetScriptName(state), ar.source, ar.currentline);
- }
- else
- ret = data->option_window_option;
- }
- return ret;
- }
- Quest* LuaInterface::GetQuest(lua_State* state, int8 arg_num) {
- std::shared_lock lock(MLUAUserData);
- Quest* ret = 0;
- if(lua_islightuserdata(state, arg_num)){
- LUAUserData* data = (LUAUserData*)lua_touserdata(state, arg_num);
- if(!data || !data->IsCorrectlyInitialized()){
- LogError("%s: GetQuest error while processing %s", GetScriptName(state), lua_tostring(state, 0));
- }
- else if(!data->IsQuest()){
- lua_Debug ar;
- lua_getstack (state, 1, &ar);
- lua_getinfo(state, "Sln", &ar);
- LogError("%s: Invalid data type used for GetQuest in %s (line %d)", GetScriptName(state), ar.source, ar.currentline);
- }
- else
- ret = data->quest;
- }
- return ret;
- }
- Item* LuaInterface::GetItem(lua_State* state, int8 arg_num) {
- std::shared_lock lock(MLUAUserData);
- Item* ret = 0;
- if(lua_islightuserdata(state, arg_num)){
- LUAUserData* data = (LUAUserData*)lua_touserdata(state, arg_num);
- if(!data || !data->IsCorrectlyInitialized()){
- LogError("%s: GetItem error while processing %s", GetScriptName(state), lua_tostring(state, 0));
- }
- else if(!data->IsItem()){
- lua_Debug ar;
- lua_getstack (state, 1, &ar);
- lua_getinfo(state, "Sln", &ar);
- LogError("%s: Invalid data type used for GetItem in %s (line %d)", GetScriptName(state), ar.source, ar.currentline);
- }
- else
- ret = data->item;
- }
- return ret;
- }
- Skill* LuaInterface::GetSkill(lua_State* state, int8 arg_num) {
- std::shared_lock lock(MLUAUserData);
- Skill* ret = 0;
- if (lua_islightuserdata(state, arg_num)) {
- LUAUserData* data = (LUAUserData*)lua_touserdata(state, arg_num);
- if (!data || !data->IsCorrectlyInitialized()) {
- LogError("%s: GetSkill error while processing %s", GetScriptName(state), lua_tostring(state, 0));
- }
- else if (!data->IsSkill()) {
- lua_Debug ar;
- lua_getstack(state, 1, &ar);
- lua_getinfo(state, "Sln", &ar);
- LogError("%s: Invalid data type used for GetSkill in %s (line %d)", GetScriptName(state), ar.source, ar.currentline);
- }
- else
- ret = data->skill;
- }
- return ret;
- }
- LuaSpell* LuaInterface::GetSpell(lua_State* state, int8 arg_num) {
- std::shared_lock lock(MLUAUserData);
- LuaSpell* ret = 0;
- if (lua_islightuserdata(state, arg_num)) {
- LUAUserData* data = (LUAUserData*)lua_touserdata(state, arg_num);
- if (!data || !data->IsCorrectlyInitialized()) {
- LogError("%s: GetSpell error while processing %s", GetScriptName(state), lua_tostring(state, 0));
- }
- else if (!data->IsSpell()) {
- lua_Debug ar;
- lua_getstack(state, 1, &ar);
- lua_getinfo(state, "Sln", &ar);
- LogError("%s: Invalid data type used for GetSpell in %s (line %d)", GetScriptName(state), ar.source, ar.currentline);
- }
- else
- ret = data->spell;
- }
- return ret;
- }
- ZoneServer* LuaInterface::GetZone(lua_State* state, int8 arg_num) {
- std::shared_lock lock(MLUAUserData);
- ZoneServer* ret = 0;
- if(lua_islightuserdata(state, arg_num)){
- LUAUserData* data = (LUAUserData*)lua_touserdata(state, arg_num);
- if(!data || !data->IsCorrectlyInitialized()){
- LogError("%s: GetZone error while processing %s", GetScriptName(state), lua_tostring(state, -1));
- }
- else if(!data->IsZone()){
- lua_Debug ar;
- lua_getstack (state, 1, &ar);
- lua_getinfo(state, "Sln", &ar);
- LogError("%s: Invalid data type used for GetZone in %s (line %d)", GetScriptName(state), ar.source, ar.currentline);
- }
- else
- ret = data->zone;
- }
- return ret;
- }
- sint64 LuaInterface::GetSInt64Value(lua_State* state, int8 arg_num) {
- sint64 val = 0;
- if(lua_isnumber(state, arg_num)){
- val = (sint64)lua_tointeger(state, arg_num);
- }
- return val;
- }
- int64 LuaInterface::GetInt64Value(lua_State* state, int8 arg_num) {
- int64 val = 0;
- if(lua_isnumber(state, arg_num)){
- val = (int64)lua_tonumber(state, arg_num);
- }
- return val;
- }
- sint32 LuaInterface::GetSInt32Value(lua_State* state, int8 arg_num) {
- sint32 val = 0;
- if(lua_isnumber(state, arg_num)){
- val = lua_tointeger(state, arg_num);
- }
- return val;
- }
- int32 LuaInterface::GetInt32Value(lua_State* state, int8 arg_num) {
- int32 val = 0;
- if(lua_isnumber(state, arg_num)){
- val = (int32)lua_tonumber(state, arg_num);
- }
- return val;
- }
- int16 LuaInterface::GetInt16Value(lua_State* state, int8 arg_num) {
- int16 val = 0;
- if(lua_isnumber(state, arg_num)){
- val = lua_tointeger(state, arg_num);
- }
- return val;
- }
- int8 LuaInterface::GetInt8Value(lua_State* state, int8 arg_num) {
- int8 val = 0;
- if(lua_isnumber(state, arg_num)){
- val = lua_tointeger(state, arg_num);
- }
- return val;
- }
- float LuaInterface::GetFloatValue(lua_State* state, int8 arg_num) {
- float val = 0;
- if(lua_isnumber(state, arg_num))
- val = (float)lua_tonumber(state, arg_num);
- return val;
- }
- string LuaInterface::GetStringValue(lua_State* state, int8 arg_num) {
- string val;
- if(lua_isstring(state, arg_num)){
- size_t size = 0;
- const char* str = lua_tolstring(state, arg_num, &size);
- if(str)
- val = string(str);
- }
- return val;
- }
- bool LuaInterface::GetBooleanValue(lua_State* state, int8 arg_num) {
- return lua_toboolean(state, arg_num) == 1;
- }
- void LuaInterface::SetStringValue(lua_State* state, const char* value) {
- lua_pushstring(state, value);
- }
- void LuaInterface::SetBooleanValue(lua_State* state, bool value) {
- lua_pushboolean(state, value);
- }
- void LuaInterface::SetFloatValue(lua_State* state, float value) {
- lua_pushnumber(state, value);
- }
- void LuaInterface::SetInt32Value(lua_State* state, int32 value) {
- lua_pushinteger(state, value);
- }
- void LuaInterface::SetSInt32Value(lua_State* state, sint32 value) {
- lua_pushinteger(state, value);
- }
- void LuaInterface::SetInt64Value(lua_State* state, int64 value) {
- lua_pushinteger(state, value);
- }
- void LuaInterface::SetSInt64Value(lua_State* state, sint64 value) {
- lua_pushinteger(state, value);
- }
- void LuaInterface::SetSpawnValue(lua_State* state, Spawn* spawn) {
- LUASpawnWrapper* spawn_wrapper = new LUASpawnWrapper();
- spawn_wrapper->spawn = spawn;
- AddUserDataPtr(spawn_wrapper, spawn);
- lua_pushlightuserdata(state, spawn_wrapper);
- }
- void LuaInterface::SetSpawnListValue(lua_State* state, vector<Spawn*>* spawnList) {
- LUASpawnListWrapper* spawnList_wrapper = new LUASpawnListWrapper();
- spawnList_wrapper->spawn_list = spawnList;
- AddUserDataPtr(spawnList_wrapper, spawnList);
- lua_pushlightuserdata(state, spawnList_wrapper);
- }
- void LuaInterface::SetConversationValue(lua_State* state, vector<ConversationOption>* conversation) {
- LUAConversationOptionWrapper* conv_wrapper = new LUAConversationOptionWrapper();
- conv_wrapper->conversation_options = conversation;
- AddUserDataPtr(conv_wrapper, conversation);
- lua_pushlightuserdata(state, conv_wrapper);
- }
- void LuaInterface::SetOptionWindowValue(lua_State* state, vector<OptionWindowOption>* optionWindow) {
- LUAOptionWindowWrapper* option_wrapper = new LUAOptionWindowWrapper();
- option_wrapper->option_window_option = optionWindow;
- AddUserDataPtr(option_wrapper, optionWindow);
- lua_pushlightuserdata(state, option_wrapper);
- }
- void LuaInterface::SetItemValue(lua_State* state, Item* item) {
- LUAItemWrapper* item_wrapper = new LUAItemWrapper();
- item_wrapper->item = item;
- AddUserDataPtr(item_wrapper, item);
- lua_pushlightuserdata(state, item_wrapper);
- }
- void LuaInterface::SetSkillValue(lua_State* state, Skill* skill) {
- LUASkillWrapper* skill_wrapper = new LUASkillWrapper();
- skill_wrapper->skill = skill;
- AddUserDataPtr(skill_wrapper, skill);
- lua_pushlightuserdata(state, skill_wrapper);
- }
- void LuaInterface::SetQuestValue(lua_State* state, Quest* quest) {
- LUAQuestWrapper* quest_wrapper = new LUAQuestWrapper();
- quest_wrapper->quest = quest;
- AddUserDataPtr(quest_wrapper, quest);
- lua_pushlightuserdata(state, quest_wrapper);
- }
- void LuaInterface::SetZoneValue(lua_State* state, ZoneServer* zone) {
- LUAZoneWrapper* zone_wrapper = new LUAZoneWrapper();
- zone_wrapper->zone = zone;
- AddUserDataPtr(zone_wrapper, zone);
- lua_pushlightuserdata(state, zone_wrapper);
- }
- void LuaInterface::SetSpellValue(lua_State* state, LuaSpell* spell) {
- LUASpellWrapper* spell_wrapper = new LUASpellWrapper();
- spell_wrapper->spell = spell;
- AddUserDataPtr(spell_wrapper, spell);
- lua_pushlightuserdata(state, spell_wrapper);
- }
- LuaSpell* LuaInterface::GetSpell(const char* name) {
- string lua_script = string(name);
- if (lua_script.find(".lua") == string::npos)
- lua_script.append(".lua");
- if(spells.count(lua_script) > 0)
- {
- LogWrite(LUA__DEBUG, 0, "LUA", "Found LUA Spell Script: '%s'", lua_script.c_str());
- LuaSpell* spell = spells[lua_script];
- LuaSpell* new_spell = new LuaSpell;
- new_spell->state = spell->state;
- new_spell->file_name = string(spell->file_name);
- new_spell->timer = spell->timer;
- new_spell->timer.Disable();
- new_spell->resisted = false;
- new_spell->interrupted = false;
- new_spell->crit = false;
- new_spell->last_spellattack_hit = false;
- new_spell->MSpellTargets.SetName("LuaSpell.MSpellTargets");
- new_spell->cancel_after_all_triggers = false;
- new_spell->num_triggers = 0;
- new_spell->num_calls = 0;
- new_spell->is_recast_timer = false;
- new_spell->had_triggers = false;
- new_spell->had_dmg_remaining = false;
- new_spell->slot_pos = 0;
- new_spell->damage_remaining = 0;
- new_spell->effect_bitmask = 0;
- new_spell->caster = 0;
- new_spell->initial_target = 0;
- new_spell->spell = 0;
- new_spell->restored = false;
- new_spell->initial_caster_char_id = 0;
- new_spell->initial_target_char_id = 0;
- return new_spell;
- }
- else{
- LogWrite(LUA__ERROR, 0, "LUA", "Error LUA Spell Script: '%s'", name);
- return 0;
- }
- }
- Mutex* LuaInterface::GetItemScriptMutex(const char* name) {
- Mutex* mutex = 0;
- if(item_scripts_mutex.count(name) > 0)
- mutex = item_scripts_mutex[name];
- if(!mutex){
- mutex = new Mutex();
- item_scripts_mutex[name] = mutex;
- }
- return mutex;
- }
- Mutex* LuaInterface::GetSpawnScriptMutex(const char* name) {
- Mutex* mutex = 0;
- if(spawn_scripts_mutex.count(string(name)) > 0)
- mutex = spawn_scripts_mutex[name];
- if(!mutex){
- mutex = new Mutex();
- spawn_scripts_mutex[name] = mutex;
- }
- return mutex;
- }
- Mutex* LuaInterface::GetZoneScriptMutex(const char* name) {
- Mutex* mutex = 0;
- if(zone_scripts_mutex.count(name) > 0)
- mutex = zone_scripts_mutex[name];
- if(!mutex){
- mutex = new Mutex();
- zone_scripts_mutex[name] = mutex;
- }
- return mutex;
- }
- Mutex* LuaInterface::GetRegionScriptMutex(const char* name) {
- Mutex* mutex = 0;
- if(region_scripts_mutex.count(name) > 0)
- mutex = region_scripts_mutex[name];
- if(!mutex){
- mutex = new Mutex();
- region_scripts_mutex[name] = mutex;
- }
- return mutex;
- }
- void LuaInterface::UseItemScript(const char* name, lua_State* state, bool val) {
- MItemScripts.writelock(__FUNCTION__, __LINE__);
- item_scripts[name][state] = val;
- item_inverse_scripts[state] = name;
- MItemScripts.releasewritelock(__FUNCTION__, __LINE__);
- }
- void LuaInterface::UseSpawnScript(const char* name, lua_State* state, bool val) {
- MSpawnScripts.writelock(__FUNCTION__, __LINE__);
- spawn_scripts[name][state] = val;
- spawn_inverse_scripts[state] = name;
- MSpawnScripts.releasewritelock(__FUNCTION__, __LINE__);
- }
- void LuaInterface::UseZoneScript(const char* name, lua_State* state, bool val) {
- MZoneScripts.writelock(__FUNCTION__, __LINE__);
- zone_scripts[name][state] = val;
- zone_inverse_scripts[state] = name;
- MZoneScripts.releasewritelock(__FUNCTION__, __LINE__);
- }
- void LuaInterface::UseRegionScript(const char* name, lua_State* state, bool val) {
- MRegionScripts.writelock(__FUNCTION__, __LINE__);
- region_scripts[name][state] = val;
- region_inverse_scripts[state] = name;
- MRegionScripts.releasewritelock(__FUNCTION__, __LINE__);
- }
- lua_State* LuaInterface::GetItemScript(const char* name, bool create_new, bool use) {
- map<string, map<lua_State*, bool> >::iterator itr;
- map<lua_State*, bool>::iterator item_script_itr;
- lua_State* ret = 0;
- Mutex* mutex = 0;
- itr = item_scripts.find(name);
- if(itr != item_scripts.end()) {
- mutex = GetItemScriptMutex(name);
- mutex->readlock(__FUNCTION__, __LINE__);
- for(item_script_itr = itr->second.begin(); item_script_itr != itr->second.end(); item_script_itr++){
- if(!item_script_itr->second){ //not in use
- ret = item_script_itr->first;
- if (use)
- {
- item_script_itr->second = true;
- break; // don't keep iterating, we already have our result
- }
- }
- }
- mutex->releasereadlock(__FUNCTION__, __LINE__);
- }
- if(!ret && create_new){
- if(name && LoadItemScript(name))
- ret = GetItemScript(name, create_new, use);
- else{
- LogError("Error LUA Item Script '%s'", name);
- return 0;
- }
- }
- return ret;
- }
- lua_State* LuaInterface::GetSpawnScript(const char* name, bool create_new, bool use) {
- if (lua_system_reloading)
- return 0;
- map<string, map<lua_State*, bool> >::iterator itr;
- map<lua_State*, bool>::iterator spawn_script_itr;
- lua_State* ret = 0;
- Mutex* mutex = 0;
- itr = spawn_scripts.find(name);
- if(itr != spawn_scripts.end()) {
- mutex = GetSpawnScriptMutex(name);
- mutex->readlock(__FUNCTION__, __LINE__);
- for(spawn_script_itr = itr->second.begin(); spawn_script_itr != itr->second.end(); spawn_script_itr++){
- if(!spawn_script_itr->second){ //not in use
- ret = spawn_script_itr->first;
- if (use)
- {
- spawn_script_itr->second = true;
- break; // don't keep iterating, we already have our result
- }
- }
- }
- mutex->releasereadlock(__FUNCTION__, __LINE__);
- }
- if(!ret && create_new){
- if(name && LoadSpawnScript(name))
- ret = GetSpawnScript(name, create_new, use);
- else{
- LogError("Error LUA Spawn Script '%s'", name);
- return 0;
- }
- }
- return ret;
- }
- lua_State* LuaInterface::GetZoneScript(const char* name, bool create_new, bool use) {
- map<string, map<lua_State*, bool> >::iterator itr;
- map<lua_State*, bool>::iterator zone_script_itr;
- lua_State* ret = 0;
- Mutex* mutex = 0;
- itr = zone_scripts.find(name);
- if(itr != zone_scripts.end()) {
- mutex = GetZoneScriptMutex(name);
- mutex->readlock(__FUNCTION__, __LINE__);
- for(zone_script_itr = itr->second.begin(); zone_script_itr != itr->second.end(); zone_script_itr++){
- if(!zone_script_itr->second){ //not in use
- ret = zone_script_itr->first;
- if (use)
- {
- zone_script_itr->second = true;
- break; // don't keep iterating, we already have our result
- }
- }
- }
- mutex->releasereadlock(__FUNCTION__, __LINE__);
- }
- if(!ret && create_new){
- if(name && LoadZoneScript(name))
- ret = GetZoneScript(name);
- else{
- LogError("Error LUA Zone Script '%s'", name);
- return 0;
- }
- }
- return ret;
- }
- lua_State* LuaInterface::GetRegionScript(const char* name, bool create_new, bool use) {
- map<string, map<lua_State*, bool> >::iterator itr;
- map<lua_State*, bool>::iterator region_script_itr;
- lua_State* ret = 0;
- Mutex* mutex = 0;
- itr = region_scripts.find(name);
- if(itr != region_scripts.end()) {
- mutex = GetRegionScriptMutex(name);
- mutex->readlock(__FUNCTION__, __LINE__);
- for(region_script_itr = itr->second.begin(); region_script_itr != itr->second.end(); region_script_itr++){
- if(!region_script_itr->second){ //not in use
- ret = region_script_itr->first;
- if (use)
- {
- region_script_itr->second = true;
- break; // don't keep iterating, we already have our result
- }
- }
- }
- mutex->releasereadlock(__FUNCTION__, __LINE__);
- }
- if(!ret && create_new){
- if(name && LoadRegionScript(name))
- ret = GetRegionScript(name);
- else{
- LogError("Error LUA Zone Script '%s'", name);
- return 0;
- }
- }
- return ret;
- }
- bool LuaInterface::RunItemScript(string script_name, const char* function_name, Item* item, Spawn* spawn, Spawn* target, sint64* returnValue) {
- if(!item)
- return false;
- lua_State* state = GetItemScript(script_name.c_str(), true, true);
- if(state){
- Mutex* mutex = GetItemScriptMutex(script_name.c_str());
- if(mutex)
- mutex->readlock(__FUNCTION__, __LINE__);
- else{
- LogError("Error getting lock for '%s'", script_name.c_str());
- UseItemScript(script_name.c_str(), state, false);
- return false;
- }
- lua_getglobal(state, function_name);
- if (!lua_isfunction(state, lua_gettop(state))){
- lua_pop(state, 1);
- mutex->releasereadlock(__FUNCTION__);
- UseItemScript(script_name.c_str(), state, false);
- return false;
- }
- SetItemValue(state, item);
- int8 num_parms = 1;
- if(spawn){
- SetSpawnValue(state, spawn);
- num_parms++;
- }
- if(target){
- SetSpawnValue(state, target);
- num_parms++;
- }
- if(!CallItemScript(state, num_parms, returnValue)){
- if(mutex)
- mutex->releasereadlock(__FUNCTION__, __LINE__);
- UseItemScript(script_name.c_str(), state, false);
- return false;
- }
- if(mutex)
- mutex->releasereadlock(__FUNCTION__, __LINE__);
- UseItemScript(script_name.c_str(), state, false);
- return true;
- }
- else
- return false;
- }
- bool LuaInterface::RunItemScriptWithReturnString(string script_name, const char* function_name, Item* item, Spawn* spawn, std::string* returnValue) {
- if(!item)
- return false;
- lua_State* state = GetItemScript(script_name.c_str(), true, true);
- if(state){
- Mutex* mutex = GetItemScriptMutex(script_name.c_str());
- if(mutex)
- mutex->readlock(__FUNCTION__, __LINE__);
- else{
- LogError("Error getting lock for '%s'", script_name.c_str());
- UseItemScript(script_name.c_str(), state, false);
- return false;
- }
- lua_getglobal(state, function_name);
- if (!lua_isfunction(state, lua_gettop(state))){
- lua_pop(state, 1);
- mutex->releasereadlock(__FUNCTION__);
- UseItemScript(script_name.c_str(), state, false);
- return false;
- }
- SetItemValue(state, item);
- int8 num_parms = 1;
- if(spawn){
- SetSpawnValue(state, spawn);
- num_parms++;
- }
- if(!CallItemScript(state, num_parms, returnValue)){
- if(mutex)
- mutex->releasereadlock(__FUNCTION__, __LINE__);
- UseItemScript(script_name.c_str(), state, false);
- return false;
- }
- if(mutex)
- mutex->releasereadlock(__FUNCTION__, __LINE__);
- UseItemScript(script_name.c_str(), state, false);
- return true;
- }
- else
- return false;
- }
- bool LuaInterface::RunSpawnScript(string script_name, const char* function_name, Spawn* npc, Spawn* spawn, const char* message, bool is_door_open, sint32 input_value, sint32* return_value) {
- if(!npc || lua_system_reloading)
- return false;
- bool isUseDoorFunction = false;
- if(!strcmp(function_name,"usedoor"))
- isUseDoorFunction = true;
-
- lua_State* state = GetSpawnScript(script_name.c_str(), true, true);
- if(state){
- Mutex* mutex = GetSpawnScriptMutex(script_name.c_str());
- if(mutex)
- mutex->readlock(__FUNCTION__, __LINE__);
- else{
- LogError("Error getting lock for '%s'", script_name.c_str());
- UseSpawnScript(script_name.c_str(), state, false);
- return false;
- }
- lua_getglobal(state, function_name);
- if (!lua_isfunction(state, lua_gettop(state))){
- lua_pop(state, 1);
- mutex->releasereadlock(__FUNCTION__);
- UseSpawnScript(script_name.c_str(), state, false);
- return false;
- }
- SetSpawnValue(state, npc);
- int8 num_parms = 1;
- // we always send spawn, even if null (nil) when its 'usedoor' function
- if(spawn || isUseDoorFunction){
- SetSpawnValue(state, spawn);
- num_parms++;
- }
- // usedoor function always passes just npc, spawn and is_door_open
- if(isUseDoorFunction){
- SetBooleanValue(state, is_door_open);
- num_parms++;
- }
- else {
- if(message){
- SetStringValue(state, message);
- num_parms++;
- }
- if(!strcmp(function_name,"healthchanged"))
- {
- // passes as damage dealt
- SetSInt32Value(state, input_value);
- num_parms++;
- }
- }
- if(!CallScriptSInt32(state, num_parms, return_value)){
- if(mutex)
- mutex->releasereadlock(__FUNCTION__, __LINE__);
- UseSpawnScript(script_name.c_str(), state, false);
- return false;
- }
- if(mutex)
- mutex->releasereadlock(__FUNCTION__, __LINE__);
- UseSpawnScript(script_name.c_str(), state, false);
- return true;
- }
- else
- return false;
- }
- bool LuaInterface::RunZoneScript(string script_name, const char* function_name, ZoneServer* zone, Spawn* spawn, int32 int32_arg1, const char* str_arg1, Spawn* spawn_arg1, int32 int32_arg2, const char* str_arg2, Spawn* spawn_arg2) {
- if (!zone)
- return false;
- lua_State* state = GetZoneScript(script_name.c_str(), true, true);
- if (state) {
- Mutex* mutex = GetZoneScriptMutex(script_name.c_str());
- if (mutex)
- mutex->readlock(__FUNCTION__, __LINE__);
- else {
- LogError("Error getting lock for '%s'", script_name.c_str());
- UseZoneScript(script_name.c_str(), state, false);
- return false;
- }
- lua_getglobal(state, function_name);
- if (!lua_isfunction(state, lua_gettop(state))) {
- lua_pop(state, 1);
- mutex->releasereadlock(__FUNCTION__);
- UseZoneScript(script_name.c_str(), state, false);
- return false;
- }
- SetZoneValue(state, zone);
- int8 num_params = 1;
- if (spawn) {
- SetSpawnValue(state, spawn);
- num_params++;
- }
- if (int32_arg1 > 0) {
- SetInt32Value(state, int32_arg1);
- num_params++;
- }
- if (str_arg1) {
- SetStringValue(state, str_arg1);
- num_params++;
- }
- if (spawn_arg1) {
- SetSpawnValue(state, spawn_arg1);
- num_params++;
- }
- if (int32_arg2 > 0) {
- SetInt32Value(state, int32_arg2);
- num_params++;
- }
- if (str_arg2) {
- SetStringValue(state, str_arg2);
- num_params++;
- }
- if (spawn_arg2) {
- SetSpawnValue(state, spawn_arg2);
- num_params++;
- }
- if (!CallScriptInt32(state, num_params)) {
- if (mutex)
- mutex->releasereadlock(__FUNCTION__, __LINE__);
- UseZoneScript(script_name.c_str(), state, false);
- return false;
- }
- if (mutex)
- mutex->releasereadlock(__FUNCTION__, __LINE__);
- UseZoneScript(script_name.c_str(), state, false);
- return true;
- }
- else
- return false;
- }
- bool LuaInterface::RunZoneScriptWithReturn(string script_name, const char* function_name, ZoneServer* zone, Spawn* spawn, int32 int32_arg1, int32 int32_arg2, int32 int32_arg3, int32* returnValue) {
- if (!zone)
- return false;
- lua_State* state = GetZoneScript(script_name.c_str(), true, true);
- if (state) {
- Mutex* mutex = GetZoneScriptMutex(script_name.c_str());
- if (mutex)
- mutex->readlock(__FUNCTION__, __LINE__);
- else {
- LogError("Error getting lock for '%s'", script_name.c_str());
- UseZoneScript(script_name.c_str(), state, false);
- return false;
- }
- lua_getglobal(state, function_name);
- if (!lua_isfunction(state, lua_gettop(state))) {
- lua_pop(state, 1);
- mutex->releasereadlock(__FUNCTION__);
- UseZoneScript(script_name.c_str(), state, false);
- return false;
- }
- SetZoneValue(state, zone);
- int8 num_params = 1;
- SetSpawnValue(state, spawn);
- num_params++;
- SetInt32Value(state, int32_arg1);
- num_params++;
- SetInt32Value(state, int32_arg2);
- num_params++;
- SetInt32Value(state, int32_arg3);
- num_params++;
- if (!CallScriptInt32(state, num_params, returnValue)) {
- if (mutex)
- mutex->releasereadlock(__FUNCTION__, __LINE__);
- UseZoneScript(script_name.c_str(), state, false);
- return false;
- }
- if (mutex)
- mutex->releasereadlock(__FUNCTION__, __LINE__);
- UseZoneScript(script_name.c_str(), state, false);
- return true;
- }
- else
- return false;
- }
- bool LuaInterface::RunRegionScript(string script_name, const char* function_name, ZoneServer* zone, Spawn* spawn, sint32 int32_arg1, int32* returnValue) {
- if (!zone)
- return false;
- lua_State* state = GetRegionScript(script_name.c_str(), true, true);
- if (state) {
- Mutex* mutex = GetRegionScriptMutex(script_name.c_str());
- if (mutex)
- mutex->readlock(__FUNCTION__, __LINE__);
- else {
- LogError("Error getting lock for '%s'", script_name.c_str());
- UseRegionScript(script_name.c_str(), state, false);
- return false;
- }
- lua_getglobal(state, function_name);
- if (!lua_isfunction(state, lua_gettop(state))) {
- lua_pop(state, 1);
- mutex->releasereadlock(__FUNCTION__);
- UseRegionScript(script_name.c_str(), state, false);
- return false;
- }
- SetZoneValue(state, zone);
- int8 num_params = 1;
- if (spawn) {
- SetSpawnValue(state, spawn);
- num_params++;
- }
- if (int32_arg1 > 0) {
- SetSInt32Value(state, int32_arg1);
- num_params++;
- }
- if (!CallRegionScript(state, num_params, returnValue)) {
- if (mutex)
- mutex->releasereadlock(__FUNCTION__, __LINE__);
- UseRegionScript(script_name.c_str(), state, false);
- return false;
- }
- if (mutex)
- mutex->releasereadlock(__FUNCTION__, __LINE__);
- UseRegionScript(script_name.c_str(), state, false);
- return true;
- }
- else
- return false;
- }
- void LuaInterface::AddPendingSpellDelete(LuaSpell* spell) {
- MSpellDelete.lock();
- if ( spells_pending_delete.count(spell) == 0 )
- spells_pending_delete[spell] = Timer::GetCurrentTime2() + 10000;
- MSpellDelete.unlock();
- }
- void LuaInterface::AddCustomSpell(LuaSpell* spell)
- {
- MCustomSpell.writelock();
- custom_spells[spell->spell->GetSpellID()] = spell;
- MCustomSpell.releasewritelock();
- }
- void LuaInterface::RemoveCustomSpell(int32 id)
- {
- MCustomSpell.writelock();
- map<int32, LuaSpell*>::iterator itr = custom_spells.find(id);
- if (itr != custom_spells.end())
- {
- custom_spells.erase(itr);
- custom_free_spell_ids.push_front(id);
- }
- MCustomSpell.releasewritelock();
- }
- // prior to calling FindCustomSpell you should call FindCustomSpellLock and after FindCustomSpellUnlock
- LuaSpell* LuaInterface::FindCustomSpell(int32 id)
- {
- LuaSpell* spell = 0;
- map<int32, LuaSpell*>::iterator itr = custom_spells.find(id);
- if (itr != custom_spells.end())
- spell = itr->second;
- return spell;
- }
- int32 LuaInterface::GetFreeCustomSpellID()
- {
- int32 id = 0;
- MCustomSpell.writelock();
- if (!custom_free_spell_ids.empty())
- {
- id = custom_free_spell_ids.front();
- custom_free_spell_ids.pop_front();
- }
- MCustomSpell.releasewritelock();
- return id;
- }
- void LuaInterface::SetLuaUserDataStale(void* ptr) {
- std::unique_lock lock(MLUAUserData);
- std::map<void*, LUAUserData*>::iterator itr = user_data_ptr.find(ptr);
- if(itr != user_data_ptr.end()) {
- itr->second->correctly_initialized = false;
- }
- }
- LUAUserData::LUAUserData(){
- correctly_initialized = false;
- quest = 0;
- conversation_options = 0;
- spawn = 0;
- zone = 0;
- skill = 0;
- option_window_option = 0;
- item = 0;
- spawn_list = 0;
- }
- bool LUAUserData::IsCorrectlyInitialized(){
- return correctly_initialized;
- }
- bool LUAUserData::IsConversationOption(){
- return false;
- }
- bool LUAUserData::IsSpawnList() {
- return false;
- }
- bool LUAUserData::IsOptionWindow() {
- return false;
- }
- bool LUAUserData::IsSpawn(){
- return false;
- }
- bool LUAUserData::IsQuest(){
- return false;
- }
- bool LUAUserData::IsZone(){
- return false;
- }
- bool LUAUserData::IsItem(){
- return false;
- }
- bool LUAUserData::IsSkill() {
- return false;
- }
- bool LUAUserData::IsSpell() {
- return false;
- }
- LUAConversationOptionWrapper::LUAConversationOptionWrapper(){
- correctly_initialized = true;
- }
- bool LUAConversationOptionWrapper::IsConversationOption(){
- return true;
- }
- LUASpawnListWrapper::LUASpawnListWrapper() {
- correctly_initialized = true;
- }
- bool LUASpawnListWrapper::IsSpawnList() {
- return true;
- }
- LUAOptionWindowWrapper::LUAOptionWindowWrapper() {
- correctly_initialized = true;
- }
- bool LUAOptionWindowWrapper::IsOptionWindow() {
- return true;
- }
- LUASpawnWrapper::LUASpawnWrapper(){
- correctly_initialized = true;
- }
- bool LUASpawnWrapper::IsSpawn(){
- return true;
- }
- LUAZoneWrapper::LUAZoneWrapper(){
- correctly_initialized = true;
- }
- bool LUAZoneWrapper::IsZone(){
- return true;
- }
- LUAQuestWrapper::LUAQuestWrapper(){
- correctly_initialized = true;
- }
- bool LUAQuestWrapper::IsQuest(){
- return true;
- }
- LUAItemWrapper::LUAItemWrapper(){
- correctly_initialized = true;
- }
- bool LUAItemWrapper::IsItem(){
- return true;
- }
- LUASkillWrapper::LUASkillWrapper() {
- correctly_initialized = true;
- }
- bool LUASkillWrapper::IsSkill() {
- return true;
- }
- LUASpellWrapper::LUASpellWrapper() {
- correctly_initialized = true;
- }
- bool LUASpellWrapper::IsSpell() {
- return true;
- }
|