From a99e71dd8e1c6f2f62b6790fe0cef7be3d05d794 Mon Sep 17 00:00:00 2001 From: 4n0n <4n0n@tinkr.site> Date: Thu, 3 Aug 2023 09:25:44 -0500 Subject: [PATCH] Aura table updates --- src/AuraTable/AuraTable.lua | 135 ++++++++++++++++++++++++++++++++++++ 1 file changed, 135 insertions(+) diff --git a/src/AuraTable/AuraTable.lua b/src/AuraTable/AuraTable.lua index 2eceb38..2959fb9 100644 --- a/src/AuraTable/AuraTable.lua +++ b/src/AuraTable/AuraTable.lua @@ -437,6 +437,141 @@ function AuraTable:FindAnyFrom(spells, source) end, Bastion.Aura:New()) end +-- FindLongestOf +---@param spells List +---@return Aura +function AuraTable:FindLongestOf(spells) + return spells:reduce(function(acc, cur) + local aura = self:Find(cur) + if aura:IsValid() then + if aura:GetRemainingTime() > acc:GetRemainingTime() then + return aura + end + end + return acc + end, Bastion.Aura:New()) +end + +-- FindLongestOfMy +---@param spells List +---@return Aura +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 aura:GetRemainingTime() > acc:GetRemainingTime() then + return aura + end + end + return acc + end, Bastion.Aura:New()) +end + +-- FindLongestOfTheirs +---@param spells List +---@return Aura +function AuraTable:FindLongestOfTheirs(spells) + return spells:reduce(function(acc, cur) + local aura = self:FindTheirs(cur) + if aura:IsValid() then + if aura:GetRemainingTime() > acc:GetRemainingTime() then + return aura + end + end + return acc + end, Bastion.Aura:New()) +end + +-- FindLongestOfFrom +---@param spells List +---@param source Unit +---@return Aura +function AuraTable:FindLongestOfFrom(spells, source) + return spells:reduce(function(acc, cur) + local aura = self:FindFrom(cur, source) + if aura:IsValid() then + if aura:GetRemainingTime() > acc:GetRemainingTime() then + return aura + end + end + return acc + end, Bastion.Aura:New()) +end + +-- FindShortestOf +---@param spells List +---@return Aura +function AuraTable:FindShortestOf(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 + end + return acc + end, Bastion.Aura:New()) +end + +-- FindShortestOfMy +---@param spells List +---@return Aura +function AuraTable:FindShortestOfMy(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:GetRemainingTime() < acc:GetRemainingTime() then + return aura + end + end + return acc + end, Bastion.Aura:New()) +end + +-- FindShortestOfTheirs +---@param spells List +---@return Aura +function AuraTable:FindShortestOfTheirs(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 + end + return acc + end, Bastion.Aura:New()) +end + +-- FindShortestOfFrom +---@param spells List +---@param source Unit +---@return Aura +function AuraTable:FindShortestOfFrom(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 + end + return acc + end, Bastion.Aura:New()) +end + -- Has any stealable aura ---@return boolean function AuraTable:HasAnyStealableAura()