From 54484b7fa2c99091032632f97f8719b71b6abb82 Mon Sep 17 00:00:00 2001 From: iThorgrim <125808072+iThorgrim@users.noreply.github.com> Date: Sat, 25 Jan 2025 20:17:55 +0100 Subject: [PATCH] feat(methods/guild): add new guild methods (#228) --- src/LuaEngine/LuaFunctions.cpp | 10 ++ src/LuaEngine/methods/GuildMethods.h | 172 +++++++++++++++++++++++++++ 2 files changed, 182 insertions(+) diff --git a/src/LuaEngine/LuaFunctions.cpp b/src/LuaEngine/LuaFunctions.cpp index b5db1b3..337dfdf 100644 --- a/src/LuaEngine/LuaFunctions.cpp +++ b/src/LuaEngine/LuaFunctions.cpp @@ -1081,11 +1081,14 @@ ElunaRegister GuildMethods[] = { "GetMOTD", &LuaGuild::GetMOTD }, { "GetInfo", &LuaGuild::GetInfo }, { "GetMemberCount", &LuaGuild::GetMemberCount }, + { "GetCreatedDate", &LuaGuild::GetCreatedDate }, + { "GetTotalBankMoney", &LuaGuild::GetTotalBankMoney }, // Setters { "SetBankTabText", &LuaGuild::SetBankTabText }, { "SetMemberRank", &LuaGuild::SetMemberRank }, { "SetLeader", &LuaGuild::SetLeader }, + { "SetName", &LuaGuild::SetName }, // Other { "SendPacket", &LuaGuild::SendPacket }, @@ -1093,6 +1096,13 @@ ElunaRegister GuildMethods[] = { "Disband", &LuaGuild::Disband }, { "AddMember", &LuaGuild::AddMember }, { "DeleteMember", &LuaGuild::DeleteMember }, + { "SendMessage", &LuaGuild::SendMessage }, + { "UpdateMemberData", &LuaGuild::UpdateMemberData }, + { "MassInviteToEvent", &LuaGuild::MassInviteToEvent }, + { "SwapItems", &LuaGuild::SwapItems }, + { "SwapItemsWithInventory", &LuaGuild::SwapItemsWithInventory }, + { "ResetTimes", &LuaGuild::ResetTimes }, + { "ModifyBankMoney", &LuaGuild::ModifyBankMoney }, { NULL, NULL } }; diff --git a/src/LuaEngine/methods/GuildMethods.h b/src/LuaEngine/methods/GuildMethods.h index 4915012..b86f1ab 100644 --- a/src/LuaEngine/methods/GuildMethods.h +++ b/src/LuaEngine/methods/GuildMethods.h @@ -234,5 +234,177 @@ namespace LuaGuild guild->ChangeMemberRank(player->GET_GUID(), newRank); return 0; } + + /** + * Sets the new name of the specified [Guild]. + * + * @param string name : new name of this guild + */ + int SetName(lua_State* L, Guild* guild) + { + std::string name = Eluna::CHECKVAL(L, 2); + + guild->SetName(name); + return 0; + } + + /** + * Update [Player] data in [Guild] member list. + * + * enum GuildMemberData + * { + * GUILD_MEMBER_DATA_ZONEID = 0 + * GUILD_MEMBER_DATA_LEVEL = 1 + * }; + * + * @param [Player] player = plkayer you need to update data + * @param [GuildMemberData] dataid = data you need to update + * @param uint32 value + */ + int UpdateMemberData(lua_State* L, Guild* guild) + { + Player* player = Eluna::CHECKOBJ(L, 2); + uint8 dataid = Eluna::CHECKVAL(L, 3); + uint32 value = Eluna::CHECKVAL(L, 4); + + guild->UpdateMemberData(player, dataid, value); + return 0; + } + + /** + * Send message to [Guild] from specific [Player]. + * + * @param [Player] player = the [Player] is the author of the message + * @param bool officierOnly = send message only on officier channel + * @param string msg = the message you need to send + * @param uint32 lang = language the [Player] will speak + */ + int SendMessage(lua_State* L, Guild* guild) + { + Player* player = Eluna::CHECKOBJ(L, 2); + bool officierOnly = Eluna::CHECKVAL(L, 3, false); + std::string msg = Eluna::CHECKVAL(L, 4); + uint32 language = Eluna::CHECKVAL(L, 5, false); + + guild->BroadcastToGuild(player->GetSession(), officierOnly, msg, language); + return 0; + } + + /** + * Invites [Guild] members to events based on level and rank filters. + * + * @param Player player = who sends the invitation + * @param minLevel = the required min level + * @param maxLevel = the required max level + * @param minRank = the required min rank + */ + int MassInviteToEvent(lua_State* L, Guild* guild) + { + Player* player = Eluna::CHECKOBJ(L, 2); + uint32 minLevel = Eluna::CHECKVAL(L, 3); + uint32 maxLevel = Eluna::CHECKVAL(L, 4); + uint32 minRank = Eluna::CHECKVAL(L, 5); + + guild->MassInviteToEvent(player->GetSession(), minLevel, maxLevel, minRank); + return 0; + } + + /** + * Swap item from a specific tab and slot [Guild] bank to another one. + * + * @param [Player] player = who Swap the item + * @param uint8 tabId = source tab id + * @param uint8 slotId = source slot id + * @param uint8 destTabId = destination tab id + * @param uint8 destSlotId = destination slot id + * @param uint8 splitedAmount = if the item is stackable, how much should be swaped + */ + int SwapItems(lua_State* L, Guild* guild) + { + Player* player = Eluna::CHECKOBJ(L, 2); + uint8 tabId = Eluna::CHECKVAL(L, 3); + uint8 slotId = Eluna::CHECKVAL(L, 4); + uint8 destTabId = Eluna::CHECKVAL(L, 5); + uint8 destSlotId = Eluna::CHECKVAL(L, 6); + uint32 splitedAmount = Eluna::CHECKVAL(L, 7); + + guild->SwapItems(player, tabId, slotId, destTabId, destSlotId, splitedAmount); + return 0; + } + + /** + * Swap an item from a specific tab and location in the [guild] bank to the bags and locations in the inventory of a specific [player] and vice versa. + * + * @param [Player] player = who Swap the item + * @param bool toChar = the item goes to the [Player]'s inventory or comes from the [Player]'s inventory + * @param uint8 tabId = tab id + * @param uint8 slotId = slot id + * @param uint8 playerBag = bag id + * @param uint8 playerSlotId = slot id + * @param uint32 splitedAmount = if the item is stackable, how much should be swaped + */ + int SwapItemsWithInventory(lua_State* L, Guild* guild) + { + Player* player = Eluna::CHECKOBJ(L, 2); + bool toChar = Eluna::CHECKVAL(L, 3, false); + uint8 tabId = Eluna::CHECKVAL(L, 4); + uint8 slotId = Eluna::CHECKVAL(L, 5); + uint8 playerBag = Eluna::CHECKVAL(L, 6); + uint8 playerSlotId = Eluna::CHECKVAL(L, 7); + uint32 splitedAmount = Eluna::CHECKVAL(L, 8); + + guild->SwapItemsWithInventory(player, toChar, tabId, slotId, playerBag, playerSlotId, splitedAmount); + return 0; + } + + /** + * Return the total bank money. + * + * @return number totalBankMoney + */ + int GetTotalBankMoney(lua_State* L, Guild* guild) + { + Eluna::Push(L, guild->GetTotalBankMoney()); + return 1; + } + + /** + * Return the created date. + * + * @return uint64 created date + */ + int GetCreatedDate(lua_State* L, Guild* guild) + { + Eluna::Push(L, guild->GetCreatedDate()); + return 1; + } + + /** + * Resets the number of item withdraw in all tab's for all [Guild] members. + */ + int ResetTimes(lua_State* L, Guild* guild) + { + guild->ResetTimes(); + return 0; + } + + /** + * Modify the [Guild] bank money. You can deposit or withdraw. + * + * @param uint64 amount = amount to add or remove + * @param bool add = true (add money) | false (withdraw money) + * @return bool is_applied + */ + int ModifyBankMoney(lua_State* L, Guild* guild) + { + uint64 amount = Eluna::CHECKVAL(L, 2); + bool add = Eluna::CHECKVAL(L, 2); + + CharacterDatabaseTransaction trans = CharacterDatabase.BeginTransaction(); + Eluna::Push(L, guild->ModifyBankMoney(trans, amount, add)); + + CharacterDatabase.CommitTransaction(trans); + return 1; + } }; #endif