Skip to content

Commit

Permalink
Added combat:GetBossHealth(); combat:GetBossName(); combat:GetCurrent…
Browse files Browse the repository at this point in the history
…Phase()
  • Loading branch information
Tercioo committed Mar 13, 2024
1 parent 2c613e0 commit f9d2e81
Show file tree
Hide file tree
Showing 14 changed files with 294 additions and 75 deletions.
7 changes: 7 additions & 0 deletions Definitions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,8 @@
---@field last_events_tables table[] where the death log of each player is stored
---@field boss_hp number percentage of the health points of the boss
---@field training_dummy boolean if true, the combat is against a training dummy
---@field playerTalents table<actorname, string> [playerName] = "talent string"
---@field bossName string? the name of the boss, if the combat has no unitId "boss1", this value is nil
---@field
---@field
---@field __call table
Expand Down Expand Up @@ -256,6 +258,8 @@
---@field is_world_trash_combat boolean when true this combat is a regular combat done in the world, not in a dungeon, raid, battleground, arena, ...
---@field player_last_events table<string, table[]> record the latest events of each player, latter used to build the death log
---@field
---@field GetCurrentPhase fun(combat: combat) : number return the current phase of the combat or the phase where the combat ended
---@field StoreTalents fun(self:combat)
---@field FindEnemyName fun(combat: combat) : string attempt to get the name of the enemy in the combat by getting the top most damaged unit by the player
---@field GetTryNumber fun(combat: combat) : number?
---@field GetFormattedCombatTime fun(combat: combat) : string
Expand Down Expand Up @@ -298,6 +302,9 @@
---@field GetEncounterName fun(combat: combat) : string get the name of the encounter
---@field GetBossImage fun(combat: combat) : texturepath|textureid get the icon of the encounter
---@field SetDateToNow fun(combat: combat, bSetStartDate: boolean?, bSetEndDate: boolean?) set the date to the current time. format: "H:M:S"
---@field GetBossHealth fun(combat: combat) : number get the percentage of the boss health when the combat ended
---@field GetBossName fun(combat: combat) : string? return the name of the unitId "boss1", nil if the unit doesn't existed during the combat


---@class actorcontainer : table contains two tables _ActorTable and _NameIndexTable, the _ActorTable contains the actors, the _NameIndexTable contains the index of the actors in the _ActorTable, making quick to reorder them without causing overhead
---@field need_refresh boolean when true the container is dirty and needs to be refreshed
Expand Down
17 changes: 17 additions & 0 deletions Libs/DF/definitions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,23 @@
---@field SliderCounter number when no name is given, a string plus an incremental number is used instead
---@field SwitchCounter number when no name is given, a string plus an incremental number is used instead
---@field SplitBarCounter number when no name is given, a string plus an incremental number is used instead
---@field TalentExporter table
---@field FormatNumber fun(number:number) : string abbreviate a number, e.g. 1000 -> 1k 1000 -> 1, depending on the client language
---@field UnitGroupRolesAssigned fun(unitId: unit, bUseSupport:boolean?, specId: specializationid?) : string there's no self here
---@field IsDragonflight fun():boolean
---@field IsDragonflightAndBeyond fun():boolean
---@field IsTimewalkWoW fun():boolean
---@field IsClassicWow fun():boolean
---@field IsTBCWow fun():boolean
---@field IsWotLKWow fun():boolean
---@field IsCataWow fun():boolean
---@field IsPandaWow fun():boolean
---@field IsWarlordsWow fun():boolean
---@field IsLegionWow fun():boolean
---@field IsBFAWow fun():boolean
---@field IsShadowlandsWow fun():boolean
---@field IsDragonflightWow fun():boolean
---@field IsWarWow fun():boolean
---@field LoadSpellCache fun(self:table, hashMap:table, indexTable:table, allSpellsSameName:table) : hashMap:table, indexTable:table, allSpellsSameName:table load all spells in the game and add them into the passed tables
---@field UnloadSpellCache fun(self:table) wipe the table contents filled with LoadSpellCache()
---@field GetCurrentClassName fun(self:table) : string return the name of the class the player is playing
Expand All @@ -167,7 +182,9 @@
---@field GetCurrentSpec fun(self:table):number?
---@field GetCurrentSpecId fun(self:table):number? return the specId of the current spec, retuns nil if the expansion the player is playing does not support specs
---@field GetClassSpecIds fun(self:table, engClass:string):number[]
---@field GetClassSpecIDs fun(self:table, engClass:string):number[]
---@field IsValidSpecId fun(self:table, specId:number):boolean check if the passed specId is valid for the player class, also return false for tutorial specs
---@field GetDragonlightTalentString fun(self:table):string return the talent config string
---@field GetClassList fun(self:table):{ID:number, Name:string, FileString:string, Texture:string, TexCoord:number[]}[]
---@field DebugVisibility fun(self:table, object:uiobject) print the reason why the frame isn't shown in the screen
---@field Dispatch fun(self:table, callback:function, ...) : any dispatch a function call using xpcall, print to chat if the function passed is invalid
Expand Down
110 changes: 79 additions & 31 deletions Libs/DF/fw.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@


