Refactor AutoLoot to use options instead of hardcoded values

This commit is contained in:
2024-09-22 16:22:38 +02:00
parent 457ee1477e
commit a1743dc37c
2 changed files with 56 additions and 123 deletions

View File

@@ -163,6 +163,7 @@ Filter = {
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
@@ -175,6 +176,7 @@ local goldFilter = Filter.new({ ["name"] = getItemName },
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
@@ -185,6 +187,7 @@ local orderResourcesFilter = Filter.new({ ["name"] = getItemName },
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
@@ -195,7 +198,8 @@ local mountFilter = Filter.new({ ["type"] = getItemType },
local ilvlFilter = Filter.new({ ["ilvl"] = getItemLevel },
function(slot, provided)
---@cast provided { ilvl: number }
if provided.ilvl and provided.ilvl > 800 then
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
@@ -208,17 +212,18 @@ local professionFilter = Filter.new({
},
function(slot, provided)
---@cast provided { type: string, subtype: string }
if not aura_env.config.professionFilter then return false end
local enabled = {
["Cloth"] = true,
["Cooking"] = true,
["Enchanting"] = true,
["Herb"] = true,
["Inscription"] = true,
["Jewelcrafting"] = true,
["Leather"] = true,
["Metal & Stone"] = true,
["Ore"] = true,
["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
@@ -237,12 +242,12 @@ local valueFilter = Filter.new({
},
function(slot, provided)
---@cast provided { value: number, quantity: number }
if not aura_env.config.valueFilter then return false end
local valueThreshold = 35 * 100 * 100
local applyValueTostack = false
local valueThreshold = aura_env.config.valueFilterThreshold
local value = provided.value
if applyValueTostack then value = value * provided.quantity end
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
@@ -258,13 +263,13 @@ local greyValueFilter = Filter.new({
},
function(slot, provided)
---@cast provided { quality: number, value: number, quantity: number }
if not aura_env.config.greyValueFilter then return false end
local valueThreshold = 0.1 * 100 * 100
local applyValueTostack = false
local valueThreshold = aura_env.config.greyValueFilterThreshold
if provided.quality == 0 then
local value = provided.value
if applyValueTostack then value = value * provided.quantity end
if aura_env.config.greyValueFilterApplyValueToStack then value = value * provided.quantity end
if value > valueThreshold then
if debug then
@@ -286,6 +291,8 @@ local questItemFilter = Filter.new({
},
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,
@@ -308,9 +315,10 @@ local classGearFilter = Filter.new({
},
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 = 800
local qualityThreshold = 2
local ilvlThreshold = aura_env.config.classGearFilterIlvlThreshold
local qualityThreshold = aura_env.config.classGearFilterQualityThreshold
local isEquippable = aura_env.skills[select(3, UnitClass("player"))][provided.subtype] == 1
@@ -327,26 +335,27 @@ local classGearFilter = Filter.new({
end
return false
end)
local arguniteFilter = Filter.new({ ["name"] = getItemName },
local nameFilter = Filter.new({ ["name"] = getItemName },
function(slot, provided)
---@cast provided { name: string }
if provided.name == "Veiled Argunite" then
if debug then
print(string.format("Argunite filter pass for %s", provided.name))
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
return true
end
if debug then print(string.format("Argunite filter fail for %s", provided.name)) end
return false
end)
local ancientManaFilter = Filter.new({ ["name"] = getItemName },
function(slot, provided)
---@cast provided { name: string }
if string.find(provided.name, "Ancient Mana") then
if debug then print(string.format("Ancient Mana filter pass for %s", provided.name)) end
return true
end
if debug then print(string.format("Ancient Mana filter fail for %s", provided.name)) end
if debug then print(string.format("Name filter fail for %s", provided.name)) end
return false
end)
local reicpeFilter = Filter.new({ ["name"] = getItemName },
@@ -359,66 +368,6 @@ local reicpeFilter = Filter.new({ ["name"] = getItemName },
if debug then print(string.format("Recipe filter fail for %s", provided.name)) end
return false
end)
local bloodOfSargerasFilter = Filter.new({ ["name"] = getItemName },
function(slot, provided)
---@cast provided { name: string }
if provided.name == "Blood of Sargeras" then
if debug then print(string.format("Blood of Sargeras filter pass for %s", provided.name)) end
return true
end
if debug then print(string.format("Blood of Sargeras filter fail for %s", provided.name)) end
return false
end)
local primalSpiritFilter = Filter.new({ ["name"] = getItemName },
function(slot, provided)
---@cast provided { name: string }
if provided.name == "Primal Spirit" then
if debug then print(string.format("Primal Spirit filter pass for %s", provided.name)) end
return true
end
if debug then print(string.format("Primal Spirit filter fail for %s", provided.name)) end
return false
end)
local apexisCrystalFilter = Filter.new({ ["name"] = getItemName },
function(slot, provided)
---@cast provided { name: string }
if provided.name == "Apexis Crystal" then
if debug then print(string.format("Apexis Crystal filter pass for %s", provided.name)) end
return true
end
if debug then print(string.format("Apexis Crystal filter fail for %s", provided.name)) end
return false
end)
local nethershardFilter = Filter.new({ ["name"] = getItemName },
function(slot, provided)
---@cast provided { name: string }
if provided.name == "Nethershard" then
if debug then print(string.format("Nethershard filter pass for %s", provided.name)) end
return true
end
if debug then print(string.format("Nethershard filter fail for %s", provided.name)) end
return false
end)
local bloodhunerQuarryFilter = Filter.new({ ["name"] = getItemName },
function(slot, provided)
---@cast provided { name: string }
if provided.name == "Bloodhunter's Quarry" then
if debug then print(string.format("Bloodhunter's Quarry filter pass for %s", provided.name)) end
return true
end
if debug then print(string.format("Bloodhunter's Quarry filter fail for %s", provided.name)) end
return false
end)
local arguniteClusterFilter = Filter.new({ ["name"] = getItemName },
function(slot, provided)
---@cast provided { name: string }
if provided.name == "Argunite Cluster" then
if debug then print(string.format("Argunite Cluster filter pass for %s", provided.name)) end
return true
end
if debug then print(string.format("Argunite Cluster filter fail for %s", provided.name)) end
return false
end)
local boeFilter = Filter.new({
["ilvl"] = getItemLevel,
["type"] = getItemType,
@@ -428,9 +377,10 @@ local boeFilter = Filter.new({
},
function(slot, provided)
---@cast provided { ilvl: number, type: string, quality: number, equiploc: string, bindtype: number }
aura_env.config.boeFilter = true
local ilvlThreshold = 800
local qualityThreshold = 1
local ilvlThreshold = aura_env.config.boeFilterIlvlThreshold
local qualityThreshold = aura_env.config.boeFilterQualityThreshold
local itemType = provided.type
local itemEquipLoc = provided.equiploc
@@ -459,6 +409,7 @@ local artifactPowerFilter = Filter.new({
["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",
@@ -473,32 +424,16 @@ local artifactPowerFilter = Filter.new({
end
return false
end)
-- local azeriteFilter = {
-- enabled = true,
-- ilvlThreshold = 800,
-- qualityThreshold = 2,
-- filter = function(self, slot)
-- if self.enabled the
-- 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 the
-- return true
-- en
-- tostring(itemType) .. " " .. tostring(itemSubtype) .. " " .. tostring(itemQuality))
-- end
-- end
-- }
local everythingFilter = Filter.new({ ["name"] = getItemName },
function(slot, provided)
---@cast provided { name: string }
return aura_env.config.everythingFilter
end)
---@type table<Filter>
local filters = {
ancientManaFilter,
arguniteFilter,
everythingFilter,
artifactPowerFilter,
bloodhunerQuarryFilter,
bloodOfSargerasFilter,
boeFilter,
classGearFilter,
goldFilter,
@@ -510,10 +445,7 @@ local filters = {
questItemFilter,
-- reicpeFilter,
valueFilter,
arguniteClusterFilter,
primalSpiritFilter,
apexisCrystalFilter,
nethershardFilter,
nameFilter,
}
---@class FilterService
@@ -527,7 +459,7 @@ aura_env.FilterService = {
local itemname = getItemName(slot)
print(string.format("Checking slot %d for %s", slot, itemname))
end
for _, filter in pairs(filters) do
for _, filter in ipairs(filters) do
local res, err = filter:Run(slot)
if err then
if debug then print(err) end

File diff suppressed because one or more lines are too long