From 65071f34fd8bdda3be5dc9f64cb118f21e4e7927 Mon Sep 17 00:00:00 2001 From: "M. David" Date: Thu, 18 Aug 2022 22:31:07 +0200 Subject: [PATCH] Add new autoloot aura, better than ever --- LegionWA/NewAutoLoot/Event.lua | 9 + LegionWA/NewAutoLoot/Init.lua | 591 +++++++++++++++++++++++++++++++++ 2 files changed, 600 insertions(+) create mode 100644 LegionWA/NewAutoLoot/Event.lua create mode 100644 LegionWA/NewAutoLoot/Init.lua diff --git a/LegionWA/NewAutoLoot/Event.lua b/LegionWA/NewAutoLoot/Event.lua new file mode 100644 index 0000000..56f8992 --- /dev/null +++ b/LegionWA/NewAutoLoot/Event.lua @@ -0,0 +1,9 @@ +-- LOOT_READY +function(allstates, e) + aura_env.allstates = allstates + + local lootInfo = GetLootInfo() + aura_env.filterService:run(lootInfo) + CloseLoot() + return true +end diff --git a/LegionWA/NewAutoLoot/Init.lua b/LegionWA/NewAutoLoot/Init.lua new file mode 100644 index 0000000..54336fd --- /dev/null +++ b/LegionWA/NewAutoLoot/Init.lua @@ -0,0 +1,591 @@ +local debug = false +local iconDisplayDuration = 3 + +-- itemName, itemLink, itemQuality, itemLevel, itemMinLevel, itemType, itemSubType,itemStackCount, itemEquipLoc, itemTexture, sellPrice, classID, subclassID, bindType,expacID, setID, isCraftingReagent = GetItemInfo(slot) +-- lootIcon, lootName, lootQuantity, currencyID, lootQuality, locked, isQuestItem, questID, isActive = GetLootSlotInfo(slot) +local function getItemLink(slot) + return GetLootSlotLink(slot) +end +local function getItemName(slot) + return select(2, GetLootSlotInfo(slot)) +end +local function getItemType(slot) + return select(6, GetItemInfo(getItemLink(slot))) +end +local function getItemSubtype(slot) + return select(7, GetItemInfo(getItemLink(slot))) +end +local function getItemLevel(slot) + return select(4, GetItemInfo(getItemLink(slot))) +end +local function getItemValue(slot) + return select(11, GetItemInfo(getItemLink(slot))) +end +local function getItemQuantity(slot) + return select(3, GetLootSlotInfo(slot)) +end +local function getItemQuality(slot) + return select(3, GetItemInfo(getItemLink(slot))) +end +local function getItemEquipLocation(slot) + return select(9, GetItemInfo(getItemLink(slot))) +end +local function getItemIcon(slot) + return select(10, GetItemInfo(getItemLink(slot))) +end + + +local doLoot = function(slot) + aura_env.debugLog("Looting slot: " .. slot) + LootSlot(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, + } +end + + +local goldFilter = { + enabled = true, + filter = function(self, slot) + if (self.enabled) then + aura_env.debugLog("Gold filter; slot: " .. slot) + local itemName = getItemName(slot) + if (itemName:match("%d+ (Gold|Silver|Copper)")) then + aura_env.debugLog("Gold filter pass") + return true + end + end + end +} +local orderResourcesFilter = { + enabled = true, + filter = function(self, slot) + if (self.enabled) then + aura_env.debugLog("Resource filter; slot: " .. slot) + local itemName = getItemName(slot) + if (itemName:match("Order Resources")) then + aura_env.debugLog("Order resource filter pass") + return true + end + end + end +} +local mountFilter = { + enabled = true, + filter = function(self, slot) + if (self.enabled) then + aura_env.debugLog("Mount filter; slot: " .. slot) + local itemType = getItemType(slot) + if (itemType == "Mount") then + aura_env.debugLog("Mount filter pass") + return true + end + end + end +} +local ilvlFilter = { + enabled = true, + ilvlThreshold = 880, + filter = function(self, slot) + if (self.enabled) then + aura_env.debugLog("ILvl filter; slot: " .. slot) + local itemLevel = getItemLevel(slot) + if (itemLevel > self.ilvlThreshold) then + aura_env.debugLog("Item level filter pass") + return true + end + end + end +} +local professionFilter = { + enabled = true, + herbs = true, + cloth = false, + ore = false, + leather = false, + cooking = false, + filter = function(self, slot) + if (self.enabled) then + aura_env.debugLog("Profession filter; slot: " .. slot) + local itemType = getItemType(slot) + if (itemType == "Tradeskill") then + local itemSubtype = getItemSubtype(slot) + if (itemSubtype == "Herb" and self.herbs) + or (itemSubtype == "Leather" and self.leather) + or (itemSubtype == "Cloth" and self.cloth) + or (itemSubtype == "Ore" and self.ore) + or (itemSubtype == "Cooking" and self.cooking) then + aura_env.debugLog("Profession filter pass") + return true + end + end + end + end +} +local valueFilter = { + enabled = true, + valueThreshold = 35 * 100 * 100, + applyThresholdToItemStack = false, + filter = function(self, slot) + if (self.enabled) then + aura_env.debugLog("Value filter; slot: " .. slot) + local itemValue = getItemValue(slot) + + if (self.applyThresholdToItemStack) then + local itemQuantity = getItemQuantity(slot) + aura_env.debugLog("There exist " .. itemQuantity .. " items in slot " .. slot) + itemValue = itemValue * itemQuantity + end + + if (itemValue > self.valueThreshold) then + aura_env.debugLog("Value filter pass") + return true + end + end + end +} +local greyValueFilter = { + enabled = true, + -- Set threshold to 0 to loot all greys + valueThreshold = 5 * 100 * 100, + applyThresholdToItemStack = false, + filter = function(self, slot) + if (self.enabled) then + aura_env.debugLog("Grey value filter; slot: " .. slot) + local itemQuality = getItemQuality(slot) + if (itemQuality > 0) then + local itemValue = getItemValue(slot) + + if (self.applyThresholdToItemStack) then + local itemQuantity = getItemQuantity(slot) + aura_env.debugLog("There exist " .. itemQuantity .. " items in slot " .. slot) + itemValue = itemValue * itemQuantity + end + + if (itemValue > self.valueThreshold) then + aura_env.debugLog("Grey value filter pass") + return true + end + end + end + end +} +local questItemFilter = { + enabled = true, + filter = function(self, slot) + if (self.enabled) then + aura_env.debugLog("Quest item filter; slot: " .. slot) + local itemType = getItemType(slot) + local itemSubtype = getItemSubtype(slot) + if (itemType == itemSubtype == "Quest") then + aura_env.debugLog("Quest item filter pass") + return true + end + end + end +} +local classGearFilter = { + enabled = true, + ilvlThreshold = 800, + qualityThreshold = 2, + filter = function(self, slot) + if (self.enabled) then + aura_env.debugLog("Class gear filter; slot: " .. slot) + local itemType = getItemType(slot) + local itemEquipLoc = getItemEquipLocation(slot) + 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 = getItemLevel(slot) + local itemQuality = getItemQuality(slot) + local isEquippable = aura_env.skills[select(3, UnitClass("player"))][subtype] == 1 + + if (isEquippable and itemLevel > self.ilvlThreshold and itemQuality > self.qualityThreshold) then + aura_env.debugLog("Class gear filter pass") + return true + end + end + end + end +} + +aura_env.filterService = { + filters = { + goldFilter, + orderResourcesFilter, + mountFilter, + ilvlFilter, + professionFilter, + valueFilter, + greyValueFilter, + questItemFilter, + classGearFilter + }, + slotsToLoot = {}, + run = function(self, lootInfo) + self.slotsToLoot = {} + for slot, item in pairs(lootInfo) do + aura_env.debugLog("Loot slot: " .. slot .. " " .. item.item) + for k, filter in pairs(self.filters) do + if (filter:filter(slot)) then + self.slotsToLoot[#self.slotsToLoot + 1] = slot + end + end + end + + aura_env.debugLog("Slots to loot: " .. #self.slotsToLoot) + aura_env.debugLog(self.slotsToLoot) + for i = #self.slotsToLoot, 1, -1 do + local slot = self.slotsToLoot[i] + aura_env.debugLog("Looting slot (iterator): " .. slot) + doLoot(slot) + end + end +} + +aura_env.debugLog = function(obj) + if (debug) then + print(GetTime()) + DevTools_Dump(obj) + print() + 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 +} \ No newline at end of file