Add more error handling and ancient mana filter

This commit is contained in:
M. David
2022-08-19 13:10:04 +02:00
parent 1f78ad8d5e
commit f618d2bc34
2 changed files with 48 additions and 16 deletions

File diff suppressed because one or more lines are too long

View File

@@ -14,19 +14,27 @@ local function getItemName(slot)
end end
local function getItemType(slot) local function getItemType(slot)
if (slot == nil) then return nil end if (slot == nil) then return nil end
return select(6, GetItemInfo(getItemLink(slot))) local itemLink = getItemLink(slot)
if (itemLink == nil) then return nil end
return select(6, GetItemInfo(itemLink))
end end
local function getItemSubtype(slot) local function getItemSubtype(slot)
if (slot == nil) then return nil end if (slot == nil) then return nil end
return select(7, GetItemInfo(getItemLink(slot))) local itemLink = getItemLink(slot)
if (itemLink == nil) then return nil end
return select(7, GetItemInfo(itemLink))
end end
local function getItemLevel(slot) local function getItemLevel(slot)
if (slot == nil) then return nil end if (slot == nil) then return nil end
return select(4, GetItemInfo(getItemLink(slot))) local itemLink = getItemLink(slot)
if (itemLink == nil) then return nil end
return select(4, GetItemInfo(itemLink))
end end
local function getItemValue(slot) local function getItemValue(slot)
if (slot == nil) then return nil end if (slot == nil) then return nil end
return select(11, GetItemInfo(getItemLink(slot))) local itemLink = getItemLink(slot)
if (itemLink == nil) then return nil end
return select(11, GetItemInfo(itemLink))
end end
local function getItemQuantity(slot) local function getItemQuantity(slot)
if (slot == nil) then return nil end if (slot == nil) then return nil end
@@ -34,15 +42,21 @@ local function getItemQuantity(slot)
end end
local function getItemQuality(slot) local function getItemQuality(slot)
if (slot == nil) then return nil end if (slot == nil) then return nil end
return select(3, GetItemInfo(getItemLink(slot))) local itemLink = getItemLink(slot)
if (itemLink == nil) then return nil end
return select(3, GetItemInfo(itemLink))
end end
local function getItemEquipLocation(slot) local function getItemEquipLocation(slot)
if (slot == nil) then return nil end if (slot == nil) then return nil end
return select(9, GetItemInfo(getItemLink(slot))) local itemLink = getItemLink(slot)
if (itemLink == nil) then return nil end
return select(9, GetItemInfo(itemLink))
end end
local function getItemIcon(slot) local function getItemIcon(slot)
if (slot == nil) then return nil end if (slot == nil) then return nil end
return select(10, GetItemInfo(getItemLink(slot))) local itemLink = getItemLink(slot)
if (itemLink == nil) then return nil end
return select(10, GetItemInfo(itemLink))
end end
@@ -50,10 +64,11 @@ local doLoot = function(slot)
aura_env.debugLog("Looting slot: " .. slot) aura_env.debugLog("Looting slot: " .. slot)
LootSlot(slot) LootSlot(slot)
local itemIcon = getItemIcon(slot) local itemIcon = getItemIcon(slot) or 134400
local itemName = getItemName(slot) local itemName = getItemName(slot) or "Unknown"
local itemQuantity = getItemQuantity(slot) itemName = itemName:gsub("\n", ", ")
local itemQuality = getItemQuality(slot) local itemQuantity = getItemQuantity(slot) or 1
local itemQuality = getItemQuality(slot) or 0
aura_env.debugLog("Drawing icon for " .. itemName .. " with quality " .. itemQuality) aura_env.debugLog("Drawing icon for " .. itemName .. " with quality " .. itemQuality)
local nameWithColor = aura_env.qualityColors[itemQuality + 1] .. "[" .. itemName .. "]\124r" local nameWithColor = aura_env.qualityColors[itemQuality + 1] .. "[" .. itemName .. "]\124r"
@@ -84,7 +99,9 @@ local goldFilter = {
if (self.enabled) then if (self.enabled) then
aura_env.debugLog("Gold filter; slot: " .. slot) aura_env.debugLog("Gold filter; slot: " .. slot)
local itemName = getItemName(slot) local itemName = getItemName(slot)
if (itemname and itemName:match("%d+ (Gold|Silver|Copper)")) then -- 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") aura_env.debugLog("Gold filter pass")
return true return true
end end
@@ -187,7 +204,7 @@ local greyValueFilter = {
if (self.enabled) then if (self.enabled) then
aura_env.debugLog("Grey value filter; slot: " .. slot) aura_env.debugLog("Grey value filter; slot: " .. slot)
local itemQuality = getItemQuality(slot) local itemQuality = getItemQuality(slot)
if (itemQuality > 0) then if (itemQuality and itemQuality > 0) then
local itemValue = getItemValue(slot) local itemValue = getItemValue(slot)
if (self.applyThresholdToItemStack) then if (self.applyThresholdToItemStack) then
@@ -277,6 +294,20 @@ local arguniteFilter = {
end end
end end
} }
local ancientManaFilter = {
enabled = true,
qualityThreshold = 1,
filter = function(self, slot)
if (self.enabled) then
aura_env.debugLog("Ancient mana filter; slot: " .. slot)
local itemName = getItemName(slot)
if (itemName and itemName:match("Ancient Mana")) then
aura_env.debugLog("Ancient mana filter pass")
return true
end
end
end
}
aura_env.filterService = { aura_env.filterService = {
filters = { filters = {
@@ -290,14 +321,14 @@ aura_env.filterService = {
questItemFilter, questItemFilter,
classGearFilter, classGearFilter,
azeriteFilter, azeriteFilter,
arguniteFilter arguniteFilter,
ancientManaFilter
}, },
slotsToLoot = {}, slotsToLoot = {},
run = function(self, lootInfo) run = function(self, lootInfo)
self.slotsToLoot = {} self.slotsToLoot = {}
for slot, item in pairs(lootInfo) do for slot, item in pairs(lootInfo) do
aura_env.debugLog("Loot slot: " .. slot .. " " .. item.item) aura_env.debugLog("Loot slot: " .. slot .. " " .. item.item)
aura_env.debugLog(getItemSubtype(slot))
self:runFilters(slot) self:runFilters(slot)
end end
@@ -312,6 +343,7 @@ aura_env.filterService = {
runFilters = function(self, slot) runFilters = function(self, slot)
for k, filter in pairs(self.filters) do for k, filter in pairs(self.filters) do
if (filter:filter(slot)) then 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 self.slotsToLoot[#self.slotsToLoot + 1] = slot
return return
end end