From 7d8b84a216562d658b1ce596f8cdd88bb9f6e923 Mon Sep 17 00:00:00 2001 From: Tercio Jose Date: Fri, 1 Mar 2024 17:30:59 -0300 Subject: [PATCH] More bug fixes and implementations on the backend of mythic dungeons handling. --- Definitions.lua | 26 +- Libs/LibLuaServer/LibLuaServer.lua | 4 + classes/class_combat.lua | 2 +- core/control.lua | 88 ++++--- frames/window_main.lua | 11 +- functions/mythicdungeon/segments.lua | 355 +++++++++++++-------------- 6 files changed, 250 insertions(+), 236 deletions(-) diff --git a/Definitions.lua b/Definitions.lua index bf4ce1833..9821b5f00 100644 --- a/Definitions.lua +++ b/Definitions.lua @@ -115,19 +115,19 @@ ---@field key7 guid pet guid ---@class bossinfo : table .is_boss on combatObjects ----@field diff_string string ----@field index number ----@field zone string ----@field encounter string ----@field mapid number ----@field try_number number ----@field name string ----@field ej_instance_id number ----@field id number ----@field unixtime unixtime ----@field diff number ----@field killed boolean ----@field bossimage texturepath|number +---@field diff_string string? +---@field index number? +---@field zone string? +---@field encounter string? +---@field mapid number? +---@field try_number number? +---@field name string? +---@field ej_instance_id number? +---@field id number? +---@field unixtime unixtime? +---@field diff number? +---@field killed boolean? +---@field bossimage texturepath|number? ---@class details ---@field pets table store the pet guid as the key and the petinfo as the value diff --git a/Libs/LibLuaServer/LibLuaServer.lua b/Libs/LibLuaServer/LibLuaServer.lua index 5a22189e2..e83deee92 100644 --- a/Libs/LibLuaServer/LibLuaServer.lua +++ b/Libs/LibLuaServer/LibLuaServer.lua @@ -1459,6 +1459,10 @@ function loadstring(code) return function()end end ---@return string function date(format, time) return "" end +---lua os.time() function +---@return number +function time() return 0 end + ---returns the number of members in the current group. ---@return number GetNumGroupMembers = function() return 0 end diff --git a/classes/class_combat.lua b/classes/class_combat.lua index 3740a26fc..999c5f36f 100644 --- a/classes/class_combat.lua +++ b/classes/class_combat.lua @@ -206,7 +206,7 @@ local segmentTypeToString = { ---@return boolean ---@return number function classCombat:IsMythicDungeon() - local bIsMythicPlusSegment = self.is_mythic_dungeon_segment and self:GetMythicDungeonInfo() + local bIsMythicPlusSegment = self.is_mythic_dungeon_segment local runId = self.is_mythic_dungeon_run_id return bIsMythicPlusSegment, runId end diff --git a/core/control.lua b/core/control.lua index c71bbdc03..7ef6e6dbf 100644 --- a/core/control.lua +++ b/core/control.lua @@ -558,14 +558,12 @@ currentCombat.player_last_events = {} --flag instance type - local _, InstanceType = GetInstanceInfo() - currentCombat.instance_type = InstanceType + local zoneName, instanceType, DifficultyID, DifficultyName, _, _, _, zoneMapID = GetInstanceInfo() + currentCombat.instance_type = instanceType if (not currentCombat.is_boss and bIsFromEncounterEnd and type(bIsFromEncounterEnd) == "table") then local encounterID, encounterName, difficultyID, raidSize, endStatus = unpack(bIsFromEncounterEnd) if (encounterID) then - local ZoneName, InstanceType, DifficultyID, DifficultyName, _, _, _, ZoneMapID = GetInstanceInfo() - local mapID = C_Map.GetBestMapForUnit("player") if (not mapID) then @@ -577,14 +575,14 @@ ejid = Details:GetInstanceEJID() end - local _, boss_index = Details:GetBossEncounterDetailsFromEncounterId(ZoneMapID, encounterID) + local _, boss_index = Details:GetBossEncounterDetailsFromEncounterId(zoneMapID, encounterID) currentCombat.is_boss = { index = boss_index or 0, name = encounterName, encounter = encounterName, - zone = ZoneName, - mapid = ZoneMapID, + zone = zoneName, + mapid = zoneMapID, diff = DifficultyID, diff_string = DifficultyName, ej_instance_id = ejid or 0, @@ -599,6 +597,23 @@ if (mythicLevel and mythicLevel >= 2) then currentCombat.is_mythic_dungeon_segment = true currentCombat.is_mythic_dungeon_run_id = Details.mythic_dungeon_id + + ---@type mythicdungeoninfo + local mythicPlusInfo = { + ZoneName = Details.MythicPlus.DungeonName or zoneName, + MapID = Details.MythicPlus.DungeonID or zoneMapID, + Level = Details.MythicPlus.Level, + EJID = Details.MythicPlus.ejID, + RunID = Details.mythic_dungeon_id, + StartedAt = time() - currentCombat:GetCombatTime(), + EndedAt = time(), + SegmentID = Details.MythicPlus.SegmentID, --segment number within the dungeon + --default to trash + SegmentType = DETAILS_SEGMENTTYPE_MYTHICDUNGEON_TRASH, + SegmentName = "Trash #" .. (Details.MythicPlus.SegmentID or 0), --localize-me + } + + currentCombat.is_mythic_dungeon = mythicPlusInfo end --send item level after a combat if is in raid or party group @@ -614,43 +629,27 @@ currentCombat.enemy = "[" .. ARENA .. "] " .. currentCombat.is_arena.name end - local in_instance = IsInInstance() --garrison returns party as instance type. - if ((InstanceType == "party" or InstanceType == "raid") and in_instance) then - if (InstanceType == "party") then - if (currentCombat.is_mythic_dungeon_segment) then --setted just above - --is inside a mythic+ dungeon and this is not a boss segment, so tag it as a dungeon mythic+ trash segment - local zoneName, instanceType, difficultyID, difficultyName, maxPlayers, dynamicDifficulty, isDynamic, instanceMapID, instanceGroupSize = GetInstanceInfo() - - ---@type mythicdungeoninfo - local mythicPlusInfo = { - ZoneName = Details.MythicPlus.DungeonName or zoneName, - MapID = Details.MythicPlus.DungeonID or instanceMapID, - Level = Details.MythicPlus.Level, - EJID = Details.MythicPlus.ejID, - RunID = Details.mythic_dungeon_id, - StartedAt = time() - currentCombat:GetCombatTime(), - EndedAt = time(), - SegmentID = Details.MythicPlus.SegmentID, --segment number within the dungeon - OverallSegment = false, - SegmentType = DETAILS_SEGMENTTYPE_MYTHICDUNGEON_TRASH, - SegmentName = "Trash #" .. (Details.MythicPlus.SegmentID or 0), --localize-me - } - currentCombat.is_mythic_dungeon = mythicPlusInfo - - currentCombat.is_mythic_dungeon_trash = true - - if (Details.debug) then - Details:Msg("segment tagged as mythic+ trash.") - end - else + if (currentCombat.is_mythic_dungeon_segment) then + --is inside a mythic+ dungeon and this is not a boss segment, so tag it as a dungeon mythic+ trash segment + currentCombat.is_mythic_dungeon.SegmentType = DETAILS_SEGMENTTYPE_MYTHICDUNGEON_TRASH + currentCombat.is_mythic_dungeon.SegmentName = "Trash #" .. (Details.MythicPlus.SegmentID or 0) --localize-me + currentCombat.is_mythic_dungeon_trash = true + + if (Details.debug) then + Details:Msg("segment tagged as mythic+ trash.") + end + end + + local bInInstance = IsInInstance() --garrison returns party as instance type. + if ((instanceType == "party" or instanceType == "raid") and bInInstance) then + if (instanceType == "party") then + if (currentCombat.is_mythic_dungeon_segment) then --tag the combat as trash clean up currentCombat.is_trash = true end - else - currentCombat.is_trash = true end else - if (not in_instance) then + if (not bInInstance) then if (Details.world_combat_is_trash) then currentCombat.is_world_trash_combat = true end @@ -669,6 +668,7 @@ Details:FlagActorsOnCommonFight() --fight_component else + --combat is boss encounter --calling here without checking for combat since the does not ran too long for scripts Details:FlagActorsOnBossFight() @@ -685,6 +685,11 @@ Details.schedule_store_boss_encounter = true end + if (currentCombat.is_mythic_dungeon_segment) then + currentCombat.is_mythic_dungeon.SegmentType = DETAILS_SEGMENTTYPE_MYTHICDUNGEON_BOSS + currentCombat.is_mythic_dungeon.SegmentName = (currentCombat.is_boss.name or Loc["STRING_UNKNOW"]) .. " (" .. string.lower(_G["BOSS"]) .. ")" + end + Details:SendEvent("COMBAT_BOSS_DEFEATED", nil, currentCombat) Details:CheckFor_TrashSuppressionOnEncounterEnd() else @@ -698,6 +703,11 @@ else Details.schedule_store_boss_encounter_wipe = true end + + if (currentCombat.is_mythic_dungeon_segment) then + currentCombat.is_mythic_dungeon.SegmentType = DETAILS_SEGMENTTYPE_MYTHICDUNGEON_BOSSWIPE + currentCombat.is_mythic_dungeon.SegmentName = (currentCombat.is_boss.name or Loc["STRING_UNKNOW"]) .. " (" .. string.lower(_G["BOSS"]) .. ")" + end end currentCombat.is_boss.index = currentCombat.is_boss.index or 1 diff --git a/frames/window_main.lua b/frames/window_main.lua index 05ce00d6f..c204e40a6 100644 --- a/frames/window_main.lua +++ b/frames/window_main.lua @@ -6658,7 +6658,7 @@ local buildSegmentTooltip = function(self, deltaTime) --> current combat local thisCombat = Details:GetCurrentCombat() local dateStart, dateEnd = thisCombat:GetDate() - local segment_info_added + local bSegmentInfoAdded local enemy = thisCombat.is_boss and thisCombat.is_boss.name or thisCombat.enemy or "--x--x--" local file, coords @@ -6675,8 +6675,9 @@ local buildSegmentTooltip = function(self, deltaTime) if (mythicDungeonInfo) then --is a boss, trash overall or run overall segment local bossInfo = thisCombat.is_boss - local isMythicOverallSegment, segmentID, mythicLevel, EJID, mapID, zoneName, encounterID, encounterName, startedAt, endedAt, runID = Details:UnpackMythicDungeonInfo (mythicDungeonInfo) + local isMythicOverallSegment, segmentID, mythicLevel, EJID, mapID, zoneName, encounterID, encounterName, startedAt, endedAt, runID = Details:UnpackMythicDungeonInfo(mythicDungeonInfo) local combatElapsedTime = thisCombat:GetCombatTime() + local combatName = thisCombat:GetCombatName() --is mythic overall if (isMythicOverallSegment) then @@ -6694,7 +6695,7 @@ local buildSegmentTooltip = function(self, deltaTime) gameCooltip:AddLine(encounterName .. " (" .. Loc["STRING_SEGMENTS_LIST_TRASH"] .. ")", nil, 2, "white", "white") else --CoolTip:AddLine(encounterName .. " (" .. Loc["STRING_SEGMENTS_LIST_BOSS"] .. ")", _detalhes.gump:IntegerToTimer(combat_time), 1, dungeon_color, "gray") - gameCooltip:AddLine(encounterName .. " (" .. Loc["STRING_SEGMENTS_LIST_BOSS"] .. ")", nil, 2, "white", "white") + gameCooltip:AddLine(combatName, nil, 2, "white", "white") end --CoolTip:AddIcon([[Interface\AddOns\Details\images\icons]], "main", "left", 14, 10, 479/512, 510/512, 24/512, 51/512) end @@ -6768,7 +6769,7 @@ local buildSegmentTooltip = function(self, deltaTime) end end - segment_info_added = true + bSegmentInfoAdded = true elseif (thisCombat.is_boss and thisCombat.is_boss.name) then local portrait = Details:GetBossPortrait(thisCombat.is_boss.mapid, thisCombat.is_boss.index) or thisCombat.is_boss.bossimage @@ -6828,7 +6829,7 @@ local buildSegmentTooltip = function(self, deltaTime) end end - if (not segment_info_added) then + if (not bSegmentInfoAdded) then gameCooltip:AddLine(Loc["STRING_SEGMENT_ENEMY"] .. ":", enemy, 2, "white", "white") if (not thisCombat:GetEndTime()) then diff --git a/functions/mythicdungeon/segments.lua b/functions/mythicdungeon/segments.lua index b420d0cf4..b29afdd43 100644 --- a/functions/mythicdungeon/segments.lua +++ b/functions/mythicdungeon/segments.lua @@ -19,75 +19,8 @@ local Loc = _G.LibStub("AceLocale-3.0"):GetLocale("Details") local DetailsMythicPlusFrame = _G["DetailsMythicPlusFrame"] -function Details222.MythicPlus.OnMythicDungeonFinished(encounterID, encounterName) - - -end - -function Details222.MythicPlus.MergeTrashAfterLastBoss() - local segmentsToMerge = {} - --table with all past segments - local segmentsTable = Details:GetCombatSegments() - - for i = 1, #segmentsTable do - local pastCombat = segmentsTable [i] - --does the combat exists - - if (pastCombat and not pastCombat._trashoverallalreadyadded and pastCombat:GetCombatTime() > 5) then - --is the last boss? - if (pastCombat.is_boss) then - break - end - - --is the combat a mythic segment from this run? - local isMythicSegment, SegmentID = pastCombat:IsMythicDungeon() - if (isMythicSegment and SegmentID == Details.mythic_dungeon_id and pastCombat.is_mythic_dungeon_trash) then - - --if have mythic dungeon info, cancel the loop - local mythicDungeonInfo = pastCombat:GetMythicDungeonInfo() - if (mythicDungeonInfo) then - break - end - - --merge this segment - table.insert(segmentsToMerge, pastCombat) - - if (DetailsMythicPlusFrame.DevelopmentDebug) then - print("MythicDungeonFinished() > found after last boss combat") - end - end - end - end - - if (#segmentsToMerge > 0) then - if (DetailsMythicPlusFrame.DevelopmentDebug) then - print("Details!", "MythicDungeonFinished() > found ", #segmentsToMerge, "segments after the last boss") - end - - --find the latest trash overall - segmentsTable = Details:GetCombatSegments() - local latestTrashOverall - for i = 1, #segmentsTable do - local pastCombat = segmentsTable [i] - if (pastCombat and pastCombat.is_mythic_dungeon and pastCombat.is_mythic_dungeon.SegmentID == "trashoverall") then - latestTrashOverall = pastCombat - break - end - end - - if (latestTrashOverall) then - --stores the segment table and the trash overall segment to use on the merge - DetailsMythicPlusFrame.TrashMergeScheduled2 = segmentsToMerge - DetailsMythicPlusFrame.TrashMergeScheduled2_OverallCombat = latestTrashOverall - - if (DetailsMythicPlusFrame.DevelopmentDebug) then - print("Details!", "MythicDungeonFinished() > not in combat, merging last pack of trash now") - end - - DetailsMythicPlusFrame.MergeRemainingTrashAfterAllBossesDone() - end - end -end +--empty +function Details222.MythicPlus.OnMythicDungeonFinished(encounterID, encounterName)end function Details222.MythicPlus.OnBossDefeated(encounterID, encounterName) local currentCombat = Details:GetCurrentCombat() @@ -160,6 +93,110 @@ function Details222.MythicPlus.OnBossDefeated(encounterID, encounterName) end end +--after each boss fight, if enalbed on settings, create an extra segment with all trash segments from the boss just killed +function DetailsMythicPlusFrame.MergeTrashCleanup() + if (DetailsMythicPlusFrame.DevelopmentDebug) then + print("Details!", "MergeTrashCleanup() > running", DetailsMythicPlusFrame.TrashMergeScheduled and #DetailsMythicPlusFrame.TrashMergeScheduled) + end + + local segmentsToMerge = DetailsMythicPlusFrame.TrashMergeScheduled + + --table exists and there's at least one segment + if (segmentsToMerge and segmentsToMerge[1]) then + Details222.MythicPlus.LogStep("MergeTrashCleanup started.") + + --the first segment is the segment where all other trash segments will be added + local masterSegment = segmentsToMerge[1] + masterSegment.is_mythic_dungeon_trash = nil + + --get the current combat just created and the table with all past segments + local newCombat = masterSegment + local totalTime = newCombat:GetCombatTime() + local startDate, endDate = "", "" + local lastSegment + + --add segments + for i = 2, #segmentsToMerge do --segment #1 is the host + local pastCombat = segmentsToMerge[i] + newCombat = newCombat + pastCombat + totalTime = totalTime + pastCombat:GetCombatTime() + + newCombat:CopyDeathsFrom(pastCombat, true) + + --tag this combat as already added to a boss trash overall + pastCombat._trashoverallalreadyadded = true + + if (endDate == "") then + local _, whenEnded = pastCombat:GetDate() + endDate = whenEnded + end + lastSegment = pastCombat + end + + --get the date where the first segment started + if (lastSegment) then + startDate = lastSegment:GetDate() + end + + local zoneName, instanceType, difficultyID, difficultyName, maxPlayers, dynamicDifficulty, isDynamic, instanceMapID, instanceGroupSize = GetInstanceInfo() + + --tag the segment as mythic overall segment + newCombat.is_mythic_dungeon = { + StartedAt = segmentsToMerge.PreviousBossKilledAt, --start of the mythic run or when the previous boss got killed + EndedAt = segmentsToMerge.LastBossKilledAt, --the time() when encounter_end got triggered + SegmentID = "trashoverall", + RunID = Details.mythic_dungeon_id, + TrashOverallSegment = true, + ZoneName = Details.MythicPlus.DungeonName, + MapID = instanceMapID, + Level = Details.MythicPlus.Level, + EJID = Details.MythicPlus.ejID, + EncounterID = segmentsToMerge.EncounterID, + EncounterName = segmentsToMerge.EncounterName or Loc ["STRING_UNKNOW"], + SegmentType = DETAILS_SEGMENTTYPE_MYTHICDUNGEON_BOSSTRASH, + SegmentName = (segmentsToMerge.EncounterName or Loc ["STRING_UNKNOW"]) .. " (" .. string.lower(Loc["STRING_SEGMENTS_LIST_TRASH"]) .. ")", + } + + newCombat.is_mythic_dungeon_segment = true + newCombat.is_mythic_dungeon_run_id = Details.mythic_dungeon_id + + --set the segment time / using a sum of combat times, this combat time is reliable + newCombat:SetStartTime(GetTime() - totalTime) + newCombat:SetEndTime(GetTime()) + --set the segment date + newCombat:SetDate(startDate, endDate) + + if (DetailsMythicPlusFrame.DevelopmentDebug) then + print("Details!", "MergeTrashCleanup() > finished merging trash segments.", Details.tabela_vigente, Details.tabela_vigente.is_boss) + end + + --delete all segments that were merged + local segmentsTable = Details:GetCombatSegments() + for segmentId = #segmentsTable, 1, -1 do + local segment = segmentsTable[segmentId] + if (segment and segment._trashoverallalreadyadded) then + table.remove(segmentsTable, segmentId) + end + end + + for i = #segmentsToMerge, 1, -1 do + table.remove(segmentsToMerge, i) + end + + --call the segment removed event to notify third party addons + Details:SendEvent("DETAILS_DATA_SEGMENTREMOVED") + + --update all windows + Details:InstanceCallDetailsFunc(Details.FadeHandler.Fader, "IN", nil, "barras") + Details:InstanceCallDetailsFunc(Details.UpdateCombatObjectInUse) + Details:InstanceCallDetailsFunc(Details.AtualizaSoloMode_AfertReset) + Details:InstanceCallDetailsFunc(Details.ResetaGump) + Details:RefreshMainWindow(-1, true) + else + Details222.MythicPlus.LogStep("MergeTrashCleanup | no segments to merge.") + end +end + function DetailsMythicPlusFrame.MergeSegmentsOnEnd() --~merge --at the end of a mythic run, if enable on settings, merge all the segments from the mythic run into only one if (DetailsMythicPlusFrame.DevelopmentDebug) then @@ -329,110 +366,6 @@ function DetailsMythicPlusFrame.MergeSegmentsOnEnd() --~merge Details:SendEvent("COMBAT_MYTHICPLUS_OVERALL_READY") end ---after each boss fight, if enalbed on settings, create an extra segment with all trash segments from the boss just killed -function DetailsMythicPlusFrame.MergeTrashCleanup() - if (DetailsMythicPlusFrame.DevelopmentDebug) then - print("Details!", "MergeTrashCleanup() > running", DetailsMythicPlusFrame.TrashMergeScheduled and #DetailsMythicPlusFrame.TrashMergeScheduled) - end - - local segmentsToMerge = DetailsMythicPlusFrame.TrashMergeScheduled - - --table exists and there's at least one segment - if (segmentsToMerge and segmentsToMerge[1]) then - Details222.MythicPlus.LogStep("MergeTrashCleanup started.") - - --the first segment is the segment where all other trash segments will be added - local masterSegment = segmentsToMerge[1] - masterSegment.is_mythic_dungeon_trash = nil - - --get the current combat just created and the table with all past segments - local newCombat = masterSegment - local totalTime = newCombat:GetCombatTime() - local startDate, endDate = "", "" - local lastSegment - - --add segments - for i = 2, #segmentsToMerge do --segment #1 is the host - local pastCombat = segmentsToMerge[i] - newCombat = newCombat + pastCombat - totalTime = totalTime + pastCombat:GetCombatTime() - - newCombat:CopyDeathsFrom(pastCombat, true) - - --tag this combat as already added to a boss trash overall - pastCombat._trashoverallalreadyadded = true - - if (endDate == "") then - local _, whenEnded = pastCombat:GetDate() - endDate = whenEnded - end - lastSegment = pastCombat - end - - --get the date where the first segment started - if (lastSegment) then - startDate = lastSegment:GetDate() - end - - local zoneName, instanceType, difficultyID, difficultyName, maxPlayers, dynamicDifficulty, isDynamic, instanceMapID, instanceGroupSize = GetInstanceInfo() - - --tag the segment as mythic overall segment - newCombat.is_mythic_dungeon = { - StartedAt = segmentsToMerge.PreviousBossKilledAt, --start of the mythic run or when the previous boss got killed - EndedAt = segmentsToMerge.LastBossKilledAt, --the time() when encounter_end got triggered - SegmentID = "trashoverall", - RunID = Details.mythic_dungeon_id, - TrashOverallSegment = true, - ZoneName = Details.MythicPlus.DungeonName, - MapID = instanceMapID, - Level = Details.MythicPlus.Level, - EJID = Details.MythicPlus.ejID, - EncounterID = segmentsToMerge.EncounterID, - EncounterName = segmentsToMerge.EncounterName or Loc ["STRING_UNKNOW"], - SegmentType = DETAILS_SEGMENTTYPE_MYTHICDUNGEON_BOSSTRASH, - SegmentName = (segmentsToMerge.EncounterName or Loc ["STRING_UNKNOW"]) .. " (" .. string.lower(Loc["STRING_SEGMENTS_LIST_TRASH"]) .. ")", - } - - newCombat.is_mythic_dungeon_segment = true - newCombat.is_mythic_dungeon_run_id = Details.mythic_dungeon_id - - --set the segment time / using a sum of combat times, this combat time is reliable - newCombat:SetStartTime(GetTime() - totalTime) - newCombat:SetEndTime(GetTime()) - --set the segment date - newCombat:SetDate(startDate, endDate) - - if (DetailsMythicPlusFrame.DevelopmentDebug) then - print("Details!", "MergeTrashCleanup() > finished merging trash segments.", Details.tabela_vigente, Details.tabela_vigente.is_boss) - end - - --delete all segments that were merged - local segmentsTable = Details:GetCombatSegments() - for segmentId = #segmentsTable, 1, -1 do - local segment = segmentsTable[segmentId] - if (segment and segment._trashoverallalreadyadded) then - table.remove(segmentsTable, segmentId) - end - end - - for i = #segmentsToMerge, 1, -1 do - table.remove(segmentsToMerge, i) - end - - --call the segment removed event to notify third party addons - Details:SendEvent("DETAILS_DATA_SEGMENTREMOVED") - - --update all windows - Details:InstanceCallDetailsFunc(Details.FadeHandler.Fader, "IN", nil, "barras") - Details:InstanceCallDetailsFunc(Details.UpdateCombatObjectInUse) - Details:InstanceCallDetailsFunc(Details.AtualizaSoloMode_AfertReset) - Details:InstanceCallDetailsFunc(Details.ResetaGump) - Details:RefreshMainWindow(-1, true) - else - Details222.MythicPlus.LogStep("MergeTrashCleanup | no segments to merge.") - end -end - --this function merges trash segments after all bosses of the mythic dungeon are defeated --happens when the group finishes all bosses but don't complete the trash requirement function DetailsMythicPlusFrame.MergeRemainingTrashAfterAllBossesDone() @@ -497,10 +430,10 @@ function DetailsMythicPlusFrame.MergeRemainingTrashAfterAllBossesDone() local segmentsTable = Details:GetCombatSegments() for _, pastCombat in ipairs(segmentsToMerge) do for i = #segmentsTable, 1, -1 do - local segment = segmentsTable [i] + local segment = segmentsTable[i] if (segment == pastCombat) then --remove the segment - if (Details.tabela_vigente == segment) then + if (Details:GetCurrentCombat() == segment) then removedCurrentSegment = true end table.remove(segmentsTable, i) @@ -516,12 +449,12 @@ function DetailsMythicPlusFrame.MergeRemainingTrashAfterAllBossesDone() if (removedCurrentSegment) then --find another current segment local segmentsTable = Details:GetCombatSegments() - Details.tabela_vigente = segmentsTable [1] + Details:SetCurrentCombat(segmentsTable[1]) - if (not Details.tabela_vigente) then + if (not Details:GetCurrentCombat()) then --assuming there's no segment from the dungeon run Details:StartCombat() - Details:SairDoCombate() + Details:EndCombat() end --update all windows @@ -541,4 +474,70 @@ function DetailsMythicPlusFrame.MergeRemainingTrashAfterAllBossesDone() if (DetailsMythicPlusFrame.DevelopmentDebug) then print("Details!", "MergeRemainingTrashAfterAllBossesDone() > done merging") end +end + +--does not do the merge, just scheduling, the merger is on the function above +function Details222.MythicPlus.MergeTrashAfterLastBoss() + local segmentsToMerge = {} + --table with all past segments + local segmentsTable = Details:GetCombatSegments() + + for i = 1, #segmentsTable do + local pastCombat = segmentsTable[i] + --does the combat exists + + if (pastCombat and not pastCombat._trashoverallalreadyadded and pastCombat:GetCombatTime() > 5) then + --is the last boss? + if (pastCombat.is_boss) then + break + end + + --is the combat a mythic segment from this run? + local isMythicSegment, SegmentID = pastCombat:IsMythicDungeon() + if (isMythicSegment and SegmentID == Details.mythic_dungeon_id and pastCombat.is_mythic_dungeon_trash) then + + --if have mythic dungeon info, cancel the loop + local mythicDungeonInfo = pastCombat:GetMythicDungeonInfo() + if (mythicDungeonInfo) then + break + end + + --merge this segment + table.insert(segmentsToMerge, pastCombat) + + if (DetailsMythicPlusFrame.DevelopmentDebug) then + print("MythicDungeonFinished() > found after last boss combat") + end + end + end + end + + if (#segmentsToMerge > 0) then + if (DetailsMythicPlusFrame.DevelopmentDebug) then + print("Details!", "MythicDungeonFinished() > found ", #segmentsToMerge, "segments after the last boss") + end + + --find the latest trash overall + segmentsTable = Details:GetCombatSegments() + local latestTrashOverall + for i = 1, #segmentsTable do + local pastCombat = segmentsTable[i] + if (pastCombat and pastCombat.is_mythic_dungeon and pastCombat.is_mythic_dungeon.SegmentID == "trashoverall") then + latestTrashOverall = pastCombat + break + end + end + + if (latestTrashOverall) then + --stores the segment table and the trash overall segment to use on the merge + DetailsMythicPlusFrame.TrashMergeScheduled2 = segmentsToMerge + DetailsMythicPlusFrame.TrashMergeScheduled2_OverallCombat = latestTrashOverall + + if (DetailsMythicPlusFrame.DevelopmentDebug) then + print("Details!", "MythicDungeonFinished() > not in combat, merging last pack of trash now") + end + + DetailsMythicPlusFrame.MergeRemainingTrashAfterAllBossesDone() + end + end end \ No newline at end of file