Update UnitManager to enum enemies more efficiently. Update resto for natures cure/aoe purge logic

4n0n-patch-1
4n0n 2 years ago
parent 0b11028caf
commit 26d1d2430b
  1. 79
      scripts/restodruid.lua
  2. 55
      src/UnitManager/UnitManager.lua

@ -139,11 +139,12 @@ local Lowest = Bastion.UnitManager:CreateCustomUnit('lowest', function(unit)
return lowest return lowest
end) end)
local DispelTarget = Bastion.UnitManager:CreateCustomUnit('dispel', function() local DispelTarget = Bastion.UnitManager:CreateCustomUnit('rejuv', function(unit)
local dispelTarget = nil local lowest = nil
local lowestHP = math.huge
Bastion.UnitManager:EnumFriends(function(unit) Bastion.UnitManager:EnumFriends(function(unit)
if Player:GetDistance(unit) > 40 then if unit:IsDead() then
return false return false
end end
@ -151,24 +152,57 @@ local DispelTarget = Bastion.UnitManager:CreateCustomUnit('dispel', function()
return false return false
end end
if unit:IsDead() then if Player:GetDistance(unit) > 40 then
return false return false
end end
if unit:GetAuras():HasAnyDispelableAura(NaturesCure) then if not unit:IsDead() and Player:CanSee(unit) and
return true unit:GetAuras():HasAnyDispelableAura(NaturesCure) then
end
return false local hp = unit:GetHP()
if hp < lowestHP then
lowest = unit
lowestHP = hp
end
end
end) end)
if not dispelTarget then if lowest == nil then
dispelTarget = Player lowest = None
end end
return dispelTarget return lowest
end) end)
-- local PurgeTarget = Bastion.UnitManager:CreateCustomUnit('purge', function(unit)
-- local purge = nil
-- Bastion.UnitManager:EnumEnemies(function(unit)
-- if unit:IsDead() then
-- return false
-- end
-- if not Player:CanSee(unit) then
-- return false
-- end
-- if Player:GetDistance(unit) > 40 then
-- return false
-- end
-- if not unit:IsDead() and Player:CanSee(unit) and
-- unit:GetAuras():HasAnyStealableAura() then
-- purge = unit
-- end
-- end)
-- if purge == nil then
-- purge = None
-- end
-- return purge
-- end)
local Tank = Bastion.UnitManager:CreateCustomUnit('tank', function(unit) local Tank = Bastion.UnitManager:CreateCustomUnit('tank', function(unit)
local tank = nil local tank = nil
@ -277,7 +311,7 @@ local SwiftmendUnit = Bastion.UnitManager:CreateCustomUnit('swiftmend', function
if lowest == nil then if lowest == nil then
lowest = Player lowest = None
end end
return lowest return lowest
@ -319,10 +353,17 @@ DefaultAPL:AddAction(
DefaultAPL:AddSpell( DefaultAPL:AddSpell(
NaturesCure:CastableIf(function(self) NaturesCure:CastableIf(function(self)
return DispelTarget:Exists() and self:IsKnownAndUsable() and not Player:IsCastingOrChanneling() and return DispelTarget:Exists() and self:IsKnownAndUsable() and not Player:IsCastingOrChanneling() and
self:IsInRange(DispelTarget) and DispelTarget:GetAuras():HasAnyDispelableAura(self) self:IsInRange(DispelTarget) and DispelTarget:GetAuras():HasAnyDispelableAura(NaturesCure)
end):SetTarget(DispelTarget) end):SetTarget(DispelTarget)
) )
DefaultAPL:AddSpell(
Soothe:CastableIf(function(self)
return Target:Exists() and self:IsKnownAndUsable() and not Player:IsCastingOrChanneling() and
self:IsInRange(Target) and Target:GetAuras():HasAnyStealableAura()
end):SetTarget(Target)
)
DefaultAPL:AddSpell( DefaultAPL:AddSpell(
NaturesSwiftness:CastableIf(function(self) NaturesSwiftness:CastableIf(function(self)
return Lowest:Exists() and self:IsKnownAndUsable() and not Player:IsCastingOrChanneling() return Lowest:Exists() and self:IsKnownAndUsable() and not Player:IsCastingOrChanneling()
@ -459,7 +500,8 @@ DefaultAPL:AddSpell(
and Player:CanSee(Target) and and Player:CanSee(Target) and
( (
not Target:GetAuras():FindMy(SunfireAura):IsUp() or not Target:GetAuras():FindMy(SunfireAura):IsUp() or
Target:GetAuras():FindMy(SunfireAura):GetRemainingTime() <= 5.4) Target:GetAuras():FindMy(SunfireAura):GetRemainingTime() <= 5.4) and Target:IsHostile() and
Target:IsAffectingCombat()
end):SetTarget(Target) end):SetTarget(Target)
) )
@ -469,21 +511,24 @@ DefaultAPL:AddSpell(
and Player:CanSee(Target) and and Player:CanSee(Target) and
( (
not Target:GetAuras():FindMy(MoonfireAura):IsUp() or not Target:GetAuras():FindMy(MoonfireAura):IsUp() or
Target:GetAuras():FindMy(MoonfireAura):GetRemainingTime() <= 5.4) Target:GetAuras():FindMy(MoonfireAura):GetRemainingTime() <= 5.4) and Target:IsHostile() and
Target:IsAffectingCombat()
end):SetTarget(Target) end):SetTarget(Target)
) )
DefaultAPL:AddSpell( DefaultAPL:AddSpell(
Starsurge:CastableIf(function(self) Starsurge:CastableIf(function(self)
return Target:Exists() and self:IsKnownAndUsable() and not Player:IsCastingOrChanneling() return Target:Exists() and self:IsKnownAndUsable() and not Player:IsCastingOrChanneling()
and Player:CanSee(Target) and Player:CanSee(Target) and Target:IsHostile() and
Target:IsAffectingCombat()
end):SetTarget(Target) end):SetTarget(Target)
) )
DefaultAPL:AddSpell( DefaultAPL:AddSpell(
Wrath:CastableIf(function(self) Wrath:CastableIf(function(self)
return Target:Exists() and self:IsKnownAndUsable() and not Player:IsCastingOrChanneling() return Target:Exists() and self:IsKnownAndUsable() and not Player:IsCastingOrChanneling()
and Player:CanSee(Target) and not Player:IsMoving() and Player:CanSee(Target) and not Player:IsMoving() and Target:IsHostile() and
Target:IsAffectingCombat()
end):SetTarget(Target) end):SetTarget(Target)
) )

@ -1,5 +1,7 @@
local Tinkr, Bastion = ... local Tinkr, Bastion = ...
local ObjectManager = Tinkr.Util.ObjectManager
local Unit = Bastion.Unit local Unit = Bastion.Unit
local prefixes = { local prefixes = {
@ -49,6 +51,7 @@ end
local UnitManager = { local UnitManager = {
units = {}, units = {},
customUnits = {}, customUnits = {},
objects = {},
cache = {} cache = {}
} }
@ -70,6 +73,10 @@ function UnitManager:__index(k)
return self.customUnits[k].unit return self.customUnits[k].unit
end end
if self.objects[k] then
return self.objects[k]
end
-- if not Validate(k) then -- if not Validate(k) then
-- error("UnitManager:Get - Invalid token: " .. k) -- error("UnitManager:Get - Invalid token: " .. k)
-- end -- end
@ -78,6 +85,8 @@ function UnitManager:__index(k)
self.units[k] = Unit:New(k) self.units[k] = Unit:New(k)
end end
return self.units[k] return self.units[k]
end end
@ -107,6 +116,14 @@ function UnitManager:Get(token)
return self.units[token] return self.units[token]
end end
function UnitManager:GetObject(guid)
return self.objects[guid]
end
function UnitManager:SetObject(unit)
self.objects[unit:GetGUID()] = unit
end
-- Create a custom unit and cache it for .5 seconds -- Create a custom unit and cache it for .5 seconds
function UnitManager:CreateCustomUnit(token, cb) function UnitManager:CreateCustomUnit(token, cb)
local unit = cb() local unit = cb()
@ -160,14 +177,18 @@ end
-- Enum Enemies (object manager) -- Enum Enemies (object manager)
function UnitManager:EnumEnemies(cb) function UnitManager:EnumEnemies(cb)
local objs = Objects() for obj in ObjectManager:Objects() do
for i = 1, #objs do
local obj = objs[i]
if ObjectType(obj) == 5 or ObjectType(obj) == 6 then if ObjectType(obj) == 5 or ObjectType(obj) == 6 then
local unit = Unit:New(obj) local unit = UnitManager:GetObject(ObjectGUID(obj))
if unit:IsHostile() and unit:IsAffectingCombat() and unit:IsAlive() and unit:CanSee(self) if not unit then
unit = Unit:New(obj)
UnitManager:SetObject(unit)
end
if unit:IsHostile() and unit:IsAffectingCombat() and unit:IsAlive()
then then
cb(unit) if cb(unit) then
break
end
end end
end end
end end
@ -179,8 +200,26 @@ function UnitManager:EnumUnits(cb)
for i = 1, #objs do for i = 1, #objs do
local obj = objs[i] local obj = objs[i]
if ObjectType(obj) == 5 or ObjectType(obj) == 6 then if ObjectType(obj) == 5 or ObjectType(obj) == 6 then
local unit = Unit:New(obj) local unit = UnitManager:GetObject(ObjectGUID(obj))
cb(unit) if not unit then
unit = Unit:New(obj)
UnitManager:SetObject(unit)
end
if cb(unit) then
break
end
end
end
end
-- Enum enemies (nameplates)
function UnitManager:EnumNameplates(cb)
for i = 1, 50 do
local unit = self:Get('nameplate' .. i)
if unit:IsValid() then
if cb(unit) then
break
end
end end
end end
end end

Loading…
Cancel
Save