Skip to content

Commit

Permalink
updated lib RaidStatus and general bug fixes; ToC Updates
Browse files Browse the repository at this point in the history
  • Loading branch information
Tercioo committed Jul 1, 2021
1 parent 2da8f23 commit 07a60b4
Show file tree
Hide file tree
Showing 15 changed files with 303 additions and 108 deletions.
2 changes: 1 addition & 1 deletion Details.toc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## Interface: 90005
## Interface: 90100
## Title: Details! Damage Meter
## Notes: Essential tool to impress that chick in your raid.
## SavedVariables: _detalhes_global
Expand Down
126 changes: 94 additions & 32 deletions Libs/LibRaidStatus/LibRaidStatus.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

local major = "LibRaidStatus-1.0"
local CONST_LIB_VERSION = 16
local CONST_LIB_VERSION = 17
LIB_RAID_STATUS_CAN_LOAD = false

--declae the library within the LibStub
Expand All @@ -27,7 +27,8 @@ LIB_RAID_STATUS_CAN_LOAD = false
local CONST_COMM_GEARINFO_DURABILITY_PREFIX = "R"
local CONST_COMM_PLAYER_DEAD_PREFIX = "D"
local CONST_COMM_PLAYER_ALIVE_PREFIX = "A"
local CONST_COMM_PLAYER_INFO_PREFIX = "P"
local CONST_COMM_PLAYERINFO_PREFIX = "P"
local CONST_COMM_PLAYERINFO_TALENTS_PREFIX = "T"

local CONST_ONE_SECOND = 1.0
local CONST_TWO_SECONDS = 2.0
Expand Down Expand Up @@ -117,7 +118,7 @@ LIB_RAID_STATUS_CAN_LOAD = false
end
end

--transform a table index a string dividing values with a comma
--transform a table index into a string dividing values with a comma
--@table: an indexed table with unknown size
function raidStatusLib.PackTable(table)
local tableSize = #table
Expand Down Expand Up @@ -251,7 +252,8 @@ LIB_RAID_STATUS_CAN_LOAD = false
[CONST_COMM_GEARINFO_DURABILITY_PREFIX] = {}, --an update of the player gear durability
[CONST_COMM_PLAYER_DEAD_PREFIX] = {}, --player is dead
[CONST_COMM_PLAYER_ALIVE_PREFIX] = {}, --player is alive
[CONST_COMM_PLAYER_INFO_PREFIX] = {}, --info about the player
[CONST_COMM_PLAYERINFO_PREFIX] = {}, --info about the player
[CONST_COMM_PLAYERINFO_TALENTS_PREFIX] = {}, --cooldown info
}

function raidStatusLib.commHandler.RegisterComm(prefix, func)
Expand Down Expand Up @@ -366,6 +368,7 @@ LIB_RAID_STATUS_CAN_LOAD = false
"GearUpdate",
"GearDurabilityUpdate",
"PlayerUpdate",
"TalentUpdate",
}

--save build the table to avoid lose registered events on older versions
Expand Down Expand Up @@ -539,11 +542,25 @@ LIB_RAID_STATUS_CAN_LOAD = false
end,

["PLAYER_REGEN_DISABLED"] = function(...)

--entered in combat
end,

["PLAYER_REGEN_ENABLED"] = function(...)

--left combat
raidStatusLib.Schedules.NewUniqueTimer(10 + math.random(0, 4), raidStatusLib.gearManager.SendDurability, "gearManager", "sendDurability_Schedule")
end,

["UPDATE_INVENTORY_DURABILITY"] = function(...)
--an item has changed its durability
--do not trigger this event while in combat
if (not InCombatLockdown()) then
raidStatusLib.Schedules.NewUniqueTimer(5 + math.random(0, 4), raidStatusLib.gearManager.SendDurability, "gearManager", "sendDurability_Schedule")
end
end,

["PLAYER_EQUIPMENT_CHANGED"] = function(...)
--player changed an equipment
raidStatusLib.Schedules.NewUniqueTimer(4 + math.random(0, 5), raidStatusLib.gearManager.SendAllGearInfo, "gearManager", "sendAllGearInfo_Schedule")
end,
}

