From c4ad6356ca46320f60167558a3b08feabff1d8cb Mon Sep 17 00:00:00 2001 From: sruon Date: Tue, 27 Jan 2026 05:40:53 -0700 Subject: [PATCH] Standardize NPC shop packets --- src/map/packets/c2s/0x083_shop_buy.cpp | 12 ++++++------ src/map/packets/c2s/0x084_shop_sell_req.cpp | 10 +++++----- src/map/packets/c2s/0x085_shop_sell_set.cpp | 13 ++++++++----- 3 files changed, 19 insertions(+), 16 deletions(-) diff --git a/src/map/packets/c2s/0x083_shop_buy.cpp b/src/map/packets/c2s/0x083_shop_buy.cpp index bf9b9737c1d..74ba54840c8 100644 --- a/src/map/packets/c2s/0x083_shop_buy.cpp +++ b/src/map/packets/c2s/0x083_shop_buy.cpp @@ -31,22 +31,22 @@ auto GP_CLI_COMMAND_SHOP_BUY::validate(MapSession* PSession, const CCharEntity* PChar) const -> PacketValidationResult { return PacketValidator() - .mustEqual(PropertyItemIndex, 0, "PropertyItemIndex not 0"); + .mustEqual(this->PropertyItemIndex, 0, "PropertyItemIndex not 0"); } void GP_CLI_COMMAND_SHOP_BUY::process(MapSession* PSession, CCharEntity* PChar) const { - auto quantity = ItemNum; + auto quantity = this->ItemNum; // Prevent users from buying from invalid container slots - if (ShopItemIndex > PChar->Container->getExSize() - 1) + if (this->ShopItemIndex > PChar->Container->getExSize() - 1) { ShowError("User '%s' attempting to buy vendor item from an invalid slot!", PChar->getName()); return; } - const uint16 itemId = PChar->Container->getItemID(ShopItemIndex); - const uint32 price = PChar->Container->getQuantity(ShopItemIndex); // We used the "quantity" to store the item's sale price + const uint16 itemId = PChar->Container->getItemID(this->ShopItemIndex); + const uint32 price = PChar->Container->getQuantity(this->ShopItemIndex); // We used the "quantity" to store the item's sale price const CItem* PItem = itemutils::GetItemPointer(itemId); if (!PItem) @@ -75,7 +75,7 @@ void GP_CLI_COMMAND_SHOP_BUY::process(MapSession* PSession, CCharEntity* PChar) { charutils::UpdateItem(PChar, LOC_INVENTORY, 0, -static_cast(price * quantity)); ShowInfo("User '%s' purchased %u of item of ID %u [from VENDOR] ", PChar->getName(), quantity, itemId); - PChar->pushPacket(ShopItemIndex, quantity); + PChar->pushPacket(this->ShopItemIndex, quantity); PChar->pushPacket(); } } diff --git a/src/map/packets/c2s/0x084_shop_sell_req.cpp b/src/map/packets/c2s/0x084_shop_sell_req.cpp index c08254cee40..a73b8a8784f 100644 --- a/src/map/packets/c2s/0x084_shop_sell_req.cpp +++ b/src/map/packets/c2s/0x084_shop_sell_req.cpp @@ -33,14 +33,14 @@ auto GP_CLI_COMMAND_SHOP_SELL_REQ::validate(MapSession* PSession, const CCharEnt void GP_CLI_COMMAND_SHOP_SELL_REQ::process(MapSession* PSession, CCharEntity* PChar) const { - uint32 quantity = ItemNum; + uint32 quantity = this->ItemNum; - const CItem* PItem = PChar->getStorage(LOC_INVENTORY)->GetItem(ItemIndex); - if (PItem && (PItem->getID() == ItemNo) && !(PItem->getFlag() & ITEM_FLAG_NOSALE)) + const CItem* PItem = PChar->getStorage(LOC_INVENTORY)->GetItem(this->ItemIndex); + if (PItem && (PItem->getID() == this->ItemNo) && !(PItem->getFlag() & ITEM_FLAG_NOSALE)) { quantity = std::min(quantity, PItem->getQuantity()); // Store item-to-sell in the last slot of the shop container - PChar->Container->setItem(PChar->Container->getExSize(), ItemNo, ItemIndex, quantity); - PChar->pushPacket(ItemIndex, PItem->getBasePrice()); + PChar->Container->setItem(PChar->Container->getExSize(), this->ItemNo, this->ItemIndex, quantity); + PChar->pushPacket(this->ItemIndex, PItem->getBasePrice()); } } diff --git a/src/map/packets/c2s/0x085_shop_sell_set.cpp b/src/map/packets/c2s/0x085_shop_sell_set.cpp index 578662e2d6a..80f86518d13 100644 --- a/src/map/packets/c2s/0x085_shop_sell_set.cpp +++ b/src/map/packets/c2s/0x085_shop_sell_set.cpp @@ -58,7 +58,7 @@ auto GP_CLI_COMMAND_SHOP_SELL_SET::validate(MapSession* PSession, const CCharEnt { return PacketValidator() .isNotCrafting(PChar) - .mustEqual(SellFlag, 1, "SellFlag not 1"); + .mustEqual(this->SellFlag, 1, "SellFlag not 1"); } void GP_CLI_COMMAND_SHOP_SELL_SET::process(MapSession* PSession, CCharEntity* PChar) const @@ -112,13 +112,16 @@ void GP_CLI_COMMAND_SHOP_SELL_SET::process(MapSession* PSession, CCharEntity* PC } const auto cost = quantity * PItem->getBasePrice(); - - auditSale(PChar, itemId, quantity, PItem->getBasePrice()); + if (charutils::UpdateItem(PChar, LOC_INVENTORY, slotId, -static_cast(quantity)) == 0) + { + ShowWarningFmt("GP_CLI_COMMAND_SHOP_SELL_SET: Player {} failed to remove item ID {} from inventory!", PChar->getName(), PItem->getID()); + return; + } charutils::UpdateItem(PChar, LOC_INVENTORY, 0, cost); - charutils::UpdateItem(PChar, LOC_INVENTORY, slotId, -static_cast(quantity)); + auditSale(PChar, itemId, quantity, PItem->getBasePrice()); ShowInfo("GP_CLI_COMMAND_SHOP_SELL_SET: Player '%s' sold %u of itemID %u (Total: %u gil) [to VENDOR] ", PChar->getName(), quantity, itemId, cost); PChar->pushPacket(nullptr, itemId, quantity, MsgStd::Sell); PChar->pushPacket(); - PChar->Container->setItem(PChar->Container->getSize() - 1, 0, -1, 0); + PChar->Container->setItem(PChar->Container->getExSize(), 0, -1, 0); }