Skip to content

Commit

Permalink
Added the new wipe counter for tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Tercioo committed Jul 15, 2024
1 parent 8d65e6a commit b8df714
Show file tree
Hide file tree
Showing 5 changed files with 168 additions and 49 deletions.
1 change: 1 addition & 0 deletions Libs/LibLuaServer/LibLuaServer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,7 @@ function LibStub:IterateLibraries()end
---@alias encounterid number encounter ID number received by the event ENCOUNTER_START and ENCOUNTER_END
---@alias encounterejid number encounter ID number used by the encounter journal
---@alias encountername string encounter name received by the event ENCOUNTER_START and ENCOUNTER_END also used by the encounter journal
---@alias encounterdifficulty number difficulty of the encounter received by the event ENCOUNTER_START and ENCOUNTER_END
---@alias instancename string localized name of an instance (e.g. "The Nighthold")
---@alias spellid number each spell in the game has a unique spell id, this id can be used to identify a spell.
---@alias unitname string name of a unit
Expand Down
89 changes: 85 additions & 4 deletions classes/container_segments.lua
Original file line number Diff line number Diff line change
Expand Up @@ -319,13 +319,88 @@ function Details:CanAddCombatToOverall(combatObject)
return false
end

---get the amount of wipes for a guilda in a specific boss and difficulty
---@param guildName string
---@param encounterId number
---@param difficultyId number
---@return number
function Details:GetWipeCounter(guildName, encounterId, difficultyId)
local guildWipes = Details.boss_wipe_counter[guildName]
if (guildWipes) then
local bossWipes = guildWipes[encounterId]
if (bossWipes) then
local difficultyWipes = bossWipes[difficultyId]
if (difficultyWipes) then
return difficultyWipes
end
end
end
return 0
end

---count boss tries and set the value in the combat object
---@param combatToBeAdded combat
local setBossTryCounter = function(combatToBeAdded, segmentsTable, amountSegmentsInUse)
---@type string
local bossName = combatToBeAdded.is_boss and combatToBeAdded.is_boss.name
---@type bossinfo
local bossInfo = combatToBeAdded:GetBossInfo()
local bossName = bossInfo and bossInfo.name
local encounterId = bossInfo and bossInfo.id
local bossDifficultyId = bossInfo and bossInfo.diff

if (bossName and encounterId and bossDifficultyId) then
--account global
---@type table<guildname, table<encounterid, table<encounterdifficulty, number>>>
local bossTriesDatabase = Details.boss_wipe_counter

--to store a wipe 70% of the raid must be from the same guild
--get the player guild name
local playerGuildName = GetGuildInfo("player")
if (playerGuildName) then
local amountOfPlayersInGroup = GetNumGroupMembers()
local amountOfPlayersFromGuild = 0

local cachedRaidUnitIds = Details222.UnitIdCache.Raid
for i = 1, amountOfPlayersInGroup do
local unitId = cachedRaidUnitIds[i]
--get the guild name of the unit
local unitGuildName = GetGuildInfo(unitId)
if (unitGuildName and unitGuildName == playerGuildName) then
amountOfPlayersFromGuild = amountOfPlayersFromGuild + 1
end
end

--check the 70%
if (amountOfPlayersFromGuild / amountOfPlayersInGroup >= 0.7) then
--check the elapsed time of the encounter is bigger than the min allowed
if (Details.boss_wipe_min_time <= combatToBeAdded:GetCombatTime()) then
--check if there is a table for the guild name in the database
local guildWipes = bossTriesDatabase[playerGuildName]
if (not guildWipes) then
guildWipes = {}
bossTriesDatabase[playerGuildName] = guildWipes
end

--check if there is a table for the bossId in the guild table
local bossWipes = guildWipes[encounterId]
if (not bossWipes) then
bossWipes = {}
guildWipes[encounterId] = bossWipes
end

--check if there's a difficulty table inside the boss wipes table
local difficultyWipes = bossWipes[bossDifficultyId]
if (not difficultyWipes) then
difficultyWipes = 0
bossWipes[bossDifficultyId] = difficultyWipes
end

--increment the wipe counter
bossWipes[bossDifficultyId] = difficultyWipes + 1
Details:Msg("(testing) wipes on this boss with this guild in this difficulty:", bossWipes[bossDifficultyId])
end
end
end