Expand All @@ -552,6 +569,8 @@ LIB_RAID_STATUS_CAN_LOAD = false
eventFrame:RegisterEvent("PLAYER_ENTERING_WORLD")
eventFrame:RegisterEvent("PLAYER_REGEN_DISABLED")
eventFrame:RegisterEvent("PLAYER_REGEN_ENABLED")
eventFrame:RegisterEvent("UPDATE_INVENTORY_DURABILITY")
eventFrame:RegisterEvent("PLAYER_EQUIPMENT_CHANGED")

--eventFrame:RegisterEvent("PLAYER_SPECIALIZATION_CHANGED")
if (not isTimewalkWoW()) then
Expand Down Expand Up @@ -743,12 +762,12 @@ LIB_RAID_STATUS_CAN_LOAD = false
unitCooldownTable[spellId] = spellIdTable
end

function raidStatusLib.cooldownManager.GetCooldownTable()
function raidStatusLib.cooldownManager.GetAllPlayersCooldown()
return raidStatusLib.cooldownManager.playerData
end

--@playerName: name of the player
function raidStatusLib.cooldownManager.GetPlayerCooldownTable(playerName)
function raidStatusLib.cooldownManager.GetPlayerCooldowns(playerName)
return raidStatusLib.cooldownManager.playerData[playerName]
end

Expand All @@ -760,12 +779,13 @@ LIB_RAID_STATUS_CAN_LOAD = false
--get the cooldown time for this spell
local timeLeft, charges, startTime, duration = raidStatusLib.cooldownManager.GetCooldownStatus(spellId)
local playerName = UnitName("player")
local playerCooldownTable = raidStatusLib.cooldownManager.GetPlayerCooldowns(playerName)

--update the time left
singleCooldownUpdate(playerName, spellId, timeLeft, charges, startTime, duration)

--trigger a public callback
raidStatusLib.publicCallback.TriggerCallback("CooldownUpdate", playerName, spellId, timeLeft, charges, startTime, duration, raidStatusLib.cooldownManager.playerData)
raidStatusLib.publicCallback.TriggerCallback("CooldownUpdate", playerName, spellId, timeLeft, charges, startTime, duration, playerCooldownTable, raidStatusLib.cooldownManager.playerData)

--send to comm
raidStatusLib.cooldownManager.SendCooldownUpdate(spellId, timeLeft, charges, startTime, duration)
Expand Down Expand Up @@ -842,7 +862,7 @@ LIB_RAID_STATUS_CAN_LOAD = false
raidStatusLib.TCopy(unitCooldownTable, cooldownsTable)

--trigger a public callback
raidStatusLib.publicCallback.TriggerCallback("CooldownListUpdate", unitName, raidStatusLib.cooldownManager.playerData)
raidStatusLib.publicCallback.TriggerCallback("CooldownListUpdate", unitName, unitCooldownTable, raidStatusLib.cooldownManager.playerData)
end

--check if a player cooldown is ready or if is in cooldown
Expand Down Expand Up @@ -972,7 +992,7 @@ C_Timer.After(0.1, function()
if (UnitInParty(unit) or UnitInRaid(unit)) then
local unitName = UnitName(unit)
local cooldownInfo = allCooldownsFromLib[spellId]
if (cooldownInfo and unitName and not raidStatusLib.cooldownManager.GetPlayerCooldownTable(unitName)) then
if (cooldownInfo and unitName and not raidStatusLib.cooldownManager.GetPlayerCooldowns(unitName)) then
--check for cast_success spam from channel spells
local unitCastCooldown = recentCastedSpells[UnitGUID(unit)]
if (not unitCastCooldown) then
Expand Down Expand Up @@ -1009,11 +1029,11 @@ end)
playerData = {},
}

function raidStatusLib.gearManager.GetGearTable()
function raidStatusLib.gearManager.GetAllPlayersGear()
return raidStatusLib.gearManager.playerData
end

function raidStatusLib.gearManager.GetPlayerGearTable(playerName, createNew)
function raidStatusLib.gearManager.GetPlayerGear(playerName, createNew)
local playerGearInfo = raidStatusLib.gearManager.playerData[playerName]
if (not playerGearInfo and createNew) then
playerGearInfo = {
Expand Down Expand Up @@ -1090,10 +1110,10 @@ end)

