added function Unit:GetFriends(range)

added function Unit:GetFriends(range)
pull/14/head
CiscOH 2 years ago
parent 0b37f1dc27
commit e18e2d07cd
  1. 22
      src/Unit/Unit.lua

@ -522,6 +522,28 @@ function Unit:IsInterruptibleAt(percent, ignoreInterruptible)
return false return false
end 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 -- Get the number of enemies in a given range of the unit and cache the result for .5 seconds
---@param range number ---@param range number
---@return number ---@return number

Loading…
Cancel
Save