if (bossName) then
local tryNumber = Details.encounter_counter[bossName]
if (not tryNumber) then
---@type combat
Expand Down Expand Up @@ -392,7 +467,10 @@ function Details222.Combat.AddCombat(combatToBeAdded)
end
end

setBossTryCounter(combatToBeAdded, segmentsTable, amountSegmentsInUse)
local bRunOkay, errorText = pcall(setBossTryCounter, combatToBeAdded, segmentsTable, amountSegmentsInUse)
if (not bRunOkay) then
Details:Msg("error > failed to set boss try counter > ", errorText)
end

--shutdown actors from the previous combat from the time machine
---@type combat
Expand Down Expand Up @@ -467,6 +545,9 @@ function Details222.Combat.AddCombat(combatToBeAdded)
end
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

--update the amount of segments in use in case a segment was removed
amountSegmentsInUse = #segmentsTable

Expand Down
16 changes: 8 additions & 8 deletions core/gears.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1952,12 +1952,12 @@ print(1)
local guildName = GetGuildInfo("player")
local raidSize = GetNumGroupMembers() or 0

local cachedUnitIds = Details222.UnitIdCache.Raid
local cachedRaidUnitIds = Details222.UnitIdCache.Raid

if (not Details222.storage.IsDebug) then
if (guildName) then
for i = 1, raidSize do
local gName = GetGuildInfo(cachedUnitIds[i]) or ""
local gName = GetGuildInfo(cachedRaidUnitIds[i]) or ""
if (gName == guildName) then
match = match + 1
end
Expand Down Expand Up @@ -1996,16 +1996,16 @@ print(1)
print(6, diff)

for i = 1, GetNumGroupMembers() do
local role = UnitGroupRolesAssigned(cachedUnitIds[i])
local role = UnitGroupRolesAssigned(cachedRaidUnitIds[i])

if (UnitIsInMyGuild(cachedUnitIds[i])) then
if (UnitIsInMyGuild(cachedRaidUnitIds[i])) then
if (role == "DAMAGER" or role == "TANK") then
local playerName = Details:GetFullName(cachedUnitIds[i])
local playerName = Details:GetFullName(cachedRaidUnitIds[i])
local _, _, class = Details:GetUnitClassFull(playerName)

local damagerActor = damageContainer:GetActor(playerName)
if (damagerActor) then
local guid = UnitGUID(cachedUnitIds[i])
local guid = UnitGUID(cachedRaidUnitIds[i])

