Fix aura list finding

main
4n0n 1 year ago
parent 7b3b714d39
commit 559c4339a4
  1. 40
      src/AuraTable/AuraTable.lua
  2. 6
      src/List/List.lua

@ -388,27 +388,39 @@ end
---@param spells List ---@param spells List
---@return Aura ---@return Aura
function AuraTable:FindAnyOf(spells) function AuraTable:FindAnyOf(spells)
return spells:find(function(spell) return spells:reduce(function(acc, cur)
return self:FindAny(spell):IsValid() local aura = self:FindAny(cur)
end) or Bastion.Aura:New() if aura:IsValid() then
return aura, true
end
return acc
end, Bastion.Aura:New())
end end
-- FindAnyOfMy -- FindAnyOfMy
---@param spells List ---@param spells List
---@return Aura ---@return Aura
function AuraTable:FindAnyOfMy(spells) function AuraTable:FindAnyOfMy(spells)
return spells:find(function(spell) return spells:reduce(function(acc, cur)
return self:FindMy(spell):IsValid() local aura = self:FindMy(cur)
end) or Bastion.Aura:New() if aura:IsValid() then
return aura, true
end
return acc
end, Bastion.Aura:New())
end end
-- FindAnyOfTheirs -- FindAnyOfTheirs
---@param spells List ---@param spells List
---@return Aura ---@return Aura
function AuraTable:FindAnyOfTheirs(spells) function AuraTable:FindAnyOfTheirs(spells)
return spells:find(function(spell) return spells:reduce(function(acc, cur)
return self:FindTheirs(spell):IsValid() local aura = self:FindTheirs(cur)
end) or Bastion.Aura:New() if aura:IsValid() then
return aura, true
end
return acc
end, Bastion.Aura:New())
end end
-- FindAnyFrom -- FindAnyFrom
@ -416,9 +428,13 @@ end
---@param source Unit ---@param source Unit
---@return Aura ---@return Aura
function AuraTable:FindAnyFrom(spells, source) function AuraTable:FindAnyFrom(spells, source)
return spells:find(function(spell) return spells:reduce(function(acc, cur)
return self:FindFrom(spell, source):IsValid() local aura = self:FindFrom(cur, source)
end) or Bastion.Aura:New() if aura:IsValid() then
return aura, true
end
return acc
end, Bastion.Aura:New())
end end
-- Has any stealable aura -- Has any stealable aura

@ -114,8 +114,12 @@ end
---@return boolean ---@return boolean
function List:reduce(callback, initialValue) function List:reduce(callback, initialValue)
local result = initialValue local result = initialValue
local done = false
for _, v in ipairs(self._list) do for _, v in ipairs(self._list) do
result = callback(result, v) result, done = callback(result, v)
if done then
break
end
end end
return result return result
end end

Loading…
Cancel
Save