From d4b1b61c6c3f982606bf0122508486159eae66fa Mon Sep 17 00:00:00 2001 From: Eduardo Dantas Date: Thu, 5 Sep 2024 21:16:38 -0300 Subject: [PATCH] fix: remove bakragore icons talkaction (#2828) --- .../talkactions/god/icons_functions.lua | 6 +----- src/creatures/players/player.cpp | 14 ++++++++++++++ src/creatures/players/player.hpp | 2 ++ .../creatures/player/player_functions.cpp | 19 +++++++++++++++++++ .../creatures/player/player_functions.hpp | 2 ++ 5 files changed, 38 insertions(+), 5 deletions(-) diff --git a/data/scripts/talkactions/god/icons_functions.lua b/data/scripts/talkactions/god/icons_functions.lua index 9f1ee85c0f3..059d7ac6ed9 100644 --- a/data/scripts/talkactions/god/icons_functions.lua +++ b/data/scripts/talkactions/god/icons_functions.lua @@ -78,11 +78,7 @@ function bakragoreIcon.onSay(player, words, param) end if param == "remove" then - for i = 1, 10 do - if player:hasCondition(CONDITION_BAKRAGORE, i) then - player:removeCondition(CONDITION_BAKRAGORE, i) - end - end + player:removeIconBakragore() player:sendTextMessage(MESSAGE_EVENT_ADVANCE, "Removed all Bakragore icons.") return true end diff --git a/src/creatures/players/player.cpp b/src/creatures/players/player.cpp index 45f5808d633..9ba9f3b74d6 100644 --- a/src/creatures/players/player.cpp +++ b/src/creatures/players/player.cpp @@ -6209,6 +6209,20 @@ void Player::sendIconBakragore(const IconBakragore icon) { } } +void Player::removeBakragoreIcons() { + for (auto icon : magic_enum::enum_values()) { + if (hasCondition(CONDITION_BAKRAGORE, enumToValue(icon))) { + removeCondition(CONDITION_BAKRAGORE, CONDITIONID_DEFAULT, true); + } + } +} + +void Player::removeBakragoreIcon(const IconBakragore icon) { + if (hasCondition(CONDITION_BAKRAGORE, enumToValue(icon))) { + removeCondition(CONDITION_BAKRAGORE, CONDITIONID_DEFAULT, true); + } +} + void Player::sendCyclopediaCharacterAchievements(uint16_t secretsUnlocked, std::vector> achievementsUnlocked) { if (client) { client->sendCyclopediaCharacterAchievements(secretsUnlocked, achievementsUnlocked); diff --git a/src/creatures/players/player.hpp b/src/creatures/players/player.hpp index 83515b2e004..5a703a1d0bf 100644 --- a/src/creatures/players/player.hpp +++ b/src/creatures/players/player.hpp @@ -1422,6 +1422,8 @@ class Player final : public Creature, public Cylinder, public Bankable { void sendClosePrivate(uint16_t channelId); void sendIcons(); void sendIconBakragore(const IconBakragore icon); + void removeBakragoreIcons(); + void removeBakragoreIcon(const IconBakragore icon); void sendClientCheck() const { if (client) { client->sendClientCheck(); diff --git a/src/lua/functions/creatures/player/player_functions.cpp b/src/lua/functions/creatures/player/player_functions.cpp index d360b482a7b..7bbe495f7c2 100644 --- a/src/lua/functions/creatures/player/player_functions.cpp +++ b/src/lua/functions/creatures/player/player_functions.cpp @@ -4412,3 +4412,22 @@ int PlayerFunctions::luaPlayerSendIconBakragore(lua_State* L) { pushBoolean(L, true); return 1; } + +int PlayerFunctions::luaPlayerRemoveIconBakragore(lua_State* L) { + // player:removeIconBakragore(iconType or nil for remove all bakragore icons) + const auto &player = getUserdataShared(L, 1); + if (!player) { + lua_pushnil(L); + return 1; + } + + auto iconType = getNumber(L, 2, IconBakragore::None); + if (iconType == IconBakragore::None) { + player->removeBakragoreIcons(); + } else { + player->removeBakragoreIcon(iconType); + } + + pushBoolean(L, true); + return 1; +} diff --git a/src/lua/functions/creatures/player/player_functions.hpp b/src/lua/functions/creatures/player/player_functions.hpp index 000c5f755c0..7cee43424cd 100644 --- a/src/lua/functions/creatures/player/player_functions.hpp +++ b/src/lua/functions/creatures/player/player_functions.hpp @@ -378,6 +378,7 @@ class PlayerFunctions final : LuaScriptInterface { registerMethod(L, "Player", "takeScreenshot", PlayerFunctions::luaPlayerTakeScreenshot); registerMethod(L, "Player", "sendIconBakragore", PlayerFunctions::luaPlayerSendIconBakragore); + registerMethod(L, "Player", "removeIconBakragore", PlayerFunctions::luaPlayerRemoveIconBakragore); GroupFunctions::init(L); GuildFunctions::init(L); @@ -743,6 +744,7 @@ class PlayerFunctions final : LuaScriptInterface { static int luaPlayerTakeScreenshot(lua_State* L); static int luaPlayerSendIconBakragore(lua_State* L); + static int luaPlayerRemoveIconBakragore(lua_State* L); friend class CreatureFunctions; };