123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327 |
- /*
- 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/>.
- */
- #ifndef LUA_INTERFACE_H
- #define LUA_INTERFACE_H
- #include "Spawn.h"
- #include "Spells.h"
- #include "../common/Mutex.h"
- #include "Quests.h"
- #include "zoneserver.h"
- #include "client.h"
- #include "../LUA/lua.hpp"
- using namespace std;
- struct ConversationOption{
- string option;
- string function;
- };
- struct OptionWindowOption {
- string optionName;
- string optionDescription;
- string optionCommand;
- int32 optionIconSheet;
- int16 optionIconID;
- string optionConfirmTitle;
- };
- //Bitmask Values
- #define EFFECT_FLAG_STUN 1
- #define EFFECT_FLAG_ROOT 2
- #define EFFECT_FLAG_MEZ 4
- #define EFFECT_FLAG_STIFLE 8
- #define EFFECT_FLAG_DAZE 16
- #define EFFECT_FLAG_FEAR 32
- #define EFFECT_FLAG_SPELLBONUS 64
- #define EFFECT_FLAG_SKILLBONUS 128
- #define EFFECT_FLAG_STEALTH 256
- #define EFFECT_FLAG_INVIS 512
- #define EFFECT_FLAG_SNARE 1024
- #define EFFECT_FLAG_WATERWALK 2048
- #define EFFECT_FLAG_WATERJUMP 4096
- #define EFFECT_FLAG_FLIGHT 8192
- #define EFFECT_FLAG_GLIDE 16384
- #define EFFECT_FLAG_AOE_IMMUNE 32768
- #define EFFECT_FLAG_STUN_IMMUNE 65536
- #define EFFECT_FLAG_MEZ_IMMUNE 131072
- #define EFFECT_FLAG_DAZE_IMMUNE 262144
- #define EFFECT_FLAG_ROOT_IMMUNE 524288
- #define EFFECT_FLAG_STIFLE_IMMUNE 1048576
- #define EFFECT_FLAG_FEAR_IMMUNE 2097152
- #define EFFECT_FLAG_SAFEFALL 4194304
- struct LuaSpell{
- Entity* caster;
- int32 initial_target;
- vector<int32> targets;
- Spell* spell;
- lua_State* state;
- string file_name;
- Timer timer;
- int16 num_calls;
- int16 num_triggers;
- int8 slot_pos;
- int32 damage_remaining;
- bool resisted;
- bool interrupted;
- bool crit;
- bool last_spellattack_hit;
- bool cancel_after_all_triggers;
- bool had_triggers;
- bool had_dmg_remaining;
- Mutex MSpellTargets;
- int32 effect_bitmask;
- };
- class LUAUserData{
- public:
- LUAUserData();
- virtual ~LUAUserData(){};
- virtual bool IsCorrectlyInitialized();
- virtual bool IsConversationOption();
- virtual bool IsSpawnList();
- virtual bool IsOptionWindow();
- virtual bool IsSpawn();
- virtual bool IsQuest();
- virtual bool IsZone();
- virtual bool IsItem();
- virtual bool IsSkill();
- virtual bool IsSpell();
- bool correctly_initialized;
- Item* item;
- ZoneServer* zone;
- Spawn* spawn;
- vector<ConversationOption>* conversation_options;
- vector<OptionWindowOption>* option_window_option;
- vector<Spawn*>* spawn_list;
- Quest* quest;
- Skill* skill;
- LuaSpell* spell;
- };
- class LUAConversationOptionWrapper : public LUAUserData{
- public:
- LUAConversationOptionWrapper();
- bool IsConversationOption();
- };
- class LUASpawnListWrapper: public LUAUserData{
- public:
- LUASpawnListWrapper();
- ~LUASpawnListWrapper() { safe_delete(spawn_list); }
- bool IsSpawnList();
- };
- class LUAOptionWindowWrapper : public LUAUserData {
- public:
- LUAOptionWindowWrapper();
- bool IsOptionWindow();
- };
- class LUASpawnWrapper : public LUAUserData{
- public:
- LUASpawnWrapper();
- bool IsSpawn();
- };
- class LUAZoneWrapper : public LUAUserData{
- public:
- LUAZoneWrapper();
- bool IsZone();
- };
- class LUAQuestWrapper : public LUAUserData{
- public:
- LUAQuestWrapper();
- bool IsQuest();
- };
- class LUAItemWrapper : public LUAUserData{
- public:
- LUAItemWrapper();
- bool IsItem();
- };
- class LUASkillWrapper: public LUAUserData {
- public:
- LUASkillWrapper();
- bool IsSkill();
- };
- class LUASpellWrapper : public LUAUserData {
- public:
- LUASpellWrapper();
- bool IsSpell();
- };
- class LuaInterface {
- public:
- LuaInterface();
- ~LuaInterface();
- int GetNumberOfArgs(lua_State* state);
- bool LoadLuaSpell(const char* name);
- bool LoadLuaSpell(string name);
- bool LoadItemScript(string name);
- bool LoadItemScript(const char* name);
- bool LoadSpawnScript(string name);
- bool LoadSpawnScript(const char* name);
- bool LoadZoneScript(string name);
- bool LoadZoneScript(const char* name);
- void RemoveSpell(LuaSpell* spell, bool call_remove_function = true, bool can_delete = true, string reason = "");
- Spawn* GetSpawn(lua_State* state, int8 arg_num = 1);
- Item* GetItem(lua_State* state, int8 arg_num = 1);
- Quest* GetQuest(lua_State* state, int8 arg_num = 1);
- ZoneServer* GetZone(lua_State* state, int8 arg_num = 1);
- Skill* GetSkill(lua_State* state, int8 arg_num = 1);
- LuaSpell* GetSpell(lua_State* state, int8 arg_num = 1);
- vector<ConversationOption>* GetConversation(lua_State* state, int8 arg_num = 1);
- vector<Spawn*>* GetSpawnList(lua_State* state, int8 arg_num = 1);
- vector<OptionWindowOption>* GetOptionWindow(lua_State* state, int8 arg_num = 1);
- int8 GetInt8Value(lua_State* state, int8 arg_num = 1);
- int16 GetInt16Value(lua_State* state, int8 arg_num = 1);
- int32 GetInt32Value(lua_State* state, int8 arg_num = 1);
- sint32 GetSInt32Value(lua_State* state, int8 arg_num = 1);
- float GetFloatValue(lua_State* state, int8 arg_num = 1);
- string GetStringValue(lua_State* state, int8 arg_num = 1);
- bool GetBooleanValue(lua_State*state, int8 arg_num = 1);
- void Process();
- void SetInt32Value(lua_State* state, int32 value);
- void SetSInt32Value(lua_State* state, sint32 value);
- void SetFloatValue(lua_State* state, float value);
- void SetBooleanValue(lua_State* state, bool value);
- void SetStringValue(lua_State* state, const char* value);
- void SetSpawnValue(lua_State* state, Spawn* spawn);
- void SetSkillValue(lua_State* state, Skill* skill);
- void SetItemValue(lua_State* state, Item* item);
- void SetQuestValue(lua_State* state, Quest* quest);
- void SetZoneValue(lua_State* state, ZoneServer* zone);
- void SetSpawnListValue(lua_State* state, vector<Spawn*>* spawnList);
- void SetSpellValue(lua_State* state, LuaSpell* spell);
- void SetConversationValue(lua_State* state, vector<ConversationOption>* conversation);
- void SetOptionWindowValue(lua_State* state, vector<OptionWindowOption>* optionWindow);
- void AddSpawnPointers(LuaSpell* spell, bool first_cast, bool precast = false, const char* function = 0, SpellScriptTimer* timer = 0, bool passLuaSpell=false);
- LuaSpell* GetCurrentSpell(lua_State* state);
- bool CallSpellProcess(LuaSpell* spell, int8 num_parameters);
- LuaSpell* GetSpell(const char* name);
- void UseItemScript(const char* name, lua_State* state, bool val);
- void UseSpawnScript(const char* name, lua_State* state, bool val);
- void UseZoneScript(const char* name, lua_State* state, bool val);
- lua_State* GetItemScript(const char* name, bool create_new = true, bool use = false);
- lua_State* GetSpawnScript(const char* name, bool create_new = true, bool use = false);
- lua_State* GetZoneScript(const char* name, bool create_new = true, bool use = false);
- Quest* LoadQuest(int32 id, const char* name, const char* type, const char* zone, int8 level, const char* description, char* script_name);
- const char* GetScriptName(lua_State* state);
- void RemoveSpawnScript(const char* name);
- bool RunItemScript(string script_name, const char* function_name, Item* item, Spawn* spawn = 0);
- bool CallItemScript(lua_State* state, int8 num_parameters);
- bool RunSpawnScript(string script_name, const char* function_name, Spawn* npc, Spawn* spawn = 0, const char* message = 0);
- bool CallSpawnScript(lua_State* state, int8 num_parameters);
- bool RunZoneScript(string script_name, const char* function_name, ZoneServer* zone, Spawn* spawn = 0, int32 int32_arg1 = 0, const char* str_arg1 = 0, Spawn* spawn_arg1 = 0, int32 int32_arg2 = 0, const char* str_arg2 = 0, Spawn* spawn_arg2 = 0);
- bool CallZoneScript(lua_State* state, int8 num_parameters);
- void ResetFunctionStack(lua_State* state);
- void DestroySpells();
- void DestroySpawnScripts();
- void DestroyItemScripts();
- void ReloadSpells();
- void DestroyQuests(bool reload = false);
- void DestroyZoneScripts();
- void SimpleLogError(const char* error);
- void LogError(const char* error, ...);
- void CallQuestFunction(Quest* quest, const char* function, Spawn* player, int32 step_id = 0xFFFFFFFF);
- void RemoveDebugClients(Client* client);
- void UpdateDebugClients(Client* client);
- void ProcessErrorMessage(const char* message);
- map<Client*, int32> GetDebugClients(){ return debug_clients; }
- void AddUserDataPtr(LUAUserData* data);
- void DeleteUserDataPtrs(bool all);
- void DeletePendingSpells(bool all);
- void DeletePendingSpell(LuaSpell* spell);
- Mutex* GetSpawnScriptMutex(const char* name);
- Mutex* GetItemScriptMutex(const char* name);
- Mutex* GetZoneScriptMutex(const char* name);
- Mutex* GetQuestMutex(Quest* quest);
- void SetSpawnScriptsReloading(bool val) { spawn_scripts_reloading = val; }
- void AddPendingSpellDelete(LuaSpell* spell);
- void AddCustomSpell(LuaSpell* spell);
- void RemoveCustomSpell(int32 id);
- void FindCustomSpellLock() { MCustomSpell.readlock(); }
- void FindCustomSpellUnlock() { MCustomSpell.releasereadlock(); }
- LuaSpell* FindCustomSpell(int32 id);
- int32 GetFreeCustomSpellID();
- private:
- bool shutting_down;
- bool spawn_scripts_reloading;
- map<LuaSpell*, int32> spells_pending_delete;
- Timer* user_data_timer;
- Timer* spell_delete_timer;
- map<LUAUserData*, int32> user_data;
- map<Client*, int32> debug_clients;
- map<lua_State*, LuaSpell*> current_spells;
- vector<string>* GetDirectoryListing(const char* directory);
- lua_State* LoadLuaFile(const char* name);
- void RegisterFunctions(lua_State* state);
- map<string, LuaSpell*> spells;
- map<lua_State*, string> inverse_spells;
- map<int32, Quest*> quests;
- map<int32, lua_State*> quest_states;
- map<string, map<lua_State*, bool> > item_scripts;
- map<string, map<lua_State*, bool> > spawn_scripts;
- map<string, map<lua_State*, bool> > zone_scripts;
- map<int32, LuaSpell*> custom_spells;
- std::deque<int32> custom_free_spell_ids;
- map<lua_State*, string> item_inverse_scripts;
- map<lua_State*, string> spawn_inverse_scripts;
- map<lua_State*, string> zone_inverse_scripts;
- map<string, Mutex*> item_scripts_mutex;
- map<string, Mutex*> spawn_scripts_mutex;
- map<string, Mutex*> zone_scripts_mutex;
- map<int32, Mutex*> quests_mutex;
- Mutex MDebugClients;
- Mutex MSpells;
- Mutex MSpawnScripts;
- Mutex MItemScripts;
- Mutex MZoneScripts;
- Mutex MQuests;
- Mutex MLUAUserData;
- Mutex MLUAMain;
- Mutex MSpellDelete;
- Mutex MCustomSpell;
- };
- #endif
|