updated lib RaidStatus and general bug fixes; ToC Updates

This commit is contained in:
Tercio Jose
2021-07-01 18:46:46 -03:00
parent 2da8f23489
commit 07a60b42ec
15 changed files with 306 additions and 111 deletions
+94 -32
View File
@@ -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
@@ -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
@@ -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
@@ -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)
@@ -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
@@ -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,
}
@@ -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
@@ -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
@@ -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)
@@ -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
@@ -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
@@ -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 = {
@@ -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
@@ -1222,7 +1242,7 @@ 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
@@ -1230,7 +1250,7 @@ end)
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
@@ -1281,7 +1301,7 @@ end)
--------------------------------------------------------------------------------------------------------------------------------
--> ~player general info
--> ~player general ~info
raidStatusLib.playerInfoManager = {
--structure:
@@ -1289,11 +1309,11 @@ end)
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 = {
@@ -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
@@ -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
@@ -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
@@ -1471,7 +1491,6 @@ function raidStatusLib.playerInfoManager.GetPlayerFullInfo()
["spellID"] = 0
}
--]=]
end
function raidStatusLib.playerInfoManager.onEnterWorld()
@@ -1479,6 +1498,49 @@ function raidStatusLib.playerInfoManager.onEnterWorld()
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