Guest User

luascript.h

a guest
Apr 13th, 2020
218
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ////////////////////////////////////////////////////////////////////////
  2. // OpenTibia - an opensource roleplaying game
  3. ////////////////////////////////////////////////////////////////////////
  4. // This program is free software: you can redistribute it and/or modify
  5. // it under the terms of the GNU General Public License as published by
  6. // the Free Software Foundation, either version 3 of the License, or
  7. // (at your option) any later version.
  8. //
  9. // This program is distributed in the hope that it will be useful,
  10. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. // GNU General Public License for more details.
  13. //
  14. // You should have received a copy of the GNU General Public License
  15. // along with this program.  If not, see <http://www.gnu.org/licenses/>.
  16. ////////////////////////////////////////////////////////////////////////
  17.  
  18. #ifndef __LUASCRIPT__
  19. #define __LUASCRIPT__
  20. #include "otsystem.h"
  21. #ifdef __LUAJIT__
  22. #include <lua.hpp>
  23.  
  24. extern "C"
  25. {
  26.     #include <lauxlib.h>
  27.     #include <lualib.h>
  28. }
  29. #else
  30.  
  31. extern "C"
  32. {
  33.     #include "lua.h"
  34.     #include "lualib.h"
  35.     #include "lauxlib.h"
  36. }
  37. #endif
  38.  
  39. #include "database.h"
  40. #include "position.h"
  41.  
  42. enum LuaVariantType_t
  43. {
  44.     VARIANT_NONE = 0,
  45.     VARIANT_NUMBER,
  46.     VARIANT_POSITION,
  47.     VARIANT_TARGETPOSITION,
  48.     VARIANT_STRING
  49. };
  50.  
  51. struct LuaVariant
  52. {
  53.     LuaVariant()
  54.     {
  55.         type = VARIANT_NONE;
  56.         text = "";
  57.         pos = PositionEx();
  58.         number = 0;
  59.     }
  60.  
  61.     LuaVariantType_t type;
  62.     std::string text;
  63.     PositionEx pos;
  64.     uint32_t number;
  65. };
  66.  
  67. class Game;
  68. class Thing;
  69. class LuaInterface;
  70.  
  71. class Creature;
  72. class Player;
  73. class Npc;
  74.  
  75. class Item;
  76. class Container;
  77.  
  78. class Combat;
  79. class CombatArea;
  80. class Condition;
  81.  
  82. struct Outfit_t;
  83. class ScriptEnviroment
  84. {
  85.     public:
  86.         ScriptEnviroment();
  87.         virtual ~ScriptEnviroment();
  88.  
  89.         static bool saveGameState();
  90.         static bool loadGameState();
  91.  
  92.         bool getStorage(const uint32_t key, std::string& value) const;
  93.         void setStorage(const uint32_t key, const std::string& value) {m_storageMap[key] = value;}
  94.         void eraseStorage(const uint32_t key) {m_storageMap.erase(key);}
  95.  
  96.         int32_t getScriptId() {return m_scriptId;}
  97.         void setScriptId(int32_t scriptId, LuaInterface* interface)
  98.             {m_scriptId = scriptId; m_interface = interface;}
  99.  
  100.         int32_t getCallbackId() {return m_callbackId;}
  101.         bool setCallbackId(int32_t callbackId, LuaInterface* interface);
  102.  
  103.         std::string getEvent() {return m_event;}
  104.         void setEvent(const std::string& desc) {m_event = desc;}
  105.  
  106.         Position getRealPos() {return m_realPos;}
  107.         void setRealPos(const Position& realPos) {m_realPos = realPos;}
  108.  
  109.         Npc* getNpc() const {return m_curNpc;}
  110.         void setNpc(Npc* npc) {m_curNpc = npc;}
  111.  
  112.         static uint32_t addCombatArea(CombatArea* area);
  113.         static CombatArea* getCombatArea(uint32_t areaId);
  114.  
  115.         static uint32_t addCombatObject(Combat* combat);
  116.         static Combat* getCombatObject(uint32_t combatId);
  117.  
  118.         static uint32_t addConditionObject(Condition* condition);
  119.         static uint32_t addTempConditionObject(Condition* condition);
  120.         static Condition* getConditionObject(uint32_t conditionId);
  121.  
  122.         Thing* getThingByUID(uint32_t uid);
  123.         Item* getItemByUID(uint32_t uid);
  124.         Container* getContainerByUID(uint32_t uid);
  125.         Creature* getCreatureByUID(uint32_t uid);
  126.         Player* getPlayerByUID(uint32_t uid);
  127.  
  128.         uint32_t addThing(Thing* thing);
  129.         void insertThing(uint32_t uid, Thing* thing);
  130.         void removeThing(uint32_t uid);
  131.  
  132.         static void addTempItem(ScriptEnviroment* env, Item* item);
  133.         static void removeTempItem(ScriptEnviroment* env, Item* item);
  134.         static void removeTempItem(Item* item);
  135.  
  136.         DBResult* getResultByID(uint32_t id);
  137.         uint32_t addResult(DBResult* res);
  138.         bool removeResult(uint32_t id);
  139.  
  140.         static void addUniqueThing(Thing* thing);
  141.         static void removeUniqueThing(Thing* thing);
  142.  
  143.         static uint32_t getLastConditionId() {return m_lastConditionId;}
  144.         static uint32_t getLastCombatId() {return m_lastCombatId;}
  145.         static uint32_t getLastAreaId() {return m_lastAreaId;}
  146.  
  147.         void setTimerEvent() {m_timerEvent = true;}
  148.         void resetTimerEvent() {m_timerEvent = false;}
  149.  
  150.         LuaInterface* getInterface() {return m_interface;}
  151.         void getInfo(int32_t& scriptId, std::string& desc, LuaInterface*& interface, int32_t& callbackId, bool& timerEvent);
  152.         void reset();
  153.         void resetCallback() {m_callbackId = 0;}
  154.  
  155.         void streamVariant(std::stringstream& stream, const std::string& local, const LuaVariant& var);
  156.         void streamThing(std::stringstream& stream, const std::string& local, Thing* thing, uint32_t id = 0);
  157.         void streamPosition(std::stringstream& stream, const std::string& local, const PositionEx& position)
  158.             {streamPosition(stream, local, position, position.stackpos);}
  159.         void streamPosition(std::stringstream& stream, const std::string& local, const Position& position, uint32_t stackpos);
  160.         void streamOutfit(std::stringstream& stream, const std::string& local, const Outfit_t& outfit);
  161.  
  162.     private:
  163.         typedef std::map<uint64_t, Thing*> ThingMap;
  164.         typedef std::vector<const LuaVariant*> VariantVector;
  165.         typedef std::list<Item*> ItemList;
  166.         typedef std::map<ScriptEnviroment*, ItemList> TempItemListMap;
  167.  
  168.         typedef std::map<uint32_t, std::string> StorageMap;
  169.         typedef std::map<uint32_t, CombatArea*> AreaMap;
  170.         typedef std::map<uint32_t, Combat*> CombatMap;
  171.         typedef std::map<uint32_t, Condition*> ConditionMap;
  172.         typedef std::map<uint32_t, DBResult*> DBResultMap;
  173.  
  174.         LuaInterface* m_interface;
  175.         int32_t m_scriptId, m_callbackId;
  176.         std::string m_event;
  177.         bool m_timerEvent;
  178.  
  179.         ThingMap m_localMap;
  180.         DBResultMap m_tempResults;
  181.  
  182.         static TempItemListMap m_tempItems;
  183.         static StorageMap m_storageMap;
  184.         static ThingMap m_globalMap;
  185.  
  186.         static uint32_t m_lastAreaId;
  187.         static AreaMap m_areaMap;
  188.  
  189.         static uint32_t m_lastCombatId;
  190.         static CombatMap m_combatMap;
  191.  
  192.         static uint32_t m_lastConditionId;
  193.         static ConditionMap m_conditionMap;
  194.         static ConditionMap m_tempConditionMap;
  195.  
  196.         int32_t m_lastUID;
  197.         bool m_loaded;
  198.         Position m_realPos;
  199.         Npc* m_curNpc;
  200. };
  201.  
  202. enum ErrorCode_t
  203. {
  204.     LUA_ERROR_PLAYER_NOT_FOUND,
  205.     LUA_ERROR_MONSTER_NOT_FOUND,
  206.     LUA_ERROR_NPC_NOT_FOUND,
  207.     LUA_ERROR_CREATURE_NOT_FOUND,
  208.     LUA_ERROR_ITEM_NOT_FOUND,
  209.     LUA_ERROR_THING_NOT_FOUND,
  210.     LUA_ERROR_TILE_NOT_FOUND,
  211.     LUA_ERROR_HOUSE_NOT_FOUND,
  212.     LUA_ERROR_COMBAT_NOT_FOUND,
  213.     LUA_ERROR_CONDITION_NOT_FOUND,
  214.     LUA_ERROR_AREA_NOT_FOUND,
  215.     LUA_ERROR_CONTAINER_NOT_FOUND,
  216.     LUA_ERROR_VARIANT_NOT_FOUND,
  217.     LUA_ERROR_VARIANT_UNKNOWN,
  218.     LUA_ERROR_SPELL_NOT_FOUND
  219. };
  220.  
  221. #define errorEx(a) error(__FUNCTION__, a)
  222.  
  223. class LuaInterface
  224. {
  225.     public:
  226.         LuaInterface(std::string interfaceName);
  227.         virtual ~LuaInterface();
  228.  
  229.         virtual bool initState();
  230.         bool reInitState();
  231.  
  232.         static bool reserveEnv()
  233.         {
  234.             ++m_scriptEnvIndex;
  235.             if(m_scriptEnvIndex > 20)
  236.             {
  237.                 --m_scriptEnvIndex;
  238.                 return false;
  239.             }
  240.  
  241.             return true;
  242.         }
  243.         static void releaseEnv()
  244.         {
  245.             if(m_scriptEnvIndex >= 0)
  246.             {
  247.                 m_scriptEnv[m_scriptEnvIndex].reset();
  248.                 --m_scriptEnvIndex;
  249.             }
  250.         }
  251.  
  252.         bool loadBuffer(const std::string& text, Npc* npc = NULL);
  253.         bool loadFile(const std::string& file, Npc* npc = NULL);
  254.         bool loadDirectory(const std::string& dir, Npc* npc = NULL);
  255.  
  256.         std::string getName() {return m_interfaceName;}
  257.         std::string getScript(int32_t scriptId);
  258.         std::string getLastError() const {return m_lastError;}
  259.  
  260.         int32_t getEvent(const std::string& eventName);
  261.         lua_State* getState() {return m_luaState;}
  262.         static ScriptEnviroment* getEnv()
  263.         {
  264.             assert(m_scriptEnvIndex >= 0 && m_scriptEnvIndex < 21);
  265.             return &m_scriptEnv[m_scriptEnvIndex];
  266.         }
  267.  
  268.         bool pushFunction(int32_t functionId);
  269.         bool callFunction(uint32_t params);
  270.         static int32_t handleFunction(lua_State* L);
  271.  
  272.         void dumpStack(lua_State* L = NULL);
  273.  
  274.         //push/pop common structures
  275.         static void pushThing(lua_State* L, Thing* thing, uint32_t id = 0);
  276.         static void pushVariant(lua_State* L, const LuaVariant& var);
  277.         static void pushPosition(lua_State* L, const PositionEx& position) {pushPosition(L, position, position.stackpos);}
  278.         static void pushPosition(lua_State* L, const Position& position, uint32_t stackpos);
  279.         static void pushOutfit(lua_State* L, const Outfit_t& outfit);
  280.         static void pushCallback(lua_State* L, int32_t callback);
  281.  
  282.         // change loot rates per player 1
  283.         static int32_t luaDoPlayerSetSpecialRateLoot(lua_State* L);
  284.         static int32_t luaDoPlayerGetSpecialRateLoot(lua_State* L);
  285.  
  286.         static LuaVariant popVariant(lua_State* L);
  287.         static void popPosition(lua_State* L, PositionEx& position);
  288.         static void popPosition(lua_State* L, Position& position, uint32_t& stackpos);
  289.         static bool popBoolean(lua_State* L);
  290.         static int64_t popNumber(lua_State* L);
  291.         static double popFloatNumber(lua_State* L);
  292.         static std::string popString(lua_State* L);
  293.         static int32_t popCallback(lua_State* L);
  294.         static Outfit_t popOutfit(lua_State* L);
  295.  
  296.         static int64_t getField(lua_State* L, const char* key);
  297.         static uint64_t getFieldUnsigned(lua_State* L, const char* key);
  298.         static std::string getFieldString(lua_State* L, const char* key);
  299.         static bool getFieldBool(lua_State* L, const char* key);
  300.  
  301.         static void setField(lua_State* L, const char* index, int32_t val);
  302.         static void setField(lua_State* L, const char* index, const std::string& val);
  303.         static void setFieldBool(lua_State* L, const char* index, bool val);
  304.         static void setFieldFloat(lua_State* L, const char* index, double val);
  305.  
  306.         static void createTable(lua_State* L, const char* index);
  307.         static void createTable(lua_State* L, const char* index, int32_t narr, int32_t nrec);
  308.         static void createTable(lua_State* L, int32_t index);
  309.         static void createTable(lua_State* L, int32_t index, int32_t narr, int32_t nrec);
  310.         static void pushTable(lua_State* L);
  311.  
  312.         static std::string getGlobalString(lua_State* L, const std::string& _identifier, const std::string& _default = "");
  313.         static bool getGlobalBool(lua_State* L, const std::string& _identifier, bool _default = false);
  314.         static int32_t getGlobalNumber(lua_State* L, const std::string& _identifier, const int32_t _default = 0);
  315.         static double getGlobalDouble(lua_State* L, const std::string& _identifier, const double _default = 0);
  316.  
  317.         static void getValue(const std::string& key, lua_State* L, lua_State* _L);
  318.         static void moveValue(lua_State* from, lua_State* to);
  319.  
  320.         static void error(const char* function, const std::string& desc);
  321.  
  322.     protected:
  323.         virtual bool closeState();
  324.  
  325.         static std::string getError(ErrorCode_t code);
  326.         static bool getArea(lua_State* L, std::list<uint32_t>& list, uint32_t& rows);
  327.  
  328.         virtual void registerFunctions();
  329.  
  330.         //lua functions
  331.         static int32_t luaGetCastsOnline(lua_State* L);
  332.         static int32_t luaDoPlayerSetCastPassword(lua_State* L);
  333.         static int32_t luaDoPlayerSetCastDescription(lua_State* L);
  334.         static int32_t luaDoPlayerSetCastState(lua_State* L);
  335.         static int32_t luaGetPlayerCast(lua_State* L);
  336.         static int32_t luaDoPlayerAddCastBan(lua_State* L);
  337.         static int32_t luaDoPlayerRemoveCastBan(lua_State* L);
  338.         static int32_t luaGetPlayerCastBans(lua_State* L);
  339.         static int32_t luaGetPlayerCastViewers(lua_State* L);
  340.         static int32_t luaDoPlayerAddCastMute(lua_State* L);
  341.         static int32_t luaDoPlayerRemoveCastMute(lua_State* L);
  342.         static int32_t luaGetPlayerCastMutes(lua_State* L);
  343.  
  344.         static int32_t luaDoPlayerSetMagicLevel(lua_State* L);
  345.         static int32_t luaDoPlayerSetSkillLevel(lua_State* L);
  346.  
  347.         // Ping
  348.         static int32_t luaDoPlayerSendPing(lua_State* L);
  349.         static int32_t luaGetPlayerLastPing(lua_State* L);
  350.         static int32_t luaGetPlayerLastPong(lua_State* L);
  351.         static int32_t luaGetOtsysTime(lua_State* L);
  352.         // /Ping
  353.        
  354.         static int32_t luaDoRemoveItem(lua_State* L);
  355.         static int32_t luaDoPlayerFeed(lua_State* L);
  356.         static int32_t luaDoPlayerSendCancel(lua_State* L);
  357.         static int32_t luaDoSendDefaultCancel(lua_State* L);
  358.         static int32_t luaGetSearchString(lua_State* L);
  359.         static int32_t luaGetClosestFreeTile(lua_State* L);
  360.         static int32_t luaDoTeleportThing(lua_State* L);
  361.         static int32_t luaDoTransformItem(lua_State* L);
  362.         static int32_t luaDoSendCreatureSquare(lua_State* L);
  363.         static int32_t luaDoSendAnimatedText(lua_State* L);
  364.         static int32_t luaDoSendMagicEffect(lua_State* L);
  365.         static int32_t luaDoSendDistanceShoot(lua_State* L);
  366.         static int32_t luaDoShowTextWindow(lua_State* L);
  367.         static int32_t luaDoShowTextDialog(lua_State* L);
  368.         static int32_t luaDoDecayItem(lua_State* L);
  369.         static int32_t luaDoCreateItem(lua_State* L);
  370.         static int32_t luaDoCreateItemEx(lua_State* L);
  371.         static int32_t luaDoCreateTeleport(lua_State* L);
  372.         static int32_t luaDoCreateMonster(lua_State* L);
  373.         static int32_t luaDoCreateNpc(lua_State* L);
  374.         static int32_t luaDoSummonMonster(lua_State* L);
  375.         static int32_t luaDoConvinceCreature(lua_State* L);
  376.         static int32_t luaGetMonsterTargetList(lua_State* L);
  377.         static int32_t luaGetMonsterFriendList(lua_State* L);
  378.         static int32_t luaDoMonsterSetTarget(lua_State* L);
  379.         static int32_t luaDoMonsterChangeTarget(lua_State* L);
  380.         static int32_t luaDoAddCondition(lua_State* L);
  381.         static int32_t luaDoRemoveCondition(lua_State* L);
  382.         static int32_t luaDoRemoveConditions(lua_State* L);
  383.         static int32_t luaDoRemoveCreature(lua_State* L);
  384.         static int32_t luaDoMoveCreature(lua_State* L);
  385.         static int32_t luaDoCreatureSay(lua_State* L);
  386.         static int32_t luaDoPlayerAddSkillTry(lua_State* L);
  387.         static int32_t luaDoCreatureAddHealth(lua_State* L);
  388.         static int32_t luaDoCreatureAddMana(lua_State* L);
  389.         static int32_t luaSetCreatureMaxHealth(lua_State* L);
  390.         static int32_t luaSetCreatureMaxMana(lua_State* L);
  391.         static int32_t luaDoPlayerSetMaxCapacity(lua_State* L);
  392.         static int32_t luaDoPlayerAddSpentMana(lua_State* L);
  393.         static int32_t luaDoPlayerAddItem(lua_State* L);
  394.         static int32_t luaDoPlayerAddItemEx(lua_State* L);
  395.         static int32_t luaDoTileAddItemEx(lua_State* L);
  396.         static int32_t luaDoAddContainerItemEx(lua_State* L);
  397.         static int32_t luaDoRelocate(lua_State* L);
  398.         static int32_t luaDoCleanTile(lua_State* L);
  399.         static int32_t luaDoPlayerSendTextMessage(lua_State* L);
  400.         static int32_t luaDoPlayerSendChannelMessage(lua_State* L);
  401.        
  402.         static int32_t luaDoPlayerSendToChannel(lua_State* L);
  403.         static int32_t luaDoPlayerOpenChannel(lua_State* L);
  404.         static int32_t luaDoPlayerAddMoney(lua_State* L);
  405.         static int32_t luaDoPlayerRemoveMoney(lua_State* L);
  406.         static int32_t luaDoPlayerTransferMoneyTo(lua_State* L);
  407.         static int32_t luaDoPlayerSetPzLocked(lua_State* L);
  408.         static int32_t luaDoPlayerSetTown(lua_State* L);
  409.         static int32_t luaDoPlayerSetVocation(lua_State* L);
  410.         static int32_t luaDoPlayerRemoveItem(lua_State* L);
  411.         static int32_t luaDoPlayerAddSoul(lua_State* L);
  412.         static int32_t luaDoPlayerSetStamina(lua_State* L);
  413.         static int32_t luaDoPlayerAddExperience(lua_State* L);
  414.         static int32_t luaDoPlayerSetGuildId(lua_State* L);
  415.         static int32_t luaDoPlayerSetGuildLevel(lua_State* L);
  416.         static int32_t luaDoPlayerSetGuildNick(lua_State* L);
  417.         static int32_t luaDoPlayerSetSex(lua_State* L);
  418.         static int32_t luaDoPlayerSetIdleTime(lua_State* L);
  419.         static int32_t luaGetPlayerIdleTime(lua_State* L);
  420.         static int32_t luaDoCreatureSetLookDir(lua_State* L);
  421.         static int32_t luaGetCreatureHideHealth(lua_State* L);
  422.         static int32_t luaDoCreatureSetHideHealth(lua_State* L);
  423.         static int32_t luaGetCreatureSpeakType(lua_State* L);
  424.         static int32_t luaDoCreatureSetSpeakType(lua_State* L);
  425.         static int32_t luaGetCreatureGuildEmblem(lua_State* L);
  426.         static int32_t luaDoCreatureSetGuildEmblem(lua_State* L);
  427.         static int32_t luaGetCreaturePartyShield(lua_State* L);
  428.         static int32_t luaDoCreatureSetPartyShield(lua_State* L);
  429.         static int32_t luaGetCreatureSkullType(lua_State* L);
  430.         static int32_t luaDoCreatureSetSkullType(lua_State* L);
  431.         static int32_t luaGetPlayerSkullEnd(lua_State* L);
  432.         static int32_t luaDoPlayerSetSkullEnd(lua_State* L);
  433.         static int32_t luaDoPlayerSwitchSaving(lua_State* L);
  434.         static int32_t luaDoPlayerSave(lua_State* L);
  435.         static int32_t luaDoPlayerSendOutfitWindow(lua_State* L);
  436.         static int32_t luaDoCreatureExecuteTalkAction(lua_State* L);
  437.         static int32_t luaGetCreatureByName(lua_State* L);
  438.         static int32_t luaGetPlayerByGUID(lua_State* L);
  439.         static int32_t luaGetPlayerByNameWildcard(lua_State* L);
  440.         static int32_t luaGetPlayerGUIDByName(lua_State* L);
  441.         static int32_t luaGetPlayerNameByGUID(lua_State* L);
  442.         static int32_t luaGetPlayersByAccountId(lua_State* L);
  443.         static int32_t luaGetAccountIdByName(lua_State* L);
  444.         static int32_t luaGetAccountByName(lua_State* L);
  445.         static int32_t luaGetAccountIdByAccount(lua_State* L);
  446.         static int32_t luaGetAccountByAccountId(lua_State* L);
  447.         static int32_t luaGetIpByName(lua_State* L);
  448.         static int32_t luaGetPlayersByIp(lua_State* L);
  449.         static int32_t luaIsIpBanished(lua_State* L);
  450.         static int32_t luaIsPlayerBanished(lua_State* L);
  451.         static int32_t luaIsAccountBanished(lua_State* L);
  452.         static int32_t luaDoAddIpBanishment(lua_State* L);
  453.         static int32_t luaDoAddPlayerBanishment(lua_State* L);
  454.         static int32_t luaDoAddAccountBanishment(lua_State* L);
  455.         static int32_t luaDoAddNotation(lua_State* L);
  456.         static int32_t luaDoAddStatement(lua_State* L);
  457.         static int32_t luaDoRemoveIpBanishment(lua_State* L);
  458.         static int32_t luaDoRemovePlayerBanishment(lua_State* L);
  459.         static int32_t luaDoRemoveAccountBanishment(lua_State* L);
  460.         static int32_t luaDoRemoveNotations(lua_State* L);
  461.         static int32_t luaDoRemoveStatements(lua_State* L);
  462.         static int32_t luaGetNotationsCount(lua_State* L);
  463.         static int32_t luaGetStatementsCount(lua_State* L);
  464.         static int32_t luaGetBanData(lua_State* L);
  465.         static int32_t luaGetBanReason(lua_State* L);
  466.         static int32_t luaGetBanAction(lua_State* L);
  467.         static int32_t luaGetBanList(lua_State* L);
  468.         static int32_t luaGetPlayerModes(lua_State* L);
  469.         static int32_t luaGetPlayerRates(lua_State* L);
  470.         static int32_t luaDoPlayerSetRate(lua_State* L);
  471.         static int32_t luaDoCreatureSetDropLoot(lua_State* L);
  472.         static int32_t luaGetPlayerLossPercent(lua_State* L);
  473.         static int32_t luaDoPlayerSetLossPercent(lua_State* L);
  474.         static int32_t luaDoPlayerSetLossSkill(lua_State* L);
  475.         static int32_t luaGetPlayerLossSkill(lua_State* L);
  476.         static int32_t luaGetThing(lua_State* L);
  477.         static int32_t luaGetThingPosition(lua_State* L);
  478.         static int32_t luaDoItemRaidUnref(lua_State* L);
  479.         static int32_t luaHasItemProperty(lua_State* L);
  480.         static int32_t luaGetThingFromPos(lua_State* L);
  481.         static int32_t luaGetTileItemById(lua_State* L);
  482.         static int32_t luaGetTileItemByType(lua_State* L);
  483.         static int32_t luaGetTileThingByPos(lua_State* L);
  484.         static int32_t luaGetTopCreature(lua_State* L);
  485.         static int32_t luaGetTileInfo(lua_State* L);
  486.         static int32_t luaDoTileQueryAdd(lua_State* L);
  487.         static int32_t luaGetHouseInfo(lua_State* L);
  488.         static int32_t luaGetHouseAccessList(lua_State* L);
  489.         static int32_t luaGetHouseByPlayerGUID(lua_State* L);
  490.         static int32_t luaGetHouseFromPos(lua_State* L);
  491.         static int32_t luaSetHouseOwner(lua_State* L);
  492.         static int32_t luaSetHouseAccessList(lua_State* L);
  493.         static int32_t luaDoPlayerSetNameDescription(lua_State* L);
  494.         static int32_t luaGetPlayerNameDescription(lua_State* L);
  495.         static int32_t luaDoPlayerSetSpecialDescription(lua_State* L);
  496.         static int32_t luaGetPlayerSpecialDescription(lua_State* L);
  497.         static int32_t luaGetPlayerFood(lua_State* L);
  498.         static int32_t luaGetPlayerAccess(lua_State* L);
  499.         static int32_t luaGetPlayerGhostAccess(lua_State* L);
  500.         static int32_t luaGetPlayerLevel(lua_State* L);
  501.         static int32_t luaGetPlayerExperience(lua_State* L);
  502.         static int32_t luaGetPlayerMagLevel(lua_State* L);
  503.         static int32_t luaGetPlayerSpentMana(lua_State* L);
  504.         static int32_t luaGetCreatureMana(lua_State* L);
  505.         static int32_t luaGetCreatureMaxMana(lua_State* L);
  506.         static int32_t luaGetCreatureHealth(lua_State* L);
  507.         static int32_t luaGetCreatureMaxHealth(lua_State* L);
  508.         static int32_t luaGetCreatureSpeed(lua_State* L);
  509.         static int32_t luaGetCreatureBaseSpeed(lua_State* L);
  510.         static int32_t luaGetCreatureTarget(lua_State* L);
  511.         static int32_t luaGetCreatureLookDirection(lua_State* L);
  512.         static int32_t luaGetPlayerSkillLevel(lua_State* L);
  513.         static int32_t luaGetPlayerSkillTries(lua_State* L);
  514.         static int32_t luaGetPlayerVocation(lua_State* L);
  515.         static int32_t luaGetPlayerTown(lua_State* L);
  516.         static int32_t luaGetPlayerItemCount(lua_State* L);
  517.         static int32_t luaGetPlayerMoney(lua_State* L);
  518.         static int32_t luaGetPlayerSoul(lua_State* L);
  519.         static int32_t luaGetPlayerStamina(lua_State* L);
  520.         static int32_t luaGetPlayerFreeCap(lua_State* L);
  521.         static int32_t luaGetPlayerLight(lua_State* L);
  522.         static int32_t luaGetPlayerSlotItem(lua_State* L);
  523.         static int32_t luaGetPlayerWeapon(lua_State* L);
  524.         static int32_t luaGetPlayerItemById(lua_State* L);
  525.         static int32_t luaGetPlayerRequiredMana(lua_State* L);
  526.         static int32_t luaGetPlayerRequiredSkillTries(lua_State* L);
  527.         static int32_t luaGetPlayerIp(lua_State* L);
  528.         static int32_t luaGetPlayerLastLoad(lua_State* L);
  529.         static int32_t luaGetPlayerLastLogin(lua_State* L);
  530.         static int32_t luaGetPlayerTradeState(lua_State* L);
  531.         static int32_t luaGetPlayerAccountManager(lua_State* L);
  532.         static int32_t luaGetPlayerAccountId(lua_State* L);
  533.         static int32_t luaGetPlayerAccount(lua_State* L);
  534.         static int32_t luaGetPlayerDepotItems(lua_State* L);
  535.         static int32_t luaGetPlayerGuildId(lua_State* L);
  536.         static int32_t luaGetPlayerGuildName(lua_State* L);
  537.         static int32_t luaGetPlayerGuildRank(lua_State* L);
  538.         static int32_t luaGetPlayerGuildRankId(lua_State* L);
  539.         static int32_t luaGetPlayerGuildLevel(lua_State* L);
  540.         static int32_t luaGetPlayerGuildNick(lua_State* L);
  541.         static int32_t luaGetPlayerSex(lua_State* L);
  542.         static int32_t luaGetPlayerGUID(lua_State* L);
  543.         static int32_t luaGetPlayerFlagValue(lua_State* L);
  544.         static int32_t luaGetPlayerCustomFlagValue(lua_State* L);
  545.         static int32_t luaGetCreatureCondition(lua_State* L);
  546.         static int32_t luaHasPlayerClient(lua_State* L);
  547.         static int32_t luaGetDepotId(lua_State* L);
  548.         static int32_t luaGetVocationInfo(lua_State* L);
  549.         static int32_t luaGetGroupInfo(lua_State* L);
  550.         static int32_t luaGetMonsterInfo(lua_State* L);
  551.         static int32_t luaGetPlayerPromotionLevel(lua_State* L);
  552.         static int32_t luaDoPlayerSetPromotionLevel(lua_State* L);
  553.         static int32_t luaGetPlayerGroupId(lua_State* L);
  554.         static int32_t luaDoPlayerSetGroupId(lua_State* L);
  555.         static int32_t luaDoPlayerLearnInstantSpell(lua_State* L);
  556.         static int32_t luaDoPlayerUnlearnInstantSpell(lua_State* L);
  557.         static int32_t luaGetPlayerLearnedInstantSpell(lua_State* L);
  558.         static int32_t luaGetPlayerInstantSpellCount(lua_State* L);
  559.         static int32_t luaGetPlayerInstantSpellInfo(lua_State* L);
  560.         static int32_t luaGetInstantSpellInfo(lua_State* L);
  561.         static int32_t luaGetPlayerPartner(lua_State* L);
  562.         static int32_t luaDoPlayerSetPartner(lua_State* L);
  563.         static int32_t luaDoPlayerFollowCreature(lua_State* L);
  564.         static int32_t luaGetPlayerParty(lua_State* L);
  565.         static int32_t luaDoPlayerJoinParty(lua_State* L);
  566.         static int32_t luaDoPlayerLeaveParty(lua_State* L);
  567.         static int32_t luaGetPartyMembers(lua_State* L);
  568.         static int32_t luaGetCreatureStorage(lua_State* L);
  569.         static int32_t luaDoCreatureSetStorage(lua_State* L);
  570.         static int32_t luaDoPlayerAddBlessing(lua_State* L);
  571.         static int32_t luaGetPlayerBlessing(lua_State* L);
  572.  
  573.         static int32_t luaDoGuildAddEnemy(lua_State* L);
  574.         static int32_t luaDoGuildRemoveEnemy(lua_State* L);
  575.  
  576.         static int32_t luaGetStorage(lua_State* L);
  577.         static int32_t luaDoSetStorage(lua_State* L);
  578.         static int32_t luaDoPlayerAddOutfit(lua_State* L);
  579.         static int32_t luaDoPlayerRemoveOutfit(lua_State* L);
  580.         static int32_t luaDoPlayerAddOutfitId(lua_State* L);
  581.         static int32_t luaDoPlayerRemoveOutfitId(lua_State* L);
  582.         static int32_t luaCanPlayerWearOutfit(lua_State* L);
  583.         static int32_t luaCanPlayerWearOutfitId(lua_State* L);
  584.         static int32_t luaGetWorldType(lua_State* L);
  585.         static int32_t luaSetWorldType(lua_State* L);
  586.         static int32_t luaGetWorldTime(lua_State* L);
  587.         static int32_t luaGetWorldLight(lua_State* L);
  588.         static int32_t luaGetWorldCreatures(lua_State* L);
  589.         static int32_t luaGetWorldUpTime(lua_State* L);
  590.         static int32_t luaGetGuildId(lua_State* L);
  591.         static int32_t luaGetGuildMotd(lua_State* L);
  592.         static int32_t luaIsPlayerPzLocked(lua_State* L);
  593.         static int32_t luaIsPlayerSaving(lua_State* L);
  594.         static int32_t luaIsCreature(lua_State* L);
  595.         static int32_t luaIsContainer(lua_State* L);
  596.         static int32_t luaIsMovable(lua_State* L);
  597.         static int32_t luaGetContainerSize(lua_State* L);
  598.         static int32_t luaGetContainerCap(lua_State* L);
  599.         static int32_t luaGetContainerItem(lua_State* L);
  600.         static int32_t luaDoAddContainerItem(lua_State* L);
  601.         static int32_t luaCreateCombatObject(lua_State* L);
  602.         static int32_t luaCreateCombatArea(lua_State* L);
  603.         static int32_t luaSetCombatArea(lua_State* L);
  604.         static int32_t luaSetCombatCondition(lua_State* L);
  605.         static int32_t luaSetCombatParam(lua_State* L);
  606.         static int32_t luaCreateConditionObject(lua_State* L);
  607.         static int32_t luaSetConditionParam(lua_State* L);
  608.         static int32_t luaAddDamageCondition(lua_State* L);
  609.         static int32_t luaAddOutfitCondition(lua_State* L);
  610.         static int32_t luaSetCombatCallBack(lua_State* L);
  611.         static int32_t luaSetCombatFormula(lua_State* L);
  612.         static int32_t luaSetConditionFormula(lua_State* L);
  613.         static int32_t luaDoCombat(lua_State* L);
  614.         static int32_t luaDoCombatAreaHealth(lua_State* L);
  615.         static int32_t luaDoTargetCombatHealth(lua_State* L);
  616.         static int32_t luaDoCombatAreaMana(lua_State* L);
  617.         static int32_t luaDoTargetCombatMana(lua_State* L);
  618.         static int32_t luaDoCombatAreaCondition(lua_State* L);
  619.         static int32_t luaDoTargetCombatCondition(lua_State* L);
  620.         static int32_t luaDoCombatAreaDispel(lua_State* L);
  621.         static int32_t luaDoTargetCombatDispel(lua_State* L);
  622.         static int32_t luaDoChallengeCreature(lua_State* L);
  623.         static int32_t luaNumberToVariant(lua_State* L);
  624.         static int32_t luaStringToVariant(lua_State* L);
  625.         static int32_t luaPositionToVariant(lua_State* L);
  626.         static int32_t luaTargetPositionToVariant(lua_State* L);
  627.         static int32_t luaVariantToNumber(lua_State* L);
  628.         static int32_t luaVariantToString(lua_State* L);
  629.         static int32_t luaVariantToPosition(lua_State* L);
  630.         static int32_t luaDoChangeSpeed(lua_State* L);
  631.         static int32_t luaGetExperienceStage(lua_State* L);
  632.         static int32_t luaDoCreatureChangeOutfit(lua_State* L);
  633.         static int32_t luaSetCreatureOutfit(lua_State* L);
  634.         static int32_t luaGetCreatureOutfit(lua_State* L);
  635.         static int32_t luaSetMonsterOutfit(lua_State* L);
  636.         static int32_t luaSetItemOutfit(lua_State* L);
  637.         static int32_t luaGetCreatureLastPosition(lua_State* L);
  638.         static int32_t luaGetCreatureName(lua_State* L);
  639.         static int32_t luaGetCreaturePathTo(lua_State* L);
  640.         static int32_t luaGetCreatureMaster(lua_State* L);
  641.         static int32_t luaGetCreatureSummons(lua_State* L);
  642.         static int32_t luaGetHighscoreString(lua_State* L);
  643.         static int32_t luaIsSightClear(lua_State* L);
  644.         static int32_t luaIsInArray(lua_State* L);
  645.         static int32_t luaAddEvent(lua_State* L);
  646.         static int32_t luaStopEvent(lua_State* L);
  647.         static int32_t luaRegisterCreatureEvent(lua_State* L);
  648.         static int32_t luaUnregisterCreatureEvent(lua_State* L);
  649.         static int32_t luaGetPlayerBalance(lua_State* L);
  650.         static int32_t luaDoPlayerSetBalance(lua_State* L);
  651.         static int32_t luaDoPlayerPopupFYI(lua_State* L);
  652.         static int32_t luaDoPlayerSendTutorial(lua_State* L);
  653.         static int32_t luaDoPlayerSendMailByName(lua_State* L);
  654.         static int32_t luaDoPlayerAddMapMark(lua_State* L);
  655.         static int32_t luaGetPlayerPremiumDays(lua_State* L);
  656.         static int32_t luaDoPlayerAddPremiumDays(lua_State* L);
  657.         static int32_t luaGetCreatureNoMove(lua_State* L);
  658.         static int32_t luaDoCreatureSetNoMove(lua_State* L);
  659.         static int32_t luaGetTownId(lua_State* L);
  660.         static int32_t luaGetTownName(lua_State* L);
  661.         static int32_t luaGetTownTemplePosition(lua_State* L);
  662.         static int32_t luaGetTownHouses(lua_State* L);
  663.         static int32_t luaGetSpectators(lua_State* L);
  664.         static int32_t luaGetGameState(lua_State* L);
  665.         static int32_t luaDoSetGameState(lua_State* L);
  666.         static int32_t luaGetChannelUsers(lua_State* L);
  667.         static int32_t luaGetPlayersOnline(lua_State* L);
  668.         static int32_t luaDoExecuteRaid(lua_State* L);
  669.         static int32_t luaDoReloadInfo(lua_State* L);
  670.         static int32_t luaDoSaveServer(lua_State* L);
  671.         static int32_t luaDoCleanHouse(lua_State* L);
  672.         static int32_t luaDoCleanMap(lua_State* L);
  673.         static int32_t luaDoRefreshMap(lua_State* L);
  674.         static int32_t luaDoUpdateHouseAuctions(lua_State* L);
  675.         static int32_t luaGetItemIdByName(lua_State* L);
  676.         static int32_t luaGetItemInfo(lua_State* L);
  677.         static int32_t luaGetItemWeight(lua_State* L);
  678.         static int32_t luaGetItemParent(lua_State* L);
  679.         static int32_t luaGetItemAttribute(lua_State* L);
  680.         static int32_t luaDoItemSetAttribute(lua_State* L);
  681.         static int32_t luaDoItemEraseAttribute(lua_State* L);
  682.         static int32_t luaGetTalkActionList(lua_State* L);
  683.         static int32_t luaGetExperienceStageList(lua_State* L);
  684.         static int32_t luaGetTownList(lua_State* L);
  685.         static int32_t luaGetWaypointList(lua_State* L);
  686.         static int32_t luaGetWaypointPosition(lua_State* L);
  687.         static int32_t luaDoWaypointAddTemporial(lua_State* L);
  688.         static int32_t luaGetDataDir(lua_State* L);
  689.         static int32_t luaGetLogsDir(lua_State* L);
  690.         static int32_t luaGetConfigFile(lua_State* L);
  691.         static int32_t luaGetConfigValue(lua_State* L);
  692.         static int32_t luaGetModList(lua_State* L);
  693.         static int32_t luaIsPlayerUsingOtclient(lua_State* L);
  694.         static int32_t luaDoPlayerSendExtendedOpcode(lua_State* L);
  695.  
  696.         static int32_t luaL_errors(lua_State* L);
  697.         static int32_t luaL_loadmodlib(lua_State* L);
  698.         static int32_t luaL_domodlib(lua_State* L);
  699.         static int32_t luaL_dodirectory(lua_State* L);
  700.  
  701.         static const luaL_Reg luaSystemTable[2];
  702.         static int32_t luaSystemTime(lua_State* L);
  703.  
  704.         static const luaL_Reg luaDatabaseTable[8];
  705.         static int32_t luaDatabaseExecute(lua_State* L);
  706.         static int32_t luaDatabaseStoreQuery(lua_State* L);
  707.         static int32_t luaDatabaseEscapeString(lua_State* L);
  708.         static int32_t luaDatabaseEscapeBlob(lua_State* L);
  709.         static int32_t luaDatabaseLastInsertId(lua_State* L);
  710.         static int32_t luaDatabaseStringComparer(lua_State* L);
  711.         static int32_t luaDatabaseUpdateLimiter(lua_State* L);
  712.  
  713.         static const luaL_Reg luaResultTable[7];
  714.         static int32_t luaResultGetDataInt(lua_State* L);
  715.         static int32_t luaResultGetDataLong(lua_State* L);
  716.         static int32_t luaResultGetDataString(lua_State* L);
  717.         static int32_t luaResultGetDataStream(lua_State* L);
  718.         static int32_t luaResultNext(lua_State* L);
  719.         static int32_t luaResultFree(lua_State* L);
  720.  
  721.         static const luaL_Reg luaBitTable[13];
  722.         static int32_t luaBitNot(lua_State* L);
  723.         static int32_t luaBitAnd(lua_State* L);
  724.         static int32_t luaBitOr(lua_State* L);
  725.         static int32_t luaBitXor(lua_State* L);
  726.         static int32_t luaBitLeftShift(lua_State* L);
  727.         static int32_t luaBitRightShift(lua_State* L);
  728.         static int32_t luaBitUNot(lua_State* L);
  729.         static int32_t luaBitUAnd(lua_State* L);
  730.         static int32_t luaBitUOr(lua_State* L);
  731.         static int32_t luaBitUXor(lua_State* L);
  732.         static int32_t luaBitULeftShift(lua_State* L);
  733.         static int32_t luaBitURightShift(lua_State* L);
  734.  
  735.         static const luaL_Reg luaStdTable[9];
  736.         static int32_t luaStdCout(lua_State* L);
  737.         static int32_t luaStdClog(lua_State* L);
  738.         static int32_t luaStdCerr(lua_State* L);
  739.         static int32_t luaStdMD5(lua_State* L);
  740.         static int32_t luaStdSHA1(lua_State* L);
  741.         static int32_t luaStdSHA256(lua_State* L);
  742.         static int32_t luaStdSHA512(lua_State* L);
  743.  
  744.         lua_State* m_luaState;
  745.         bool m_errors;
  746.         std::string m_lastError;
  747.  
  748.     private:
  749.         void executeTimer(uint32_t eventIndex);
  750.  
  751.         enum PlayerInfo_t
  752.         {
  753.             PlayerInfoFood,
  754.             PlayerInfoAccess,
  755.             PlayerInfoGhostAccess,
  756.             PlayerInfoLevel,
  757.             PlayerInfoExperience,
  758.             PlayerInfoManaSpent,
  759.             PlayerInfoVocation,
  760.             PlayerInfoTown,
  761.             PlayerInfoPromotionLevel,
  762.             PlayerInfoSoul,
  763.             PlayerInfoFreeCap,
  764.             PlayerInfoGuildId,
  765.             PlayerInfoGuildName,
  766.             PlayerInfoGuildRankId,
  767.             PlayerInfoGuildRank,
  768.             PlayerInfoGuildLevel,
  769.             PlayerInfoGuildNick,
  770.             PlayerInfoGroupId,
  771.             PlayerInfoGUID,
  772.             PlayerInfoAccountId,
  773.             PlayerInfoAccount,
  774.             PlayerInfoPremiumDays,
  775.             PlayerInfoBalance,
  776.             PlayerInfoStamina,
  777.             PlayerInfoLossSkill,
  778.             PlayerInfoMarriage,
  779.             PlayerInfoPzLock,
  780.             PlayerInfoSaving,
  781.             PlayerInfoIp,
  782.             PlayerInfoSkullEnd,
  783.             PlayerInfoOutfitWindow,
  784.             PlayerInfoNameDescription,
  785.             PlayerInfoSpecialDescription,
  786.             PlayerInfoIdleTime,
  787.             PlayerInfoClient,
  788.             PlayerInfoLastLoad,
  789.             PlayerInfoLastLogin,
  790.             PlayerInfoAccountManager,
  791.             PlayerInfoTradeState
  792.         };
  793.         static int32_t internalGetPlayerInfo(lua_State* L, PlayerInfo_t info);
  794.  
  795.         int32_t m_runningEvent;
  796.         uint32_t m_lastTimer;
  797.         std::string m_loadingFile, m_interfaceName;
  798.  
  799.         static ScriptEnviroment m_scriptEnv[21];
  800.         static int32_t m_scriptEnvIndex;
  801.  
  802.         //events information
  803.         struct LuaTimerEvent
  804.         {
  805.             int32_t scriptId, function;
  806.             uint32_t eventId;
  807.             std::list<int32_t> parameters;
  808.         };
  809.  
  810.         typedef std::map<uint32_t, LuaTimerEvent> LuaTimerEvents;
  811.         LuaTimerEvents m_timerEvents;
  812.  
  813.         //script file cache
  814.         typedef std::map<int32_t, std::string> ScriptsCache;
  815.         ScriptsCache m_cacheFiles;
  816. };
  817. #endif
RAW Paste Data