From febee39182925948a8d45e66e4f7413adfa7567c Mon Sep 17 00:00:00 2001 From: 4n0n <4n0n@tinkr.site> Date: Thu, 3 Aug 2023 11:11:44 -0500 Subject: [PATCH] Add highest/leastof functions to auratable, remove print --- src/AuraTable/AuraTable.lua | 159 +++++++++++++++++++++++++++++++++++- 1 file changed, 158 insertions(+), 1 deletion(-) diff --git a/src/AuraTable/AuraTable.lua b/src/AuraTable/AuraTable.lua index 2959fb9..b7e7a2c 100644 --- a/src/AuraTable/AuraTable.lua +++ b/src/AuraTable/AuraTable.lua @@ -444,6 +444,9 @@ function AuraTable:FindLongestOf(spells) return spells:reduce(function(acc, cur) local aura = self:Find(cur) if aura:IsValid() then + if not acc:IsValid() then + return aura + end if aura:GetRemainingTime() > acc:GetRemainingTime() then return aura end @@ -459,7 +462,9 @@ function AuraTable:FindLongestOfMy(spells) return spells:reduce(function(acc, cur) local aura = self:FindMy(cur) if aura:IsValid() then - print(aura:GetRemainingTime(), acc:GetRemainingTime()) + if not acc:IsValid() then + return aura + end if aura:GetRemainingTime() > acc:GetRemainingTime() then return aura end @@ -475,6 +480,9 @@ function AuraTable:FindLongestOfTheirs(spells) return spells:reduce(function(acc, cur) local aura = self:FindTheirs(cur) if aura:IsValid() then + if not acc:IsValid() then + return aura + end if aura:GetRemainingTime() > acc:GetRemainingTime() then return aura end @@ -491,6 +499,9 @@ function AuraTable:FindLongestOfFrom(spells, source) return spells:reduce(function(acc, cur) local aura = self:FindFrom(cur, source) if aura:IsValid() then + if not acc:IsValid() then + return aura + end if aura:GetRemainingTime() > acc:GetRemainingTime() then return aura end @@ -572,6 +583,152 @@ function AuraTable:FindShortestOfFrom(spells, source) end, Bastion.Aura:New()) end +-- FindMostOf +---@param spells List +---@return Aura +function AuraTable:FindMostOf(spells) + return spells:reduce(function(acc, cur) + local aura = self:Find(cur) + if aura:IsValid() then + if not acc:IsValid() then + return aura + end + if aura:GetCount() > acc:GetCount() then + return aura + end + end + return acc + end, Bastion.Aura:New()) +end + +-- FindMostOfMy +---@param spells List +---@return Aura +function AuraTable:FindMostOfMy(spells) + return spells:reduce(function(acc, cur) + local aura = self:FindMy(cur) + if aura:IsValid() then + if not acc:IsValid() then + return aura + end + if aura:GetCount() > acc:GetCount() then + return aura + end + end + return acc + end, Bastion.Aura:New()) +end + +-- FindMostOfTheirs +---@param spells List +---@return Aura +function AuraTable:FindMostOfTheirs(spells) + return spells:reduce(function(acc, cur) + local aura = self:FindTheirs(cur) + if aura:IsValid() then + if not acc:IsValid() then + return aura + end + if aura:GetCount() > acc:GetCount() then + return aura + end + end + return acc + end, Bastion.Aura:New()) +end + +-- FindMostOfFrom +---@param spells List +---@param source Unit +---@return Aura +function AuraTable:FindMostOfFrom(spells, source) + return spells:reduce(function(acc, cur) + local aura = self:FindFrom(cur, source) + if aura:IsValid() then + if not acc:IsValid() then + return aura + end + if aura:GetCount() > acc:GetCount() then + return aura + end + end + return acc + end, Bastion.Aura:New()) +end + +-- FindLeastOf +---@param spells List +---@return Aura +function AuraTable:FindLeastOf(spells) + return spells:reduce(function(acc, cur) + local aura = self:Find(cur) + if aura:IsValid() then + if not acc:IsValid() then + return aura + end + if aura:GetCount() < acc:GetCount() then + return aura + end + end + return acc + end, Bastion.Aura:New()) +end + +-- FindLeastOfMy +---@param spells List +---@return Aura +function AuraTable:FindLeastOfMy(spells) + return spells:reduce(function(acc, cur) + local aura = self:FindMy(cur) + if aura:IsValid() then + if not acc:IsValid() then + return aura + end + if aura:GetCount() < acc:GetCount() then + return aura + end + end + return acc + end, Bastion.Aura:New()) +end + +-- FindLeastOfTheirs +---@param spells List +---@return Aura +function AuraTable:FindLeastOfTheirs(spells) + return spells:reduce(function(acc, cur) + local aura = self:FindTheirs(cur) + if aura:IsValid() then + if not acc:IsValid() then + return aura + end + if aura:GetCount() < acc:GetCount() then + return aura + end + end + return acc + end, Bastion.Aura:New()) +end + +-- FindLeastOfFrom +---@param spells List +---@param source Unit +---@return Aura +function AuraTable:FindLeastOfFrom(spells, source) + return spells:reduce(function(acc, cur) + local aura = self:FindFrom(cur, source) + if aura:IsValid() then + if not acc:IsValid() then + return aura + end + if aura:GetCount() < acc:GetCount() then + return aura + end + end + return acc + end, Bastion.Aura:New()) +end + -- Has any stealable aura ---@return boolean function AuraTable:HasAnyStealableAura()