--on receive the durability (sent when the player get a ress)
function raidStatusLib.gearManager.UpdateUnitGearDurability(playerName, durability)
local playerGearInfo = raidStatusLib.gearManager.GetPlayerGearTable(playerName)
local playerGearInfo = raidStatusLib.gearManager.GetPlayerGear(playerName)
if (playerGearInfo) then
playerGearInfo.durability = durability
raidStatusLib.publicCallback.TriggerCallback("GearDurabilityUpdate", playerName, durability, raidStatusLib.gearManager.GetGearTable())
raidStatusLib.publicCallback.TriggerCallback("GearDurabilityUpdate", playerName, durability, playerGearInfo, raidStatusLib.gearManager.GetAllPlayersGear())
end
end

Expand Down Expand Up @@ -1222,15 +1242,15 @@ end)

--when received the gear update from another player, store it and trigger a callback
function raidStatusLib.gearManager.AddUnitGearInfoList(playerName, itemLevel, durability, weaponEnchant, noEnchantTable, noGemsTable)
local playerGearInfo = raidStatusLib.gearManager.GetPlayerGearTable(playerName, true)
local playerGearInfo = raidStatusLib.gearManager.GetPlayerGear(playerName, true)

playerGearInfo.ilevel = itemLevel
playerGearInfo.durability = durability
playerGearInfo.weaponEnchant = weaponEnchant
playerGearInfo.noGems = noGemsTable
playerGearInfo.noEnchants = noEnchantTable

raidStatusLib.publicCallback.TriggerCallback("GearUpdate", playerName, playerGearInfo, raidStatusLib.gearManager.GetGearTable())
raidStatusLib.publicCallback.TriggerCallback("GearUpdate", playerName, playerGearInfo, raidStatusLib.gearManager.GetAllPlayersGear())
end

--triggered when the lib receives a gear information from another player in the raid
Expand Down Expand Up @@ -1281,19 +1301,19 @@ end)


--------------------------------------------------------------------------------------------------------------------------------
--> ~player general info
--> ~player general ~info

raidStatusLib.playerInfoManager = {
--structure:
--[playerName] = {ilevel = 100, durability = 100, weaponEnchant = 0, noGems = {}, noEnchants = {}}
playerData = {},
}

function raidStatusLib.playerInfoManager.GetPlayerInfo()
function raidStatusLib.playerInfoManager.GetAllPlayersInfo()
return raidStatusLib.playerInfoManager.playerData
end

function raidStatusLib.playerInfoManager.GetPlayerInfoTable(playerName, createNew)
function raidStatusLib.playerInfoManager.GetPlayerInfo(playerName, createNew)
local playerInfo = raidStatusLib.playerInfoManager.playerData[playerName]
if (not playerInfo and createNew) then
playerInfo = {
Expand All @@ -1309,15 +1329,15 @@ end)
end

function raidStatusLib.playerInfoManager.AddPlayerInfo(playerName, specId, renown, covenantId, talentsTableUnpacked, conduitsTableUnpacked)
local playerInfoTable = raidStatusLib.playerInfoManager.GetPlayerInfoTable(playerName, true)
local playerInfo = raidStatusLib.playerInfoManager.GetPlayerInfo(playerName, true)

playerInfoTable.specId = specId
playerInfoTable.renown = renown
playerInfoTable.covenantId = covenantId
playerInfoTable.talents = talentsTableUnpacked
playerInfoTable.conduits = conduitsTableUnpacked
playerInfo.specId = specId
playerInfo.renown = renown
playerInfo.covenantId = covenantId
playerInfo.talents = talentsTableUnpacked
playerInfo.conduits = conduitsTableUnpacked

raidStatusLib.publicCallback.TriggerCallback("PlayerUpdate", playerName, raidStatusLib.playerInfoManager.playerData[playerName], raidStatusLib.playerInfoManager.GetPlayerInfo())
raidStatusLib.publicCallback.TriggerCallback("PlayerUpdate", playerName, raidStatusLib.playerInfoManager.playerData[playerName], raidStatusLib.playerInfoManager.GetAllPlayersInfo())
end

--triggered when the lib receives a gear information from another player in the raid
Expand All @@ -1338,15 +1358,15 @@ end)
--unpack the conduits data as a ipairs table
local conduitsTableUnpacked = raidStatusLib.UnpackTable(data, conduitsTableIndex, false, false, conduitsSize)

