local debug = false if not WeakAurasSaved then WeakAurasSaved = {} end if not WeakAurasSaved.Cyka then WeakAurasSaved.Cyka = {} end if not WeakAurasSaved.Cyka.ItemCache then WeakAurasSaved.Cyka.ItemCache = {} end ---@param slot number ---@return string, string|nil local function getItemLink(slot) if slot == nil then return "", string.format("Slot can not be nil") end local link = GetLootSlotLink(slot) if link == nil then return "", string.format("GetLootSlotLink returned nil for slot %d", slot) end return link, nil end ---@param slot number ---@return string, string|nil local function getItemName(slot) if slot == nil then return "", string.format("Slot can not be null") end local name = select(2, GetLootSlotInfo(slot)) if name == nil then return "", string.format("GetLootSlotInfo returned nil for slot %d", slot) end return name, nil end ---@param slot number ---@return string, string|nil local function getItemType(slot) if slot == nil then return "", string.format("Slot can not be nil") end local itemLink, err = getItemLink(slot) if err then return "", err end local itemType = select(6, GetItemInfo(itemLink)) if itemType == nil then return "", string.format("GetItemInfo returned nil for slot %d", slot) end return itemType, nil end ---@param slot number ---@return string, string|nil local function getItemSubtype(slot) if slot == nil then return "", string.format("Slot can not be nil") end local itemLink, err = getItemLink(slot) if err then return "", err end local itemSubtype = select(7, GetItemInfo(itemLink)) if itemSubtype == nil then return "", string.format("GetItemInfo returned nil for slot %d", slot) end return itemSubtype, nil end ---@param slot number ---@return number, string|nil local function getItemLevel(slot) if slot == nil then return 0, string.format("Slot can not be nil") end local itemLink, err = getItemLink(slot) if err then return 0, err end local itemLevel = select(4, GetItemInfo(itemLink)) if itemLevel == nil then return 0, string.format("GetItemInfo returned nil for slot %d", slot) end return itemLevel, nil end ---The vendor price in copper, or 0 for items that cannot be sold ---@param slot number ---@return number, string|nil local function getItemValue(slot) if slot == nil then return 0, string.format("Slot can not be nil") end local itemLink, err = getItemLink(slot) if err then return 0, err end local value = select(11, GetItemInfo(itemLink)) if value == nil then return 0, string.format("GetItemInfo returned nil for slot %d", slot) end return value, nil end ---@param slot number ---@return number, string|nil local function getItemSubclassId(slot) if slot == nil then return 0, string.format("Slot can not be nil") end local itemLink, err = getItemLink(slot) if err then return 0, err end local subclassId = select(13, GetItemInfo(itemLink)) if subclassId == nil then return 0, string.format("GetItemInfo returned nil for slot %d", slot) end return subclassId, nil end ---@param slot number ---@return number, string|nil local function getItemQuantity(slot) if slot == nil then return 0, string.format("Slot can not be nil") end local quantity = select(3, GetLootSlotInfo(slot)) if quantity == nil then return 0, string.format("GetLootSlotInfo returned nil for slot %d", slot) end return quantity, nil end ---@param slot number ---@return Enum.ItemQuality, string|nil local function getItemQuality(slot) if slot == nil then return 0, string.format("Slot can not be nil") end local itemLink, err = getItemLink(slot) if err then return 0, err end local quality = select(3, GetItemInfo(itemLink)) if quality == nil then return 0, string.format("GetItemInfo returned nil for slot %d", slot) end return quality, nil end ---@param slot number ---@return string, string|nil local function getItemEquipLocation(slot) if slot == nil then return "", string.format("Slot can not be nil") end local itemLink, err = getItemLink(slot) if err then return "", err end local equipLoc = select(9, GetItemInfo(itemLink)) if equipLoc == nil then return "", string.format("GetItemInfo returned nil for slot %d", slot) end return equipLoc, nil end ---@param slot number ---@return number, string|nil local function getItemIcon(slot) if slot == nil then return 134400, string.format("Slot can not be nil") end local itemLink, err = getItemLink(slot) if err then return 134400, err end local icon = select(10, GetItemInfo(itemLink)) if icon == nil then return 134400, string.format("GetItemInfo returned nil for slot %d", slot) end return icon, nil end ---@param slot number ---@return number, string|nil local function getBindType(slot) if slot == nil then return 0, string.format("Slot can not be nil") end local itemLink, err = getItemLink(slot) if err then return 0, err end local bindType = select(14, GetItemInfo(itemLink)) if bindType == nil then return 0, string.format("GetItemInfo returned nil for slot %d", slot) end return bindType, nil end ---@class Filter ---@field requires table | nil ---@field filter fun(slot: number, provided: table): boolean Filter = { ---@param requires table | nil ---@param filter fun(slot: number, provided: table): boolean ---@return Filter new = function(requires, filter) local self = setmetatable({}, { __index = Filter, }) self.requires = requires self.filter = filter return self end, ---@param self Filter ---@param slot number ---@return boolean, string|nil Run = function(self, slot) ---@type table local provided = {} if self.requires then for k, v in pairs(self.requires) do local res, err = v(slot) if err ~= nil then if debug then print(err) end return false, err end provided[k] = res end end local res, err = self.filter(slot, provided) if err ~= nil then if debug then print(err) end end return res, nil end, } local goldFilter = Filter.new({ ["name"] = getItemName }, function(slot, provided) ---@cast provided { name: string } if not aura_env.config.goldFilter then return false end if string.find(provided.name, "Gold") or string.find(provided.name, "Silver") or string.find(provided.name, "Copper") then if debug then print(string.format("Gold filter pass for %s", provided.name)) end return true end if debug then print(string.format("Gold filter fail for %s", provided.name)) end return false end) local orderResourcesFilter = Filter.new({ ["name"] = getItemName }, function(slot, provided) ---@cast provided { name: string } if not aura_env.config.orderResourcesFilter then return false end if string.find(provided.name, "Order Resources") then if debug then print(string.format("Order resource filter pass for %s", provided.name)) end return true end if debug then print(string.format("Order resource filter fail for %s", provided.name)) end return false end) local mountFilter = Filter.new({ ["type"] = getItemType }, function(slot, provided) ---@cast provided { type: string } if not aura_env.config.mountFilter then return false end if provided.type == "Mount" then if debug then print(string.format("Mount filter pass for type %s", provided.type)) end return true end if debug then print(string.format("Mount filter fail for type %s", provided.type)) end return false end) local ilvlFilter = Filter.new({ ["ilvl"] = getItemLevel }, function(slot, provided) ---@cast provided { ilvl: number } if not aura_env.config.ilvlFilter then return false end if provided.ilvl and provided.ilvl > aura_env.config.ilvlFilterThreshold then if debug then print(string.format("ilvl filter pass for ilvl %d", provided.ilvl)) end return true end if debug then print(string.format("ilvl filter fail for ilvl %d", provided.ilvl)) end return false end) local professionFilter = Filter.new({ ["type"] = getItemType, ["subtype"] = getItemSubtype, }, function(slot, provided) ---@cast provided { type: string, subtype: string } if not aura_env.config.professionFilter then return false end local enabled = { ["Cloth"] = aura_env.config.professionFilterProfessions[1], ["Cooking"] = aura_env.config.professionFilterProfessions[2], ["Enchanting"] = aura_env.config.professionFilterProfessions[3], ["Herb"] = aura_env.config.professionFilterProfessions[4], ["Inscription"] = aura_env.config.professionFilterProfessions[5], ["Jewelcrafting"] = aura_env.config.professionFilterProfessions[6], ["Leather"] = aura_env.config.professionFilterProfessions[7], ["Metal & Stone"] = aura_env.config.professionFilterProfessions[8], ["Ore"] = aura_env.config.professionFilterProfessions[9], } -- Maybe implement an expansion based filter if provided.type == "Tradeskill" then if enabled[provided.subtype] then if debug then print(string.format("Profession filter pass for type %s", provided.type)) end return true end end if debug then print(string.format("Profession filter fail for type %s", provided.type)) end return false end) local valueFilter = Filter.new({ ["value"] = getItemValue, ["quantity"] = getItemQuality, }, function(slot, provided) ---@cast provided { value: number, quantity: number } if not aura_env.config.valueFilter then return false end local valueThreshold = aura_env.config.valueFilterThreshold local value = provided.value if aura_env.config.valueFilterApplyValueToStack then value = value * provided.quantity end if value > valueThreshold then if debug then print(string.format("Value filter pass for value %d", value)) end return true end if debug then print(string.format("Value filter fail for value %d", value)) end return false end) local greyValueFilter = Filter.new({ ["quality"] = getItemQuality, ["value"] = getItemValue, ["quantity"] = getItemQuantity, }, function(slot, provided) ---@cast provided { quality: number, value: number, quantity: number } if not aura_env.config.greyValueFilter then return false end local valueThreshold = aura_env.config.greyValueFilterThreshold if provided.quality == 0 then local value = provided.value if aura_env.config.greyValueFilterApplyValueToStack then value = value * provided.quantity end if value > valueThreshold then if debug then print(string.format("Grey value filter pass for value %d of %s quality items", value, provided.quality)) end return true end end if debug then print( string.format("Grey value filter fail for value %d of %s quality items", provided.value, provided.quality) ) end return false end) local questItemFilter = Filter.new({ ["type"] = getItemType, ["subtype"] = getItemSubtype, }, function(slot, provided) ---@cast provided { type: string, subtype: string } if not aura_env.config.questItemsFilter then return false end if provided.type == "Quest" and provided.subtype == "Quest" then if debug then print(string.format("Quest item filter pass for type %s and subtype", provided.type, provided.subtype)) end return true end if debug then print(string.format("Quest item filter fail for type %s and subtype", provided.type, provided.subtype)) end return false end) local classGearFilter = Filter.new({ ["ilvl"] = getItemLevel, ["quality"] = getItemQuality, ["type"] = getItemType, ["subtype"] = getItemSubtype, ["equiploc"] = getItemEquipLocation, }, function(slot, provided) ---@cast provided { ilvl: number, quality: number, type: string, subtype: string, equiploc: string } if not aura_env.config.classGearFilter then return false end local ilvlThreshold = aura_env.config.classGearFilterIlvlThreshold local qualityThreshold = aura_env.config.classGearFilterQualityThreshold local isEquippable = aura_env.skills[select(3, UnitClass("player"))][provided.subtype] == 1 if isEquippable and provided.ilvl > ilvlThreshold and provided.quality > qualityThreshold then if debug then print(string.format("Class gear filter pass for ilvl %d and quality %d", provided.ilvl, provided.quality)) end return true end if debug then print(string.format("Class gear filter fail for ilvl %d and quality %d", provided.ilvl, provided.quality)) end return false end) local nameFilter = Filter.new({ ["name"] = getItemName }, function(slot, provided) ---@cast provided { name: string } if not aura_env.config.nameFilter then return false end local names = string.split(",", aura_env.config.nameFilterNames or "") if #names == 0 then return false end for _, name in ipairs(names) do name = string.trim(name) if aura_env.config.nameFilterIgnoreCase then name = string.lower(name) provided.name = string.lower(provided.name) end if provided.name == name then if debug then print(string.format("Name filter pass for %s", provided.name)) end return true end end if debug then print(string.format("Name filter fail for %s", provided.name)) end return false end) local reicpeFilter = Filter.new({ ["name"] = getItemName }, function(slot, provided) ---@cast provided { name: string } if string.find(provided.name, "Recipe") or string.find(provided.name, "Technique") then if debug then print(string.format("Recipe filter pass for %s", provided.name)) end return true end if debug then print(string.format("Recipe filter fail for %s", provided.name)) end return false end) local boeFilter = Filter.new({ ["ilvl"] = getItemLevel, ["type"] = getItemType, ["quality"] = getItemQuality, ["equiploc"] = getItemEquipLocation, ["bindtype"] = getBindType, }, function(slot, provided) ---@cast provided { ilvl: number, type: string, quality: number, equiploc: string, bindtype: number } aura_env.config.boeFilter = true local ilvlThreshold = aura_env.config.boeFilterIlvlThreshold local qualityThreshold = aura_env.config.boeFilterQualityThreshold local itemType = provided.type local itemEquipLoc = provided.equiploc if itemType == "Armor" or itemType == "Weapon" or itemEquipLoc == "INVTYPE_FINGER" or itemEquipLoc == "INVTYPE_TRINKET" or itemEquipLoc == "INVTYPE_CLOAK" or itemEquipLoc == "INVTYPE_NECK" then local itemLevel = provided.ilvl local itemQuality = provided.quality local bindType = provided.bindtype if itemLevel > ilvlThreshold and itemQuality > qualityThreshold and bindType == 1 then if debug then print(string.format("BoE filter pass for ilvl %d and quality %d", itemLevel, itemQuality)) end return true end end if debug then print(string.format("BoE filter fail for ilvl %d and quality %d", provided.ilvl, provided.quality)) end return false end) local artifactPowerFilter = Filter.new({ ["type"] = getItemType, ["subtype"] = getItemSubtype, ["subclassid"] = getItemSubclassId, ["value"] = getItemValue, }, function(slot, provided) ---@cast provided { type: string, subtype: string, subclassid: number, value: number } if not aura_env.config.artifactPowerFilter then return false end if provided.value == 0 and provided.type == "Consumable" and provided.subtype == "Other" and provided.subclassid == 8 then if debug then print( string.format( "Artifact power filter pass for type %s and subtype %s and subclassid %d with value %d", provided.type, provided.subtype, provided.subclassid, provided.value ) ) end return true end if debug then DevTools_Dump(provided) print( string.format( "Artifact power filter fail for type %s and subtype %s and subclassid %d with value %d", provided.type, provided.subtype, provided.subclassid, provided.value ) ) end return false end) local everythingFilter = Filter.new({ ["name"] = getItemName }, function(slot, provided) ---@cast provided { name: string } return aura_env.config.everythingFilter end) ---@type table local filters = { everythingFilter, artifactPowerFilter, boeFilter, classGearFilter, goldFilter, greyValueFilter, ilvlFilter, mountFilter, orderResourcesFilter, professionFilter, questItemFilter, -- reicpeFilter, valueFilter, nameFilter, } ---@class FilterService aura_env.FilterService = { ---@param lootInfo table Run = function(lootInfo) ---@type table local slotsToLoot = {} for slot, item in pairs(lootInfo) do if debug then local itemname = getItemName(slot) print(string.format("Checking slot %d for %s", slot, itemname)) end for _, filter in ipairs(filters) do local res, err = filter:Run(slot) if err then if debug then print(err) end end if res then slotsToLoot[#slotsToLoot + 1] = slot break end end end aura_env.FilterService.doLoot(slotsToLoot) end, ---@param slots table ---@return nil doLoot = function(slots) for i = #slots, 1, -1 do aura_env.FilterService.lootslot(slots[i]) end end, ---@param slot number ---@return nil lootslot = function(slot) LootSlot(slot) local itemIcon = getItemIcon(slot) or 134400 local itemName = getItemName(slot) or "Unknown" itemName = itemName:gsub("\n", ", ") local itemQuality = getItemQuality(slot) or 0 if string.find(itemName, "Gold") == nil and string.find(itemName, "Silver") == nil and string.find(itemName, "Copper") == nil then if not WeakAurasSaved.Cyka.ItemCache[itemName] then WeakAurasSaved.Cyka.ItemCache[itemName] = { icon = itemIcon, quality = itemQuality, } end end end, } aura_env.skills = { --Warrior [1] = { --Armor Skills ["Cloth"] = 0, ["Leather"] = 0, ["Mail"] = 0, ["Plate"] = 1, ["Shields"] = 1, --Weapon Skills ["One-Handed Axes"] = 1, ["Two-Handed Axes"] = 1, ["Bows"] = 1, ["Guns"] = 1, ["One-Handed Maces"] = 1, ["Two-Handed Maces"] = 1, ["Polearms"] = 1, ["One-Handed Swords"] = 1, ["Two-Handed Swords"] = 1, ["Warglaives"] = 1, ["Staves"] = 1, ["Fist Weapons"] = 1, ["Daggers"] = 1, ["Crossbows"] = 1, ["Wands"] = 0, }, --Paladin [2] = { --Armor Skills ["Cloth"] = 0, ["Leather"] = 0, ["Mail"] = 0, ["Plate"] = 1, ["Shields"] = 1, --Weapon Skills ["One-Handed Axes"] = 1, ["Two-Handed Axes"] = 1, ["Bows"] = 0, ["Guns"] = 0, ["One-Handed Maces"] = 1, ["Two-Handed Maces"] = 1, ["Polearms"] = 1, ["One-Handed Swords"] = 1, ["Two-Handed Swords"] = 1, ["Warglaives"] = 0, ["Staves"] = 0, ["Fist Weapons"] = 0, ["Daggers"] = 0, ["Crossbows"] = 0, ["Wands"] = 0, }, --Hunter [3] = { --Armor Skills ["Cloth"] = 0, ["Leather"] = 0, ["Mail"] = 1, ["Plate"] = 0, ["Shields"] = 0, --Weapon Skills ["One-Handed Axes"] = 1, ["Two-Handed Axes"] = 1, ["Bows"] = 1, ["Guns"] = 1, ["One-Handed Maces"] = 0, ["Two-Handed Maces"] = 0, ["Polearms"] = 1, ["One-Handed Swords"] = 1, ["Two-Handed Swords"] = 1, ["Warglaives"] = 0, ["Staves"] = 1, ["Fist Weapons"] = 1, ["Daggers"] = 1, ["Crossbows"] = 1, ["Wands"] = 0, }, --Rogue [4] = { --Armor Skills ["Cloth"] = 0, ["Leather"] = 1, ["Mail"] = 0, ["Plate"] = 0, ["Shields"] = 0, --Weapon Skills ["One-Handed Axes"] = 1, ["Two-Handed Axes"] = 0, ["Bows"] = 0, ["Guns"] = 0, ["One-Handed Maces"] = 1, ["Two-Handed Maces"] = 0, ["Polearms"] = 0, ["One-Handed Swords"] = 1, ["Two-Handed Swords"] = 0, ["Warglaives"] = 0, ["Staves"] = 0, ["Fist Weapons"] = 1, ["Daggers"] = 1, ["Crossbows"] = 0, ["Wands"] = 0, }, --Priest [5] = { --Armor Skills ["Cloth"] = 1, ["Leather"] = 0, ["Mail"] = 0, ["Plate"] = 0, ["Shields"] = 0, --Weapon Skills ["One-Handed Axes"] = 0, ["Two-Handed Axes"] = 0, ["Bows"] = 0, ["Guns"] = 0, ["One-Handed Maces"] = 1, ["Two-Handed Maces"] = 0, ["Polearms"] = 0, ["One-Handed Swords"] = 0, ["Two-Handed Swords"] = 0, ["Warglaives"] = 0, ["Staves"] = 1, ["Fist Weapons"] = 0, ["Daggers"] = 1, ["Crossbows"] = 0, ["Wands"] = 1, }, --Death Knight [6] = { --Armor Skills ["Cloth"] = 0, ["Leather"] = 0, ["Mail"] = 0, ["Plate"] = 1, ["Shields"] = 0, --Weapon Skills ["One-Handed Axes"] = 1, ["Two-Handed Axes"] = 1, ["Bows"] = 0, ["Guns"] = 0, ["One-Handed Maces"] = 1, ["Two-Handed Maces"] = 1, ["Polearms"] = 1, ["One-Handed Swords"] = 1, ["Two-Handed Swords"] = 1, ["Warglaives"] = 0, ["Staves"] = 0, ["Fist Weapons"] = 0, ["Daggers"] = 0, ["Crossbows"] = 0, ["Wands"] = 0, }, --Shaman [7] = { --Armor Skills ["Cloth"] = 0, ["Leather"] = 0, ["Mail"] = 1, ["Plate"] = 0, ["Shields"] = 1, --Weapon Skills ["One-Handed Axes"] = 1, ["Two-Handed Axes"] = 0, ["Bows"] = 0, ["Guns"] = 0, ["One-Handed Maces"] = 1, ["Two-Handed Maces"] = 0, ["Polearms"] = 0, ["One-Handed Swords"] = 0, ["Two-Handed Swords"] = 0, ["Warglaives"] = 0, ["Staves"] = 1, ["Fist Weapons"] = 1, ["Daggers"] = 1, ["Crossbows"] = 0, ["Wands"] = 0, }, --Mage [8] = { --Armor Skills ["Cloth"] = 1, ["Leather"] = 0, ["Mail"] = 0, ["Plate"] = 0, ["Shields"] = 0, --Weapon Skills ["One-Handed Axes"] = 0, ["Two-Handed Axes"] = 0, ["Bows"] = 0, ["Guns"] = 0, ["One-Handed Maces"] = 0, ["Two-Handed Maces"] = 0, ["Polearms"] = 0, ["One-Handed Swords"] = 1, ["Two-Handed Swords"] = 0, ["Warglaives"] = 0, ["Staves"] = 1, ["Fist Weapons"] = 0, ["Daggers"] = 1, ["Crossbows"] = 0, ["Wands"] = 1, }, --Warlock [9] = { --Armor Skills ["Cloth"] = 1, ["Leather"] = 0, ["Mail"] = 0, ["Plate"] = 0, ["Shields"] = 0, --Weapon Skills ["One-Handed Axes"] = 0, ["Two-Handed Axes"] = 0, ["Bows"] = 0, ["Guns"] = 0, ["One-Handed Maces"] = 0, ["Two-Handed Maces"] = 0, ["Polearms"] = 0, ["One-Handed Swords"] = 1, ["Two-Handed Swords"] = 0, ["Warglaives"] = 0, ["Staves"] = 1, ["Fist Weapons"] = 0, ["Daggers"] = 1, ["Crossbows"] = 0, ["Wands"] = 1, }, --Monk [10] = { --Armor Skills ["Cloth"] = 0, ["Leather"] = 1, ["Mail"] = 0, ["Plate"] = 1, ["Shields"] = 1, --Weapon Skills ["One-Handed Axes"] = 1, ["Two-Handed Axes"] = 0, ["Bows"] = 0, ["Guns"] = 0, ["One-Handed Maces"] = 1, ["Two-Handed Maces"] = 0, ["Polearms"] = 1, ["One-Handed Swords"] = 1, ["Two-Handed Swords"] = 0, ["Warglaives"] = 0, ["Staves"] = 1, ["Fist Weapons"] = 1, ["Daggers"] = 0, ["Crossbows"] = 0, ["Wands"] = 0, }, --Druid [11] = { --Armor Skills ["Cloth"] = 0, ["Leather"] = 1, ["Mail"] = 0, ["Plate"] = 0, ["Shields"] = 0, --Weapon Skills ["One-Handed Axes"] = 0, ["Two-Handed Axes"] = 0, ["Bows"] = 0, ["Guns"] = 0, ["One-Handed Maces"] = 1, ["Two-Handed Maces"] = 0, ["Polearms"] = 1, ["One-Handed Swords"] = 0, ["Two-Handed Swords"] = 0, ["Warglaives"] = 0, ["Staves"] = 1, ["Fist Weapons"] = 1, ["Daggers"] = 1, ["Crossbows"] = 0, ["Wands"] = 0, }, --Demon Hunter [12] = { --Armor Skills ["Cloth"] = 0, ["Leather"] = 1, ["Mail"] = 0, ["Plate"] = 0, ["Shields"] = 0, --Weapon Skills ["One-Handed Axes"] = 1, ["Two-Handed Axes"] = 0, ["Bows"] = 0, ["Guns"] = 0, ["One-Handed Maces"] = 0, ["Two-Handed Maces"] = 0, ["Polearms"] = 0, ["One-Handed Swords"] = 1, ["Two-Handed Swords"] = 0, ["Warglaives"] = 1, ["Staves"] = 0, ["Fist Weapons"] = 1, ["Daggers"] = 0, ["Crossbows"] = 0, ["Wands"] = 0, }, } aura_env.qualityColors = { "\124cff9d9d9d", -- Poor "\124cffffffff", -- Common "\124cff1eff00", -- Uncommon "\124cff0070dd", -- Rare "\124cffa335ee", -- Epic "\124cffff8000", -- Legendary "\124cffe6cc80", -- Artifact "\124cff00ccff", -- Heirloom }