Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: prevent sell items with duration to the npc #2898

Merged
merged 9 commits into from
Oct 14, 2024
2 changes: 1 addition & 1 deletion data-otservbr-global/npc/perod.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand Down
8 changes: 8 additions & 0 deletions src/creatures/npcs/npc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,10 @@ void Npc::onPlayerSellItem(std::shared_ptr<Player> player, uint16_t itemId, uint
continue;
}

if (!item->hasMarketAttributes()) {
continue;
}

auto removeCount = std::min<uint16_t>(toRemove, item->getItemCount());

if (g_game().internalRemoveItem(item, removeCount) != RETURNVALUE_NOERROR) {
Expand All @@ -410,6 +414,10 @@ void Npc::onPlayerSellItem(std::shared_ptr<Player> player, uint16_t itemId, uint
}

auto totalRemoved = amount - toRemove;
if (totalRemoved == 0) {
return;
}

auto totalCost = static_cast<uint64_t>(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) {
Expand Down
4 changes: 4 additions & 0 deletions src/creatures/players/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4118,6 +4118,10 @@ std::map<uint32_t, uint32_t> &Player::getAllItemTypeCount(std::map<uint32_t, uin

std::map<uint16_t, uint16_t> &Player::getAllSaleItemIdAndCount(std::map<uint16_t, uint16_t> &countMap) const {
for (const auto &item : getAllInventoryItems(false, true)) {
if (!item->hasMarketAttributes()) {
continue;
}

if (const auto &container = item->getContainer()) {
if (container->size() > 0) {
continue;
Expand Down
Loading