Update on LibOpenRaid to version 24

This commit is contained in:
Tercio Jose
2022-04-01 11:38:04 -03:00
parent aef114249f
commit 0d8b09ffb7
7 changed files with 207 additions and 70 deletions
+43 -1
View File
@@ -1,6 +1,6 @@
local dversion = 294
local dversion = 300
local major, minor = "DetailsFramework-1.0", dversion
local DF, oldminor = LibStub:NewLibrary (major, minor)
@@ -759,6 +759,48 @@ function DF.SortOrder3R (t1, t2)
return t1[3] < t2[3]
end
--return a list of spells from the player spellbook
function DF:GetSpellBookSpells()
local spellNamesInSpellBook = {}
for i = 1, GetNumSpellTabs() do
local tabName, tabTexture, offset, numSpells, isGuild, offspecId = GetSpellTabInfo(i)
if (offspecId == 0) then
offset = offset + 1
local tabEnd = offset + numSpells
for j = offset, tabEnd - 1 do
local spellType, spellId = GetSpellBookItemInfo(j, "player")
if (spellId) then
if (spellType ~= "FLYOUT") then
local spellName = GetSpellInfo(spellId)
if (spellName) then
spellNamesInSpellBook[spellName] = true
end
else
local _, _, numSlots, isKnown = GetFlyoutInfo(spellId)
if (isKnown and numSlots > 0) then
for k = 1, numSlots do
local spellID, overrideSpellID, isKnown = GetFlyoutSlotInfo(spellId, k)
if (isKnown) then
local spellName = GetSpellInfo(spellID)
spellNamesInSpellBook[spellName] = true
end
end
end
end
end
end
end
end
return spellNamesInSpellBook
end
------------------------------
--flash animation
local onFinish = function (self)
if (self.showWhenDone) then
self.frame:SetAlpha (1)
+89 -22
View File
@@ -5218,6 +5218,7 @@ DF.IconRowFunctions = {
if (not iconFrame) then
local newIconFrame = CreateFrame ("frame", "$parentIcon" .. self.NextIcon, self, "BackdropTemplate")
newIconFrame.parentIconRow = self
newIconFrame.Texture = newIconFrame:CreateTexture (nil, "artwork")
PixelUtil.SetPoint (newIconFrame.Texture, "topleft", newIconFrame, "topleft", 1, -1)
@@ -5263,7 +5264,7 @@ DF.IconRowFunctions = {
local anchor = self.options.anchor
local anchorTo = self.NextIcon == 1 and self or self.IconPool [self.NextIcon - 1]
local xPadding = self.NextIcon == 1 and self.options.left_padding or self.options.icon_padding
local xPadding = self.NextIcon == 1 and self.options.left_padding or self.options.icon_padding or 1
local growDirection = self.options.grow_direction
if (growDirection == 1) then --grow to right
@@ -5288,16 +5289,16 @@ DF.IconRowFunctions = {
return iconFrame
end,
SetIcon = function (self, spellId, borderColor, startTime, duration, forceTexture, descText, count, debuffType, caster, canStealOrPurge)
SetIcon = function (self, spellId, borderColor, startTime, duration, forceTexture, descText, count, debuffType, caster, canStealOrPurge, spellName, isBuff)
local spellName, _, spellIcon
local actualSpellName, _, spellIcon = GetSpellInfo (spellId)
if (not forceTexture) then
spellName, _, spellIcon = GetSpellInfo (spellId)
else
if forceTexture then
spellIcon = forceTexture
end
spellName = spellName or actualSpellName or "unknown_aura"
if (spellIcon) then
local iconFrame = self:GetIcon()
iconFrame.Texture:SetTexture (spellIcon)
@@ -5315,30 +5316,36 @@ DF.IconRowFunctions = {
if (self.options.show_text) then
iconFrame.CountdownText:Show()
local formattedTime = floor (startTime + duration - GetTime())
local now = GetTime()
if (formattedTime >= 3600) then
formattedTime = floor (formattedTime / 3600) .. "h"
elseif (formattedTime >= 60) then
formattedTime = floor (formattedTime / 60) .. "m"
else
formattedTime = floor (formattedTime)
end
iconFrame.timeRemaining = startTime + duration - now
iconFrame.expirationTime = startTime + duration
local formattedTime = (iconFrame.timeRemaining > 0) and iconFrame.parentIconRow.FormatCooldownTime(iconFrame.timeRemaining) or ""
iconFrame.CountdownText:SetText (formattedTime)
iconFrame.CountdownText:SetPoint (self.options.text_anchor or "center", iconFrame, self.options.text_rel_anchor or "center", self.options.text_x_offset or 0, self.options.text_y_offset or 0)
DF:SetFontSize (iconFrame.CountdownText, self.options.text_size)
DF:SetFontFace (iconFrame.CountdownText, self.options.text_font)
DF:SetFontOutline (iconFrame.CountdownText, self.options.text_outline)
iconFrame.CountdownText:SetText (formattedTime)
if self.options.on_tick_cooldown_update then
iconFrame.lastUpdateCooldown = now
iconFrame:SetScript("OnUpdate", self.OnIconTick)
else
iconFrame:SetScript("OnUpdate", nil)
end
else
iconFrame:SetScript("OnUpdate", nil)
iconFrame.CountdownText:Hide()
end
iconFrame.Cooldown:SetHideCountdownNumbers (self.options.surpress_blizzard_cd_timer)
else
iconFrame.timeRemaining = nil
iconFrame.expirationTime = nil
iconFrame:SetScript("OnUpdate", nil)
iconFrame.CountdownText:Hide()
end
@@ -5381,6 +5388,12 @@ DF.IconRowFunctions = {
iconFrame.debuffType = debuffType
iconFrame.caster = caster
iconFrame.canStealOrPurge = canStealOrPurge
iconFrame.isBuff = isBuff
iconFrame.spellName = spellName
--add the spell into the cache
self.AuraCache [spellId] = true
self.AuraCache [spellName] = true
--> show the frame
self:Show()
@@ -5389,12 +5402,64 @@ DF.IconRowFunctions = {
end
end,
ClearIcons = function (self)
for i = 1, self.NextIcon -1 do
self.IconPool [i]:Hide()
OnIconTick = function (self, deltaTime)
local now = GetTime()
if (self.lastUpdateCooldown + 0.05) <= now then
self.timeRemaining = self.expirationTime - now
if self.timeRemaining > 0 then
self.CountdownText:SetText (self.parentIconRow.FormatCooldownTime(self.timeRemaining))
else
self.CountdownText:SetText ("")
end
self.lastUpdateCooldown = now
end
self.NextIcon = 1
self:Hide()
end,
FormatCooldownTime = function (formattedTime)
if (formattedTime >= 3600) then
formattedTime = floor (formattedTime / 3600) .. "h"
elseif (formattedTime >= 60) then
formattedTime = floor (formattedTime / 60) .. "m"
else
formattedTime = floor (formattedTime)
end
return formattedTime
end,
ClearIcons = function (self, resetBuffs, resetDebuffs)
resetBuffs = resetBuffs ~= false
resetDebuffs = resetDebuffs ~= false
table.wipe (self.AuraCache)
local iconPool = self.IconPool
local countStillShown = 0
for i = 1, self.NextIcon -1 do
if iconPool[i].isBuff == nil then
iconPool[i]:Hide()
iconPool[i]:ClearAllPoints()
elseif resetBuffs and iconPool[i].isBuff then
iconPool[i]:Hide()
iconPool[i]:ClearAllPoints()
elseif resetDebuffs and not iconPool[i].isBuff then
iconPool[i]:Hide()
iconPool[i]:ClearAllPoints()
else
self.AuraCache [iconPool[i].spellId] = true
self.AuraCache [iconPool[i].spellName] = true
countStillShown = countStillShown + 1
end
end
if countStillShown == 0 then
self.NextIcon = 1
self:Hide()
else
self.NextIcon = countStillShown + 1
table.sort (iconPool, function(i1, i2) return i1:IsShown() and not i2:IsShown() end)
end
end,
GetIconGrowDirection = function (self)
@@ -5476,12 +5541,14 @@ local default_icon_row_options = {
grow_direction = 1, --1 = to right 2 = to left
surpress_blizzard_cd_timer = false,
surpress_tulla_omni_cc = false,
on_tick_cooldown_update = true,
}
function DF:CreateIconRow (parent, name, options)
local f = CreateFrame("frame", name, parent, "BackdropTemplate")
f.IconPool = {}
f.NextIcon = 1
f.AuraCache = {}
DF:Mixin (f, DF.IconRowFunctions)
DF:Mixin (f, DF.OptionsFunctions)
+60 -39
View File
@@ -13,12 +13,14 @@ to be implemented:
- raid lockouts normal-heroic-mythic
- make GUID to be used when passing the player name
- make "player" unit information always be available even not in a group
- soulbind character (covenant choise) - probably not used in 10.0
- keystone info
--]=]
local major = "LibOpenRaid-1.0"
local CONST_LIB_VERSION = 22
local CONST_LIB_VERSION = 24
LIB_OPEN_RAID_CAN_LOAD = false
--declae the library within the LibStub
@@ -743,13 +745,14 @@ LIB_OPEN_RAID_CAN_LOAD = false
playerData = {}, --stores the list of cooldowns each player has sent
playerCurrentCooldowns = {},
cooldownTickers = {}, --store C_Timer.NewTicker
playersWithLib = {}, --store player names with the library
}
--check if a cooldown has changed or done
--check if a cooldown time has changed or done
local cooldownTimeLeftCheck = function(tickerObject)
local spellId = tickerObject.spellId
tickerObject.cooldownTimeLeft = tickerObject.cooldownTimeLeft - CONST_COOLDOWN_CHECK_INTERVAL
local timeLeft, charges, startTime, duration = openRaidLib.cooldownManager.GetCooldownStatus(spellId)
local timeLeft, charges, startTimeOffset, duration = openRaidLib.cooldownManager.GetCooldownStatus(spellId)
--is the spell ready to use?
if (timeLeft == 0) then
@@ -761,7 +764,7 @@ LIB_OPEN_RAID_CAN_LOAD = false
--check if the time left has changed
if (not openRaidLib.isNearlyEqual(tickerObject.cooldownTimeLeft, timeLeft, CONST_COOLDOWN_TIMELEFT_HAS_CHANGED)) then
--there's a deviation, send a comm to communicate the change in the time left
openRaidLib.cooldownManager.SendCooldownUpdate(spellId, timeLeft, charges, startTime, duration)
openRaidLib.cooldownManager.SendCooldownUpdate(spellId, timeLeft, charges, startTimeOffset, duration)
tickerObject.cooldownTimeLeft = timeLeft
end
end
@@ -771,7 +774,7 @@ LIB_OPEN_RAID_CAN_LOAD = false
local cooldownStartTicker = function(spellId, cooldownTimeLeft)
local existingTicker = openRaidLib.cooldownManager.cooldownTickers[spellId]
if (existingTicker) then
--is a ticker already exists, might be the cooldown of a charge
--if a ticker already exists, might be the cooldown of a charge
--if the ticker isn't about to expire, just keep the timer
--when the ticker finishes it'll check again for charges
if (existingTicker.startTime + existingTicker.cooldownTimeLeft - GetTime() > 2) then
@@ -812,16 +815,17 @@ LIB_OPEN_RAID_CAN_LOAD = false
return unitCooldownTable
end
--update a single spell time and charges
--update a single cooldown timer
--called when the player casted a cooldown and when received a cooldown update from another player
--only update the db, no other action is taken
local singleCooldownUpdate = function(unitName, spellId, newTimeLeft, newCharges, startTime, duration)
local singleCooldownUpdate = function(unitName, spellId, newTimeLeft, newCharges, startTimeOffset, duration)
local unitCooldownTable = cooldownGetUnitTable(unitName)
local spellIdTable = unitCooldownTable[spellId] or {}
spellIdTable[1] = newTimeLeft
spellIdTable[2] = newCharges
spellIdTable[3] = startTime
spellIdTable[3] = startTimeOffset
spellIdTable[4] = duration
spellIdTable[5] = GetTime()
unitCooldownTable[spellId] = spellIdTable
end
@@ -840,18 +844,18 @@ LIB_OPEN_RAID_CAN_LOAD = false
if (playerSpec) then
if (LIB_OPEN_RAID_COOLDOWNS_BY_SPEC[playerSpec] and LIB_OPEN_RAID_COOLDOWNS_BY_SPEC[playerSpec][spellId]) then
--get the cooldown time for this spell
local timeLeft, charges, startTime, duration = openRaidLib.cooldownManager.GetCooldownStatus(spellId)
local timeLeft, charges, startTimeOffset, duration = openRaidLib.cooldownManager.GetCooldownStatus(spellId)
local playerName = UnitName("player")
local playerCooldownTable = openRaidLib.cooldownManager.GetPlayerCooldowns(playerName)
--update the time left
singleCooldownUpdate(playerName, spellId, timeLeft, charges, startTime, duration)
singleCooldownUpdate(playerName, spellId, timeLeft, charges, startTimeOffset, duration)
--trigger a public callback
openRaidLib.publicCallback.TriggerCallback("CooldownUpdate", playerName, spellId, timeLeft, charges, startTime, duration, playerCooldownTable, openRaidLib.cooldownManager.playerData)
openRaidLib.publicCallback.TriggerCallback("CooldownUpdate", playerName, spellId, timeLeft, charges, startTimeOffset, duration, playerCooldownTable, openRaidLib.cooldownManager.playerData)
--send to comm
openRaidLib.cooldownManager.SendCooldownUpdate(spellId, timeLeft, charges, startTime, duration)
openRaidLib.cooldownManager.SendCooldownUpdate(spellId, timeLeft, charges, startTimeOffset, duration)
--create a timer to monitor the time of this cooldown
--as there's just a few of them to monitor, there's no issue on creating one timer per spell
@@ -871,7 +875,7 @@ LIB_OPEN_RAID_CAN_LOAD = false
local startTime = tonumber(dataAsArray[4])
local duration = tonumber(dataAsArray[5])
--check integraty
--check integrity
if (not spellId or spellId == 0) then
return diagnosticError("cooldownManager|comm received|spellId is invalid")
@@ -880,7 +884,7 @@ LIB_OPEN_RAID_CAN_LOAD = false
elseif (not charges) then
return diagnosticError("cooldownManager|comm received|charges is invalid")
elseif (not startTime) then
return diagnosticError("cooldownManager|comm received|startTime is invalid")
@@ -919,11 +923,17 @@ LIB_OPEN_RAID_CAN_LOAD = false
openRaidLib.internalCallback.RegisterCallback("onLeaveGroup", openRaidLib.cooldownManager.OnLeaveGroup)
--adds a list of cooldowns for another player in the group
--this is called from the received cooldown list from comm
--this is only called from the received cooldown list from comm
function openRaidLib.cooldownManager.AddUnitCooldownsList(unitName, cooldownsTable)
local unitCooldownTable = cooldownGetUnitTable(unitName, true)
openRaidLib.TCopy(unitCooldownTable, cooldownsTable)
--get the time where the cooldown data was received, this is used with the timeleft and startTimeOffset
local timeNow = GetTime()
for spellId, cooldownTable in pairs(cooldownsTable) do
cooldownTable[5] = timeNow
end
--trigger a public callback
openRaidLib.publicCallback.TriggerCallback("CooldownListUpdate", unitName, unitCooldownTable, openRaidLib.cooldownManager.playerData)
end
@@ -977,8 +987,8 @@ LIB_OPEN_RAID_CAN_LOAD = false
end
--send to comm a specific cooldown that was just used, a charge got available or its cooldown is over (ready to use)
function openRaidLib.cooldownManager.SendCooldownUpdate(spellId, cooldownTimeLeft, charges, startTime, duration)
local dataToSend = CONST_COMM_COOLDOWNUPDATE_PREFIX .. "," .. spellId .. "," .. cooldownTimeLeft .. "," .. charges .. "," .. startTime .. "," .. duration
function openRaidLib.cooldownManager.SendCooldownUpdate(spellId, cooldownTimeLeft, charges, startTimeOffset, duration)
local dataToSend = CONST_COMM_COOLDOWNUPDATE_PREFIX .. "," .. spellId .. "," .. cooldownTimeLeft .. "," .. charges .. "," .. startTimeOffset .. "," .. duration
openRaidLib.commHandler.SendCommData(dataToSend)
diagnosticComm("SendCooldownUpdate| " .. dataToSend) --debug
end
@@ -987,6 +997,8 @@ LIB_OPEN_RAID_CAN_LOAD = false
--@data: table received from comm
--@source: player name
function openRaidLib.cooldownManager.OnReceiveCooldowns(data, source)
--add the playerName to the list of players detected with the lib
openRaidLib.cooldownManager.playersWithLib[source] = true
--unpack the table as a pairs table | the cooldown info uses 5 indexes
local unpackedTable = openRaidLib.UnpackTable(data, 1, true, true, 5)
--add the list of cooldowns
@@ -996,6 +1008,7 @@ LIB_OPEN_RAID_CAN_LOAD = false
--build a list with the local player cooldowns
--called only from SendAllCooldowns()
function openRaidLib.cooldownManager.GetPlayerCooldownList()
--get the player specId
local specId = openRaidLib.GetPlayerSpecId()
@@ -1020,18 +1033,18 @@ LIB_OPEN_RAID_CAN_LOAD = false
--check if the player has the talent selected
if (talentsHash[talentId]) then
cooldowns[#cooldowns+1] = cooldownSpellId
local timeLeft, charges, startTime, duration = openRaidLib.cooldownManager.GetCooldownStatus(cooldownSpellId)
local timeLeft, charges, startTimeOffset, duration = openRaidLib.cooldownManager.GetCooldownStatus(cooldownSpellId)
cooldowns[#cooldowns+1] = timeLeft
cooldowns[#cooldowns+1] = charges
cooldowns[#cooldowns+1] = startTime
cooldowns[#cooldowns+1] = startTimeOffset
cooldowns[#cooldowns+1] = duration
end
else
cooldowns[#cooldowns+1] = cooldownSpellId
local timeLeft, charges, startTime, duration = openRaidLib.cooldownManager.GetCooldownStatus(cooldownSpellId)
local timeLeft, charges, startTimeOffset, duration = openRaidLib.cooldownManager.GetCooldownStatus(cooldownSpellId)
cooldowns[#cooldowns+1] = timeLeft
cooldowns[#cooldowns+1] = charges
cooldowns[#cooldowns+1] = startTime
cooldowns[#cooldowns+1] = startTimeOffset
cooldowns[#cooldowns+1] = duration
end
end
@@ -1052,27 +1065,35 @@ C_Timer.After(0.1, function()
vintageCDTrackerFrame:SetScript("OnEvent", function(self, event, ...)
if (event == "UNIT_SPELLCAST_SUCCEEDED") then
local unit, castGUID, spellId = ...
if (UnitInParty(unit) or UnitInRaid(unit)) then
local unitName = UnitName(unit)
local cooldownInfo = allCooldownsFromLib[spellId]
if (cooldownInfo and unitName and not openRaidLib.cooldownManager.GetPlayerCooldowns(unitName)) then
--check for cast_success spam from channel spells
local unitCastCooldown = recentCastedSpells[UnitGUID(unit)]
if (not unitCastCooldown) then
unitCastCooldown = {}
recentCastedSpells[UnitGUID(unit)] = unitCastCooldown
end
if (not unitCastCooldown[spellId] or unitCastCooldown[spellId]+5 < GetTime()) then
unitCastCooldown[spellId] = GetTime()
--trigger a cooldown usage
local unitIsThePlayer = UnitIsUnit(unit, "player")
if (not unitIsThePlayer) then
local unitName = GetUnitName(unit, true)
local hasLib = openRaidLib.cooldownManager.playersWithLib[unitName]
if (unitName and not hasLib) then
local unitInGroup = UnitInParty(unit) or UnitInRaid(unit)
if (unitInGroup) then
local cooldownInfo = allCooldownsFromLib[spellId]
if (cooldownInfo) then -- and not openRaidLib.cooldownManager.GetPlayerCooldowns(unitName)
--check for cast_success spam from channel spells
local unitCastCooldown = recentCastedSpells[unitName]
if (not unitCastCooldown) then
unitCastCooldown = {}
recentCastedSpells[unitName] = unitCastCooldown
end
local duration = cooldownInfo.duration
--time left, charges, startTimeDeviation, duration
singleCooldownUpdate(unitName, spellId, duration, 0, 0, duration)
if (not unitCastCooldown[spellId] or unitCastCooldown[spellId]+5 < GetTime()) then
unitCastCooldown[spellId] = GetTime()
--trigger a public callback
openRaidLib.publicCallback.TriggerCallback("CooldownUpdate", unitName, spellId, duration, 0, 0, duration, openRaidLib.cooldownManager.playerData)
--trigger a cooldown usage
local duration = cooldownInfo.duration
--time left, charges, startTimeOffset, duration
singleCooldownUpdate(unitName, spellId, duration, 0, 0, duration)
--trigger a public callback
openRaidLib.publicCallback.TriggerCallback("CooldownUpdate", unitName, spellId, duration, 0, 0, duration, openRaidLib.cooldownManager.playerData)
end
end
end
end
end
+1 -1
View File
@@ -1,4 +1,4 @@
## Interface: 90105
## Interface: 90200
## Title: Library Open Raid
## Notes: This is a library used by addons.
+2 -2
View File
@@ -263,7 +263,7 @@ LIB_OPEN_RAID_COOLDOWNS_BY_SPEC = {
[10060] = 1, --Power Infusion
[200183] = 2, --Apotheosis
[47788] = 3, --Guardian Spirit
[64844] = 4, --Divine Hymn
[64843] = 4, --Divine Hymn
[64901] = 4, --Symbol of Hope
[265202] = 4, --Holy Word: Salvation (talent)
--[88625] = 5, --Holy Word: Chastise
@@ -879,7 +879,7 @@ LIB_OPEN_RAID_COOLDOWNS_INFO = {
[19236] = {cooldown = 90, duration = 10, talent = false, charges = 1, class = "PRIEST", type = 5}, --Desperate Prayer
[200183] = {cooldown = 120, duration = 20, talent = 21644, charges = 1, class = "PRIEST", type = 2}, --Apotheosis (talent)
[47788] = {cooldown = 180, duration = 10, talent = false, charges = 1, class = "PRIEST", type = 3}, --Guardian Spirit
[64844] = {cooldown = 180, duration = 8, talent = false, charges = 1, class = "PRIEST", type = 4}, --Divine Hymn
[64843] = {cooldown = 180, duration = 8, talent = false, charges = 1, class = "PRIEST", type = 4}, --Divine Hymn
[64901] = {cooldown = 300, duration = 6, talent = false, charges = 1, class = "PRIEST", type = 4}, --Symbol of Hope
[265202] = {cooldown = 720, duration = false, talent = 23145, charges = 1, class = "PRIEST", type = 4}, --Holy Word: Salvation (talent)
[109964] = {cooldown = 60, duration = 12, talent = 21184, charges = 1, class = "PRIEST", type = 4}, --Spirit Shell (talent)
+7 -4
View File
@@ -48,8 +48,9 @@ playerCooldows = {
[cooldownSpellId] = {
[1] = time left (number),
[2] = charges (number),
[3] = start time (number),
[4] = duration (number)
[3] = start time offset (number) - time offset from when the cooldown was used,
[4] = duration (number),
[5] = GetTime() of when the information was received
}
}
@@ -84,10 +85,12 @@ function MyAddonObject.OnReceiveCooldownListUpdate(unitName, playerCooldows, all
local timeLeft = cooldownInfoTable[1]
--in some cases the spell is on cooldown but there's a charge to use
local charges = cooldownInfoTable[2]
--cooldown start time
local startTime = cooldownInfoTable[3]
--cooldown start time offset (how much time has passed since the cooldown was used)
local startTimeOffset = cooldownInfoTable[3]
--cooldown duration, e.g. 180 for 3 minutes cooldown
local totalDuration = cooldownInfoTable[4]
--time when received this information
local timeReceived = cooldownInfoTable[5]
end
end
+5 -1
View File
@@ -693,7 +693,11 @@
end
end
end
--
--Jailer
if (_current_encounter_id == 2537) then
end
--> npcId check for ignored npcs
local npcId = npcid_cache[alvo_serial]