Advertisement
Guest User

Untitled

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