local dversion = 521
local dversion = 522
local major, minor = "DetailsFramework-1.0", dversion
local DF, oldminor = LibStub:NewLibrary(major, minor)

Expand Down Expand Up @@ -31,6 +31,8 @@ local UnitIsTapDenied = UnitIsTapDenied
SMALL_NUMBER = 0.000001
ALPHA_BLEND_AMOUNT = 0.8400251

local _, _, _, buildInfo = GetBuildInfo()

DF.dversion = dversion

DF.AuthorInfo = {
Expand Down Expand Up @@ -77,62 +79,104 @@ function DF:GetDefaultBackdropColor()
return 0.1215, 0.1176, 0.1294, 0.8
end

---return if the wow version the player is playing is dragonflight or an expansion after it
---@return boolean
function DF.IsDragonflightAndBeyond()
return select(4, GetBuildInfo()) >= 100000
end

---return if the wow version the player is playing is dragonflight
---@return boolean
function DF.IsDragonflight()
local _, _, _, buildInfo = GetBuildInfo()
if (buildInfo < 110000 and buildInfo >= 100000) then
return true
end
if (buildInfo < 110000 and buildInfo >= 100000) then return true end
return false
end

---return if the wow version the player is playing is dragonflight or an expansion after it
---@return boolean
function DF.IsDragonflightAndBeyond()
return select(4, GetBuildInfo()) >= 100000
end

---return if the wow version the player is playing is a classic version of wow
---@return boolean
function DF.IsTimewalkWoW()
local _, _, _, buildInfo = GetBuildInfo()
if (buildInfo < 40000) then
return true
end
if (buildInfo < 40000) then return true end
return false
end

---return if the wow version the player is playing is the vanilla version of wow
---@return boolean
function DF.IsClassicWow()
local _, _, _, buildInfo = GetBuildInfo()
if (buildInfo < 20000) then
return true
end
if (buildInfo < 20000) then return true end
return false
end

---return true if the player is playing in the TBC version of wow
---@return boolean
function DF.IsTBCWow()
local _, _, _, buildInfo = GetBuildInfo()
if (buildInfo < 30000 and buildInfo >= 20000) then
return true
end
if (buildInfo < 30000 and buildInfo >= 20000) then return true end
return false
end

---return true if the player is playing in the WotLK version of wow
---@return boolean
function DF.IsWotLKWow()
local _, _, _, buildInfo = GetBuildInfo()
if (buildInfo < 40000 and buildInfo >= 30000) then
return true
end
if (buildInfo < 40000 and buildInfo >= 30000) then return true end
return false
end

---return true if the player is playing in the Cataclysm version of wow
---@return boolean
function DF.IsCataWow()
if (buildInfo < 50000 and buildInfo >= 40000) then return true end
return false
end

---return true if the player is playing in the Mists version of wow
---@return boolean
function DF.IsPandaWow()
if (buildInfo < 60000 and buildInfo >= 50000) then return true end
return false
end

---return true if the player is playing in the Warlords of Draenor version of wow
---@return boolean
function DF.IsWarlordsWow()
if (buildInfo < 70000 and buildInfo >= 60000) then return true end
return false
end

---return true if the player is playing in the Legion version of wow
---@return boolean
function DF.IsLegionWow()
if (buildInfo < 80000 and buildInfo >= 70000) then return true end
return false
end

---return true if the player is playing in the BFA version of wow
---@return boolean
function DF.IsBFAWow()
if (buildInfo < 90000 and buildInfo >= 80000) then return true end
return false
end

---return true if the player is playing in the Shadowlands version of wow
---@return boolean
function DF.IsShadowlandsWow()
if (buildInfo < 100000 and buildInfo >= 90000) then return true end
return false
end

---return if the wow version the player is playing is dragonflight
---@return boolean
function DF.IsDragonflightWow()
if (buildInfo < 110000 and buildInfo >= 100000) then return true end
return false
end

---return if the wow version the player is playing is the war within
---@return boolean
function DF.IsWarWow()
if (buildInfo < 120000 and buildInfo >= 110000) then return true end
return false
end


---return true if the player is playing in the WotLK version of wow with the retail api
---@return boolean
function DF.IsNonRetailWowWithRetailAPI()
Expand Down Expand Up @@ -4287,6 +4331,9 @@ local specs_per_class = {
}


---return an array table with the spec ids the class can have
---@param engClass string
---@return table
function DF:GetClassSpecIDs(engClass)
return specs_per_class[engClass]
end
Expand Down Expand Up @@ -4320,7 +4367,6 @@ local getDragonflightTalents = function()

local treeInfo = C_Traits.GetTreeInfo(configId, configInfo.treeIDs[1])
local treeHash = C_Traits.GetTreeHash(treeInfo.ID)

local serializationVersion = C_Traits.GetLoadoutSerializationVersion()

DF.TalentExporter:WriteLoadoutHeader(exportStream, serializationVersion, currentSpecID, treeHash)
Expand All @@ -4329,12 +4375,14 @@ local getDragonflightTalents = function()
return exportStream:GetExportString()
end

--/dump DetailsFramework:GetDragonlightTalentExportString()
--/dump DetailsFramework:GetDragonlightTalentString()
function DF:GetDragonlightTalentString()
local talentString, errorText = pcall(getDragonflightTalents)
if (errorText) then
local runOkay, errorText = pcall(getDragonflightTalents)
if (not runOkay) then
DF:Msg("error 0x4517", errorText)
return ""
else
local talentString = errorText
return talentString
end
end
Expand Down
61 changes: 61 additions & 0 deletions classes/class_combat.lua
Original file line number Diff line number Diff line change
Expand Up @@ -863,6 +863,7 @@ local segmentTypeToString = {
end

---Return how many attempts were made for this boss
---@param self combat
---@return number|nil
function classCombat:GetTryNumber()
---@type bossinfo
Expand All @@ -872,6 +873,32 @@ local segmentTypeToString = {
end
end

---Return the percentage of the boss health when the combat ended
---1 = 100% 0.5 = 50%
---@param self combat
---@return number
function classCombat:GetBossHealth()
return self.boss_hp
end

---Get the boss name
---@param self combat
---@return string?
function classCombat:GetBossName()
return self.bossName
end

---Return the current phase of the combat or which phase the combat was when it ended
---@param self combat
---@return number
function classCombat:GetCurrentPhase()
local phaseData = self.PhaseData
local lastPhase = #phaseData
--the phase data has on its first index the ID of the phase and on the second the time when it started
local lastPhaseId = phaseData[lastPhase][1]
return lastPhaseId
end

---copy deaths from combat2 into combat1
---if bMythicPlus is true it'll check if the death has mythic plus death time and use it instead of the normal death time
---@param combat1 combat
Expand All @@ -896,6 +923,11 @@ local segmentTypeToString = {
--return the total of a specific attribute
local power_table = {0, 1, 3, 6, 0, "alternatepower"}

---return the total of a specific attribute, example: total damage, total healing, total resources, etc
---@param attribute number
---@param subAttribute number
---@param onlyGroup boolean?
---@return number
function classCombat:GetTotal(attribute, subAttribute, onlyGroup)
if (attribute == 1 or attribute == 2) then
if (onlyGroup) then
Expand Down Expand Up @@ -936,6 +968,20 @@ local segmentTypeToString = {
return alternatePowerTable
end

---transfer talents from Details talent cache to the combat combat
---@param self combat
function classCombat:StoreTalents()
local talentStorage = Details.cached_talents
local damageContainer = self:GetContainer(DETAILS_ATTRIBUTE_DAMAGE)
for idx, actorObject in damageContainer:ListActors() do
local thisActorTalents = talentStorage[actorObject.serial]
if (thisActorTalents) then
local actorName = actorObject:Name()
self.playerTalents[actorName] = thisActorTalents
end
end
end

--delete an actor from the combat ~delete ~erase ~remove
function classCombat:DeleteActor(attribute, actorName, removeDamageTaken, cannotRemap)
local container = self[attribute]
Expand Down Expand Up @@ -1026,6 +1072,15 @@ function classCombat:CreateNewCombatTable()
return classCombat:NovaTabela()
end

local getBossName = function()
if (UnitExists("boss1") and Details.in_combat) then
local bossName = UnitName("boss1")
if (bossName) then
Details:GetCurrentCombat().bossName = bossName
end
end
end

---class constructor
---@param bTimeStarted boolean if true set the start time to now with GetTime
---@param overallCombatObject combat
Expand Down Expand Up @@ -1084,11 +1139,17 @@ function classCombat:NovaTabela(bTimeStarted, overallCombatObject, combatId, ...

combatObject.boss_hp = 1

C_Timer.After(0.5, getBossName)

combatObject.bossTimers = {}

---store trinket procs
combatObject.trinketProcs = {}

--store talents of players
---@type table<actorname, string>
combatObject.playerTalents = {}

---store the amount of casts of each player
---@type table<actorname, table<spellname, number>>
combatObject.amountCasts = {}
Expand Down
4 changes: 4 additions & 0 deletions core/control.lua
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,7 @@
local combatCounter = Details:GetOrSetCombatId(1)

--create a new combat object and preplace the current one
---@type combat
local newCombatObject = Details.combate:NovaTabela(true, Details.tabela_overall, combatCounter, ...)
Details:SetCurrentCombat(newCombatObject)

Expand Down Expand Up @@ -771,6 +772,9 @@
if (not bShouldForceDiscard and (zoneType == "none" or tempo_do_combate >= Details.minimum_combat_time or not segmentsTable[1])) then
--combat accepted
Details.tabela_historico:AddCombat(currentCombat) --move a tabela atual para dentro do hist�rico

currentCombat:StoreTalents()

if (currentCombat.is_boss) then
if (IsInRaid()) then
local cleuID = currentCombat.is_boss.id
Expand Down
Loading

0 comments on commit f9d2e81

Please sign in to comment.