From 79bc3a7fb682dcdad92e47e872ab83496a61d982 Mon Sep 17 00:00:00 2001 From: Kelsi Date: Sun, 22 Mar 2026 23:37:29 -0700 Subject: [PATCH] feat: add BuyMerchantItem and SellContainerItem for vendor interaction BuyMerchantItem(index, count) purchases an item from the current vendor by merchant slot index. Resolves itemId and slot from the vendor's ListInventoryData. SellContainerItem(bag, slot) sells an item from the player's inventory to the vendor. Supports backpack (bag=0) and bags 1-4. Enables auto-sell addons (Scrap, AutoVendor) and vendor UI addons to buy/sell items programmatically. --- src/addons/lua_engine.cpp | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/addons/lua_engine.cpp b/src/addons/lua_engine.cpp index b201067b..caf0dc04 100644 --- a/src/addons/lua_engine.cpp +++ b/src/addons/lua_engine.cpp @@ -5062,6 +5062,27 @@ void LuaEngine::registerCoreAPI() { lua_pushboolean(L, 1); // isCastable return 4; }}, + // --- Vendor Buy/Sell --- + {"BuyMerchantItem", [](lua_State* L) -> int { + auto* gh = getGameHandler(L); + int index = static_cast(luaL_checknumber(L, 1)); + int count = static_cast(luaL_optnumber(L, 2, 1)); + if (!gh || index < 1) return 0; + const auto& items = gh->getVendorItems().items; + if (index > static_cast(items.size())) return 0; + const auto& vi = items[index - 1]; + gh->buyItem(gh->getVendorGuid(), vi.itemId, vi.slot, count); + return 0; + }}, + {"SellContainerItem", [](lua_State* L) -> int { + auto* gh = getGameHandler(L); + int bag = static_cast(luaL_checknumber(L, 1)); + int slot = static_cast(luaL_checknumber(L, 2)); + if (!gh) return 0; + if (bag == 0) gh->sellItemBySlot(slot - 1); + else if (bag >= 1 && bag <= 4) gh->sellItemInBag(bag - 1, slot - 1); + return 0; + }}, // --- Repair --- {"RepairAllItems", [](lua_State* L) -> int { auto* gh = getGameHandler(L);