You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

160 lines
5.9 KiB

4 years ago
local Details = _G.Details
local addonName, Details222 = ...
4 years ago
3 years ago
local plater_integration_frame = CreateFrame("frame", "DetailsPlaterFrame", UIParent, "BackdropTemplate")
4 years ago
plater_integration_frame.DamageTaken = {}
3 years ago
--aprox. 6 updates per second
4 years ago
local CONST_REALTIME_UPDATE_TIME = 0.166
3 years ago
--how many samples to store, 30 x .166 aprox 5 seconds buffer
4 years ago
local CONST_BUFFER_SIZE = 30
3 years ago
--Dps division factor
4 years ago
PLATER_DPS_SAMPLE_SIZE = CONST_BUFFER_SIZE * CONST_REALTIME_UPDATE_TIME
3 years ago
--separate CLEU events from the Tick event for performance
plater_integration_frame.OnTickFrame = CreateFrame("frame", "DetailsPlaterFrameOnTicker", UIParent, "BackdropTemplate")
4 years ago
3 years ago
--on tick function
plater_integration_frame.OnTickFrameFunc = function(self, deltaTime)
4 years ago
if (self.NextUpdate < 0) then
3 years ago
for targetGUID, damageTable in pairs(plater_integration_frame.DamageTaken) do
4 years ago
3 years ago
--total damage
4 years ago
local totalDamage = damageTable.TotalDamageTaken
local totalDamageFromPlayer = damageTable.TotalDamageTakenFromPlayer
3 years ago
--damage on this update
4 years ago
local damageOnThisUpdate = totalDamage - damageTable.LastTotalDamageTaken
local damageOnThisUpdateFromPlayer = totalDamageFromPlayer - damageTable.LastTotalDamageTakenFromPlayer
3 years ago
--update the last damage taken
4 years ago
damageTable.LastTotalDamageTaken = totalDamage
damageTable.LastTotalDamageTakenFromPlayer = totalDamageFromPlayer
3 years ago
--sum the current damage
4 years ago
damageTable.CurrentDamage = damageTable.CurrentDamage + damageOnThisUpdate
damageTable.CurrentDamageFromPlayer = damageTable.CurrentDamageFromPlayer + damageOnThisUpdateFromPlayer
3 years ago
--add to the buffer the damage added
table.insert(damageTable.RealTimeBuffer, 1, damageOnThisUpdate)
table.insert(damageTable.RealTimeBufferFromPlayer, 1, damageOnThisUpdateFromPlayer)
4 years ago
3 years ago
--remove the damage from the buffer
local damageRemoved = tremove(damageTable.RealTimeBuffer, CONST_BUFFER_SIZE + 1)
4 years ago
if (damageRemoved) then
3 years ago
damageTable.CurrentDamage = max(damageTable.CurrentDamage - damageRemoved, 0)
4 years ago
end
3 years ago
local damageRemovedFromPlayer = tremove(damageTable.RealTimeBufferFromPlayer, CONST_BUFFER_SIZE + 1)
4 years ago
if (damageRemovedFromPlayer) then
3 years ago
damageTable.CurrentDamageFromPlayer = max(damageTable.CurrentDamageFromPlayer - damageRemovedFromPlayer, 0)
4 years ago
end
end
--update time
self.NextUpdate = CONST_REALTIME_UPDATE_TIME
else
self.NextUpdate = self.NextUpdate - deltaTime
end
end
3 years ago
--parse the damage taken by unit
4 years ago
function plater_integration_frame.AddDamageToGUID (sourceGUID, targetGUID, time, amount)
local damageTable = plater_integration_frame.DamageTaken [targetGUID]
if (not damageTable) then
plater_integration_frame.DamageTaken [targetGUID] = {
LastEvent = time,
TotalDamageTaken = amount,
TotalDamageTakenFromPlayer = 0,
--for real time
RealTimeBuffer = {},
RealTimeBufferFromPlayer = {},
LastTotalDamageTaken = 0,
LastTotalDamageTakenFromPlayer = 0,
CurrentDamage = 0,
CurrentDamageFromPlayer = 0,
}
3 years ago
--is the damage from the player it self?
4 years ago
if (sourceGUID == plater_integration_frame.PlayerGUID) then
plater_integration_frame.DamageTaken [targetGUID].TotalDamageTakenFromPlayer = amount
end
else
damageTable.LastEvent = time
damageTable.TotalDamageTaken = damageTable.TotalDamageTaken + amount
if (sourceGUID == plater_integration_frame.PlayerGUID) then
damageTable.TotalDamageTakenFromPlayer = damageTable.TotalDamageTakenFromPlayer + amount
end
end
end
3 years ago
plater_integration_frame:SetScript("OnEvent", function(self)
4 years ago
local time, token, hidding, sourceGUID, sourceName, sourceFlag, sourceFlag2, targetGUID, targetName, targetFlag, targetFlag2, spellID, spellName, spellType, amount, overKill, school, resisted, blocked, absorbed, isCritical = CombatLogGetCurrentEventInfo()
--damage taken by the GUID unit
4 years ago
if (token == "SPELL_DAMAGE" or token == "SPELL_PERIODIC_DAMAGE" or token == "RANGE_DAMAGE" or token == "DAMAGE_SHIELD") then
plater_integration_frame.AddDamageToGUID (sourceGUID, targetGUID, time, amount)
elseif (token == "SWING_DAMAGE") then
--the damage is passed in the spellID argument position
plater_integration_frame.AddDamageToGUID (sourceGUID, targetGUID, time, spellID)
end
end)
function Details:RefreshPlaterIntegration()
if (Plater and Details.plater.realtime_dps_enabled or Details.plater.realtime_dps_player_enabled or Details.plater.damage_taken_enabled) then
3 years ago
--wipe the cache
Details:Destroy(plater_integration_frame.DamageTaken)
4 years ago
3 years ago
--read cleu events
plater_integration_frame:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
4 years ago
3 years ago
--start the real time dps updater
4 years ago
plater_integration_frame.OnTickFrame.NextUpdate = CONST_REALTIME_UPDATE_TIME
3 years ago
plater_integration_frame.OnTickFrame:SetScript("OnUpdate", plater_integration_frame.OnTickFrameFunc)
4 years ago
3 years ago
--cache the player serial
plater_integration_frame.PlayerGUID = UnitGUID("player")
4 years ago
3 years ago
--cancel the timer if already have one
if (plater_integration_frame.CleanUpTimer and not plater_integration_frame.CleanUpTimer:IsCancelled()) then
4 years ago
plater_integration_frame.CleanUpTimer:Cancel()
end
3 years ago
--cleanup the old tables
plater_integration_frame.CleanUpTimer = C_Timer.NewTicker(10, function()
4 years ago
local now = time()
3 years ago
for GUID, damageTable in pairs(plater_integration_frame.DamageTaken) do
4 years ago
if (damageTable.LastEvent + 9.9 < now) then
plater_integration_frame.DamageTaken [GUID] = nil
end
end
end)
else
3 years ago
--unregister the cleu
4 years ago
plater_integration_frame:UnregisterEvent ("COMBAT_LOG_EVENT_UNFILTERED")
3 years ago
--stop the real time updater
plater_integration_frame.OnTickFrame:SetScript("OnUpdate", nil)
4 years ago
3 years ago
--stop the cleanup process
if (plater_integration_frame.CleanUpTimer and not plater_integration_frame.CleanUpTimer:IsCancelled()) then
4 years ago
plater_integration_frame.CleanUpTimer:Cancel()
end
end
end