Skip to content

Instantly share code, notes, and snippets.

@benphelps
Created October 30, 2013 04:01
Show Gist options
  • Save benphelps/7227053 to your computer and use it in GitHub Desktop.
Save benphelps/7227053 to your computer and use it in GitHub Desktop.
-- ProbablyEngine Rotations - https://probablyengine.com/
-- Released under modified BSD, see attached LICENSE.
local band = bit.band
local HostileEvents = {
['SWING_DAMAGE'] = true,
['SWING_MISSED'] = true,
['RANGE_DAMAGE'] = true,
['RANGE_MISSED'] = true,
['SPELL_DAMAGE'] = true,
['SPELL_PERIODIC_DAMAGE'] = true,
['SPELL_MISSED'] = true
}
ProbablyEngine.listener.register("COMBAT_LOG_EVENT_UNFILTERED", function(...)
local timeStamp, event, hideCaster, sourceGUID, sourceName, sourceFlags, sourceRaidFlags, destGUID, destName, destFlags, destRaidFlags, _ = ...
if sourceName and destName and sourceName ~= '' and destName ~= '' then
if HostileEvents[event] then
if band(destFlags, COMBATLOG_OBJECT_AFFILIATION_OUTSIDER) == 0 and band(sourceFlags, COMBATLOG_OBJECT_REACTION_FRIENDLY) == 0 then
ProbablyEngine.module.world.tagUnit(sourceGUID, sourceName, timeStamp)
--local damage = select(15, ...)
--ProbablyEngine.module.world.damageUnit(destGUID, damage)
elseif band(sourceFlags, COMBATLOG_OBJECT_AFFILIATION_OUTSIDER) == 0 and band(destFlags, COMBATLOG_OBJECT_REACTION_FRIENDLY) == 0 then
ProbablyEngine.module.world.tagUnit(destGUID, destName, timeStamp)
local damage = select(15, ...)
ProbablyEngine.module.world.damageUnit(destGUID, damage)
end
end
elseif (event == 'UNIT_DIED' or event == 'UNIT_DESTROYED' or event == 'UNIT_DISSIPATES') then
ProbablyEngine.module.world.killUnit(destGUID)
end
end)
-- ProbablyEngine Rotations - https://probablyengine.com/
-- Released under modified BSD, see attached LICENSE.
ProbablyEngine.module.register("world", {
current = 0,
expire = 15,
friendly = { },
enemy = { },
dead = { },
named = { },
healthCache = { },
healthCacheCount = { },
})
ProbablyEngine.module.world.aquireHealth = function(guid, maxHealth)
if maxHealth then health = UnitHealthMax else health = UnitHealth end
local inGroup = GetNumGroupMembers()
if inGroup then
if IsInRaid("player") then
for i=1,inGroup do
if guid == UnitGUID("RAID".. i .. "TARGET") then
return health("RAID".. i .. "TARGET")
end
end
else
for i=1,inGroup do
if guid == UnitGUID("PARTY".. i .. "TARGET") then
return health("PARTY".. i .. "TARGET")
end
end
if guid == UnitGUID("PLAYERTARGET") then
return health("PLAYERTARGET")
end
end
else
print(guid, UnitGUID("PLAYERTARGET"))
if guid == UnitGUID("PLAYERTARGET") then
return health("PLAYERTARGET")
end
end
-- All health checks failed, do we have a cache of this units health ?
if maxHealth then
if ProbablyEngine.module.world.healthCache[name] then
return ProbablyEngine.module.world.healthCache[name]
end
end
return false
end
ProbablyEngine.timer.register("updateCTHealth", function()
for guid,table in pairs(ProbablyEngine.module.world.enemy) do
local health = ProbablyEngine.module.world.aquireHealth(guid)
if health then
-- attempt to aquire max health again
if ProbablyEngine.module.world.enemy[guid]['maxHealth'] == false then
ProbablyEngine.module.world.enemy[guid]['maxHealth'] = ProbablyEngine.module.world.aquireHealth(guid, true)
end
ProbablyEngine.module.world.enemy[guid].health = health
end
end
end, 100)
ProbablyEngine.module.world.damageUnit = function(guid, damage)
if damage ~= nil and type(damage) == "number" then
if ProbablyEngine.module.world.enemy[guid] and ProbablyEngine.module.world.enemy[guid]['health'] then
local newHealth = ProbablyEngine.module.world.enemy[guid]['health'] - damage
if newHealth >= 0 then
ProbablyEngine.module.world.enemy[guid]['health'] = newHealth
end
end
end
end
ProbablyEngine.module.world.healthPredict = function(name, health)
end
ProbablyEngine.module.world.insert = function(guid, unitname, timestamp)
if ProbablyEngine.module.world.enemy[guid] == nil then
local maxHealth = ProbablyEngine.module.world.aquireHealth(guid, true)
local health = ProbablyEngine.module.world.aquireHealth(guid)
ProbablyEngine.module.world.enemy[guid] = { }
ProbablyEngine.module.world.enemy[guid]['maxHealth'] = maxHealth
ProbablyEngine.module.world.enemy[guid]['health'] = health
ProbablyEngine.module.world.enemy[guid]['name'] = unitname
if maxHealth then
-- we got a health value from aquire, store it for later usage
if ProbablyEngine.module.world.healthCacheCount[unitname] then
-- we've alreadt seen this type, average it
local currentAverage = ProbablyEngine.module.world.healthCache[unitname]
local currentCount = ProbablyEngine.module.world.healthCacheCount[unitname]
local newAverage = (currentAverage + maxHealth) / (currentCount + 1)
ProbablyEngine.module.world.healthCache[unitname] = newAverage
ProbablyEngine.module.world.healthCacheCount[unitname] = currentCount + 1
else
-- this is new to use, save it
ProbablyEngine.module.world.healthCache[unitname] = maxHealth
ProbablyEngine.module.world.healthCacheCount[unitname] = 1
end
end
end
end
ProbablyEngine.module.world.cleanCT = function()
ProbablyEngine.module.world.enemy = { }
end
ProbablyEngine.module.world.remove = function(guid)
ProbablyEngine.module.world.enemy[guid] = nil
end
ProbablyEngine.module.world.tagUnit = function(guid, name)
ProbablyEngine.module.world.insert(guid, name)
end
ProbablyEngine.module.world.killUnit = function(guid)
ProbablyEngine.module.world.remove(guid, name)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment