Fix vendor: correct CMSG_BUY_ITEM field order (slot before itemId), handle buy failures, show token costs; remove level-up test button (animation triggers on real level-up)

This commit is contained in:
Kelsi 2026-02-17 17:44:48 -08:00
parent b441452dcb
commit 60ebb4dc3f
3 changed files with 35 additions and 19 deletions

View file

@ -1219,7 +1219,24 @@ void GameHandler::handlePacket(network::Packet& packet) {
}
break;
}
case Opcode::SMSG_BUY_FAILED:
case Opcode::SMSG_BUY_FAILED: {
// vendorGuid(8) + itemId(4) + errorCode(1)
if (packet.getSize() - packet.getReadPos() >= 13) {
/*uint64_t vendorGuid =*/ packet.readUInt64();
/*uint32_t itemId =*/ packet.readUInt32();
uint8_t errCode = packet.readUInt8();
const char* msg = "Purchase failed.";
switch (errCode) {
case 2: msg = "You don't have enough money."; break;
case 4: msg = "Seller is too far away."; break;
case 5: msg = "That item is sold out."; break;
case 6: msg = "You can't carry any more items."; break;
default: break;
}
addSystemChatMessage(msg);
}
break;
}
case Opcode::MSG_RAID_TARGET_UPDATE:
break;
case Opcode::SMSG_GAMEOBJECT_QUERY_RESPONSE:

View file

@ -3056,8 +3056,8 @@ network::Packet ListInventoryPacket::build(uint64_t npcGuid) {
network::Packet BuyItemPacket::build(uint64_t vendorGuid, uint32_t itemId, uint32_t slot, uint32_t count) {
network::Packet packet(wireOpcode(Opcode::CMSG_BUY_ITEM));
packet.writeUInt64(vendorGuid);
packet.writeUInt32(itemId);
packet.writeUInt32(slot);
packet.writeUInt32(slot); // vendor slot (1-based position in vendor list)
packet.writeUInt32(itemId); // item entry
packet.writeUInt32(count);
packet.writeUInt8(0); // bag slot (0 = find any available bag slot)
return packet;

View file

@ -4813,13 +4813,21 @@ void GameScreen::renderVendorWindow(game::GameHandler& gameHandler) {
}
ImGui::TableSetColumnIndex(1);
uint32_t g = item.buyPrice / 10000;
uint32_t s = (item.buyPrice / 100) % 100;
uint32_t c = item.buyPrice % 100;
bool canAfford = money >= item.buyPrice;
if (!canAfford) ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(1.0f, 0.3f, 0.3f, 1.0f));
ImGui::Text("%ug %us %uc", g, s, c);
if (!canAfford) ImGui::PopStyleColor();
if (item.extendedCost != 0 && item.buyPrice == 0) {
ImGui::TextColored(ImVec4(0.4f, 0.8f, 1.0f, 1.0f), "[Tokens]");
} else {
uint32_t g = item.buyPrice / 10000;
uint32_t s = (item.buyPrice / 100) % 100;
uint32_t c = item.buyPrice % 100;
bool canAfford = money >= item.buyPrice;
if (!canAfford) ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(1.0f, 0.3f, 0.3f, 1.0f));
ImGui::Text("%ug %us %uc", g, s, c);
if (!canAfford) ImGui::PopStyleColor();
if (item.extendedCost != 0) {
ImGui::SameLine();
ImGui::TextColored(ImVec4(0.4f, 0.8f, 1.0f, 1.0f), "[+Tokens]");
}
}
ImGui::TableSetColumnIndex(2);
if (item.maxCount < 0) {
@ -5144,15 +5152,6 @@ void GameScreen::renderEscapeMenu() {
showEscapeMenu = false;
}
ImGui::Spacing();
if (ImGui::Button("Test: Level Up", ImVec2(-1, 0))) {
uint32_t lvl = 1;
if (auto* gh = core::Application::getInstance().getGameHandler()) {
lvl = gh->getPlayerLevel();
}
triggerDing(lvl > 0 ? lvl : 1);
showEscapeMenu = false;
}
ImGui::Spacing();
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(10.0f, 10.0f));
if (ImGui::Button("Back to Game", ImVec2(-1, 0))) {