Send CMSG_LOOT_MONEY for online gold looting and replace action bar right-click removal with drag-to-ground

This commit is contained in:
Kelsi 2026-02-06 19:24:44 -08:00
parent affb5f4f04
commit 0a26eef154
5 changed files with 67 additions and 12 deletions

View file

@ -1137,6 +1137,12 @@ public:
static network::Packet build(uint8_t srcBag, uint8_t srcSlot);
};
/** CMSG_LOOT_MONEY packet builder (empty body) */
class LootMoneyPacket {
public:
static network::Packet build();
};
/** CMSG_LOOT_RELEASE packet builder */
class LootReleasePacket {
public:

View file

@ -171,6 +171,10 @@ private:
std::unordered_map<uint32_t, uint32_t> spellIconIds_;
bool spellIconDbLoaded_ = false;
GLuint getSpellIcon(uint32_t spellId, pipeline::AssetManager* am);
// Action bar drag state (-1 = not dragging)
int actionBarDragSlot_ = -1;
GLuint actionBarDragIcon_ = 0;
};
} // namespace ui

View file

@ -4164,13 +4164,13 @@ void GameHandler::handleLootResponse(network::Packet& packet) {
if (currentLoot.gold > 0) {
if (singlePlayerMode_) {
addMoneyCopper(currentLoot.gold);
currentLoot.gold = 0;
} else if (state == WorldState::IN_WORLD && socket) {
// Auto-loot gold by sending CMSG_LOOT_MONEY (server handles the rest)
auto pkt = LootMoneyPacket::build();
socket->send(pkt);
currentLoot.gold = 0;
}
std::string msg = "You loot ";
msg += std::to_string(currentLoot.getGold()) + "g ";
msg += std::to_string(currentLoot.getSilver()) + "s ";
msg += std::to_string(currentLoot.getCopper()) + "c.";
addSystemChatMessage(msg);
currentLoot.gold = 0; // Clear gold from loot window after collecting
}
}

View file

@ -1928,6 +1928,11 @@ network::Packet AutoEquipItemPacket::build(uint8_t srcBag, uint8_t srcSlot) {
return packet;
}
network::Packet LootMoneyPacket::build() {
network::Packet packet(static_cast<uint16_t>(Opcode::CMSG_LOOT_MONEY));
return packet;
}
network::Packet LootReleasePacket::build(uint64_t lootGuid) {
network::Packet packet(static_cast<uint16_t>(Opcode::CMSG_LOOT_RELEASE));
packet.writeUInt64(lootGuid);

View file

@ -1505,6 +1505,22 @@ void GameScreen::renderActionBar(game::GameHandler& gameHandler) {
const auto& held = inventoryScreen.getHeldItem();
gameHandler.setActionBarSlot(i, game::ActionBarSlot::ITEM, held.itemId);
inventoryScreen.returnHeldItem(gameHandler.getInventory());
} else if (clicked && actionBarDragSlot_ >= 0) {
// Dropping a dragged action bar slot onto another slot - swap or place
if (i != actionBarDragSlot_) {
// Swap the two slots
const auto& dragSrc = bar[actionBarDragSlot_];
auto srcType = dragSrc.type;
auto srcId = dragSrc.id;
gameHandler.setActionBarSlot(actionBarDragSlot_, slot.type, slot.id);
gameHandler.setActionBarSlot(i, srcType, srcId);
}
actionBarDragSlot_ = -1;
actionBarDragIcon_ = 0;
} else if (clicked && !slot.isEmpty()) {
// Pick up this action bar slot for dragging
actionBarDragSlot_ = i;
actionBarDragIcon_ = iconTex;
} else if (clicked) {
if (slot.type == game::ActionBarSlot::SPELL && slot.isReady()) {
uint64_t target = gameHandler.hasTarget() ? gameHandler.getTargetGuid() : 0;
@ -1514,11 +1530,6 @@ void GameScreen::renderActionBar(game::GameHandler& gameHandler) {
}
}
// Right-click to clear slot
if (ImGui::IsItemClicked(ImGuiMouseButton_Right) && !slot.isEmpty()) {
gameHandler.setActionBarSlot(i, game::ActionBarSlot::EMPTY, 0);
}
// Tooltip
if (ImGui::IsItemHovered() && slot.type == game::ActionBarSlot::SPELL && slot.id != 0) {
std::string fullName = getSpellName(slot.id);
@ -1533,7 +1544,6 @@ void GameScreen::renderActionBar(game::GameHandler& gameHandler) {
} else {
ImGui::Text("Item #%u", slot.id);
}
ImGui::TextDisabled("(Right-click to remove)");
ImGui::EndTooltip();
}
@ -1567,6 +1577,36 @@ void GameScreen::renderActionBar(game::GameHandler& gameHandler) {
ImGui::PopStyleColor();
ImGui::PopStyleVar();
// Handle action bar drag: render icon at cursor and detect drop outside
if (actionBarDragSlot_ >= 0) {
ImVec2 mousePos = ImGui::GetMousePos();
// Draw dragged icon at cursor
if (actionBarDragIcon_) {
ImGui::GetForegroundDrawList()->AddImage(
(ImTextureID)(uintptr_t)actionBarDragIcon_,
ImVec2(mousePos.x - 20, mousePos.y - 20),
ImVec2(mousePos.x + 20, mousePos.y + 20));
} else {
ImGui::GetForegroundDrawList()->AddRectFilled(
ImVec2(mousePos.x - 20, mousePos.y - 20),
ImVec2(mousePos.x + 20, mousePos.y + 20),
IM_COL32(80, 80, 120, 180));
}
// On mouse release, check if outside the action bar area
if (ImGui::IsMouseReleased(ImGuiMouseButton_Left)) {
bool insideBar = (mousePos.x >= barX && mousePos.x <= barX + barW &&
mousePos.y >= barY && mousePos.y <= barY + barH);
if (!insideBar) {
// Dropped outside - clear the slot
gameHandler.setActionBarSlot(actionBarDragSlot_, game::ActionBarSlot::EMPTY, 0);
}
actionBarDragSlot_ = -1;
actionBarDragIcon_ = 0;
}
}
}
// ============================================================