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.

581 lines
18 KiB

3 years ago
local Loc = LibStub("AceLocale-3.0"):GetLocale( "Details" )
4 years ago
--lua api
3 years ago
local tremove = table.remove
local tinsert = table.insert
local wipe = table.wipe
4 years ago
3 years ago
local Details = _G._detalhes
local combatClass = Details.combate
local segmentClass = Details.historico
local timeMachine = Details.timeMachine
4 years ago
------------------------------------------------------------------------------------------------------------------------------------------------------------------------
3 years ago
--API
4 years ago
3 years ago
--reset only the overall data
function Details:ResetSegmentOverallData()
return segmentClass:resetar_overall()
4 years ago
end
3 years ago
--reset segments and overall data
function Details:ResetSegmentData()
return segmentClass:resetar()
4 years ago
end
3 years ago
--returns the current active segment
function Details:GetCurrentCombat()
return Details.tabela_vigente
4 years ago
end
3 years ago
--returns a private table containing all stored segments
function Details:GetCombatSegments()
return Details.tabela_historico.tabelas
4 years ago
end
------------------------------------------------------------------------------------------------------------------------------------------------------------------------
3 years ago
--internal
4 years ago
3 years ago
function segmentClass:NovoHistorico()
4 years ago
local esta_tabela = {tabelas = {}}
3 years ago
setmetatable(esta_tabela, segmentClass)
4 years ago
return esta_tabela
end
3 years ago
function segmentClass:adicionar_overall (tabela)
4 years ago
local zoneName, zoneType = GetInstanceInfo()
3 years ago
if (zoneType ~= "none" and tabela:GetCombatTime() <= Details.minimum_overall_combat_time) then
4 years ago
return
end
3 years ago
if (Details.overall_clear_newboss) then
--only for raids
4 years ago
if (tabela.instance_type == "raid" and tabela.is_boss) then
3 years ago
if (Details.last_encounter ~= Details.last_encounter2) then
if (Details.debug) then
Details:Msg("(debug) new boss detected 'overall_clear_newboss' is true, cleaning overall data.")
4 years ago
end
3 years ago
for index, combat in ipairs(Details.tabela_historico.tabelas) do
4 years ago
combat.overall_added = false
end
3 years ago
segmentClass:resetar_overall()
4 years ago
end
end
end
3 years ago
4 years ago
if (tabela.overall_added) then
3 years ago
Details:Msg("error > attempt to add a segment already added > func historico:adicionar_overall()")
4 years ago
return
end
3 years ago
4 years ago
local mythicInfo = tabela.is_mythic_dungeon
if (mythicInfo) then
3 years ago
--do not add overall mythic+ dungeon segments
4 years ago
if (mythicInfo.TrashOverallSegment) then
3 years ago
Details:Msg("error > attempt to add a TrashOverallSegment > func historico:adicionar_overall()")
4 years ago
return
elseif (mythicInfo.OverallSegment) then
3 years ago
Details:Msg("error > attempt to add a OverallSegment > func historico:adicionar_overall()")
4 years ago
return
end
end
3 years ago
--store the segments added to the overall data
Details.tabela_overall.segments_added = Details.tabela_overall.segments_added or {}
4 years ago
local this_clock = tabela.data_inicio
3 years ago
local combatName = tabela:GetCombatName(true)
4 years ago
local combatTime = tabela:GetCombatTime()
local combatType = tabela:GetCombatType()
3 years ago
tinsert(Details.tabela_overall.segments_added, 1, {name = combatName, elapsed = combatTime, clock = this_clock, type = combatType})
if (#Details.tabela_overall.segments_added > 40) then
tremove(Details.tabela_overall.segments_added, 41)
4 years ago
end
3 years ago
if (Details.debug) then
Details:Msg("(debug) adding the segment to overall data: " .. (tabela:GetCombatName(true) or "no name") .. " with time of: " .. (tabela:GetCombatTime() or "no time"))
4 years ago
end
3 years ago
Details.tabela_overall = Details.tabela_overall + tabela
4 years ago
tabela.overall_added = true
3 years ago
if (not Details.tabela_overall.overall_enemy_name) then
Details.tabela_overall.overall_enemy_name = tabela.is_boss and tabela.is_boss.name or tabela.enemy
4 years ago
else
3 years ago
if (Details.tabela_overall.overall_enemy_name ~= (tabela.is_boss and tabela.is_boss.name or tabela.enemy)) then
Details.tabela_overall.overall_enemy_name = "-- x -- x --"
4 years ago
end
end
3 years ago
if (Details.tabela_overall.start_time == 0) then
Details.tabela_overall:SetStartTime (tabela.start_time)
Details.tabela_overall:SetEndTime (tabela.end_time)
4 years ago
else
3 years ago
Details.tabela_overall:SetStartTime (tabela.start_time - Details.tabela_overall:GetCombatTime())
Details.tabela_overall:SetEndTime (tabela.end_time)
4 years ago
end
3 years ago
if (Details.tabela_overall.data_inicio == 0) then
Details.tabela_overall.data_inicio = Details.tabela_vigente.data_inicio or 0
4 years ago
end
3 years ago
Details.tabela_overall:seta_data (Details._detalhes_props.DATA_TYPE_END)
Details:ClockPluginTickOnSegment()
4 years ago
3 years ago
for id, instance in Details:ListInstances() do
4 years ago
if (instance:IsEnabled()) then
if (instance:GetSegment() == -1) then
instance:ForceRefresh()
end
end
end
end
3 years ago
function Details:ScheduleAddCombatToOverall (combat) --deprecated (15/03/2019)
local canAdd = Details:CanAddCombatToOverall (combat)
4 years ago
if (canAdd) then
3 years ago
Details.schedule_add_to_overall = Details.schedule_add_to_overall or {}
tinsert(Details.schedule_add_to_overall, combat)
4 years ago
end
end
3 years ago
function Details:CanAddCombatToOverall (tabela)
--already added
4 years ago
if (tabela.overall_added) then
return false
end
3 years ago
--already scheduled to add
if (Details.schedule_add_to_overall) then --deprecated
for _, combat in ipairs(Details.schedule_add_to_overall) do
4 years ago
if (combat == tabela) then
return false
end
end
end
3 years ago
--special cases
4 years ago
local mythicInfo = tabela.is_mythic_dungeon
if (mythicInfo) then
3 years ago
--do not add overall mythic+ dungeon segments
4 years ago
if (mythicInfo.TrashOverallSegment) then
return false
3 years ago
4 years ago
elseif (mythicInfo.OverallSegment) then
return false
end
end
3 years ago
--raid boss - flag 0x1
if (bit.band(Details.overall_flag, 0x1) ~= 0) then
4 years ago
if (tabela.is_boss and tabela.instance_type == "raid" and not tabela.is_pvp) then
if (tabela:GetCombatTime() >= 30) then
return true
end
end
end
3 years ago
--raid trash - flag 0x2
if (bit.band(Details.overall_flag, 0x2) ~= 0) then
4 years ago
if (tabela.is_trash and tabela.instance_type == "raid") then
return true
end
end
3 years ago
--dungeon boss - flag 0x4
if (bit.band(Details.overall_flag, 0x4) ~= 0) then
4 years ago
if (tabela.is_boss and tabela.instance_type == "party" and not tabela.is_pvp) then
return true
end
end
3 years ago
--dungeon trash - flag 0x8
if (bit.band(Details.overall_flag, 0x8) ~= 0) then
4 years ago
if ((tabela.is_trash or tabela.is_mythic_dungeon_trash) and tabela.instance_type == "party") then
return true
end
end
3 years ago
--any combat
if (bit.band(Details.overall_flag, 0x10) ~= 0) then
4 years ago
return true
end
3 years ago
--is a PvP combat
if (tabela.is_pvp or tabela.is_arena) then
4 years ago
return true
end
3 years ago
4 years ago
return false
end
3 years ago
--sai do combate, chamou adicionar a tabela ao hist�rico
function segmentClass:adicionar (tabela)
4 years ago
local tamanho = #self.tabelas
3 years ago
--verifica se precisa dar UnFreeze()
if (tamanho < Details.segments_amount) then --vai preencher um novo index vazio
4 years ago
local ultima_tabela = self.tabelas[tamanho]
3 years ago
if (not ultima_tabela) then --n�o ha tabelas no historico, esta ser� a #1
--pega a tabela do combate atual
4 years ago
ultima_tabela = tabela
end
3 years ago
Details:InstanciaCallFunction(Details.CheckFreeze, tamanho+1, ultima_tabela)
4 years ago
end
3 years ago
--add to history table
tinsert(self.tabelas, 1, tabela)
--count boss tries
4 years ago
local boss = tabela.is_boss and tabela.is_boss.name
if (boss) then
3 years ago
local try_number = Details.encounter_counter [boss]
4 years ago
if (not try_number) then
local previous_combat
for i = 2, #self.tabelas do
previous_combat = self.tabelas [i]
if (previous_combat and previous_combat.is_boss and previous_combat.is_boss.name and previous_combat.is_boss.try_number and previous_combat.is_boss.name == boss and not previous_combat.is_boss.killed) then
try_number = previous_combat.is_boss.try_number + 1
break
end
end
3 years ago
4 years ago
if (not try_number) then
try_number = 1
end
else
3 years ago
try_number = Details.encounter_counter [boss] + 1
4 years ago
end
3 years ago
Details.encounter_counter [boss] = try_number
4 years ago
tabela.is_boss.try_number = try_number
end
3 years ago
--see if can add the encounter to overall data
local canAddToOverall = Details:CanAddCombatToOverall (tabela)
4 years ago
if (canAddToOverall) then
--if (InCombatLockdown()) then
-- _detalhes:ScheduleAddCombatToOverall (tabela)
-- if (_detalhes.debug) then
3 years ago
-- _detalhes:Msg("(debug) overall data flag match > in combat scheduling overall addition.")
4 years ago
-- end
--else
3 years ago
if (Details.debug) then
Details:Msg("(debug) overall data flag match addind the combat to overall data.")
4 years ago
end
3 years ago
segmentClass:adicionar_overall (tabela)
4 years ago
--end
end
3 years ago
--erase trash segments
4 years ago
if (self.tabelas[2]) then
local _segundo_combate = self.tabelas[2]
local container_damage = _segundo_combate [1]
local container_heal = _segundo_combate [2]
3 years ago
4 years ago
--regular cleanup
3 years ago
for _, jogador in ipairs(container_damage._ActorTable) do
--remover a tabela de last events
4 years ago
jogador.last_events_table = nil
3 years ago
--verifica se ele ainda esta registrado na time machine
4 years ago
if (jogador.timeMachine) then
jogador:DesregistrarNaTimeMachine()
end
end
3 years ago
for _, jogador in ipairs(container_heal._ActorTable) do
--remover a tabela de last events
4 years ago
jogador.last_events_table = nil
3 years ago
--verifica se ele ainda esta registrado na time machine
4 years ago
if (jogador.timeMachine) then
jogador:DesregistrarNaTimeMachine()
end
end
3 years ago
if (Details.trash_auto_remove) then
4 years ago
local _terceiro_combate = self.tabelas[3]
3 years ago
4 years ago
if (_terceiro_combate and not _terceiro_combate.is_mythic_dungeon_segment) then
3 years ago
4 years ago
if ((_terceiro_combate.is_trash and not _terceiro_combate.is_boss) or (_terceiro_combate.is_temporary)) then
3 years ago
--verificar novamente a time machine
for _, jogador in ipairs(_terceiro_combate [1]._ActorTable) do --damage
4 years ago
if (jogador.timeMachine) then
jogador:DesregistrarNaTimeMachine()
end
end
3 years ago
for _, jogador in ipairs(_terceiro_combate [2]._ActorTable) do --heal
4 years ago
if (jogador.timeMachine) then
jogador:DesregistrarNaTimeMachine()
end
end
3 years ago
--remover
tremove(self.tabelas, 3)
Details:SendEvent("DETAILS_DATA_SEGMENTREMOVED", nil, nil)
4 years ago
end
3 years ago
4 years ago
end
end
3 years ago
4 years ago
end
3 years ago
--verifica se precisa apagar a �ltima tabela do hist�rico
if (#self.tabelas > Details.segments_amount) then
4 years ago
local combat_removed, combat_index
3 years ago
--verifica se est�o dando try em um boss e remove o combate menos relevante
4 years ago
local bossid = tabela.is_boss and tabela.is_boss.id
3 years ago
4 years ago
local last_segment = self.tabelas [#self.tabelas]
local last_bossid = last_segment.is_boss and last_segment.is_boss.id
3 years ago
if (Details.zone_type == "raid" and bossid and last_bossid and bossid == last_bossid) then
4 years ago
local shorter_combat
local shorter_id
local min_time = 99999
3 years ago
4 years ago
for i = 4, #self.tabelas do
local combat = self.tabelas [i]
if (combat.is_boss and combat.is_boss.id == bossid and combat:GetCombatTime() < min_time and not combat.is_boss.killed) then
shorter_combat = combat
shorter_id = i
min_time = combat:GetCombatTime()
end
end
3 years ago
4 years ago
if (shorter_combat) then
combat_removed = shorter_combat
combat_index = shorter_id
end
end
3 years ago
4 years ago
if (not combat_removed) then
combat_removed = self.tabelas [#self.tabelas]
combat_index = #self.tabelas
end
3 years ago
--verificar novamente a time machine
for _, jogador in ipairs(combat_removed [1]._ActorTable) do --damage
4 years ago
if (jogador.timeMachine) then
jogador:DesregistrarNaTimeMachine()
end
end
3 years ago
for _, jogador in ipairs(combat_removed [2]._ActorTable) do --heal
4 years ago
if (jogador.timeMachine) then
jogador:DesregistrarNaTimeMachine()
end
end
3 years ago
--remover
tremove(self.tabelas, combat_index)
Details:SendEvent("DETAILS_DATA_SEGMENTREMOVED")
end
--chama a fun��o que ir� atualizar as inst�ncias com segmentos no hist�rico
Details:InstanciaCallFunction(Details.AtualizaSegmentos_AfterCombat, self)
--_detalhes:InstanciaCallFunction(_detalhes.AtualizarJanela)
4 years ago
end
3 years ago
--verifica se tem alguma instancia congelada mostrando o segmento rec�m liberado
function Details:CheckFreeze (instancia, index_liberado, tabela)
if (instancia.freezed) then --esta congelada
4 years ago
if (instancia.segmento == index_liberado) then
instancia.showing = tabela
instancia:UnFreeze()
end
end
end
3 years ago
function Details:SetOverallResetOptions (reset_new_boss, reset_new_challenge, reset_on_logoff, reset_new_pvp)
4 years ago
if (reset_new_boss == nil) then
3 years ago
reset_new_boss = Details.overall_clear_newboss
4 years ago
end
if (reset_new_challenge == nil) then
3 years ago
reset_new_challenge = Details.overall_clear_newchallenge
4 years ago
end
if (reset_on_logoff == nil) then
3 years ago
reset_on_logoff = Details.overall_clear_logout
end
if (reset_new_pvp == nil) then
reset_new_pvp = Details.overall_clear_pvp
4 years ago
end
3 years ago
Details.overall_clear_newboss = reset_new_boss
Details.overall_clear_newchallenge = reset_new_challenge
Details.overall_clear_logout = reset_on_logoff
Details.overall_clear_pvp = reset_new_pvp
4 years ago
end
3 years ago
function segmentClass:resetar_overall()
4 years ago
--if (InCombatLockdown()) then
3 years ago
-- _detalhes:Msg(Loc ["STRING_ERASE_IN_COMBAT"])
4 years ago
-- _detalhes.schedule_remove_overall = true
--else
3 years ago
--fecha a janela de informa��es do jogador
Details:FechaJanelaInfo()
Details.tabela_overall = combatClass:NovaTabela()
for index, instancia in ipairs(Details.tabela_instancias) do
4 years ago
if (instancia.ativa and instancia.segmento == -1) then
instancia:InstanceReset()
instancia:ReajustaGump()
end
end
3 years ago
if (Details.schedule_add_to_overall) then --deprecated
wipe (Details.schedule_add_to_overall)
4 years ago
end
--end
3 years ago
--stop bar testing if any
Details:StopTestBarUpdate()
Details:ClockPluginTickOnSegment()
4 years ago
end
3 years ago
function segmentClass:resetar()
if (Details.bosswindow) then
Details.bosswindow:Reset()
end
--stop bar testing if any
Details:StopTestBarUpdate()
if (Details.tabela_vigente.verifica_combate) then --finaliza a checagem se esta ou n�o no combate
Details:CancelTimer(Details.tabela_vigente.verifica_combate)
end
Details.last_closed_combat = nil
--remove mythic dungeon schedules if any
Details.schedule_mythicdungeon_trash_merge = nil
Details.schedule_mythicdungeon_endtrash_merge = nil
Details.schedule_mythicdungeon_overallrun_merge = nil
--clear other schedules
Details.schedule_flag_boss_components = nil
Details.schedule_store_boss_encounter = nil
4 years ago
--_detalhes.schedule_remove_overall = nil
3 years ago
--fecha a janela de informa��es do jogador
Details:FechaJanelaInfo()
--empty temporary tables
Details.atributo_damage:ClearTempTables()
for _, combate in ipairs(Details.tabela_historico.tabelas) do
wipe(combate)
end
wipe(Details.tabela_vigente)
wipe(Details.tabela_overall)
wipe(Details.spellcache)
if (Details.schedule_add_to_overall) then --deprecated
wipe (Details.schedule_add_to_overall)
end
Details:LimparPets()
Details:ResetSpecCache (true) --for�ar
4 years ago
-- novo container de historico
3 years ago
Details.tabela_historico = segmentClass:NovoHistorico() --joga fora a tabela antiga e cria uma nova
4 years ago
--novo container para armazenar pets
3 years ago
Details.tabela_pets = Details.container_pets:NovoContainer()
Details:UpdateContainerCombatentes()
Details.container_pets:BuscarPets()
4 years ago
-- nova tabela do overall e current
3 years ago
Details.tabela_overall = combatClass:NovaTabela() --joga fora a tabela antiga e cria uma nova
4 years ago
-- cria nova tabela do combate atual
3 years ago
Details.tabela_vigente = combatClass:NovaTabela (nil, Details.tabela_overall)
4 years ago
--marca o addon como fora de combate
3 years ago
Details.in_combat = false
4 years ago
--zera o contador de combates
3 years ago
Details:NumeroCombate (0)
--limpa o cache de magias
Details:ClearSpellCache()
--limpa a tabela de escudos
wipe(Details.escudos)
--reinicia a time machine
4 years ago
timeMachine:Reiniciar()
3 years ago
wipe(Details.cache_damage_group)
wipe(Details.cache_healing_group)
Details:UpdateParserGears()
if (not InCombatLockdown() and not UnitAffectingCombat("player")) then
--workarround for the "script run too long" issue while outside the combat lockdown
4 years ago
local cleargarbage = function()
collectgarbage()
end
3 years ago
local successful, errortext = pcall(cleargarbage)
4 years ago
if (not successful) then
3 years ago
Details:Msg("couldn't call collectgarbage()")
4 years ago
end
else
3 years ago
Details.schedule_hard_garbage_collect = true
end
Details:InstanciaCallFunction(Details.AtualizaSegmentos) -- atualiza o instancia.showing para as novas tabelas criadas
Details:InstanciaCallFunction(Details.AtualizaSoloMode_AfertReset) -- verifica se precisa zerar as tabela da janela solo mode
Details:InstanciaCallFunction(Details.ResetaGump) --_detalhes:ResetaGump ("de todas as instancias")
Details:InstanciaCallFunction(Details.FadeHandler.Fader, "IN", nil, "barras")
Details:RefreshMainWindow(-1) --atualiza todas as instancias
Details:SendEvent("DETAILS_DATA_RESET", nil, nil)
4 years ago
end
3 years ago
function Details.refresh:r_historico (este_historico)
setmetatable(este_historico, segmentClass)
4 years ago
--este_historico.__index = historico
end
--[[
elseif (_detalhes.trash_concatenate) then
3 years ago
4 years ago
if (true) then
return
end
3 years ago
4 years ago
if (_terceiro_combate) then
if (_terceiro_combate.is_trash and _segundo_combate.is_trash and not _terceiro_combate.is_boss and not _segundo_combate.is_boss) then
3 years ago
--tabela 2 deve ser deletada e somada a tabela 1
4 years ago
if (_detalhes.debug) then
3 years ago
detalhes:Msg("(debug) concatenating two trash segments.")
4 years ago
end
3 years ago
4 years ago
_segundo_combate = _segundo_combate + _terceiro_combate
_detalhes.tabela_overall = _detalhes.tabela_overall - _terceiro_combate
3 years ago
4 years ago
_segundo_combate.is_trash = true
3 years ago
--verificar novamente a time machine
for _, jogador in ipairs(_terceiro_combate [1]._ActorTable) do --damage
4 years ago
if (jogador.timeMachine) then
jogador:DesregistrarNaTimeMachine()
end
end
3 years ago
for _, jogador in ipairs(_terceiro_combate [2]._ActorTable) do --heal
4 years ago
if (jogador.timeMachine) then
jogador:DesregistrarNaTimeMachine()
end
end
3 years ago
--remover
_table_remove(self.tabelas, 3)
_detalhes:SendEvent("DETAILS_DATA_SEGMENTREMOVED", nil, nil)
4 years ago
end
end
--]]