mirror of
https://github.com/azerothcore/mod-ale
synced 2025-11-29 15:38:17 +08:00
feat: add PLAYER_EVENT_ON_GROUP_ROLL_REWARD_ITEM and roll methods (#119)
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -777,6 +777,11 @@ public:
|
||||
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);
|
||||
|
||||
@@ -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)
|
||||
* };
|
||||
* </pre>
|
||||
*
|
||||
|
||||
@@ -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
|
||||
};
|
||||
|
||||
@@ -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)
|
||||
{
|
||||
|
||||
@@ -486,6 +486,7 @@ public:
|
||||
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
|
||||
|
||||
@@ -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<AchievementEntry> AchievementMethods[] =
|
||||
{ NULL, NULL }
|
||||
};
|
||||
|
||||
ElunaRegister<Roll> 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<Vehicle>::CollectGarbage(lua_State* L)
|
||||
@@ -1513,6 +1533,9 @@ void RegisterFunctions(Eluna* E)
|
||||
ElunaTemplate<AchievementEntry>::Register(E, "AchievementEntry");
|
||||
ElunaTemplate<AchievementEntry>::SetMethods(E, AchievementMethods);
|
||||
|
||||
ElunaTemplate<Roll>::Register(E, "Roll");
|
||||
ElunaTemplate<Roll>::SetMethods(E, RollMethods);
|
||||
|
||||
ElunaTemplate<long long>::Register(E, "long long", true);
|
||||
|
||||
ElunaTemplate<unsigned long long>::Register(E, "unsigned long long", true);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
212
src/LuaEngine/RollMethods.h
Normal file
212
src/LuaEngine/RollMethods.h
Normal file
@@ -0,0 +1,212 @@
|
||||
/*
|
||||
* Copyright (C) 2010 - 2016 Eluna Lua Engine <http://emudevs.com/>
|
||||
* 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.
|
||||
*
|
||||
* <pre>
|
||||
* enum RollVote
|
||||
* {
|
||||
* PASS = 0,
|
||||
* NEED = 1,
|
||||
* GREED = 2,
|
||||
* DISENCHANT = 3,
|
||||
* NOT_EMITED_YET = 4,
|
||||
* NOT_VALID = 5
|
||||
* };
|
||||
* </pre>
|
||||
*
|
||||
* @param ObjectGuid guid
|
||||
* @return [RollVote] vote
|
||||
*/
|
||||
int GetPlayerVote(lua_State* L, Roll* roll)
|
||||
{
|
||||
ObjectGuid guid = Eluna::CHECKVAL<ObjectGuid>(L, 2);
|
||||
|
||||
bool found = false;
|
||||
for (std::pair<const ObjectGuid, RollVote>& 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<const ObjectGuid, RollVote>& 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].
|
||||
*
|
||||
* <pre>
|
||||
* 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
|
||||
* };
|
||||
* </pre>
|
||||
*
|
||||
* @return [RollMask] rollMask
|
||||
*/
|
||||
int GetRollVoteMask(lua_State* L, Roll* roll)
|
||||
{
|
||||
Eluna::Push(L, roll->rollVoteMask);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user