Fix aura list finding

pull/1/head
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
---@return Aura
function AuraTable:FindAnyOf(spells)
return spells:find(function(spell)
return self:FindAny(spell):IsValid()
end) or Bastion.Aura:New()
return spells:reduce(function(acc, cur)
local aura = self:FindAny(cur)
if aura:IsValid() then
return aura, true
end
return acc
end, Bastion.Aura:New())
end
-- FindAnyOfMy
---@param spells List
---@return Aura
function AuraTable:FindAnyOfMy(spells)
return spells:find(function(spell)
return self:FindMy(spell):IsValid()
end) or Bastion.Aura:New()
return spells:reduce(function(acc, cur)
local aura = self:FindMy(cur)
if aura:IsValid() then
return aura, true
end
return acc
end, Bastion.Aura:New())
end
-- FindAnyOfTheirs
---@param spells List
---@return Aura
function AuraTable:FindAnyOfTheirs(spells)
return spells:find(function(spell)
return self:FindTheirs(spell):IsValid()
end) or Bastion.Aura:New()
return spells:reduce(function(acc, cur)
local aura = self:FindTheirs(cur)
if aura:IsValid() then
return aura, true
end
return acc
end, Bastion.Aura:New())
end
-- FindAnyFrom
@ -416,9 +428,13 @@ end
---@param source Unit
---@return Aura
function AuraTable:FindAnyFrom(spells, source)
return spells:find(function(spell)
return self:FindFrom(spell, source):IsValid()
end) or Bastion.Aura:New()
return spells:reduce(function(acc, cur)
local aura = self:FindFrom(cur, source)
if aura:IsValid() then
return aura, true
end
return acc
end, Bastion.Aura:New())
end
-- Has any stealable aura

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

Loading…
Cancel
Save