---@type details_storage_unitresult
local unitResultInfo = {
Expand All @@ -2017,12 +2017,12 @@ print(1)
end

elseif (role == "HEALER") then
local playerName = Details:GetFullName(cachedUnitIds[i])
local playerName = Details:GetFullName(cachedRaidUnitIds[i])
local _, _, class = Details:GetUnitClassFull(playerName)

local healingActor = healingContainer:GetActor(playerName)
if (healingActor) then
local guid = UnitGUID(cachedUnitIds[i])
local guid = UnitGUID(cachedRaidUnitIds[i])

---@type details_storage_unitresult
local unitResultInfo = {
Expand Down
100 changes: 63 additions & 37 deletions frames/window_options2_sections.lua
Original file line number Diff line number Diff line change
Expand Up @@ -401,51 +401,30 @@ do
desc = Loc ["STRING_OPTIONS_SEGMENTSSAVE_DESC"],
},

{type = "blank"},
{type = "label", get = function() return "Auto Erase:" end, text_template = subSectionTitleTextTemplate},

{--auto erase settings | erase data
type = "select",
get = function() return Details.segments_auto_erase end,
values = function()
return buildEraseDataMenu()
end,
name = Loc ["STRING_OPTIONS_ED"],
desc = Loc ["STRING_OPTIONS_ED_DESC"],
},

{--auto erase trash segments
type = "toggle",
get = function() return Details.trash_auto_remove end,
set = function(self, fixedparam, value)
Details.trash_auto_remove = value
afterUpdate()
end,
name = Loc ["STRING_OPTIONS_CLEANUP"],
desc = Loc ["STRING_OPTIONS_CLEANUP_DESC"],
boxfirst = true,
},
{--auto erase world segments
type = "toggle",
get = function() return Details.world_combat_is_trash end,
{--max segments on boss wipes
type = "range",
get = function() return Details.segments_amount_boss_wipes end,
set = function(self, fixedparam, value)
Details.world_combat_is_trash = value
Details.segments_amount_boss_wipes = value
afterUpdate()
end,
name = Loc ["STRING_OPTIONS_PERFORMANCE_ERASEWORLD"],
desc = Loc ["STRING_OPTIONS_PERFORMANCE_ERASEWORLD_DESC"],
boxfirst = true,
min = 1,
max = 40,
step = 1,
name = "Segments Boss Wipe",
desc = "Amount of segments to keep for wipes on the same boss.",
hidden = true,
},
{--erase chart data
{--wipe segments keep the best segments and delete the worst ones
type = "toggle",
get = function() return Details.clear_graphic end,
get = function() return Details.segments_boss_wipes_keep_best_performance end,
set = function(self, fixedparam, value)
Details.clear_graphic = value
afterUpdate()
Details.segments_boss_wipes_keep_best_performance = value
end,
name = Loc ["STRING_OPTIONS_ERASECHARTDATA"],
desc = Loc ["STRING_OPTIONS_ERASECHARTDATA_DESC"],
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 Expand Up @@ -686,6 +665,53 @@ do
boxfirst = true,
},

{type = "blank"},
{type = "label", get = function() return "Auto Erase:" end, text_template = subSectionTitleTextTemplate},

{--auto erase settings | erase data
type = "select",
get = function() return Details.segments_auto_erase end,
values = function()
return buildEraseDataMenu()
end,
name = Loc ["STRING_OPTIONS_ED"],
desc = Loc ["STRING_OPTIONS_ED_DESC"],
},

{--auto erase trash segments
type = "toggle",
get = function() return Details.trash_auto_remove end,
set = function(self, fixedparam, value)
Details.trash_auto_remove = value
afterUpdate()
end,
name = Loc ["STRING_OPTIONS_CLEANUP"],
desc = Loc ["STRING_OPTIONS_CLEANUP_DESC"],
boxfirst = true,
},
{--auto erase world segments
type = "toggle",
get = function() return Details.world_combat_is_trash end,
set = function(self, fixedparam, value)
Details.world_combat_is_trash = value
afterUpdate()
end,
name = Loc ["STRING_OPTIONS_PERFORMANCE_ERASEWORLD"],
desc = Loc ["STRING_OPTIONS_PERFORMANCE_ERASEWORLD_DESC"],
boxfirst = true,
},
{--erase chart data
type = "toggle",
get = function() return Details.clear_graphic end,
set = function(self, fixedparam, value)
Details.clear_graphic = value
afterUpdate()
end,
name = Loc ["STRING_OPTIONS_ERASECHARTDATA"],
desc = Loc ["STRING_OPTIONS_ERASECHARTDATA_DESC"],
boxfirst = true,
},

}

sectionFrame.sectionOptions = sectionOptions
Expand Down
11 changes: 11 additions & 0 deletions functions/profiles.lua
Original file line number Diff line number Diff line change
Expand Up @@ -904,6 +904,10 @@ local default_profile = {
--segments
segments_amount = 25,
segments_amount_to_save = 15,
--max amount of boss wipes allowed
segments_amount_boss_wipes = 10,
--should boss wipes delete segments with less progression?
segments_boss_wipes_keep_best_performance = true,
segments_panic_mode = false,
segments_auto_erase = 1,

Expand Down Expand Up @@ -1396,6 +1400,9 @@ local default_global_data = {
position = {},
},

boss_wipe_counter = {},
boss_wipe_min_time = 20, --minimum time to consider a wipe as a boss wipe

user_is_patreon_supporter = false,

show_aug_predicted_spell_damage = false,
Expand Down Expand Up @@ -2051,6 +2058,10 @@ function Details:ImportProfile (profileString, newProfileName, bImportAutoRunCod
Details.segments_amount = 25
--max segments to save between sections
Details.segments_amount_to_save = 15
--max amount of boss wipes allowed
Details.segments_amount_boss_wipes = 10
--should boss wipes delete segments with less progression?
Details.segments_boss_wipes_keep_best_performance = true

--transfer instance data to the new created profile
profileObject.instances = DetailsFramework.table.copy({}, profileData.instances)
Expand Down

0 comments on commit b8df714

Please sign in to comment.