From d4b1b61c6c3f982606bf0122508486159eae66fa Mon Sep 17 00:00:00 2001 From: Eduardo Dantas Date: Thu, 5 Sep 2024 21:16:38 -0300 Subject: [PATCH 1/3] 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; }; From dec6ad0f04bf8cdec78917376077d0189d56572e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Morais?= Date: Fri, 6 Sep 2024 10:35:31 -0300 Subject: [PATCH 2/3] fix: container:addItem missing return (#2857) --- data-otservbr-global/monster/reptiles/two-headed_turtle.lua | 2 +- data/libs/functions/container.lua | 6 +++--- src/lua/functions/items/container_functions.cpp | 1 + 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/data-otservbr-global/monster/reptiles/two-headed_turtle.lua b/data-otservbr-global/monster/reptiles/two-headed_turtle.lua index 2d1c2090b37..50b49aa8cc5 100644 --- a/data-otservbr-global/monster/reptiles/two-headed_turtle.lua +++ b/data-otservbr-global/monster/reptiles/two-headed_turtle.lua @@ -70,7 +70,7 @@ monster.loot = { { name = "two-headed turtle heads", chance = 8700 }, { name = "strong mana potion", chance = 13373 }, { name = "hydrophytes", chance = 11000 }, - { id = 1047, chance = 6388 }, -- bone + { id = 3115, chance = 6388 }, -- bone { name = "glacier shoes", chance = 4650 }, { id = 281, chance = 3582 }, -- giant shimmering pearl (green) { name = "small tropical fish", chance = 3582 }, diff --git a/data/libs/functions/container.lua b/data/libs/functions/container.lua index f932b37dfe4..824a12f5e02 100644 --- a/data/libs/functions/container.lua +++ b/data/libs/functions/container.lua @@ -20,7 +20,7 @@ function Container:addLoot(loot) local countToAdd = math.min(remainingCount, stackSize) local tmpItem = self:addItem(itemId, countToAdd, INDEX_WHEREEVER, FLAG_NOLIMIT) if not tmpItem then - logger.warn("Container:addLoot: failed to add stackable item: {}, to corpse {} with id {}", ItemType(itemId):getName(), self:getName(), self:getId()) + logger.warn("Container:addLoot: failed to add stackable item: {} with id {}, to corpse {} with id {}", ItemType(itemId):getName(), itemId, self:getName(), self:getId()) goto continue end remainingCount = remainingCount - countToAdd @@ -28,13 +28,13 @@ function Container:addLoot(loot) elseif iType:getCharges() ~= 0 then local tmpItem = self:addItem(itemId, item.count, INDEX_WHEREEVER, FLAG_NOLIMIT) if not tmpItem then - logger.warn("Container:addLoot: failed to add charge item: {}, to corpse {} with id {}", ItemType(itemId):getName(), self:getName(), self:getId()) + logger.warn("Container:addLoot: failed to add charge item: {} with id {}, to corpse {} with id {}", ItemType(itemId):getName(), itemId, self:getName(), self:getId()) end else for i = 1, item.count do local tmpItem = self:addItem(itemId, 1, INDEX_WHEREEVER, FLAG_NOLIMIT) if not tmpItem then - logger.warn("Container:addLoot: failed to add item: {}, to corpse {} with id {}", ItemType(itemId):getName(), self:getName(), self:getId()) + logger.warn("Container:addLoot: failed to add item: {} with id {}, to corpse {} with id {}", ItemType(itemId):getName(), itemId, self:getName(), self:getId()) goto continue end diff --git a/src/lua/functions/items/container_functions.cpp b/src/lua/functions/items/container_functions.cpp index a2251de641c..30eb26c6801 100644 --- a/src/lua/functions/items/container_functions.cpp +++ b/src/lua/functions/items/container_functions.cpp @@ -166,6 +166,7 @@ int ContainerFunctions::luaContainerAddItem(lua_State* L) { setItemMetatable(L, -1, item); } else { reportErrorFunc(fmt::format("Cannot add item to container, error code: '{}'", getReturnMessage(ret))); + pushBoolean(L, false); } return 1; } From b330a33d90d114eb383ecab1c389aed4e7a2131a Mon Sep 17 00:00:00 2001 From: Karin Date: Mon, 9 Sep 2024 14:22:52 -0300 Subject: [PATCH 3/3] fix: fix load unique items from map (#2881) This fix the load of unique items. Enable purchasing backpacks when the player doesn't have a main backpack --- .../startup/others/functions.lua | 19 ++++++++++++------- src/creatures/npcs/npc.cpp | 4 ++-- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/data-otservbr-global/startup/others/functions.lua b/data-otservbr-global/startup/others/functions.lua index 8624dc8b268..362e2a38b97 100644 --- a/data-otservbr-global/startup/others/functions.lua +++ b/data-otservbr-global/startup/others/functions.lua @@ -28,7 +28,7 @@ function loadLuaMapAction(tablename) if not value.itemId == false and tile:getItemCountById(value.itemId) == 0 then logger.error("[loadLuaMapAction] - Wrong item id {} found", value.itemId) logger.warn("Action id: {}, position {}", index, tile:getPosition():toString()) - break + goto continue end if value.itemId ~= false and tile:getItemCountById(value.itemId) > 0 then @@ -49,6 +49,7 @@ function loadLuaMapAction(tablename) tile:getGround():setAttribute(ITEM_ATTRIBUTE_ACTIONID, index) end end + ::continue:: end end end @@ -64,12 +65,12 @@ function loadLuaMapUnique(tablename) if not value.itemId == false and tile:getItemCountById(value.itemId) == 0 then logger.error("[loadLuaMapUnique] - Wrong item id {} found", value.itemId) logger.warn("Unique id: {}, position {}", index, tile:getPosition():toString()) - break + goto continue end if tile:getItemCountById(value.itemId) < 1 or value.itemId == false then logger.warn("[loadLuaMapUnique] - Wrong item id {} found", value.itemId) logger.warn("Unique id: {}, position {}, item id: wrong", index, tile:getPosition():toString()) - break + goto continue end item = tile:getItemById(value.itemId) -- If he found the item, add the unique id @@ -77,6 +78,8 @@ function loadLuaMapUnique(tablename) item:setAttribute(ITEM_ATTRIBUTE_UNIQUEID, index) end end + + ::continue:: end end @@ -91,7 +94,7 @@ function loadLuaMapSign(tablename) if tile:getItemCountById(value.itemId) == 0 then logger.error("[loadLuaMapSign] - Wrong item id {} found", value.itemId) logger.warn("Sign id: {}, position {}, item id: wrong", index, tile:getPosition():toString()) - break + goto continue end if tile:getItemCountById(value.itemId) == 1 then item = tile:getItemById(value.itemId) @@ -101,6 +104,7 @@ function loadLuaMapSign(tablename) item:setAttribute(ITEM_ATTRIBUTE_TEXT, value.text) end end + ::continue:: end end @@ -137,17 +141,18 @@ function loadLuaMapBookDocument(tablename) totals[2] = totals[2] + 1 else logger.warn("[loadLuaMapBookDocument] - Item not found! Index: {}, itemId: {}", index, value.itemId) - break + goto continue end else logger.warn("[loadLuaMapBookDocument] - Container not found! Index: {}, containerId: {}", index, value.containerId) - break + goto continue end else logger.warn("[loadLuaMapBookDocument] - Tile not found! Index: {}, position: x: {} y: {} z: {}", index, value.position.x, value.position.y, value.position.z) - break + goto continue end end + ::continue:: end if totals[1] == totals[2] then logger.debug("Loaded {} books and documents in the map", totals[2]) diff --git a/src/creatures/npcs/npc.cpp b/src/creatures/npcs/npc.cpp index 18ca0dd0758..6d38524aef3 100644 --- a/src/creatures/npcs/npc.cpp +++ b/src/creatures/npcs/npc.cpp @@ -234,8 +234,8 @@ void Npc::onPlayerBuyItem(std::shared_ptr player, uint16_t itemId, uint8 return; } - // Check if the player not have empty slots - if (!ignore && player->getFreeBackpackSlots() == 0) { + // Check if the player not have empty slots or the item is not a container + if (!ignore && (player->getFreeBackpackSlots() == 0 && (player->getInventoryItem(CONST_SLOT_BACKPACK) || (!Item::items[itemId].isContainer() || !(Item::items[itemId].slotPosition & SLOTP_BACKPACK))))) { player->sendCancelMessage(RETURNVALUE_NOTENOUGHROOM); return; }