Files
wow-weakauras/LegionWA/AutoLoot/Init.lua
2022-08-22 20:29:15 +02:00

720 lines
23 KiB
Lua

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
-- make blood of sargeras filter
-- 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)
-- Link sometimes does not work
local function getItemLink(slot)
aura_env.debugLog("getItemLink " .. tostring(slot))
if (slot == nil) then return nil end
return GetLootSlotLink(slot)
end
local function getItemName(slot)
aura_env.debugLog("getItemName " .. tostring(slot))
if (slot == nil) then return nil end
return select(2, GetLootSlotInfo(slot))
end
local function getItemType(slot)
aura_env.debugLog("getItemType " .. tostring(slot))
if (slot == nil) then return nil end
local itemLink = getItemLink(slot)
if (itemLink == nil) then return nil end
return select(6, GetItemInfo(itemLink))
end
local function getItemSubtype(slot)
aura_env.debugLog("getItemSubtype " .. tostring(slot))
if (slot == nil) then return nil end
local itemLink = getItemLink(slot)
if (itemLink == nil) then return nil end
return select(7, GetItemInfo(itemLink))
end
local function getItemLevel(slot)
aura_env.debugLog("getItemLevel " .. tostring(slot))
if (slot == nil) then return nil end
local itemLink = getItemLink(slot)
if (itemLink == nil) then return nil end
return select(4, GetItemInfo(itemLink))
end
local function getItemValue(slot)
aura_env.debugLog("getItemValue " .. tostring(slot))
if (slot == nil) then return nil end
local itemLink = getItemLink(slot)
if (itemLink == nil) then return nil end
return select(11, GetItemInfo(itemLink))
end
local function getItemQuantity(slot)
aura_env.debugLog("getItemQuantity " .. tostring(slot))
if (slot == nil) then return nil end
return select(3, GetLootSlotInfo(slot))
end
local function getItemQuality(slot)
aura_env.debugLog("getItemQuality " .. tostring(slot))
if (slot == nil) then return nil end
local itemLink = getItemLink(slot)
if (itemLink == nil) then return nil end
return select(3, GetItemInfo(itemLink))
end
local function getItemEquipLocation(slot)
aura_env.debugLog("getItemEquipLocation " .. tostring(slot))
if (slot == nil) then return nil end
local itemLink = getItemLink(slot)
if (itemLink == nil) then return nil end
return select(9, GetItemInfo(itemLink))
end
local function getItemIcon(slot)
aura_env.debugLog("getItemIcon " .. tostring(slot))
if (slot == nil) then return nil end
local itemLink = getItemLink(slot)
if (itemLink == nil) then return nil end
return select(10, GetItemInfo(itemLink))
end
local doLoot = function(slot)
aura_env.debugLog("Looting slot: " .. tostring(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 not WeakAurasSaved.Cyka.ItemCache[itemName] then
WeakAurasSaved.Cyka.ItemCache[itemName] = {
icon = itemIcon,
quality = itemQuality,
}
end
end
local goldFilter = {
enabled = true,
filter = function(self, slot)
if (self.enabled) then
aura_env.debugLog("Gold filter; slot: " .. tostring(slot))
local itemName = getItemName(slot)
-- I guess it does not support OR in regex?
-- itemName:match("%d+ ((Gold)|(Silver)|(Copper))")
if (itemname and itemName:match("%d+ Gold") or itemName:match("%d+ Silver") or itemName:match("%d+ Copper")) then
aura_env.debugLog("Gold filter pass")
return true
end
aura_env.debugLog("Gold filter fail " .. tostring(itemName))
end
end
}
local orderResourcesFilter = {
enabled = true,
filter = function(self, slot)
if (self.enabled) then
aura_env.debugLog("Resource filter; slot: " .. tostring(slot))
local itemName = getItemName(slot)
if (itemName and itemName:match("Order Resources")) then
aura_env.debugLog("Order resource filter pass")
return true
end
aura_env.debugLog("Order resource filter fail " .. tostring(itemName))
end
end
}
local mountFilter = {
enabled = true,
filter = function(self, slot)
if (self.enabled) then
aura_env.debugLog("Mount filter; slot: " .. tostring(slot))
local itemType = getItemType(slot)
if (itemType and itemType == "Mount") then
aura_env.debugLog("Mount filter pass")
return true
end
aura_env.debugLog("Mount filter fail " .. tostring(itemType))
end
end
}
local ilvlFilter = {
enabled = true,
ilvlThreshold = 880,
filter = function(self, slot)
if (self.enabled) then
aura_env.debugLog("ILvl filter; slot: " .. tostring(slot))
local itemLevel = getItemLevel(slot)
if (itemLevel and itemLevel > self.ilvlThreshold) then
aura_env.debugLog("Item level filter pass")
return true
end
aura_env.debugLog("Item level filter fail " .. tostring(itemLevel))
end
end
}
local professionFilter = {
enabled = true,
herbs = true,
cloth = false,
ore = false,
leather = false,
cooking = true,
inscription = true,
filter = function(self, slot)
if (self.enabled) then
aura_env.debugLog("Profession filter; slot: " .. tostring(slot))
local itemType = getItemType(slot)
local itemSubtype = getItemSubtype(slot)
if (itemType and itemType == "Tradeskill") then
if (itemSubtype and (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)
or (itemSubtype == "Inscription" and self.inscription)) then
aura_env.debugLog("Profession filter pass")
return true
end
end
aura_env.debugLog("Profession filter fail " .. tostring(itemType) .. " " .. tostring(itemSubtype))
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: " .. tostring(slot))
local itemValue = getItemValue(slot)
if (self.applyThresholdToItemStack) then
local itemQuantity = getItemQuantity(slot)
aura_env.debugLog("There exist " .. tostring(itemQuantity) .. " items in slot " .. tostring(slot))
itemValue = itemValue * itemQuantity
end
if (itemValue and itemValue > self.valueThreshold) then
aura_env.debugLog("Value filter pass")
return true
end
aura_env.debugLog("Value filter fail " .. tostring(itemValue))
end
end
}
local greyValueFilter = {
enabled = true,
-- Set threshold to 0 to loot all greys
valueThreshold = 4 * 100 * 100,
applyThresholdToItemStack = false,
filter = function(self, slot)
if (self.enabled) then
aura_env.debugLog("Grey value filter; slot: " .. tostring(slot))
local itemQuality = getItemQuality(slot)
if (itemQuality and itemQuality == 0) then
local itemValue = getItemValue(slot)
if (self.applyThresholdToItemStack) then
local itemQuantity = getItemQuantity(slot)
aura_env.debugLog("There exist " .. tostring(itemQuantity) .. " items in slot " .. tostring(slot))
itemValue = itemValue * itemQuantity
end
if (itemValue and itemValue > self.valueThreshold) then
aura_env.debugLog("Grey value filter pass")
return true
end
aura_env.debugLog("Grey value filter fail " .. tostring(itemValue))
end
aura_env.debugLog("Grey value filter fail " .. tostring(itemQuality))
end
end
}
local questItemFilter = {
enabled = true,
filter = function(self, slot)
if (self.enabled) then
aura_env.debugLog("Quest item filter; slot: " .. tostring(slot))
local itemType = getItemType(slot)
local itemSubtype = getItemSubtype(slot)
if (itemType and itemSubtype and itemType == "Quest" and itemSubtype == "Quest") then
aura_env.debugLog("Quest item filter pass")
return true
end
aura_env.debugLog("Quest item filter fais " .. tostring(itemType) .. " " .. tostring(itemSubtype))
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: " .. tostring(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
aura_env.debugLog("Class gear filter fais " .. tostring(itemType) .. " " .. tostring(itemEquipLoc))
end
end
}
local azeriteFilter = {
enabled = true,
ilvlThreshold = 800,
qualityThreshold = 2,
filter = function(self, slot)
if (self.enabled) then
aura_env.debugLog("Azerite filter; slot: " .. tostring(slot))
local itemType = getItemType(slot)
local itemSubtype = getItemSubtype(slot)
local itemQuality = getItemQuality(slot)
if (itemType and itemSubtype and itemQuality and itemType == "Consumable" and itemSubtype == "Other" and itemQuality > 1) then
aura_env.debugLog("Azerite filter pass")
return true
end
aura_env.debugLog("Azerite filter fais " .. tostring(itemType) .. " " .. tostring(itemSubtype) .. " " .. tostring(itemQuality))
end
end
}
local arguniteFilter = {
enabled = true,
qualityThreshold = 1,
filter = function(self, slot)
if (self.enabled) then
aura_env.debugLog("Argunite filter; slot: " .. tostring(slot))
local itemName = getItemName(slot)
local itemQuality = getItemQuality(slot)
if (itemName and itemQuality and itemName:match("Argunite") and itemQuality > self.qualityThreshold) then
aura_env.debugLog("Argunite filter pass")
return true
end
aura_env.debugLog("Argunite filter fais " .. tostring(itemName) .. " " .. tostring(itemQuality))
end
end
}
local ancientManaFilter = {
enabled = true,
qualityThreshold = 1,
filter = function(self, slot)
if (self.enabled) then
aura_env.debugLog("Ancient mana filter; slot: " .. tostring(slot))
local itemName = getItemName(slot)
if (itemName and itemName:match("Ancient Mana")) then
aura_env.debugLog("Ancient mana filter pass")
return true
end
aura_env.debugLog("Ancient mana filter fail " .. tostring(itemName))
end
end
}
local reicpeFilter = {
enabled = true,
filter = function(self, slot)
if (self.enabled) then
aura_env.debugLog("Recipe filter; slot: " .. tostring(slot))
local itemName = getItemName(slot)
if (itemName and (itemName:match("Recipe") or itemName:match("Technique"))) then
aura_env.debugLog("Recipe filter pass")
return true
end
aura_env.debugLog("Recipe filter fail " .. tostring(itemName))
end
end
}
local bloodOfSargerasFilter = {
enabled = true,
filter = function(self, slot)
if (self.enabled) then
aura_env.debugLog("Blood of Sargeras filter; slot: " .. tostring(slot))
local itemName = getItemName(slot)
if (itemName and itemName:match("Sargeras")) then
aura_env.debugLog("Blood of Sargeras filter pass")
return true
end
aura_env.debugLog("Blood of Sargeras filter fail " .. tostring(itemName))
end
end
}
aura_env.filterService = {
filters = {
goldFilter,
orderResourcesFilter,
mountFilter,
ilvlFilter,
professionFilter,
valueFilter,
greyValueFilter,
questItemFilter,
classGearFilter,
azeriteFilter,
arguniteFilter,
ancientManaFilter,
reicpeFilter,
bloodOfSargerasFilter
},
slotsToLoot = {},
run = function(self, lootInfo)
self.slotsToLoot = {}
for slot, item in pairs(lootInfo) do
aura_env.debugLog("Loot slot: " .. tostring(slot) .. " " .. item.item)
self:runFilters(slot)
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,
runFilters = function(self, slot)
for k, filter in pairs(self.filters) do
if (filter:filter(slot)) then
-- Might be good to, instead of just adding slot to a list, add an object with info about the item and the slot containing it so each filter can dictate the item name and icon
self.slotsToLoot[#self.slotsToLoot + 1] = slot
return
end
end
end
}
aura_env.debugLog = function(obj)
if (debug) then
print(GetTime())
DevTools_Dump(obj)
print()
end
if not WeakAurasSaved.Cyka then WeakAurasSaved.Cyka = {} end
if not WeakAurasSaved.Cyka.Log then WeakAurasSaved.Cyka.Log = {} end
if not WeakAurasSaved.Cyka.Log.AutoLoot then WeakAurasSaved.Cyka.Log.AutoLoot = {} end
WeakAurasSaved.Cyka.Log.AutoLoot[#WeakAurasSaved.Cyka.Log.AutoLoot + 1] = obj
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
}