From e18e2d07cd1dd21d3a22a61b0d00cf8f7bfba52f Mon Sep 17 00:00:00 2001 From: CiscOH Date: Sun, 6 Aug 2023 17:29:28 +0000 Subject: [PATCH] added function Unit:GetFriends(range) added function Unit:GetFriends(range) --- src/Unit/Unit.lua | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/Unit/Unit.lua b/src/Unit/Unit.lua index 581a964..45ea80b 100644 --- a/src/Unit/Unit.lua +++ b/src/Unit/Unit.lua @@ -522,6 +522,28 @@ function Unit:IsInterruptibleAt(percent, ignoreInterruptible) return false end +-- Get the number of friends in a given range of the unit and cache the result for .5 seconds +---@param range number +---@return number +function Unit:GetFriends(range) + local friends = self.cache:Get("friends_" .. range) + if friends then + return friends + end + + local count = 0 + + Bastion.UnitManager:EnumFriends(function(unit) + if not self:IsUnit(unit) and self:IsWithinCombatDistance(unit, range) and unit:IsAlive() and self:CanSee(unit) and + unit:IsFriendly() then + count = count + 1 + end + end) + + self.cache:Set("friends_" .. range, count, .5) + return count +end + -- Get the number of enemies in a given range of the unit and cache the result for .5 seconds ---@param range number ---@return number