Add list registering, add InCombatOdds()

pull/1/head
4n0n 2 years ago
parent a029f46b99
commit 5547bf37e1
  1. 1
      scripts/subtlety.lua
  2. 64
      src/ObjectManager/ObjectManager.lua
  3. 24
      src/Unit/Unit.lua
  4. 11
      src/_bastion.lua

@ -2040,6 +2040,7 @@ Stealth:CastableIf(
)
SubModulue:Sync(function()
print(Player:GetEnemies(10))
DefaultAPL:Execute()
end)

@ -7,7 +7,7 @@ ObjectManager.__index = ObjectManager
function ObjectManager:New()
local self = setmetatable({}, ObjectManager)
self._objects = {}
self._lists = {}
self.enemies = Bastion.List:New()
self.friends = Bastion.List:New()
@ -17,15 +17,54 @@ function ObjectManager:New()
return self
end
-- Register a custom list with a callback
function ObjectManager:RegisterList(name, cb)
if self._lists[name] then
return false
end
self._lists[name] = {
list = Bastion.List:New(),
cb = cb
}
return self._lists[name].list
end
-- reset custom lists
function ObjectManager:ResetLists()
for _, list in pairs(self._lists) do
list.list:clear()
end
end
-- Refresh custom lists
function ObjectManager:EnumLists(object)
for _, list in pairs(self._lists) do
local r = list.cb(object)
if r then
list.list:push(r)
end
end
end
-- Get a list
function ObjectManager:GetList(name)
return self._lists[name].list
end
function ObjectManager:Refresh()
self.enemies:clear()
self.friends:clear()
self.activeEnemies:clear()
self.explosives:clear()
self:ResetLists()
local objects = Objects()
for _, object in pairs(objects) do
self:EnumLists(object)
if ObjectType(object) == 5 or ObjectType(object) == 6 then
local unit = Bastion.UnitManager:GetObject(ObjectGUID(object))
if not unit then
@ -40,7 +79,7 @@ function ObjectManager:Refresh()
elseif unit:IsEnemy() then
self.enemies:push(unit)
if unit:IsAffectingCombat() then
if unit:InCombatOdds() > 80 then
self.activeEnemies:push(unit)
end
end
@ -49,3 +88,24 @@ function ObjectManager:Refresh()
end
return ObjectManager
-- -- Register a list of objects that are training dummies
-- local dummies = Bastion.ObjectManager:RegisterList('dummies', function(object)
-- if ObjectType(object) == 5 or ObjectType(object) == 6 then
-- local unit = Bastion.UnitManager:GetObject(ObjectGUID(object))
-- if not unit then
-- unit = Bastion.Unit:New(object)
-- Bastion.UnitManager:SetObject(unit)
-- end
-- if unit:GetID() == 198594 then
-- return unit
-- end
-- end
-- end)
-- dummies:each(function(dummy)
-- print(dummy:GetName())
-- end)

@ -12,6 +12,7 @@ local Unit = {
swings_since_sht = 0,
last_off_attack = 0,
last_main_attack = 0,
last_combat_time = 0,
}
function Unit:__index(k)
@ -386,7 +387,7 @@ function Unit:GetEnemies(range)
Bastion.UnitManager:EnumEnemies(function(unit)
if not self:IsUnit(unit) and unit:GetDistance(self) <= range and unit:IsAlive() and self:CanSee(unit) and
unit:IsEnemy() and unit:IsAffectingCombat() then
unit:IsEnemy() then
count = count + 1
end
end)
@ -627,17 +628,20 @@ end
-- Set combat time if affecting combat and return the difference between now and the last time
function Unit:GetCombatTime()
if self:IsAffectingCombat() then
self.last_combat_time = GetTime()
elseif not self:IsAffectingCombat() and self.last_combat_time then
self.last_combat_time = nil
end
return GetTime() - self.last_combat_time
end
if not self.last_combat_time then
return 0
end
function Unit:SetLastCombatTime(time)
self.last_combat_time = time
end
return GetTime() - self.last_combat_time
-- Get combat odds (if the last combat time is less than 1 minute ago return 1 / time, else return 0)
-- the closer to 0 the more likely the unit is to be in combat (0 = 100%) 60 = 0%
function Unit:InCombatOdds()
local time = self:GetCombatTime()
local percent = 1 - (time / 60)
return percent * 100
end
-- Get units gcd time

@ -83,6 +83,17 @@ Bastion.EventManager:RegisterWoWEvent("UNIT_SPELLCAST_SUCCEEDED", function(...)
end
end)
Bastion.EventManager:RegisterWoWEvent("COMBAT_LOG_EVENT_UNFILTERED", function()
local _, subtype, _, sourceGUID, sourceName, _, _, destGUID, destName, destFlags, _, spellID, spellName, _, amount, interrupt, a, b, c, d, offhand, multistrike = CombatLogGetCurrentEventInfo()
local u = Bastion.UnitManager[sourceGUID]
local u2 = Bastion.UnitManager[destGUID]
local t = GetTime()
u:SetLastCombatTime(t)
u2:SetLastCombatTime(t)
end)
Bastion.Ticker = C_Timer.NewTicker(0.1, function()
if not Bastion.CombatTimer:IsRunning() and UnitAffectingCombat("player") then
Bastion.CombatTimer:Start()

Loading…
Cancel
Save