From 432524045fa5c424c2d55c68bdc692f9e3f3100e Mon Sep 17 00:00:00 2001 From: Carlos Pessoa Date: Mon, 16 Sep 2024 21:53:37 -0300 Subject: [PATCH 1/6] fix: prevent sell items with duration --- src/creatures/npcs/npc.cpp | 8 ++++++++ src/creatures/players/player.cpp | 3 +++ 2 files changed, 11 insertions(+) diff --git a/src/creatures/npcs/npc.cpp b/src/creatures/npcs/npc.cpp index 6d38524aef3..0e083a26793 100644 --- a/src/creatures/npcs/npc.cpp +++ b/src/creatures/npcs/npc.cpp @@ -391,6 +391,10 @@ void Npc::onPlayerSellItem(std::shared_ptr player, uint16_t itemId, uint continue; } + if(item->hasAttribute(ItemAttribute_t::DURATION)){ + continue; + } + auto removeCount = std::min(toRemove, item->getItemCount()); if (g_game().internalRemoveItem(item, removeCount) != RETURNVALUE_NOERROR) { @@ -405,6 +409,10 @@ void Npc::onPlayerSellItem(std::shared_ptr player, uint16_t itemId, uint } auto totalRemoved = amount - toRemove; + if(totalRemoved == 0){ + return; + } + auto totalCost = static_cast(sellPrice * totalRemoved); g_logger().debug("[Npc::onPlayerSellItem] - Removing items from player {} amount {} of items with id {} on shop for npc {}", player->getName(), toRemove, itemId, getName()); if (totalRemoved > 0 && totalCost > 0) { diff --git a/src/creatures/players/player.cpp b/src/creatures/players/player.cpp index 6f7e33eb7f9..83a9a1c9127 100644 --- a/src/creatures/players/player.cpp +++ b/src/creatures/players/player.cpp @@ -4120,6 +4120,9 @@ std::map &Player::getAllItemTypeCount(std::map &Player::getAllSaleItemIdAndCount(std::map &countMap) const { for (const auto &item : getAllInventoryItems(false, true)) { + if(item->hasAttribute(ItemAttribute_t::DURATION)){ + continue; + } countMap[item->getID()] += item->getItemCount(); } From 1f0043c0a77c3f009f7a771079d10562cdc9bece Mon Sep 17 00:00:00 2001 From: GitHub Actions Date: Tue, 17 Sep 2024 00:54:57 +0000 Subject: [PATCH 2/6] Code format - (Clang-format) --- src/creatures/npcs/npc.cpp | 6 +++--- src/creatures/players/player.cpp | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/creatures/npcs/npc.cpp b/src/creatures/npcs/npc.cpp index 0e083a26793..48b264cf811 100644 --- a/src/creatures/npcs/npc.cpp +++ b/src/creatures/npcs/npc.cpp @@ -391,7 +391,7 @@ void Npc::onPlayerSellItem(std::shared_ptr player, uint16_t itemId, uint continue; } - if(item->hasAttribute(ItemAttribute_t::DURATION)){ + if (item->hasAttribute(ItemAttribute_t::DURATION)) { continue; } @@ -409,10 +409,10 @@ void Npc::onPlayerSellItem(std::shared_ptr player, uint16_t itemId, uint } auto totalRemoved = amount - toRemove; - if(totalRemoved == 0){ + if (totalRemoved == 0) { return; } - + auto totalCost = static_cast(sellPrice * totalRemoved); g_logger().debug("[Npc::onPlayerSellItem] - Removing items from player {} amount {} of items with id {} on shop for npc {}", player->getName(), toRemove, itemId, getName()); if (totalRemoved > 0 && totalCost > 0) { diff --git a/src/creatures/players/player.cpp b/src/creatures/players/player.cpp index 83a9a1c9127..fbe02f1303b 100644 --- a/src/creatures/players/player.cpp +++ b/src/creatures/players/player.cpp @@ -4120,7 +4120,7 @@ std::map &Player::getAllItemTypeCount(std::map &Player::getAllSaleItemIdAndCount(std::map &countMap) const { for (const auto &item : getAllInventoryItems(false, true)) { - if(item->hasAttribute(ItemAttribute_t::DURATION)){ + if (item->hasAttribute(ItemAttribute_t::DURATION)) { continue; } countMap[item->getID()] += item->getItemCount(); From 97f5aecbdad14bbe2afa3c843daa3eb0cde3f011 Mon Sep 17 00:00:00 2001 From: Carlos Pessoa Date: Tue, 17 Sep 2024 15:07:48 -0300 Subject: [PATCH 3/6] change to method --- src/creatures/npcs/npc.cpp | 2 +- src/creatures/players/player.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/creatures/npcs/npc.cpp b/src/creatures/npcs/npc.cpp index 0e083a26793..9a3317990c7 100644 --- a/src/creatures/npcs/npc.cpp +++ b/src/creatures/npcs/npc.cpp @@ -391,7 +391,7 @@ void Npc::onPlayerSellItem(std::shared_ptr player, uint16_t itemId, uint continue; } - if(item->hasAttribute(ItemAttribute_t::DURATION)){ + if(!item->hasMarketAttributes()){ continue; } diff --git a/src/creatures/players/player.cpp b/src/creatures/players/player.cpp index 83a9a1c9127..4eea358bf59 100644 --- a/src/creatures/players/player.cpp +++ b/src/creatures/players/player.cpp @@ -4120,7 +4120,7 @@ std::map &Player::getAllItemTypeCount(std::map &Player::getAllSaleItemIdAndCount(std::map &countMap) const { for (const auto &item : getAllInventoryItems(false, true)) { - if(item->hasAttribute(ItemAttribute_t::DURATION)){ + if(item->hasMarketAttributes()){ continue; } countMap[item->getID()] += item->getItemCount(); From 0aad641a5fe3700eadde13616882b99cf59b5d4d Mon Sep 17 00:00:00 2001 From: GitHub Actions Date: Tue, 17 Sep 2024 18:13:28 +0000 Subject: [PATCH 4/6] Code format - (Clang-format) --- src/creatures/npcs/npc.cpp | 2 +- src/creatures/players/player.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/creatures/npcs/npc.cpp b/src/creatures/npcs/npc.cpp index 7b4a4f2a5fb..b7bff9098dd 100644 --- a/src/creatures/npcs/npc.cpp +++ b/src/creatures/npcs/npc.cpp @@ -391,7 +391,7 @@ void Npc::onPlayerSellItem(std::shared_ptr player, uint16_t itemId, uint continue; } - if(!item->hasMarketAttributes()){ + if (!item->hasMarketAttributes()) { continue; } diff --git a/src/creatures/players/player.cpp b/src/creatures/players/player.cpp index 4eea358bf59..2a67e306db9 100644 --- a/src/creatures/players/player.cpp +++ b/src/creatures/players/player.cpp @@ -4120,7 +4120,7 @@ std::map &Player::getAllItemTypeCount(std::map &Player::getAllSaleItemIdAndCount(std::map &countMap) const { for (const auto &item : getAllInventoryItems(false, true)) { - if(item->hasMarketAttributes()){ + if (item->hasMarketAttributes()) { continue; } countMap[item->getID()] += item->getItemCount(); From 84c15598e2a72b9844a4d571e0573334f92c4b38 Mon Sep 17 00:00:00 2001 From: Karin Date: Tue, 17 Sep 2024 21:57:01 -0300 Subject: [PATCH 5/6] fix condition --- src/creatures/players/player.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/creatures/players/player.cpp b/src/creatures/players/player.cpp index 2a67e306db9..b17470231b8 100644 --- a/src/creatures/players/player.cpp +++ b/src/creatures/players/player.cpp @@ -4120,7 +4120,7 @@ std::map &Player::getAllItemTypeCount(std::map &Player::getAllSaleItemIdAndCount(std::map &countMap) const { for (const auto &item : getAllInventoryItems(false, true)) { - if (item->hasMarketAttributes()) { + if (!item->hasMarketAttributes()) { continue; } countMap[item->getID()] += item->getItemCount(); From 9371ee086b38d408a302698ac8d32dd61f7e4937 Mon Sep 17 00:00:00 2001 From: Carlos Pessoa Date: Wed, 25 Sep 2024 13:58:37 -0300 Subject: [PATCH 6/6] fix npc item spear --- data-otservbr-global/npc/perod.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/data-otservbr-global/npc/perod.lua b/data-otservbr-global/npc/perod.lua index b0bc5e7a57d..7d3f32d6ad3 100644 --- a/data-otservbr-global/npc/perod.lua +++ b/data-otservbr-global/npc/perod.lua @@ -143,7 +143,7 @@ npcConfig.shop = { { itemName = "shiver arrow", clientId = 762, buy = 5 }, { itemName = "shovel", clientId = 3457, buy = 50, sell = 8 }, { itemName = "sniper arrow", clientId = 7364, buy = 5 }, - { itemName = "spear", clientId = 3277, buy = 10, sell = 10 }, + { itemName = "spear", clientId = 3277, buy = 9, sell = 3 }, { itemName = "spectral bolt", clientId = 35902, buy = 70 }, { itemName = "tarsal arrow", clientId = 14251, buy = 6 }, { itemName = "throwing star", clientId = 3287, buy = 42 },