From d96497def0a8c1915060da3d83b185c63695661f Mon Sep 17 00:00:00 2001 From: Tercio Jose Date: Mon, 15 Jul 2024 20:14:38 -0300 Subject: [PATCH] Testing the new options for wipe limit for segments and deleting the worst try among all wipe segments in a boss --- boot.lua | 4 +- classes/container_segments.lua | 87 ++++++++++++++++++++++++++++- frames/window_options2_sections.lua | 2 - 3 files changed, 88 insertions(+), 5 deletions(-) diff --git a/boot.lua b/boot.lua index ef894fe55..1e128fe3f 100644 --- a/boot.lua +++ b/boot.lua @@ -19,8 +19,8 @@ local addonName, Details222 = ... local version, build, date, tvs = GetBuildInfo() - Details.build_counter = 12806 - Details.alpha_build_counter = 12806 --if this is higher than the regular counter, use it instead + Details.build_counter = 12807 + Details.alpha_build_counter = 12807 --if this is higher than the regular counter, use it instead Details.dont_open_news = true Details.game_version = version Details.userversion = version .. " " .. Details.build_counter diff --git a/classes/container_segments.lua b/classes/container_segments.lua index da4bbe187..0bac56f79 100644 --- a/classes/container_segments.lua +++ b/classes/container_segments.lua @@ -338,6 +338,35 @@ function Details:GetWipeCounter(guildName, encounterId, difficultyId) return 0 end +---return the amount of segments in the segments table that are from the same boss as the combat passed as argument +---@param currentCombat combat +---@return number +local getAmountOfSegmentsInThisBoss = function(currentCombat) + local segmentsTable = Details:GetCombatSegments() + local amountOfSegmentsInUse = #segmentsTable + local amountOfSegmentsInThisBoss = 0 + + ---@type bossinfo + local thisCombatBossInfo = currentCombat:GetBossInfo() + + if (thisCombatBossInfo) then + local currentBossName = thisCombatBossInfo.name + for i = 1, amountOfSegmentsInUse do + ---@type combat + local thisCombatObject = segmentsTable[i] + ---@type bossinfo + local bossInfo = thisCombatObject:GetBossInfo() + if (bossInfo and bossInfo ~= thisCombatBossInfo) then + if (bossInfo.name == currentBossName) then + amountOfSegmentsInThisBoss = amountOfSegmentsInThisBoss + 1 + end + end + end + end + + return amountOfSegmentsInThisBoss +end + ---count boss tries and set the value in the combat object ---@param combatToBeAdded combat local setBossTryCounter = function(combatToBeAdded, segmentsTable, amountSegmentsInUse) @@ -441,6 +470,9 @@ function Details222.Combat.AddCombat(combatToBeAdded) ---@type table store references of combat objects removed local removedCombats = {} + ---@type bossinfo + local combatToAddBossInfo = combatToBeAdded:GetBossInfo() + --check if there's a destroyed segment within the segment container if (amountSegmentsInUse > 0) then for i = 1, amountSegmentsInUse do @@ -546,7 +578,60 @@ function Details222.Combat.AddCombat(combatToBeAdded) end --is the wipe counter saved in the details database? - --PAREI AQUI, implementar Details.segments_amount_boss_wipes e Details.segments_boss_wipes_keep_best_performance + if (IsInRaid() and Details.zone_type == "raid") then --filter only for raids + local bRunOkay2, result = getAmountOfSegmentsInThisBoss(combatToBeAdded) + if (not bRunOkay2) then + Details:Msg("bRunOkay2 Error > failed to get amount of segments in this boss > ", result) + else + local segmentRemoveResult = "" + local bRunOkay3, errorText3 = pcall(function() + local amountOfSegmentsInThisBoss = result + if (amountOfSegmentsInThisBoss > Details.segments_amount_boss_wipes) then + ---@type combat[] + local allSegmentsWithThisBoss = {} + for i = 1, amountSegmentsInUse do + ---@type combat + local thisCombatObject = segmentsTable[i] + local thisCombatBossInfo = thisCombatObject:GetBossInfo() + if (thisCombatBossInfo and thisCombatBossInfo.name == combatToAddBossInfo.name and thisCombatBossInfo.diff == combatToAddBossInfo.diff) then + table.insert(allSegmentsWithThisBoss, thisCombatObject) + end + end + + segmentRemoveResult = segmentRemoveResult .. #allSegmentsWithThisBoss .. " added|" + + --make sure the the len of the table is the same or more of the amount of segments in this boss + if (#allSegmentsWithThisBoss >= amountOfSegmentsInThisBoss) then + --sort the table by elapsed time + table.sort(allSegmentsWithThisBoss, function(a, b) return a:GetBossHealth() < b:GetBossHealth() end) + + --remove the last segment + ---@type combat + local combatToBeRemoved = allSegmentsWithThisBoss[#allSegmentsWithThisBoss] + ---@type boolean, combat + local bSegmentRemoved, combatObjectRemoved = Details:RemoveSegmentByCombatObject(combatToBeRemoved) + ---@cast combatObjectRemoved combat + if (bSegmentRemoved and combatObjectRemoved and combatObjectRemoved == combatToBeRemoved) then + --at this point the combat has been removed but not wipped from memory + segmentRemoveResult = segmentRemoveResult .. "segment removed|" .. combatObjectRemoved:GetBossHealth() .."|" + Details:DestroyCombat(combatObjectRemoved) + bSegmentDestroyed = true + --add the combat reference to removed combats table + removedCombats[combatObjectRemoved] = true + end + end + end + end) + + if (not bRunOkay3) then + Details:Msg("bRunOkay3 Error > ", errorText3) + else + if (segmentRemoveResult ~= "") then + Details:Msg("(testing)", segmentRemoveResult) + end + end + end + end --update the amount of segments in use in case a segment was removed amountSegmentsInUse = #segmentsTable diff --git a/frames/window_options2_sections.lua b/frames/window_options2_sections.lua index 86f6f4b9a..55a03ea5b 100644 --- a/frames/window_options2_sections.lua +++ b/frames/window_options2_sections.lua @@ -413,7 +413,6 @@ do step = 1, name = "Segments Boss Wipe", desc = "Amount of segments to keep for wipes on the same boss.", - hidden = true, }, {--wipe segments keep the best segments and delete the worst ones type = "toggle", @@ -424,7 +423,6 @@ do name = "Keep Best Performance (boss wipes)", desc = "Keep the segments with more progress in the boss health and delete the ones with less progress.", boxfirst = true, - hidden = true, }, {type = "breakline"},