Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- do
- -- New TTD, hopefully more aggressive and accurate than old TTD.
- Hekili.TTD = Hekili.TTD or {}
- local db = Hekili.TTD
- local recycle = {}
- local function EliminateEnemy( guid )
- local enemy = db[ guid ]
- if not enemy then return end
- db[ guid ] = nil
- twipe( enemy )
- tinsert( recycle, enemy )
- end
- local function UpdateEnemy( guid, healthPct, time )
- local enemy = db[ guid ]
- time = time or GetTime()
- if not enemy then
- -- This is the first time we've seen the enemy.
- enemy = tremove( recycle, 1 ) or {}
- db[ guid ] = enemy
- enemy.firstSeen = time
- enemy.firstHealth = healthPct
- enemy.lastSeen = time
- enemy.lastHealth = healthPct
- enemy.rate = 0
- enemy.n = 0
- return
- end
- local difference = enemy.lastHealth - healthPct
- -- We don't recalculate the rate when enemies heal.
- if difference > 0 then
- local elapsed = time - enemy.lastSeen
- -- If this is our first health difference, just store it.
- if enemy.n == 0 then
- enemy.rate = difference / elapsed
- print( "initial rate is", enemy.rate )
- enemy.n = 1
- else
- local newRate = enemy.rate * enemy.n + ( difference / elapsed )
- enemy.n = enemy.n + 1
- enemy.rate = newRate / enemy.n
- end
- enemy.lastSeen = time
- end
- enemy.lastHealth = healthPct
- end
- local DEFAULT_TTD = 15
- local INF = ( 1 / 0 )
- function Hekili:GetTTD( unit )
- local guid = UnitExists( unit ) and UnitCanAttack( "player", unit ) and UnitGUID( unit )
- if not guid then return INF end
- local enemy = db[ guid ]
- if not enemy then return INF end
- -- Don't have enough data to predict yet.
- if enemy.rate == 0 then return INF, enemy.n end
- local health, healthMax = UnitHealth( unit ), UnitHealthMax( unit )
- local healthPct = health / healthMax
- if healthPct == 0 then return 0, enemy.n end
- return ceil( healthPct / enemy.rate ), enemy.n
- end
- function Hekili:GetGreatestTTD()
- local time = 0
- for k, v in pairs( db ) do
- if v.n > 0 then time = max( time, ceil( v.lastHealth / v.rate ) ) end
- end
- return time
- end
- function Hekili:ExpireTTDs( all )
- local now = GetTime()
- for k, v in pairs( db ) do
- if all or now - v.lastSeen > 10 then EliminateEnemy( k ) end
- end
- end
- local trackedUnits = { "target", "boss1", "boss2", "boss3", "boss4", "boss5", "focus" }
- local seen = {}
- local UpdateTTDs
- UpdateTTDs = function()
- twipe( seen )
- local now = GetTime()
- for i, unit in ipairs( trackedUnits ) do
- local guid = UnitExists( unit ) and UnitThreatSituation( "player", unit ) and not UnitIsDead( unit ) and UnitGUID( unit )
- if guid then
- local health, healthMax = UnitHealth( unit ), UnitHealthMax( unit )
- UpdateEnemy( guid, health / healthMax, now )
- seen[ guid ] = true
- end
- end
- for unit, guid in pairs( npGUIDs ) do
- if not seen[ guid ] and UnitThreatSituation( "player", unit ) then
- local health, healthMax = UnitHealth( unit ), UnitHealthMax( unit )
- UpdateEnemy( guid, health / healthMax, now )
- seen[ guid ] = true
- end
- end
- C_Timer.After( 0.25, UpdateTTDs )
- end
- C_Timer.After( 0.25, UpdateTTDs )
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement