Skip to content

Commit

Permalink
Testing the new options for wipe limit for segments and deleting the …
Browse files Browse the repository at this point in the history
…worst try among all wipe segments in a boss
  • Loading branch information
Tercioo committed Jul 15, 2024
1 parent 2e1bde4 commit d96497d
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 5 deletions.
4 changes: 2 additions & 2 deletions boot.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
87 changes: 86 additions & 1 deletion classes/container_segments.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -441,6 +470,9 @@ function Details222.Combat.AddCombat(combatToBeAdded)
---@type table<combat, boolean> 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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions frames/window_options2_sections.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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"},
Expand Down

0 comments on commit d96497d

Please sign in to comment.