From 8fef1260ca0cc27ca6e38256ab3233b3a71d72b7 Mon Sep 17 00:00:00 2001 From: Foereaper Date: Sun, 28 Jan 2024 23:02:49 +0100 Subject: [PATCH] Add new multistate methods and registry cleanup for CMangos --- CMangos/AuraMethods.h | 2 +- CMangos/BattleGroundMethods.h | 4 +- CMangos/CorpseMethods.h | 2 +- CMangos/CreatureMethods.h | 36 +++-- CMangos/ElunaQueryMethods.h | 4 +- CMangos/GameObjectMethods.h | 4 +- CMangos/GlobalMethods.h | 285 +++++++++++++++++++++++++++++++--- CMangos/GroupMethods.h | 12 +- CMangos/GuildMethods.h | 6 +- CMangos/ItemMethods.h | 15 +- CMangos/MapMethods.h | 36 ++++- CMangos/ObjectMethods.h | 2 +- CMangos/PlayerMethods.h | 100 ++++++++---- CMangos/QuestMethods.h | 6 +- CMangos/SpellMethods.h | 2 +- CMangos/UnitMethods.h | 45 ++++-- CMangos/VehicleMethods.h | 2 +- CMangos/WorldObjectMethods.h | 38 ++++- CMangos/WorldPacketMethods.h | 2 +- 19 files changed, 484 insertions(+), 119 deletions(-) diff --git a/CMangos/AuraMethods.h b/CMangos/AuraMethods.h index 2b8b8b5ab1..32d26e289c 100644 --- a/CMangos/AuraMethods.h +++ b/CMangos/AuraMethods.h @@ -200,7 +200,7 @@ namespace LuaAura // Other { "Remove", &LuaAura::Remove }, - { NULL, NULL } + { NULL, NULL, METHOD_REG_NONE } }; }; #endif diff --git a/CMangos/BattleGroundMethods.h b/CMangos/BattleGroundMethods.h index d66fbc65da..22940fb086 100644 --- a/CMangos/BattleGroundMethods.h +++ b/CMangos/BattleGroundMethods.h @@ -64,7 +64,6 @@ namespace LuaBattleGround return 1; } -#ifndef AZEROTHCORE /** * Returns the bracket ID of the specific [BattleGround]. * @@ -75,7 +74,6 @@ namespace LuaBattleGround E->Push(bg->GetBracketId()); return 1; } -#endif /** * Returns the end time of the [BattleGround]. @@ -249,7 +247,7 @@ namespace LuaBattleGround { "GetWinner", &LuaBattleGround::GetWinner }, { "GetStatus", &LuaBattleGround::GetStatus }, - { NULL, NULL } + { NULL, NULL, METHOD_REG_NONE } }; }; #endif diff --git a/CMangos/CorpseMethods.h b/CMangos/CorpseMethods.h index cb045a1566..b4f4a94793 100644 --- a/CMangos/CorpseMethods.h +++ b/CMangos/CorpseMethods.h @@ -85,7 +85,7 @@ namespace LuaCorpse { "ResetGhostTime", &LuaCorpse::ResetGhostTime }, { "SaveToDB", &LuaCorpse::SaveToDB }, - { NULL, NULL } + { NULL, NULL, METHOD_REG_NONE } }; }; #endif diff --git a/CMangos/CreatureMethods.h b/CMangos/CreatureMethods.h index a15f5f4dca..d72cf07b31 100644 --- a/CMangos/CreatureMethods.h +++ b/CMangos/CreatureMethods.h @@ -1142,6 +1142,8 @@ namespace LuaCreature { "GetCreatureFamily", &LuaCreature::GetCreatureFamily }, #ifndef CATA { "GetShieldBlockValue", &LuaCreature::GetShieldBlockValue }, +#else + { "GetShieldBlockValue", nullptr, METHOD_REG_NONE }, #endif // Setters @@ -1161,6 +1163,8 @@ namespace LuaCreature { "SetEquipmentSlots", &LuaCreature::SetEquipmentSlots }, #ifndef CATA { "SetDisableReputationGain", &LuaCreature::SetDisableReputationGain }, +#else + { "SetDisableReputationGain", nullptr, METHOD_REG_NONE }, #endif // Boolean @@ -1187,6 +1191,8 @@ namespace LuaCreature { "CanFly", &LuaCreature::CanFly }, #ifndef CATA { "IsReputationGainDisabled", &LuaCreature::IsReputationGainDisabled }, +#else + { "IsReputationGainDisabled", nullptr, METHOD_REG_NONE }, #endif // Other @@ -1203,21 +1209,21 @@ namespace LuaCreature { "UpdateEntry", &LuaCreature::UpdateEntry }, // Not implemented methods - { "GetWaypointPath", nullptr }, // TC/Acore - { "GetLootMode", nullptr }, // TC/Acore - { "SetRegeneratingHealth", nullptr }, // TC/Acore - { "SetLootMode", nullptr }, // TC/Acore - { "SetReactState", nullptr }, // TC/Acore - { "IsDungeonBoss", nullptr }, // TC/Acore - { "IsTrigger", nullptr }, // TC/Acore - { "CanStartAttack", nullptr }, // TC/Acore - { "IsDamageEnoughForLootingAndReward", nullptr }, // TC/Acore - { "HasLootMode", nullptr }, // TC/Acore - { "AddLootMode", nullptr }, // TC/Acore - { "ResetLootMode", nullptr }, // TC/Acore - { "RemoveLootMode", nullptr }, // TC/Acore - - { NULL, NULL } + { "GetWaypointPath", nullptr, METHOD_REG_NONE }, // TC/Acore + { "GetLootMode", nullptr, METHOD_REG_NONE }, // TC/Acore + { "SetRegeneratingHealth", nullptr, METHOD_REG_NONE }, // TC/Acore + { "SetLootMode", nullptr, METHOD_REG_NONE }, // TC/Acore + { "SetReactState", nullptr, METHOD_REG_NONE }, // TC/Acore + { "IsDungeonBoss", nullptr, METHOD_REG_NONE }, // TC/Acore + { "IsTrigger", nullptr, METHOD_REG_NONE }, // TC/Acore + { "CanStartAttack", nullptr, METHOD_REG_NONE }, // TC/Acore + { "IsDamageEnoughForLootingAndReward", nullptr, METHOD_REG_NONE }, // TC/Acore + { "HasLootMode", nullptr, METHOD_REG_NONE }, // TC/Acore + { "AddLootMode", nullptr, METHOD_REG_NONE }, // TC/Acore + { "ResetLootMode", nullptr, METHOD_REG_NONE }, // TC/Acore + { "RemoveLootMode", nullptr, METHOD_REG_NONE }, // TC/Acore + + { NULL, NULL, METHOD_REG_NONE } }; }; #endif diff --git a/CMangos/ElunaQueryMethods.h b/CMangos/ElunaQueryMethods.h index bc35a83e42..01dafa5bc2 100644 --- a/CMangos/ElunaQueryMethods.h +++ b/CMangos/ElunaQueryMethods.h @@ -287,7 +287,7 @@ namespace LuaQuery const char* str = row[i].GetString(); if (row[i].IsNULL() || !str) - E->Push(E->L); + E->Push(); else { // MYSQL_TYPE_LONGLONG Interpreted as string for lua @@ -335,7 +335,7 @@ namespace LuaQuery { "NextRow", &LuaQuery::NextRow }, { "IsNull", &LuaQuery::IsNull }, - { NULL, NULL } + { NULL, NULL, METHOD_REG_NONE } }; }; #undef RESULT diff --git a/CMangos/GameObjectMethods.h b/CMangos/GameObjectMethods.h index a4625a9e5d..2c679e1b01 100644 --- a/CMangos/GameObjectMethods.h +++ b/CMangos/GameObjectMethods.h @@ -332,9 +332,9 @@ namespace LuaGameObject { "SaveToDB", &LuaGameObject::SaveToDB }, // Not implemented methods - { "IsDestructible", nullptr }, // Not implemented + { "IsDestructible", nullptr, METHOD_REG_NONE }, // Not implemented - { NULL, NULL } + { NULL, NULL, METHOD_REG_NONE } }; }; #endif diff --git a/CMangos/GlobalMethods.h b/CMangos/GlobalMethods.h index edeee5b966..b331e64c34 100644 --- a/CMangos/GlobalMethods.h +++ b/CMangos/GlobalMethods.h @@ -90,6 +90,39 @@ namespace LuaGlobalFunctions return 1; } + /** + * Returns the [Map] pointer of the Lua state. Returns null for the "World" state. + * + * @return [Map] map + */ + int GetStateMap(Eluna* E) + { + E->Push(E->GetBoundMap()); + return 1; + } + + /** + * Returns the map ID of the Lua state. Returns -1 for the "World" state. + * + * @return int32 mapId + */ + int GetStateMapId(Eluna* E) + { + E->Push(E->GetBoundMapId()); + return 1; + } + + /** + * Returns the instance ID of the Lua state. Returns 0 for continent maps and the world state. + * + * @return uint32 instanceId + */ + int GetStateInstanceId(Eluna* E) + { + E->Push(E->GetBoundInstanceId()); + return 1; + } + /** * Returns [Quest] template * @@ -187,6 +220,56 @@ namespace LuaGlobalFunctions return 1; } + /** + * Returns a table with all the current [Player]s on the states map. + * + * Does not return players that may be teleporting or otherwise not on the map. + * + * enum TeamId + * { + * TEAM_ALLIANCE = 0, + * TEAM_HORDE = 1, + * TEAM_NEUTRAL = 2 + * }; + * + * In multistate, this method is only available in the MAP state + * + * @param [TeamId] team = TEAM_NEUTRAL : optional check team of the [Player], Alliance, Horde or Neutral (All) + * @param bool onlyGM = false : optional check if GM only + * @return table mapPlayers + */ + int GetPlayersOnMap(Eluna* E) + { + uint32 team = Eluna::CHECKVAL(E->L, 1, TEAM_NEUTRAL); + bool onlyGM = Eluna::CHECKVAL(E->L, 2, false); + + lua_newtable(E->L); + int tbl = lua_gettop(E->L); + uint32 i = 0; + + Map::PlayerList const& players = E->GetBoundMap()->GetPlayers(); + if (!players.isEmpty()) + { + for (Map::PlayerList::const_iterator it = players.begin(); it != players.end(); ++it) + { + if (Player* player = it->getSource()) + { + if (!player->IsInWorld()) + continue; + + if ((team == TEAM_NEUTRAL || player->GetTeamId() == team) && (!onlyGM || player->IsGameMaster())) + { + E->Push(player); + lua_rawseti(E->L, tbl, ++i); + } + } + } + } + + lua_settop(E->L, tbl); // push table to top of stack + return 1; + } + /** * Returns a [Guild] by name. * @@ -1224,7 +1307,7 @@ namespace LuaGlobalFunctions if (result) E->Push(result); else - E->Push(E->L); + E->Push(); return 1; } @@ -1248,6 +1331,65 @@ namespace LuaGlobalFunctions return 0; } + /** + * Initiates an asynchronous SQL query on the world database with a callback function. + * + * The query is executed asynchronously, and the provided Lua function is called when the query completes. + * The callback function parameter is the query result (an [ElunaQuery] or nil if no rows found). + * + *
+     * WorldDBQueryAsync("SELECT entry, name FROM creature_template LIMIT 10", function(results)
+     *    if results then
+     *        repeat
+     *            local entry, name = results:GetUInt32(0), results:GetString(1)
+     *            print(entry, name)
+     *        until not results:NextRow()
+     *    end
+     * end)
+     * 
+ * + * @param string sql : query to execute asynchronously + * @param function callback : the callback function to be called with the query results + */ + int WorldDBQueryAsync(Eluna* /*E*/) + { + // Todo: Implement async queries. Below is the code example from TC. + + /* + const char* query = Eluna::CHECKVAL(E->L, 1); + luaL_checktype(E->L, 2, LUA_TFUNCTION); + + // Push the Lua function onto the stack and create a reference + lua_pushvalue(E->L, 2); + int funcRef = luaL_ref(E->L, LUA_REGISTRYINDEX); + + // Validate the function reference + if (funcRef == LUA_REFNIL || funcRef == LUA_NOREF) + { + luaL_argerror(E->L, 2, "unable to make a ref to function"); + return 0; + } + + // Add an asynchronous query callback + E->GetQueryProcessor().AddCallback(WorldDatabase.AsyncQuery(query).WithCallback([E, funcRef](QueryResult result) + { + ElunaQuery* eq = result ? new ElunaQuery(result) : nullptr; + + // Get the Lua function from the registry + lua_rawgeti(E->L, LUA_REGISTRYINDEX, funcRef); + + // Push the query results as a parameter + E->Push(eq); + + // Call the Lua function + E->ExecuteCall(1, 0); + + // Unreference the Lua function + luaL_unref(E->L, LUA_REGISTRYINDEX, funcRef); + }));*/ + return 0; + } + /** * Executes a SQL query on the character database and returns an [ElunaQuery]. * @@ -1267,7 +1409,7 @@ namespace LuaGlobalFunctions if (result) E->Push(result); else - E->Push(E->L); + E->Push(); return 1; } @@ -1291,6 +1433,45 @@ namespace LuaGlobalFunctions return 0; } + int CharDBQueryAsync(Eluna* /*E*/) + { + // Todo: Implement async queries. Below is the code example from TC. + + /* + const char* query = Eluna::CHECKVAL(E->L, 1); + luaL_checktype(E->L, 2, LUA_TFUNCTION); + + // Push the Lua function onto the stack and create a reference + lua_pushvalue(E->L, 2); + int funcRef = luaL_ref(E->L, LUA_REGISTRYINDEX); + + // Validate the function reference + if (funcRef == LUA_REFNIL || funcRef == LUA_NOREF) + { + luaL_argerror(E->L, 2, "unable to make a ref to function"); + return 0; + } + + // Add an asynchronous query callback + E->GetQueryProcessor().AddCallback(WorldDatabase.AsyncQuery(query).WithCallback([E, funcRef](QueryResult result) + { + ElunaQuery* eq = result ? new ElunaQuery(result) : nullptr; + + // Get the Lua function from the registry + lua_rawgeti(E->L, LUA_REGISTRYINDEX, funcRef); + + // Push the query results as a parameter + E->Push(eq); + + // Call the Lua function + E->ExecuteCall(1, 0); + + // Unreference the Lua function + luaL_unref(E->L, LUA_REGISTRYINDEX, funcRef); + }));*/ + return 0; + } + /** * Executes a SQL query on the login database and returns an [ElunaQuery]. * @@ -1310,7 +1491,7 @@ namespace LuaGlobalFunctions if (result) E->Push(result); else - E->Push(E->L); + E->Push(); return 1; } @@ -1334,6 +1515,45 @@ namespace LuaGlobalFunctions return 0; } + int AuthDBQueryAsync(Eluna* /*E*/) + { + // Todo: Implement async queries. Below is the code example from TC. + + /* + const char* query = Eluna::CHECKVAL(E->L, 1); + luaL_checktype(E->L, 2, LUA_TFUNCTION); + + // Push the Lua function onto the stack and create a reference + lua_pushvalue(E->L, 2); + int funcRef = luaL_ref(E->L, LUA_REGISTRYINDEX); + + // Validate the function reference + if (funcRef == LUA_REFNIL || funcRef == LUA_NOREF) + { + luaL_argerror(E->L, 2, "unable to make a ref to function"); + return 0; + } + + // Add an asynchronous query callback + E->GetQueryProcessor().AddCallback(WorldDatabase.AsyncQuery(query).WithCallback([E, funcRef](QueryResult result) + { + ElunaQuery* eq = result ? new ElunaQuery(result) : nullptr; + + // Get the Lua function from the registry + lua_rawgeti(E->L, LUA_REGISTRYINDEX, funcRef); + + // Push the query results as a parameter + E->Push(eq); + + // Call the Lua function + E->ExecuteCall(1, 0); + + // Unreference the Lua function + luaL_unref(E->L, LUA_REGISTRYINDEX, funcRef); + }));*/ + return 0; + } + /** * Registers a global timed event. * @@ -1451,7 +1671,7 @@ namespace LuaGlobalFunctions uint32 phase = Eluna::CHECKVAL(E->L, 11, PHASEMASK_NORMAL); if (!phase) { - E->Push(E->L); + E->Push(); return 1; } #endif @@ -1459,7 +1679,7 @@ namespace LuaGlobalFunctions Map* map = eMapMgr->FindMap(mapID, instanceID); if (!map) { - E->Push(E->L); + E->Push(); return 1; } @@ -1470,7 +1690,7 @@ namespace LuaGlobalFunctions CreatureInfo const* cinfo = ObjectMgr::GetCreatureTemplate(entry); if (!cinfo) { - E->Push(E->L); + E->Push(); return 1; } @@ -1484,7 +1704,7 @@ namespace LuaGlobalFunctions uint32 lowguid = eObjectMgr->GenerateStaticCreatureLowGuid(); if (!lowguid) { - E->Push(E->L); + E->Push(); return 1; } #ifndef CATA @@ -1494,7 +1714,7 @@ namespace LuaGlobalFunctions #endif { delete pCreature; - E->Push(E->L); + E->Push(); return 1; } @@ -1527,7 +1747,7 @@ namespace LuaGlobalFunctions CreatureInfo const* cinfo = ObjectMgr::GetCreatureTemplate(entry); if (!cinfo) { - E->Push(E->L); + E->Push(); return 1; } @@ -1546,7 +1766,7 @@ namespace LuaGlobalFunctions { delete pCreature; { - E->Push(E->L); + E->Push(); return 1; } } @@ -1576,7 +1796,7 @@ namespace LuaGlobalFunctions const GameObjectInfo* gInfo = ObjectMgr::GetGameObjectInfo(entry); if (!gInfo) { - E->Push(E->L); + E->Push(); return 1; } @@ -1584,7 +1804,7 @@ namespace LuaGlobalFunctions uint32 db_lowGUID = eObjectMgr->GenerateStaticGameObjectLowGuid(); if (!db_lowGUID) { - E->Push(E->L); + E->Push(); return 1; } @@ -1598,7 +1818,7 @@ namespace LuaGlobalFunctions #endif { delete pGameObj; - E->Push(E->L); + E->Push(); return 1; } @@ -1622,7 +1842,7 @@ namespace LuaGlobalFunctions #endif { delete pGameObj; - E->Push(E->L); + E->Push(); return 1; } @@ -1647,7 +1867,7 @@ namespace LuaGlobalFunctions #endif { delete pGameObj; - E->Push(E->L); + E->Push(); return 1; } @@ -1661,7 +1881,7 @@ namespace LuaGlobalFunctions return 1; } - E->Push(E->L); + E->Push(); return 1; } @@ -2074,13 +2294,13 @@ namespace LuaGlobalFunctions int start = lua_gettop(E->L); int end = start; - E->Push(E->L); + E->Push(); // Stack: {nodes}, mountA, mountH, price, pathid, {nodes}, nil while (lua_next(E->L, -2) != 0) { // Stack: {nodes}, mountA, mountH, price, pathid, {nodes}, key, value luaL_checktype(E->L, -1, LUA_TTABLE); - E->Push(E->L); + E->Push(); // Stack: {nodes}, mountA, mountH, price, pathid, {nodes}, key, value, nil while (lua_next(E->L, -2) != 0) { @@ -2170,6 +2390,17 @@ namespace LuaGlobalFunctions return 1; } + /** + * Returns `true` if Eluna is in compatibility mode, `false` if in multistate. + * + * @return bool isCompatibilityMode + */ + int IsCompatibilityMode(Eluna* E) + { + E->Push(E->GetCompatibilityMode()); + return 1; + } + /** * Returns `true` if the bag and slot is a valid inventory position, otherwise `false`. * @@ -2993,11 +3224,15 @@ namespace LuaGlobalFunctions { "GetRealmID", &LuaGlobalFunctions::GetRealmID }, { "GetCoreVersion", &LuaGlobalFunctions::GetCoreVersion }, { "GetCoreExpansion", &LuaGlobalFunctions::GetCoreExpansion }, + { "GetStateMap", &LuaGlobalFunctions::GetStateMap, METHOD_REG_MAP }, // Map state method only in multistate + { "GetStateMapId", &LuaGlobalFunctions::GetStateMapId }, + { "GetStateInstanceId", &LuaGlobalFunctions::GetStateInstanceId }, { "GetQuest", &LuaGlobalFunctions::GetQuest }, - { "GetPlayerByGUID", &LuaGlobalFunctions::GetPlayerByGUID }, - { "GetPlayerByName", &LuaGlobalFunctions::GetPlayerByName }, + { "GetPlayerByGUID", &LuaGlobalFunctions::GetPlayerByGUID, METHOD_REG_WORLD }, // World state method only in multistate + { "GetPlayerByName", &LuaGlobalFunctions::GetPlayerByName, METHOD_REG_WORLD }, // World state method only in multistate { "GetGameTime", &LuaGlobalFunctions::GetGameTime }, - { "GetPlayersInWorld", &LuaGlobalFunctions::GetPlayersInWorld }, + { "GetPlayersInWorld", &LuaGlobalFunctions::GetPlayersInWorld, METHOD_REG_WORLD }, // World state method only in multistate + { "GetPlayersOnMap", &LuaGlobalFunctions::GetPlayersOnMap, METHOD_REG_MAP }, // Map state method only in multistate { "GetGuildByName", &LuaGlobalFunctions::GetGuildByName }, { "GetGuildByLeaderGUID", &LuaGlobalFunctions::GetGuildByLeaderGUID }, { "GetPlayerCount", &LuaGlobalFunctions::GetPlayerCount }, @@ -3016,7 +3251,7 @@ namespace LuaGlobalFunctions { "bit_or", &LuaGlobalFunctions::bit_or }, { "bit_and", &LuaGlobalFunctions::bit_and }, { "GetItemLink", &LuaGlobalFunctions::GetItemLink }, - { "GetMapById", &LuaGlobalFunctions::GetMapById }, + { "GetMapById", &LuaGlobalFunctions::GetMapById, METHOD_REG_WORLD }, // World state method only in multistate { "GetCurrTime", &LuaGlobalFunctions::GetCurrTime }, { "GetTimeDiff", &LuaGlobalFunctions::GetTimeDiff }, { "PrintInfo", &LuaGlobalFunctions::PrintInfo }, @@ -3025,6 +3260,7 @@ namespace LuaGlobalFunctions { "GetActiveGameEvents", &LuaGlobalFunctions::GetActiveGameEvents }, // Boolean + { "IsCompatibilityMode", &LuaGlobalFunctions::IsCompatibilityMode }, { "IsInventoryPos", &LuaGlobalFunctions::IsInventoryPos }, { "IsEquipmentPos", &LuaGlobalFunctions::IsEquipmentPos }, { "IsBankPos", &LuaGlobalFunctions::IsBankPos }, @@ -3037,10 +3273,13 @@ namespace LuaGlobalFunctions { "SendWorldMessage", &LuaGlobalFunctions::SendWorldMessage }, { "WorldDBQuery", &LuaGlobalFunctions::WorldDBQuery }, { "WorldDBExecute", &LuaGlobalFunctions::WorldDBExecute }, + { "WorldDBQueryAsync", &LuaGlobalFunctions::WorldDBQueryAsync, METHOD_REG_NONE }, // TODO: Implement { "CharDBQuery", &LuaGlobalFunctions::CharDBQuery }, { "CharDBExecute", &LuaGlobalFunctions::CharDBExecute }, + { "CharDBQueryAsync", &LuaGlobalFunctions::CharDBQueryAsync, METHOD_REG_NONE }, // TODO: Implement { "AuthDBQuery", &LuaGlobalFunctions::AuthDBQuery }, { "AuthDBExecute", &LuaGlobalFunctions::AuthDBExecute }, + { "AuthDBQueryAsync", &LuaGlobalFunctions::AuthDBQueryAsync, METHOD_REG_NONE }, // TODO: Implement { "CreateLuaEvent", &LuaGlobalFunctions::CreateLuaEvent }, { "RemoveEventById", &LuaGlobalFunctions::RemoveEventById }, { "RemoveEvents", &LuaGlobalFunctions::RemoveEvents }, @@ -3059,7 +3298,7 @@ namespace LuaGlobalFunctions { "StartGameEvent", &LuaGlobalFunctions::StartGameEvent }, { "StopGameEvent", &LuaGlobalFunctions::StopGameEvent }, - { NULL, NULL } + { NULL, NULL, METHOD_REG_NONE } }; } #endif diff --git a/CMangos/GroupMethods.h b/CMangos/GroupMethods.h index 6e6a1a6749..3b413bfa39 100644 --- a/CMangos/GroupMethods.h +++ b/CMangos/GroupMethods.h @@ -404,6 +404,8 @@ namespace LuaGroup { "HasFreeSlotSubGroup", &LuaGroup::HasFreeSlotSubGroup }, #if defined WOTLK { "IsLFGGroup", &LuaGroup::IsLFGGroup }, +#else + { "IsLFGGroup", nullptr, METHOD_REG_NONE }, #endif // Other @@ -411,12 +413,12 @@ namespace LuaGroup { "ConvertToRaid", &LuaGroup::ConvertToRaid }, // Not implemented methods - { "IsBFGroup", nullptr }, // not implemented - { "ConvertToLFG", nullptr }, // not implemented - { "GetMemberFlags", nullptr }, // not implemented - { "SetMemberFlag", nullptr }, // not implemented + { "IsBFGroup", nullptr, METHOD_REG_NONE }, // not implemented + { "ConvertToLFG", nullptr, METHOD_REG_NONE }, // not implemented + { "GetMemberFlags", nullptr, METHOD_REG_NONE }, // not implemented + { "SetMemberFlag", nullptr, METHOD_REG_NONE }, // not implemented - { NULL, NULL } + { NULL, NULL, METHOD_REG_NONE } }; }; diff --git a/CMangos/GuildMethods.h b/CMangos/GuildMethods.h index 7d6e3c017e..d69c609a99 100644 --- a/CMangos/GuildMethods.h +++ b/CMangos/GuildMethods.h @@ -254,10 +254,14 @@ namespace LuaGuild // Setters #if defined(TBC) || defined(WOTLK) { "SetBankTabText", &LuaGuild::SetBankTabText }, +#else + { "SetBankTabText", nullptr, METHOD_REG_NONE }, #endif { "SetMemberRank", &LuaGuild::SetMemberRank }, #ifndef CATA { "SetLeader", &LuaGuild::SetLeader }, +#else + { "SetLeader", nullptr, METHOD_REG_NONE }, #endif // Other @@ -267,7 +271,7 @@ namespace LuaGuild { "AddMember", &LuaGuild::AddMember }, { "DeleteMember", &LuaGuild::DeleteMember }, - { NULL, NULL } + { NULL, NULL, METHOD_REG_NONE } }; }; #endif diff --git a/CMangos/ItemMethods.h b/CMangos/ItemMethods.h index 775f5007a7..8f1be952a8 100644 --- a/CMangos/ItemMethods.h +++ b/CMangos/ItemMethods.h @@ -755,9 +755,13 @@ namespace LuaItem { "GetBagSize", &LuaItem::GetBagSize }, #if defined(TBC) || defined(WOTLK) { "GetRandomSuffix", &LuaItem::GetRandomSuffix }, +#else + { "GetRandomSuffix", nullptr, METHOD_REG_NONE }, #endif #if defined(WOTLK) { "GetStatsCount", &LuaItem::GetStatsCount }, +#else + { "GetStatsCount", nullptr, METHOD_REG_NONE }, #endif // Setters @@ -784,20 +788,25 @@ namespace LuaItem { "ClearEnchantment", &LuaItem::ClearEnchantment }, #if defined(TBC) || defined(WOTLK) { "IsCurrencyToken", &LuaItem::IsCurrencyToken }, +#else + { "IsCurrencyToken", nullptr, METHOD_REG_NONE }, #endif #if defined(WOTLK) { "IsBoundAccountWide", &LuaItem::IsBoundAccountWide }, { "IsWeaponVellum", &LuaItem::IsWeaponVellum }, { "IsArmorVellum", &LuaItem::IsArmorVellum }, +#else + { "IsBoundAccountWide", nullptr, METHOD_REG_NONE }, + { "IsWeaponVellum", nullptr, METHOD_REG_NONE }, + { "IsArmorVellum", nullptr, METHOD_REG_NONE }, #endif - // Other { "SaveToDB", &LuaItem::SaveToDB }, // Not implemented methods - { "IsRefundExpired", nullptr }, // not implemented + { "IsRefundExpired", nullptr, METHOD_REG_NONE }, // not implemented - { NULL, NULL } + { NULL, NULL, METHOD_REG_NONE } }; }; #endif diff --git a/CMangos/MapMethods.h b/CMangos/MapMethods.h index 62477f4838..3e5f33ccce 100644 --- a/CMangos/MapMethods.h +++ b/CMangos/MapMethods.h @@ -249,7 +249,7 @@ namespace LuaMap if (iAI) E->PushInstanceData(E->L, iAI, false); else - E->Push(E->L); // nil + E->Push(); // nil return 1; } @@ -304,7 +304,33 @@ namespace LuaMap lua_settop(E->L, tbl); return 1; } - + + /** + * Returns a runtime-persistent cache tied to the [Map]. + * This data will remain for as long as the [Map] exists, or until a server restart. + * + * A reload of the Lua state will NOT clear this cache. + * + * This cache can be added to and read from with the following sub-methods. + *
+     * -- Sets the key-value pair in the cache
+     * Map:Data():Set("key", val)
+     *
+     * -- Returns the value from the cache using the key
+     * local val = Map:Data():Get("key")
+     *
+     * -- Removes the key-value pair from the cache
+     * Map:Data():Set("key", nil)
+     *
+     * -- Returns all the key-value pairs as a Lua table indexed by the keys
+     * local table = Map:Data():AsTable()
+     * 
+ */ + int Data(Eluna* E, Map* map) + { + return LuaVal::PushLuaVal(E->L, map->lua_data); + } + ElunaRegister MapMethods[] = { // Getters @@ -330,12 +356,16 @@ namespace LuaMap #if defined(TBC) || defined(WOTLK) { "IsArena", &LuaMap::IsArena }, { "IsHeroic", &LuaMap::IsHeroic }, +#else + { "IsArena", nullptr, METHOD_REG_NONE }, + { "IsHeroic", nullptr, METHOD_REG_NONE }, #endif // Other { "SaveInstanceData", &LuaMap::SaveInstanceData }, + { "Data", &LuaMap::Data }, - { NULL, NULL } + { NULL, NULL, METHOD_REG_NONE } }; }; #endif diff --git a/CMangos/ObjectMethods.h b/CMangos/ObjectMethods.h index 12bc55226e..cee7595e9d 100644 --- a/CMangos/ObjectMethods.h +++ b/CMangos/ObjectMethods.h @@ -492,7 +492,7 @@ namespace LuaObject { "ToCorpse", &LuaObject::ToCorpse }, { "RemoveFlag", &LuaObject::RemoveFlag }, - { NULL, NULL } + { NULL, NULL, METHOD_REG_NONE } }; }; #endif diff --git a/CMangos/PlayerMethods.h b/CMangos/PlayerMethods.h index 25c760a697..eb9894f4ac 100644 --- a/CMangos/PlayerMethods.h +++ b/CMangos/PlayerMethods.h @@ -3801,14 +3801,23 @@ namespace LuaPlayer #if defined(TBC) || defined(WOTLK) { "GetArenaPoints", &LuaPlayer::GetArenaPoints }, { "GetHonorPoints", &LuaPlayer::GetHonorPoints }, +#else + { "GetArenaPoints", nullptr, METHOD_REG_NONE }, + { "GetHonorPoints", nullptr, METHOD_REG_NONE }, #endif #if defined(WOTLK) { "GetPhaseMaskForSpawn", &LuaPlayer::GetPhaseMaskForSpawn }, { "GetActiveSpec", &LuaPlayer::GetActiveSpec }, { "GetSpecsCount", &LuaPlayer::GetSpecsCount }, +#else + { "GetPhaseMaskForSpawn", nullptr, METHOD_REG_NONE }, + { "GetActiveSpec", nullptr, METHOD_REG_NONE }, + { "GetSpecsCount", nullptr, METHOD_REG_NONE }, #endif #ifndef CATA { "GetShieldBlockValue", &LuaPlayer::GetShieldBlockValue }, +#else + { "GetShieldBlockValue", nullptr, METHOD_REG_NONE }, #endif { "GetMailCount", &LuaPlayer::GetMailCount }, @@ -3843,6 +3852,11 @@ namespace LuaPlayer { "UnsetKnownTitle", &LuaPlayer::UnsetKnownTitle }, { "SetArenaPoints", &LuaPlayer::SetArenaPoints }, { "SetHonorPoints", &LuaPlayer::SetHonorPoints }, +#else + { "SetKnownTitle", nullptr, METHOD_REG_NONE }, + { "UnsetKnownTitle", nullptr, METHOD_REG_NONE }, + { "SetArenaPoints", nullptr, METHOD_REG_NONE }, + { "SetHonorPoints", nullptr, METHOD_REG_NONE }, #endif // Boolean @@ -3895,11 +3909,21 @@ namespace LuaPlayer { "InArena", &LuaPlayer::InArena }, { "CanFly", &LuaPlayer::CanFly }, { "IsFlying", &LuaPlayer::IsFlying }, +#else + { "HasTitle", nullptr, METHOD_REG_NONE }, + { "IsInArenaTeam", nullptr, METHOD_REG_NONE }, + { "InArena", nullptr, METHOD_REG_NONE }, + { "CanFly", nullptr, METHOD_REG_NONE }, + { "IsFlying", nullptr, METHOD_REG_NONE }, #endif #if defined(WOTLK) { "HasAchieved", &LuaPlayer::HasAchieved }, { "HasTalent", &LuaPlayer::HasTalent }, { "CanTitanGrip", &LuaPlayer::CanTitanGrip }, +#else + { "HasAchieved", nullptr, METHOD_REG_NONE }, + { "HasTalent", nullptr, METHOD_REG_NONE }, + { "CanTitanGrip", nullptr, METHOD_REG_NONE }, #endif { "CanCompleteRepeatableQuest", &LuaPlayer::CanCompleteRepeatableQuest }, { "CanRewardQuest", &LuaPlayer::CanRewardQuest }, @@ -3987,49 +4011,57 @@ namespace LuaPlayer { "RemoveArenaSpellCooldowns", &LuaPlayer::RemoveArenaSpellCooldowns }, { "ModifyHonorPoints", &LuaPlayer::ModifyHonorPoints }, { "ModifyArenaPoints", &LuaPlayer::ModifyArenaPoints }, +#else + { "RemoveArenaSpellCooldowns", nullptr, METHOD_REG_NONE }, + { "ModifyHonorPoints", nullptr, METHOD_REG_NONE }, + { "ModifyArenaPoints", nullptr, METHOD_REG_NONE }, #endif #if defined(WOTLK) { "ResetPetTalents", &LuaPlayer::ResetPetTalents }, { "ResetAchievements", &LuaPlayer::ResetAchievements }, { "SendMovieStart", &LuaPlayer::SendMovieStart }, +#else + { "ResetPetTalents", nullptr, METHOD_REG_NONE }, + { "ResetAchievements", nullptr, METHOD_REG_NONE }, + { "SendMovieStart", nullptr, METHOD_REG_NONE }, #endif // Not implemented methods - { "GetChampioningFaction", nullptr }, // ACore & TC only - { "GetRecruiterId", nullptr }, // not implemented - { "GetHonorStoredKills", nullptr }, // classic only - { "GetRankPoints", nullptr }, // classic only - { "GetHonorLastWeekStandingPos", nullptr }, // classic only - { "SetHonorStoredKills", nullptr }, // classic only - { "SetRankPoints", nullptr }, // classic only - { "SetHonorLastWeekStandingPos", nullptr }, // classic only - { "SetMovement", nullptr }, // not implemented - { "SetFFA", nullptr }, // not implemented + { "GetChampioningFaction", nullptr, METHOD_REG_NONE }, // ACore & TC only + { "GetRecruiterId", nullptr, METHOD_REG_NONE }, // not implemented + { "GetHonorStoredKills", nullptr, METHOD_REG_NONE }, // classic only + { "GetRankPoints", nullptr, METHOD_REG_NONE }, // classic only + { "GetHonorLastWeekStandingPos", nullptr, METHOD_REG_NONE }, // classic only + { "SetHonorStoredKills", nullptr, METHOD_REG_NONE }, // classic only + { "SetRankPoints", nullptr, METHOD_REG_NONE }, // classic only + { "SetHonorLastWeekStandingPos", nullptr, METHOD_REG_NONE }, // classic only + { "SetMovement", nullptr, METHOD_REG_NONE }, // not implemented + { "SetFFA", nullptr, METHOD_REG_NONE }, // not implemented { "IsImmuneToEnvironmentalDamage", nullptr}, // not implemented - { "InRandomLfgDungeon", nullptr }, // not implemented - { "HasPendingBind", nullptr }, //not implmented - { "CanFlyInZone", nullptr }, // not implemented - { "IsNeverVisible", nullptr }, // not implemented - { "IsUsingLfg", nullptr }, // not implemented - { "HasReceivedQuestReward", nullptr }, // not implemented - { "IsOutdoorPvPActive", nullptr }, // not implemented - { "IsARecruiter", nullptr }, // not implemented - { "SetAchievement", nullptr }, // TC/Acore - { "RemovePet", nullptr }, // not implemented - { "SummonPet", nullptr }, // not implemented - { "RemoveActiveQuest", nullptr }, // not implemented - { "RemoveRewardedQuest", nullptr }, // not implemented - { "KilledPlayerCredit", nullptr }, // not implemented - { "KillGOCredit", nullptr }, // not implemented - { "GainSpellComboPoints", nullptr }, // not implemented - { "AddTalent", nullptr }, // not implemented - { "BindToInstance", nullptr }, // not implemented - { "UpdateHonor", nullptr }, // classic only - { "ResetHonor", nullptr }, // classic only - { "ClearHonorInfo", nullptr }, // classic only - { "GetXP", nullptr }, // not implemented - { "GetXPForNextLevel", nullptr }, // not implemented + { "InRandomLfgDungeon", nullptr, METHOD_REG_NONE }, // not implemented + { "HasPendingBind", nullptr, METHOD_REG_NONE }, //not implmented + { "CanFlyInZone", nullptr, METHOD_REG_NONE }, // not implemented + { "IsNeverVisible", nullptr, METHOD_REG_NONE }, // not implemented + { "IsUsingLfg", nullptr, METHOD_REG_NONE }, // not implemented + { "HasReceivedQuestReward", nullptr, METHOD_REG_NONE }, // not implemented + { "IsOutdoorPvPActive", nullptr, METHOD_REG_NONE }, // not implemented + { "IsARecruiter", nullptr, METHOD_REG_NONE }, // not implemented + { "SetAchievement", nullptr, METHOD_REG_NONE }, // TC/Acore + { "RemovePet", nullptr, METHOD_REG_NONE }, // not implemented + { "SummonPet", nullptr, METHOD_REG_NONE }, // not implemented + { "RemoveActiveQuest", nullptr, METHOD_REG_NONE }, // not implemented + { "RemoveRewardedQuest", nullptr, METHOD_REG_NONE }, // not implemented + { "KilledPlayerCredit", nullptr, METHOD_REG_NONE }, // not implemented + { "KillGOCredit", nullptr, METHOD_REG_NONE }, // not implemented + { "GainSpellComboPoints", nullptr, METHOD_REG_NONE }, // not implemented + { "AddTalent", nullptr, METHOD_REG_NONE }, // not implemented + { "BindToInstance", nullptr, METHOD_REG_NONE }, // not implemented + { "UpdateHonor", nullptr, METHOD_REG_NONE }, // classic only + { "ResetHonor", nullptr, METHOD_REG_NONE }, // classic only + { "ClearHonorInfo", nullptr, METHOD_REG_NONE }, // classic only + { "GetXP", nullptr, METHOD_REG_NONE }, // not implemented + { "GetXPForNextLevel", nullptr, METHOD_REG_NONE }, // not implemented - { NULL, NULL } + { NULL, NULL, METHOD_REG_NONE } }; }; #endif diff --git a/CMangos/QuestMethods.h b/CMangos/QuestMethods.h index 9bbfdf2341..56107de9b5 100644 --- a/CMangos/QuestMethods.h +++ b/CMangos/QuestMethods.h @@ -187,13 +187,15 @@ namespace LuaQuest { "HasFlag", &LuaQuest::HasFlag }, #if defined(TBC) || defined(WOTLK) { "IsDaily", &LuaQuest::IsDaily }, +#else + { "IsDaily", nullptr, METHOD_REG_NONE }, #endif { "IsRepeatable", &LuaQuest::IsRepeatable }, // Not implemented methods - { "GetMaxLevel", nullptr }, // not implemented + { "GetMaxLevel", nullptr, METHOD_REG_NONE }, // not implemented - { NULL, NULL } + { NULL, NULL, METHOD_REG_NONE } }; }; #endif diff --git a/CMangos/SpellMethods.h b/CMangos/SpellMethods.h index aa031a1180..f755da8e96 100644 --- a/CMangos/SpellMethods.h +++ b/CMangos/SpellMethods.h @@ -188,7 +188,7 @@ namespace LuaSpell { "Cast", &LuaSpell::Cast }, { "Finish", &LuaSpell::Finish }, - { NULL, NULL } + { NULL, NULL, METHOD_REG_NONE } }; }; #endif diff --git a/CMangos/UnitMethods.h b/CMangos/UnitMethods.h index 1a1b279966..eba63350e8 100644 --- a/CMangos/UnitMethods.h +++ b/CMangos/UnitMethods.h @@ -2542,6 +2542,9 @@ namespace LuaUnit #if defined(WOTLK) { "GetCritterGUID", &LuaUnit::GetCritterGUID }, { "GetVehicleKit", &LuaUnit::GetVehicleKit }, +#else + { "GetCritterGUID", nullptr, METHOD_REG_NONE }, + { "GetVehicleKit", nullptr, METHOD_REG_NONE }, #endif // Setters @@ -2575,6 +2578,10 @@ namespace LuaUnit { "SetFFA", &LuaUnit::SetFFA }, { "SetSanctuary", &LuaUnit::SetSanctuary }, { "SetCritterGUID", &LuaUnit::SetCritterGUID }, +#else + { "SetFFA", nullptr, METHOD_REG_NONE }, + { "SetSanctuary", nullptr, METHOD_REG_NONE }, + { "SetCritterGUID", nullptr, METHOD_REG_NONE }, #endif // Boolean @@ -2618,7 +2625,9 @@ namespace LuaUnit { "IsStandState", &LuaUnit::IsStandState }, #if defined(TBC) || defined(WOTLK) { "IsOnVehicle", &LuaUnit::IsOnVehicle }, -#endif +#else + { "IsOnVehicle", nullptr, METHOD_REG_NONE }, +#endif // Other { "AddAura", &LuaUnit::AddAura }, @@ -2663,27 +2672,31 @@ namespace LuaUnit { "AddThreat", &LuaUnit::AddThreat }, #if defined(TBC) || defined(WOTLK) { "RemoveArenaAuras", &LuaUnit::RemoveArenaAuras }, +#else + { "RemoveArenaAuras", nullptr, METHOD_REG_NONE }, #endif #if defined(WOTLK) { "MoveJump", &LuaUnit::MoveJump }, +#else + { "MoveJump", nullptr, METHOD_REG_NONE }, #endif // Not implemented methods - { "GetVehicle", nullptr }, // not implemented - { "SetStunned", nullptr }, // not implemented - { "SetCanFly", nullptr }, // not implemented - { "SetVisible", nullptr }, // not implemented - { "IsVisible", nullptr }, // not implemented - { "IsMoving", nullptr }, // not implemented - { "IsFlying", nullptr }, // not implemented - { "RestoreDisplayId", nullptr }, // not implemented - { "RestoreFaction", nullptr }, //not implemented - { "RemoveBindSightAuras", nullptr }, // not implemented - { "RemoveCharmAuras", nullptr }, // not implemented - { "DisableMelee", nullptr }, // not implemented - { "SummonGuardian", nullptr }, // not implemented - - { NULL, NULL } + { "GetVehicle", nullptr, METHOD_REG_NONE }, // not implemented + { "SetStunned", nullptr, METHOD_REG_NONE }, // not implemented + { "SetCanFly", nullptr, METHOD_REG_NONE }, // not implemented + { "SetVisible", nullptr, METHOD_REG_NONE }, // not implemented + { "IsVisible", nullptr, METHOD_REG_NONE }, // not implemented + { "IsMoving", nullptr, METHOD_REG_NONE }, // not implemented + { "IsFlying", nullptr, METHOD_REG_NONE }, // not implemented + { "RestoreDisplayId", nullptr, METHOD_REG_NONE }, // not implemented + { "RestoreFaction", nullptr, METHOD_REG_NONE }, //not implemented + { "RemoveBindSightAuras", nullptr, METHOD_REG_NONE }, // not implemented + { "RemoveCharmAuras", nullptr, METHOD_REG_NONE }, // not implemented + { "DisableMelee", nullptr, METHOD_REG_NONE }, // not implemented + { "SummonGuardian", nullptr, METHOD_REG_NONE }, // not implemented + + { NULL, NULL, METHOD_REG_NONE } }; }; #endif diff --git a/CMangos/VehicleMethods.h b/CMangos/VehicleMethods.h index d909c5dee1..9293e436c6 100644 --- a/CMangos/VehicleMethods.h +++ b/CMangos/VehicleMethods.h @@ -106,7 +106,7 @@ namespace LuaVehicle { "AddPassenger", &LuaVehicle::AddPassenger }, { "RemovePassenger", &LuaVehicle::RemovePassenger }, - { NULL, NULL } + { NULL, NULL, METHOD_REG_NONE } }; } diff --git a/CMangos/WorldObjectMethods.h b/CMangos/WorldObjectMethods.h index 753348e23b..3a7aae4c8d 100644 --- a/CMangos/WorldObjectMethods.h +++ b/CMangos/WorldObjectMethods.h @@ -1099,6 +1099,32 @@ namespace LuaWorldObject obj->PlayDistanceSound(soundId); return 0; } + + /** + * Returns a runtime-persistent cache tied to the [WorldObject]. + * This data will remain for as long as the [WorldObject] exists, or until a server restart. + * + * A reload of the Lua state will NOT clear this cache. + * + * This cache can be added to and read from with the following sub-methods. + *
+     * -- Sets the key-value pair in the cache
+     * WorldObject:Data():Set("key", val)
+     *
+     * -- Returns the value from the cache using the key
+     * local val = WorldObject:Data():Get("key")
+     *
+     * -- Removes the key-value pair from the cache
+     * WorldObject:Data():Set("key", nil)
+     *
+     * -- Returns all the key-value pairs as a Lua table indexed by the keys
+     * local table = WorldObject:Data():AsTable()
+     * 
+ */ + int Data(Eluna* E, WorldObject* obj) + { + return LuaVal::PushLuaVal(E->L, obj->lua_data); + } ElunaRegister WorldObjectMethods[] = { @@ -1131,6 +1157,9 @@ namespace LuaWorldObject #if defined(WOTLK) { "GetPhaseMask", &LuaWorldObject::GetPhaseMask }, { "SetPhaseMask", &LuaWorldObject::SetPhaseMask }, +#else + { "GetPhaseMask", nullptr, METHOD_REG_NONE }, + { "SetPhaseMask", nullptr, METHOD_REG_NONE }, #endif // Boolean @@ -1150,14 +1179,15 @@ namespace LuaWorldObject { "SummonGameObject", &LuaWorldObject::SummonGameObject }, { "SpawnCreature", &LuaWorldObject::SpawnCreature }, { "SendPacket", &LuaWorldObject::SendPacket }, - { "RegisterEvent", &LuaWorldObject::RegisterEvent }, - { "RemoveEventById", &LuaWorldObject::RemoveEventById }, - { "RemoveEvents", &LuaWorldObject::RemoveEvents }, + { "RegisterEvent", &LuaWorldObject::RegisterEvent, METHOD_REG_MAP }, // Map state method only in multistate + { "RemoveEventById", &LuaWorldObject::RemoveEventById, METHOD_REG_MAP }, // Map state method only in multistate + { "RemoveEvents", &LuaWorldObject::RemoveEvents, METHOD_REG_MAP }, // Map state method only in multistate { "PlayMusic", &LuaWorldObject::PlayMusic }, { "PlayDirectSound", &LuaWorldObject::PlayDirectSound }, { "PlayDistanceSound", &LuaWorldObject::PlayDistanceSound }, + { "Data", &LuaWorldObject::Data }, - { NULL, NULL } + { NULL, NULL, METHOD_REG_NONE } }; }; #endif diff --git a/CMangos/WorldPacketMethods.h b/CMangos/WorldPacketMethods.h index f229dd47a8..b532d6150e 100644 --- a/CMangos/WorldPacketMethods.h +++ b/CMangos/WorldPacketMethods.h @@ -343,7 +343,7 @@ namespace LuaPacket { "WriteFloat", &LuaPacket::WriteFloat }, { "WriteDouble", &LuaPacket::WriteDouble }, - { NULL, NULL } + { NULL, NULL, METHOD_REG_NONE } }; };