--add to the list of player information
--add to the list of players information and also trigger a public callback
raidStatusLib.playerInfoManager.AddPlayerInfo(source, specId, renown, covenantId, talentsTableUnpacked, conduitsTableUnpacked)
end
raidStatusLib.commHandler.RegisterComm(CONST_COMM_PLAYER_INFO_PREFIX, raidStatusLib.playerInfoManager.OnReceivePlayerFullInfo)
raidStatusLib.commHandler.RegisterComm(CONST_COMM_PLAYERINFO_PREFIX, raidStatusLib.playerInfoManager.OnReceivePlayerFullInfo)

function raidStatusLib.playerInfoManager.SendAllPlayerInfo()
local playerInfo = raidStatusLib.playerInfoManager.GetPlayerFullInfo()

local dataToSend = CONST_COMM_PLAYER_INFO_PREFIX .. ","
local dataToSend = CONST_COMM_PLAYERINFO_PREFIX .. ","
dataToSend = dataToSend .. playerInfo[1] .. "," --spec id
dataToSend = dataToSend .. playerInfo[2] .. "," --renown
dataToSend = dataToSend .. playerInfo[3] .. "," --covenantId
Expand Down Expand Up @@ -1387,7 +1407,7 @@ function raidStatusLib.playerInfoManager.GetPlayerFullInfo()
local talents = {0, 0, 0, 0, 0, 0, 0}
for talentTier = 1, 7 do
for talentColumn = 1, 3 do
local talentId, name, texture, selected, available = GetTalentInfo(talentTier, talentColumn, 1, true, "player")
local talentId, name, texture, selected, available = GetTalentInfo(talentTier, talentColumn, 1)
if (selected) then
talents[talentTier] = talentId
break
Expand Down Expand Up @@ -1471,14 +1491,56 @@ function raidStatusLib.playerInfoManager.GetPlayerFullInfo()
["spellID"] = 0
}
--]=]

end

function raidStatusLib.playerInfoManager.onEnterWorld()
raidStatusLib.playerInfoManager.GetPlayerFullInfo()
end
raidStatusLib.internalCallback.RegisterCallback("onEnterWorld", raidStatusLib.playerInfoManager.onEnterWorld)

--talent update
function raidStatusLib.playerInfoManager.sendTalentUpdate()
--talents
local talentsToSend = {0, 0, 0, 0, 0, 0, 0}
for talentTier = 1, 7 do
for talentColumn = 1, 3 do
local talentId, name, texture, selected, available = GetTalentInfo(talentTier, talentColumn, 1)
if (selected) then
talentsToSend[talentTier] = talentId
break
end
end
end

local dataToSend = CONST_COMM_PLAYERINFO_TALENTS_PREFIX .. ","
local talentsString = raidStatusLib.PackTable(talentsToSend)
dataToSend = dataToSend .. talentsString

--send the data
raidStatusLib.commHandler.SendCommData(dataToSend)
diagnosticComm("SendTalentUpdateData| " .. dataToSend) --debug
end

function raidStatusLib.playerInfoManager.scheduleTalentUpdate()
raidStatusLib.Schedules.NewUniqueTimer(1 + math.random(0, 1), raidStatusLib.playerInfoManager.sendTalentUpdate, "playerInfoManager", "sendTalent_Schedule")
end
raidStatusLib.internalCallback.RegisterCallback("talentUpdate", raidStatusLib.playerInfoManager.scheduleTalentUpdate)

function raidStatusLib.playerInfoManager.OnReceiveTalentsUpdate(data, source)
local talentsTableUnpacked = raidStatusLib.UnpackTable(data, 1, false, false, 7)

local playerInfo = raidStatusLib.playerInfoManager.GetPlayerInfo(source)
if (playerInfo) then
playerInfo.talents = talentsTableUnpacked

--trigger public callback event
raidStatusLib.publicCallback.TriggerCallback("TalentUpdate", source, playerInfo, raidStatusLib.playerInfoManager.GetAllPlayersInfo())
end
end
raidStatusLib.commHandler.RegisterComm(CONST_COMM_PLAYERINFO_TALENTS_PREFIX, raidStatusLib.playerInfoManager.OnReceiveTalentsUpdate)



--------------------------------------------------------------------------------------------------------------------------------
--> data

Expand Down
Loading

0 comments on commit 07a60b4

Please sign in to comment.