diff --git a/README.md b/README.md index 794571a1a8..47e3305fb3 100644 --- a/README.md +++ b/README.md @@ -90,6 +90,7 @@ Eluna API for AC: - Added `RegisterPlayerEvent` `53` (`PLAYER_EVENT_ON_STORE_NEW_ITEM`): https://github.com/azerothcore/mod-eluna/pull/88 - Added `RegisterPlayerEvent` `54` (`PLAYER_EVENT_ON_COMPLETE_QUEST`): https://github.com/azerothcore/mod-eluna/pull/90 - Added `RegisterPlayerEvent` `55` (`PLAYER_EVENT_ON_CAN_GROUP_INVITE`): https://github.com/azerothcore/mod-eluna/pull/100 +- Added `RegisterPlayerEvent` `56` (`PLAYER_EVENT_ON_GROUP_ROLL_REWARD_ITEM`): https://github.com/azerothcore/mod-eluna/pull/119 - Added `Player:GetMailCount()`: https://github.com/azerothcore/mod-eluna/pull/76 - Added `Player:GetXP()`: https://github.com/azerothcore/mod-eluna/pull/77 - Added `Player:GetAchievementCriteriaProgress()`: https://github.com/azerothcore/mod-eluna/pull/78 @@ -118,6 +119,7 @@ Eluna API for AC: - Added `GetItemTemplate(itemEntry)`: https://github.com/azerothcore/mod-eluna/pull/84 - Added `ChatHandler` methods: https://github.com/azerothcore/mod-eluna/pull/23 - Added `ItemTemplate` methods: https://github.com/azerothcore/mod-eluna/pull/84 +- Added `Roll` methods: https://github.com/azerothcore/mod-eluna/pull/119 - Added logging with `ELUNA_LOG_INFO` for `RunCommand()`: https://github.com/azerothcore/mod-eluna/pull/75 - Added `GetOwnerHalaa` and `SetOwnerHalaa`: https://github.com/azerothcore/mod-eluna/pull/79 - Added `WorldDBQueryAsync`, `CharDBQueryAsync` and `AuthDBQueryAsync`: https://github.com/azerothcore/mod-eluna/pull/113 diff --git a/src/ElunaLuaEngine_SC.cpp b/src/ElunaLuaEngine_SC.cpp index d514fd5c91..9e31be5373 100644 --- a/src/ElunaLuaEngine_SC.cpp +++ b/src/ElunaLuaEngine_SC.cpp @@ -777,6 +777,11 @@ class Eluna_PlayerScript : public PlayerScript sEluna->OnQuestRewardItem(player, item, count); } + void OnGroupRollRewardItem(Player* player, Item* item, uint32 count, RollVote voteType, Roll* roll) override + { + sEluna->OnGroupRollRewardItem(player, item, count, voteType, roll); + } + void OnCreateItem(Player* player, Item* item, uint32 count) override { sEluna->OnCreateItem(player, item, count); diff --git a/src/LuaEngine/GlobalMethods.h b/src/LuaEngine/GlobalMethods.h index e0a0eb1543..99d07eeb52 100644 --- a/src/LuaEngine/GlobalMethods.h +++ b/src/LuaEngine/GlobalMethods.h @@ -728,6 +728,7 @@ namespace LuaGlobalFunctions * PLAYER_EVENT_ON_STORE_NEW_ITEM = 53, // (event, player, item, count) * PLAYER_EVENT_ON_COMPLETE_QUEST = 54, // (event, player, quest) * PLAYER_EVENT_ON_CAN_GROUP_INVITE = 55, // (event, player, memberName) - Can return false to prevent inviting + * PLAYER_EVENT_ON_GROUP_ROLL_REWARD_ITEM = 56, // (event, player, item, count, voteType, roll) * }; * * diff --git a/src/LuaEngine/Hooks.h b/src/LuaEngine/Hooks.h index 677e5c8096..6e0df8cab5 100644 --- a/src/LuaEngine/Hooks.h +++ b/src/LuaEngine/Hooks.h @@ -217,6 +217,7 @@ namespace Hooks PLAYER_EVENT_ON_STORE_NEW_ITEM = 53, // (event, player, item, count) PLAYER_EVENT_ON_COMPLETE_QUEST = 54, // (event, player, quest) PLAYER_EVENT_ON_CAN_GROUP_INVITE = 55, // (event, player, memberName) - Can return false to prevent inviting + PLAYER_EVENT_ON_GROUP_ROLL_REWARD_ITEM = 56, // (event, player, item, count, voteType, roll) PLAYER_EVENT_COUNT }; diff --git a/src/LuaEngine/ItemMethods.h b/src/LuaEngine/ItemMethods.h index cdafc7e8a0..9c8555130a 100644 --- a/src/LuaEngine/ItemMethods.h +++ b/src/LuaEngine/ItemMethods.h @@ -652,7 +652,7 @@ namespace LuaItem /** * Returns the [ItemTemplate] for this [Item]. * - * @return ItemTemplate itemTemplate + * @return [ItemTemplate] itemTemplate */ int GetItemTemplate(lua_State* L, Item* item) { diff --git a/src/LuaEngine/LuaEngine.h b/src/LuaEngine/LuaEngine.h index 29bef71d17..4bce4cb4f2 100644 --- a/src/LuaEngine/LuaEngine.h +++ b/src/LuaEngine/LuaEngine.h @@ -486,6 +486,7 @@ class ELUNA_GAME_API Eluna bool OnCanSendMail(Player* player, ObjectGuid receiverGuid, ObjectGuid mailbox, std::string& subject, std::string& body, uint32 money, uint32 cod, Item* item); bool OnCanJoinLfg(Player* player, uint8 roles, lfg::LfgDungeonSet& dungeons, const std::string& comment); bool OnCanGroupInvite(Player* player, std::string& memberName); + void OnGroupRollRewardItem(Player* player, Item* item, uint32 count, RollVote voteType, Roll* roll); #ifndef CLASSIC #ifndef TBC diff --git a/src/LuaEngine/LuaFunctions.cpp b/src/LuaEngine/LuaFunctions.cpp index 75eca7e54f..1bff86521f 100644 --- a/src/LuaEngine/LuaFunctions.cpp +++ b/src/LuaEngine/LuaFunctions.cpp @@ -39,6 +39,7 @@ extern "C" #include "ChatHandlerMethods.h" #include "AchievementMethods.h" #include "ItemTemplateMethods.h" +#include "RollMethods.h" luaL_Reg GlobalMethods[] = { @@ -1365,6 +1366,25 @@ ElunaRegister AchievementMethods[] = { NULL, NULL } }; +ElunaRegister RollMethods[] = +{ + { "GetItemGUID", &LuaRoll::GetItemGUID }, + { "GetItemId", &LuaRoll::GetItemId }, + { "GetItemRandomPropId", &LuaRoll::GetItemRandomPropId }, + { "GetItemRandomSuffix", &LuaRoll::GetItemRandomSuffix }, + { "GetItemCount", &LuaRoll::GetItemCount }, + { "GetPlayerVote", &LuaRoll::GetPlayerVote }, + { "GetPlayerVoteGUIDs", &LuaRoll::GetPlayerVoteGUIDs }, + { "GetTotalPlayersRolling", &LuaRoll::GetTotalPlayersRolling }, + { "GetTotalNeed", &LuaRoll::GetTotalNeed }, + { "GetTotalGreed", &LuaRoll::GetTotalGreed }, + { "GetTotalPass", &LuaRoll::GetTotalPass }, + { "GetItemSlot", &LuaRoll::GetItemSlot }, + { "GetRollVoteMask", &LuaRoll::GetRollVoteMask }, + + { NULL, NULL } +}; + #if (!defined(TBC) && !defined(CLASSIC)) // fix compile error about accessing vehicle destructor template<> int ElunaTemplate::CollectGarbage(lua_State* L) @@ -1513,6 +1533,9 @@ void RegisterFunctions(Eluna* E) ElunaTemplate::Register(E, "AchievementEntry"); ElunaTemplate::SetMethods(E, AchievementMethods); + ElunaTemplate::Register(E, "Roll"); + ElunaTemplate::SetMethods(E, RollMethods); + ElunaTemplate::Register(E, "long long", true); ElunaTemplate::Register(E, "unsigned long long", true); diff --git a/src/LuaEngine/PlayerHooks.cpp b/src/LuaEngine/PlayerHooks.cpp index fb4ba71859..bdf0549398 100644 --- a/src/LuaEngine/PlayerHooks.cpp +++ b/src/LuaEngine/PlayerHooks.cpp @@ -678,3 +678,14 @@ bool Eluna::OnCanGroupInvite(Player* player, std::string& memberName) Push(memberName); return CallAllFunctionsBool(PlayerEventBindings, key); } + +void Eluna::OnGroupRollRewardItem(Player* player, Item* item, uint32 count, RollVote voteType, Roll* roll) +{ + START_HOOK(PLAYER_EVENT_ON_GROUP_ROLL_REWARD_ITEM); + Push(player); + Push(item); + Push(count); + Push(voteType); + Push(roll); + CallAllFunctions(PlayerEventBindings, key); +} diff --git a/src/LuaEngine/RollMethods.h b/src/LuaEngine/RollMethods.h new file mode 100644 index 0000000000..d36fe1179c --- /dev/null +++ b/src/LuaEngine/RollMethods.h @@ -0,0 +1,212 @@ +/* +* Copyright (C) 2010 - 2016 Eluna Lua Engine +* This program is free software licensed under GPL version 3 +* Please see the included DOCS/LICENSE.md for more information +*/ + +#ifndef ROLLMETHODS_H +#define ROLLMETHODS_H + +#include "Group.h" + +namespace LuaRoll +{ + /** + * Returns the rolled [Item]'s GUID. + * + * @return ObjectGuid guid + */ + int GetItemGUID(lua_State* L, Roll* roll) + { + Eluna::Push(L, roll->itemGUID.GetCounter()); + return 1; + } + + /** + * Returns the rolled [Item]'s entry. + * + * @return uint32 entry + */ + int GetItemId(lua_State* L, Roll* roll) + { + Eluna::Push(L, roll->itemid); + return 1; + } + + /** + * Returns the rolled [Item]'s random property ID. + * + * @return int32 randomPropId + */ + int GetItemRandomPropId(lua_State* L, Roll* roll) + { + Eluna::Push(L, roll->itemRandomPropId); + return 1; + } + + /** + * Returns the rolled [Item]'s random suffix ID. + * + * @return uint32 randomSuffix + */ + int GetItemRandomSuffix(lua_State* L, Roll* roll) + { + Eluna::Push(L, roll->itemRandomSuffix); + return 1; + } + + /** + * Returns the rolled [Item]'s count. + * + * @return uint8 count + */ + int GetItemCount(lua_State* L, Roll* roll) + { + Eluna::Push(L, roll->itemCount); + return 1; + } + + /** + * Returns the vote type for a [Player] on this [Roll]. + * See [Roll:GetPlayerVoteGUIDs] to obtain the GUIDs of the [Player]s who rolled. + * + *
+     * enum RollVote
+     * {
+     *     PASS              = 0,
+     *     NEED              = 1,
+     *     GREED             = 2,
+     *     DISENCHANT        = 3,
+     *     NOT_EMITED_YET    = 4,
+     *     NOT_VALID         = 5
+     * };
+     * 
+ * + * @param ObjectGuid guid + * @return [RollVote] vote + */ + int GetPlayerVote(lua_State* L, Roll* roll) + { + ObjectGuid guid = Eluna::CHECKVAL(L, 2); + + bool found = false; + for (std::pair& pair : roll->playerVote) + { + if (pair.first == guid) + { + Eluna::Push(L, pair.second); + found = true; + } + } + + if (!found) + { + Eluna::Push(L); + } + + return 1; + } + + /** + * Returns the GUIDs of the [Player]s who rolled. + * See [Roll:GetPlayerVote] to obtain the vote type of a [Player]. + * + * @return table guids + */ + int GetPlayerVoteGUIDs(lua_State* L, Roll* roll) + { + lua_newtable(L); + int table = lua_gettop(L); + uint32 i = 1; + for (std::pair& pair : roll->playerVote) + { + Eluna::Push(L, pair.first); + lua_rawseti(L, table, i); + ++i; + } + + lua_settop(L, table); // push table to top of stack + return 1; + } + + /** + * Returns the total number of players who rolled. + * + * @return uint8 playersCount + */ + int GetTotalPlayersRolling(lua_State* L, Roll* roll) + { + Eluna::Push(L, roll->totalPlayersRolling); + return 1; + } + + /** + * Returns the total number of players who rolled need. + * + * @return uint8 playersCount + */ + int GetTotalNeed(lua_State* L, Roll* roll) + { + Eluna::Push(L, roll->totalNeed); + return 1; + } + + /** + * Returns the total number of players who rolled greed. + * + * @return uint8 playersCount + */ + int GetTotalGreed(lua_State* L, Roll* roll) + { + Eluna::Push(L, roll->totalGreed); + return 1; + } + + /** + * Returns the total number of players who passed. + * + * @return uint8 playersCount + */ + int GetTotalPass(lua_State* L, Roll* roll) + { + Eluna::Push(L, roll->totalPass); + return 1; + } + + /** + * Returns the rolled [Item]'s slot in the loot window. + * + * @return uint8 slot + */ + int GetItemSlot(lua_State* L, Roll* roll) + { + Eluna::Push(L, roll->itemSlot); + return 1; + } + + /** + * Returns the mask applied to this [Roll]. + * + *
+     * enum RollMask
+     * {
+     *     ROLL_FLAG_TYPE_PASS                 = 0x01,
+     *     ROLL_FLAG_TYPE_NEED                 = 0x02,
+     *     ROLL_FLAG_TYPE_GREED                = 0x04,
+     *     ROLL_FLAG_TYPE_DISENCHANT           = 0x08,
+     * 
+     *     ROLL_ALL_TYPE_NO_DISENCHANT         = 0x07,
+     *     ROLL_ALL_TYPE_MASK                  = 0x0F
+     * };
+     * 
+ * + * @return [RollMask] rollMask + */ + int GetRollVoteMask(lua_State* L, Roll* roll) + { + Eluna::Push(L, roll->rollVoteMask); + return 1; + } +} + +#endif