diff --git a/LegionWA/AutoVendor/Event.lua b/LegionWA/AutoVendor/Event.lua new file mode 100644 index 0000000..b253c33 --- /dev/null +++ b/LegionWA/AutoVendor/Event.lua @@ -0,0 +1,42 @@ +-- MERCHANT_SHOW +function(allstates, e) + aura_env.allstates = allstates + + if CanMerchantRepair() == true then RepairAllItems() end + + for container = 0, 4 do + for slot = 1, GetContainerNumSlots(container) do + aura_env.filterService:run(container, slot) + local link = select(7, GetContainerItemInfo(container, slot)) + if link then + local name = GetItemInfo(link) + local rarity = select(3, GetItemInfo(link)) + local ilvl = select(4, GetItemInfo(link)) or 0 + local type = select(6, GetItemInfo(link)) + local price = select(11, GetItemInfo(link)) + if price and price > 0 then + if aura_env.sellWhitelist[name] ~= 1 then + if rarity == 0 then + aura_env.toSell[#aura_env.toSell + 1] = {["container"] = container, ["slot"] = slot} + elseif (type == "Armor" or type == "Weapon") and ilvl < 350 then + aura_env.toSell[#aura_env.toSell + 1] = {["container"] = container, ["slot"] = slot} + end + end + end + end + end + end + + aura_env.ticker = C_Timer.NewTicker(0.15, function() + if aura_env.toSell[1] then + UseContainerItem(aura_env.toSell[1].c, aura_env.toSell[1].s) + table.remove(aura_env.toSell, 1) + else + aura_env.ticker:Cancel() + end + if j >= GetContainerNumSlots(i) then i = i + 1 + j = 1 end + if i >= 4 then aura_env.ticker:Cancel() end + end) + return true +end diff --git a/LegionWA/AutoVendor/Export b/LegionWA/AutoVendor/Export new file mode 100644 index 0000000..e69de29 diff --git a/LegionWA/AutoVendor/Init.lua b/LegionWA/AutoVendor/Init.lua new file mode 100644 index 0000000..42ebc7f --- /dev/null +++ b/LegionWA/AutoVendor/Init.lua @@ -0,0 +1,136 @@ +local debug = true +local iconDisplayDuration = 3 + +local function getItemLink(container, slot) + aura_env.debugLog("getItemLink", container, slot) + return select(7, GetContainerItemInfo(container, slot)) +end +local function getItemQuantity(container, slot) + +end +local function getItemName(container, slot) + return select(1, GetItemInfo(getItemLink(container, slot))) +end +local function getItemType(container, slot) + return select(6, GetItemInfo(getItemLink(container, slot))) +end +local function getItemSubtype(container, slot) + return select(7, GetItemInfo(getItemLink(container, slot))) +end +local function getItemLevel(container, slot) + return select(4, GetItemInfo(getItemLink(container, slot))) +end +local function getItemValue(container, slot) + return select(11, GetItemInfo(getItemLink(container, slot))) +end +local function getItemQuality(container, slot) + return select(3, GetItemInfo(getItemLink(container, slot))) +end +local function getItemEquipLocation(container, slot) + return select(9, GetItemInfo(getItemLink(container, slot))) +end +local function getItemIcon(container, slot) + return select(10, GetItemInfo(getItemLink(container, slot))) +end +local function getBindType(container, slot) + return select(14, GetItemInfo(getItemLink(container, slot))) +end + + + +local grayFilter = { + enabled = true, + filter = function(self, container, slot) + if (self.enabled) then + aura_env.debugLog("Gray filter; container = " .. container .. ", slot = " .. slot) + local itemQuality = getItemQuality(container, slot) + if (itemQuality and itemQuality == 0) then + aura_env.debugLog("Gray filter pass") + return true + end + end + end +} +local gearFilter = { + enabled = true, + ilvlThreshold = 850, + sellBoe = false, + filter = function(self, container, slot) + if (self.enabled) then + aura_env.debugLog("Gear filter; container = " .. container .. ", slot = " .. slot) + local itemLevel = getItemLevel(container, slot) + local itemBindType = getBindType(container, slot) + if (itemLevel and itemBindType and itemLevel < ilvlThreshold and (itemBindType == 1 or self.sellBoe)) then + aura_env.debugLog("Gear filter pass") + return true + end + end + end +} + +local function doSell(container, slot) + local itemIcon = getItemIcon(slot) + local itemName = getItemName(slot) + local itemQuantity = getItemQuantity(slot) + local itemQuality = getItemQuality(slot) + + aura_env.debugLog("Drawing icon for " .. itemName .. " with quality " .. itemQuality) + local nameWithColor = "[" .. aura_env.qualityColors[itemQuality + 1] .. itemName .. "]\124r" + local nameWithQuantity = nameWithColor .. " x" .. itemQuantity + + aura_env.debugLog("Assigning name" .. nameWithQuantity) + aura_env.allstates[#aura_env.allstates + 1] = { + show = true, + changed = true, + index = GetTime(), + resort = true, + + icon = itemIcon, + name = nameWithQuantity, + amount = itemQuantity, + + progressType = "timed", + expirationTime = GetTime() + iconDisplayDuration, + duration = iconDisplayDuration, + autoHide = true, + } + + UseContainerItem(container, slot) +end + + +aura_env.filterService = { + filters = { + grayFilter, + gearFilter, + }, + slotsToLoot = {}, + run = function(self, container, slot) + aura_env.debugLog("Filtering item in container = " .. container .. ", slot = " .. slot .. "...") + for k, filter in pairs(self.filters) do + if (filter:filter(container, slot)) then + doSell(container, slot) + return + end + end + end +} + +aura_env.debugLog = function(obj) + if (debug) then + print(GetTime()) + DevTools_Dump(obj) + print() + end +end + +aura_env.qualityColors = { + "\124cff9d9d9d", -- Poor + "\124cffffffff", -- Common + "\124cff1eff00", -- Uncommon + "\124cff0070dd", -- Rare + "\124cffa335ee", -- Epic + "\124cffff8000", -- Legendary + "\124cffe6cc80", -- Artifact + "\124cff00ccff", -- Heirloom +} \ No newline at end of file