Clean up most modern GUID usage.

This commit is contained in:
andrew6180
2024-05-20 13:13:52 -07:00
parent bd68720db3
commit 90a085acf0
5 changed files with 56 additions and 71 deletions
+1 -6
View File
@@ -1501,12 +1501,7 @@ end
---@param GUID string
---@return number
function DF:GetNpcIdFromGuid(GUID)
local npcId = select(6, strsplit("-", GUID ))
if (npcId) then
npcId = tonumber(npcId)
return npcId or 0
end
return 0
return GetCreatureIDFromGUID(GUID) or 0
end
function DF.SortOrder1(t1, t2)
+1 -12
View File
@@ -229,18 +229,7 @@ function openRaidLib.GearManager.BuildPlayerEquipmentList()
end
local playerHasPetOfNpcId = function(npcId)
if (UnitExists("pet") and UnitHealth("pet") >= 1) then
local guid = UnitGUID("pet")
if (guid) then
local split = {strsplit("-", guid)}
local playerPetNpcId = tonumber(split[6])
if (playerPetNpcId) then
if (npcId == playerPetNpcId) then
return true
end
end
end
end
return false -- 3.3.5 cant get if a pet GUID is a specific npc or not.
end
local addCooldownToTable = function(cooldowns, cooldownsHash, cooldownSpellId, timeNow)
+3 -3
View File
@@ -684,7 +684,7 @@ end
local forceClass
--get the aID (actor id)
if (actorSerial:match("^C")) then
if (GUIDIsNPC(actorSerial)) then
newActor.aID = tostring(Details:GetNpcIdFromGuid(actorSerial))
--immersion stuff
@@ -697,8 +697,8 @@ end
end
end
elseif (actorSerial:match("^P")) then
newActor.aID = actorSerial:gsub("Player%-", "")
elseif (GUIDIsPlayer(actorSerial)) then
newActor.aID = GetPlayerUIDFromGUID(actorSerial)
else
newActor.aID = ""
+6 -21
View File
@@ -640,7 +640,7 @@
local npcId = npcid_cache[targetSerial] --target npc
if (not npcId) then
--this string manipulation is running on every event
npcId = tonumber(select(6, strsplit("-", targetSerial)) or 0)
npcId = GetCreatureIDFromGUID(targetSerial) or 0
npcid_cache[targetSerial] = npcId
end
@@ -650,7 +650,7 @@
npcId = npcid_cache[sourceSerial] --source npc
if (not npcId) then
npcId = tonumber(select(6, strsplit("-", sourceSerial)) or 0)
npcId = GetCreatureIDFromGUID(sourceSerial) or 0
npcid_cache[sourceSerial] = npcId
end
@@ -2054,7 +2054,7 @@
local npcId = npcid_cache[targetSerial] --target npc
if (not npcId) then
--this string manipulation is running on every event
npcId = tonumber(select(6, strsplit("-", targetSerial)) or 0)
npcId = GetCreatureIDFromGUID(targetSerial) or 0
npcid_cache[targetSerial] = npcId
end
@@ -5733,12 +5733,7 @@ local SPELL_POWER_PAIN = SPELL_POWER_PAIN or (PowerEnum and PowerEnum.Pain) or 1
Details.combat_id = 0
Details.opened_windows = 0
local _, _, _, toc = GetBuildInfo()
if (toc >= 100200) then
Details.playername = UnitName("player") .. "-" .. (GetRealmName():gsub("%s", ''))
else
Details.playername = UnitName("player")
end
Details.playername = UnitName("player")
Details.playername = Details:Ambiguate(Details.playername)
@@ -6659,19 +6654,9 @@ local SPELL_POWER_PAIN = SPELL_POWER_PAIN or (PowerEnum and PowerEnum.Pain) or 1
local currentCombat = Details:GetCurrentCombat()
local name, killingBlows, honorableKills, deaths, honorGained, faction, race, rank, class, classToken, damageDone, healingDone
for i = 1, players do
local name, killingBlows, honorableKills, deaths, honorGained, faction, race, rank, class, classToken, damageDone, healingDone, bgRating, ratingChange, preMatchMMR, mmrChange, talentSpec
if (isWOTLK or isERA) then
name, killingBlows, honorableKills, deaths, honorGained, faction, rank, race, class, classToken, damageDone, healingDone, bgRating, ratingChange, preMatchMMR, mmrChange, talentSpec = GetBattlefieldScore(i)
else
name, killingBlows, honorableKills, deaths, honorGained, faction, race, class, classToken, damageDone, healingDone, bgRating, ratingChange, preMatchMMR, mmrChange, talentSpec = GetBattlefieldScore(i)
end
if (not isWOTLK and not isERA) then --Must be dragonflight
if (not name:match("%-")) then
name = name .. "-" .. realmName
end
end
name, killingBlows, honorableKills, deaths, honorGained, faction, rank, race, class, classToken, damageDone, healingDone = GetBattlefieldScore(i)
name = Details:Ambiguate(name)
+45 -29
View File
@@ -185,6 +185,32 @@ function Details.packFunctions.PackCombatData(combatObject, flags)
return dataEncoded
end
local function CreateGUID(realmID, guidType, unk1, unk2, uid)
if guidType == 0 then
return string.format("0x%02X%01X%03X%03X%07X", realmID, guidType, unk1, unk2, uid)
elseif guidType == 4 then
return string.format("0x%02X%01X%07X%06X", realmID, guidType, unk1, uid)
else
return string.format("0x%02X%01X%03X%04X%06X", realmID, guidType, unk1, unk2, uid)
end
end
function Details.packFunctions.CreateNPCGUID(realmID, unk1, npcID, spawnID)
return CreateGUID(realmID, 3, unk1, npcID, spawnID)
end
function Details.packFunctions.CreatePlayerGUID(realmID, unk1, unk2, uid)
return CreateGUID(realmID, 0, unk1, unk2, uid)
end
function Details.packFunctions.CreatePetGUID(realmID, petID, uid)
return CreateGUID(realmID, 4, petID, uid)
end
function Details.packFunctions.CreateVehicleGUID(realmID, unk1, npcID, spawnID)
return CreateGUID(realmID, 5, unk1, npcID, spawnID)
end
function Details.packFunctions.GenerateSerialNumber()
local serialNumber = entitySerialCounter
entitySerialCounter = entitySerialCounter + 1
@@ -337,25 +363,27 @@ end
local packActorSerial = function(actor)
local serial = actor.serial
if (serial:match("^C") == "C") then
local npcId = tonumber(select(6, strsplit("-", serial)) or 0)
if serial == "" then
return "C12345"
end
if (GUIDIsNPC(serial) == 3) then
local npcId = GetCreatureIDFromGUID(serial) or 0
return "C" .. npcId
elseif (serial:match("^P") == "P") then
elseif (GUIDIsPlayer(serial) == 0) then
return "P"
elseif (serial == "") then
return "C12345"
end
end
local unpackActorSerial = function(serialNumber)
--player serial
if (serialNumber:match("^P")) then
return "Player-1-" .. Details.packFunctions.GenerateSerialNumber()
return Details.packfunctions.CreatePlayerGUID(0, 0, 0, Details.packFunctions.GenerateSerialNumber())
elseif (serialNumber:match("^C")) then
return "Creature-0-0-0-0-" .. serialNumber:gsub("C", "") .."-" .. Details.packFunctions.GenerateSerialNumber()
return Details.packfunctions.CreateNPCGUID(0, 0, serialNumber:gsub("C", ""), Details.packFunctions.GenerateSerialNumber())
end
end
@@ -466,14 +494,10 @@ function Details.packFunctions.PackDamage(combatObject)
--check if is an enemy or neutral
if (actor:IsNeutralOrEnemy()) then
--get the spawnId
local spawnId = select(7, strsplit("-", actor.serial))
local spawnId = GetCreatureSpawnIDFromGUID(actor.serial)
if (spawnId) then
--convert hex to number
spawnId = tonumber(spawnId:sub(1, 10), 16)
if (spawnId) then
--first index is the actorObject, the second index is the spawnId to sort enemies
tinsert(allEnemies, {actor, spawnId})
end
--first index is the actorObject, the second index is the spawnId to sort enemies
tinsert(allEnemies, {actor, spawnId})
end
end
end
@@ -716,14 +740,10 @@ function Details.packFunctions.PackHeal(combatObject)
--check if is an enemy or neutral
if (actor:IsNeutralOrEnemy()) then
--get the spawnId
local spawnId = select(7, strsplit("-", actor.serial))
local spawnId = GetCreatureSpawnIDFromGUID(actor.serial)
if (spawnId) then
--convert hex to number
spawnId = tonumber(spawnId:sub(1, 10), 16)
if (spawnId) then
--first index is the actorObject, the second index is the spawnId to sort enemies
tinsert(allEnemies, {actor, spawnId})
end
--first index is the actorObject, the second index is the spawnId to sort enemies
tinsert(allEnemies, {actor, spawnId})
end
end
end
@@ -970,14 +990,10 @@ function Details.packFunctions.PackUtility(combatObject)
--check if is an enemy or neutral
if (actor:IsNeutralOrEnemy()) then
--get the spawnId
local spawnId = select(7, strsplit("-", actor.serial))
local spawnId = GetCreatureSpawnIDFromGUID(actor.serial)
if (spawnId) then
--convert hex to number
spawnId = tonumber(spawnId:sub(1, 10), 16)
if (spawnId) then
--first index is the actorObject, the second index is the spawnId to sort enemies
tinsert(allEnemies, {actor, spawnId})
end
--first index is the actorObject, the second index is the spawnId to sort enemies
tinsert(allEnemies, {actor, spawnId})
end
end
end