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