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.
This commit is contained in:
Kelsi 2026-03-22 23:37:29 -07:00
parent 0a2667aa05
commit 79bc3a7fb6

View file

@ -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<int>(luaL_checknumber(L, 1));
int count = static_cast<int>(luaL_optnumber(L, 2, 1));
if (!gh || index < 1) return 0;
const auto& items = gh->getVendorItems().items;
if (index > static_cast<int>(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<int>(luaL_checknumber(L, 1));
int slot = static_cast<int>(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);