Pet container rewritten
This commit is contained in:
@@ -13,8 +13,6 @@
|
||||
|
||||
local _IsInInstance = IsInInstance --api local
|
||||
local UnitGUID = UnitGUID --api local
|
||||
local strsplit = strsplit --api local
|
||||
|
||||
local setmetatable = setmetatable --lua local
|
||||
local bitBand = bit.band --lua local
|
||||
local bitBor = bit.bor --lua local
|
||||
@@ -27,7 +25,6 @@
|
||||
|
||||
local GetNumDeclensionSets = _G.GetNumDeclensionSets
|
||||
local DeclineName = _G.DeclineName
|
||||
|
||||
local pet_tooltip_frame = _G.DetailsPetOwnerFinder
|
||||
|
||||
local openRaidLib = LibStub:GetLibrary("LibOpenRaid-1.0", true)
|
||||
@@ -49,22 +46,23 @@
|
||||
local container_misc = Details.container_type.CONTAINER_MISC_CLASS
|
||||
local container_enemydebufftarget_target = Details.container_type.CONTAINER_ENEMYDEBUFFTARGET_CLASS
|
||||
|
||||
local container_pets = {}
|
||||
---@type petcontainer
|
||||
local petContainer = Details222.PetContainer
|
||||
---@type table<guid, petdata>
|
||||
local petCache = petContainer.Pets
|
||||
|
||||
--flags
|
||||
local REACTION_HOSTILE = 0x00000040
|
||||
local IS_GROUP_OBJECT = 0x00000007
|
||||
local REACTION_FRIENDLY = 0x00000010
|
||||
local OBJECT_TYPE_MASK = 0x0000FC00
|
||||
local OBJECT_TYPE_OBJECT = 0x00004000
|
||||
local OBJECT_TYPE_PET = 0x00001000
|
||||
local OBJECT_TYPE_GUARDIAN = 0x00002000
|
||||
local OBJECT_TYPE_CONTROL_NPC = 0x00000200
|
||||
local OBJECT_TYPE_PETGUARDIAN = OBJECT_TYPE_PET + OBJECT_TYPE_GUARDIAN
|
||||
local OBJECT_TYPE_NPC = 0x00000800
|
||||
local OBJECT_TYPE_PLAYER = 0x00000400
|
||||
|
||||
local debugPetname = false
|
||||
local REACTION_HOSTILE = 0x00000040
|
||||
local IS_GROUP_OBJECT = 0x00000007
|
||||
local REACTION_FRIENDLY = 0x00000010
|
||||
local OBJECT_TYPE_MASK = 0x0000FC00
|
||||
local OBJECT_TYPE_OBJECT = 0x00004000
|
||||
local OBJECT_TYPE_PETGUARDIAN = 0x00003000
|
||||
local OBJECT_TYPE_GUARDIAN = 0x00002000
|
||||
local OBJECT_TYPE_PET = 0x00001000
|
||||
local OBJECT_TYPE_NPC = 0x00000800
|
||||
local OBJECT_TYPE_PLAYER = 0x00000400
|
||||
local OBJECT_TYPE_PETS = OBJECT_TYPE_PET + OBJECT_TYPE_GUARDIAN
|
||||
|
||||
local SPELLID_SANGUINE_HEAL = 226510
|
||||
local sanguineActorName = Details222.GetSpellInfo(SPELLID_SANGUINE_HEAL)
|
||||
@@ -179,27 +177,28 @@ end
|
||||
---@return string|nil ownerName
|
||||
---@return string|nil ownerGUID
|
||||
---@return integer|nil ownerFlags
|
||||
function Details222.Pets.GetPetOwner(petGUID, petName)
|
||||
function Details222.Pets.GetPetOwner(petGUID, petName) --this is under the Pets namespace, the new pet system is under the PetContainer namespace
|
||||
pet_tooltip_frame:SetOwner(WorldFrame, "ANCHOR_NONE")
|
||||
pet_tooltip_frame:SetHyperlink(("unit:" .. petGUID) or "")
|
||||
---@type combat
|
||||
local currentCombat = Details:GetCurrentCombat()
|
||||
|
||||
local ownerName, ownerGUID, ownerFlags
|
||||
if (not Details.tabela_vigente) then return end --Should exist at all times but load. Just in case.
|
||||
if (not currentCombat) then return end --Should exist at all times but load. Just in case.
|
||||
|
||||
for i=1,3 do --Loop through the 3 texts on the PetOwnerFinder tooltip
|
||||
local actorNameString = _G["DetailsPetOwnerFinderTextLeft"..i]
|
||||
if (actorNameString and not ownerName) then --Tooltip line exists and we haven't found a valid match yes.
|
||||
local actorName = actorNameString:GetText()
|
||||
if (actorName and type(actorName) == "string") then
|
||||
local isInRaid = Details.tabela_vigente.raid_roster[actorName]
|
||||
local isInRaid = currentCombat.raid_roster[actorName]
|
||||
if (isInRaid) then
|
||||
ownerGUID = UnitGUID(actorName)
|
||||
ownerName = actorName
|
||||
ownerFlags = 0x514
|
||||
else
|
||||
|
||||
if (CONST_CLIENT_LANGUAGE == "ruRU") then --If russian client, then test for declensions in the string of text.
|
||||
for playerName, _ in pairs(Details.tabela_vigente.raid_roster) do
|
||||
for playerName, _ in pairs(currentCombat.raid_roster) do
|
||||
local pName = playerName
|
||||
playerName = playerName:gsub("%-.*", "") --remove realm name
|
||||
if (find_name_declension(actorName, playerName)) then
|
||||
@@ -212,7 +211,7 @@ end
|
||||
else
|
||||
for playerName in actorName:gmatch("([^%s']+)") do
|
||||
playerName = playerName:gsub(",", "")
|
||||
local playerIsOnRaidCache = Details.tabela_vigente.raid_roster[playerName]
|
||||
local playerIsOnRaidCache = currentCombat.raid_roster[playerName]
|
||||
if (playerIsOnRaidCache) then
|
||||
ownerGUID = UnitGUID(playerName)
|
||||
ownerName = playerName
|
||||
@@ -552,7 +551,7 @@ end
|
||||
end
|
||||
end
|
||||
|
||||
--does this actor has an owner?
|
||||
--does this actor has an owner? (a.k.a. is a pet)
|
||||
elseif (ownerActorObject) then
|
||||
actorObject.owner = ownerActorObject
|
||||
actorObject.ownerName = ownerActorObject.nome
|
||||
@@ -562,6 +561,9 @@ end
|
||||
else
|
||||
actorObject.displayName = actorName
|
||||
end
|
||||
|
||||
local npcId = Details:GetNpcIdFromGuid(actorSerial)
|
||||
local petCustomname = Details222.Pets.GetPetNameFromCustomSpells(actorObject.displayName, spellId, npcId)
|
||||
else
|
||||
--anything else that isn't a player or a pet
|
||||
actorObject.displayName = actorName
|
||||
@@ -593,20 +595,21 @@ end
|
||||
end
|
||||
end
|
||||
|
||||
--pet black list locally for this file
|
||||
local petBlackList = {}
|
||||
|
||||
local petOwnerFound = function(ownerName, petGUID, petName, petFlags, self, ownerGUID, ownerFlags)
|
||||
local ownerGuid = ownerGUID or UnitGUID(ownerName)
|
||||
local petOwnerFound = function(ownerName, petGuid, petName, petFlags, self, ownerGuid, ownerFlags)
|
||||
local ownerGuid = ownerGuid or UnitGUID(ownerName)
|
||||
if (ownerGuid) then
|
||||
|
||||
-- 0xA00 is the flag for NPC controlled, NPC unit. 0x500 is the flag for Player Controlled, Player Unit.
|
||||
-- Or those together with the last 2 hex bits for reaction/affiliation to 'guess' the correct flags.
|
||||
if not ownerFlags then
|
||||
local npcControlled = bitBand(petFlags, 0x200) ~= 0
|
||||
ownerFlags = bitBor( npcControlled and 0xA00 or 0x500, bitBand(petFlags, 0xFF))
|
||||
ownerFlags = bitBor(npcControlled and 0xA00 or 0x500, bitBand(petFlags, 0xFF))
|
||||
end
|
||||
Details.tabela_pets:AddPet(petGUID, petName, petFlags, ownerGuid, ownerName, ownerFlags)
|
||||
local petNameWithOwner, ownerName, ownerGUID, ownerFlags = Details.tabela_pets:GetPetOwner(petGUID, petName, petFlags)
|
||||
|
||||
petContainer.AddPet(petGuid, petName, petFlags, ownerGuid, ownerName, ownerFlags)
|
||||
local petNameWithOwner, ownerName, ownerGUID, ownerFlags = petContainer.GetOwner(petGuid, petName)
|
||||
|
||||
local petOwnerActorObject
|
||||
|
||||
@@ -640,27 +643,29 @@ end
|
||||
local petOwnerObject
|
||||
actorSerial = actorSerial or "ns"
|
||||
|
||||
if (container_pets[actorSerial]) then --this is a registered pet
|
||||
local petName, ownerName, ownerGUID, ownerFlag = Details.tabela_pets:GetPetOwner(actorSerial, actorName, actorFlags)
|
||||
if (petName and ownerName and ownerGUID ~= actorSerial) then
|
||||
--check if this actor is a pet and the pet is in the pet cache
|
||||
if (petContainer.IsPetInCache(actorSerial)) then --this is a registered pet
|
||||
local petName, ownerName, ownerGuid, ownerFlag = petContainer.GetOwner(actorSerial, actorName)
|
||||
if (petName and ownerName and ownerGuid and ownerGuid ~= actorSerial and ownerFlag) then
|
||||
actorName = petName
|
||||
petOwnerObject = self:PegarCombatente(ownerGUID, ownerName, ownerFlag, true)
|
||||
petOwnerObject = self:PegarCombatente(ownerGuid, ownerName, ownerFlag, true)
|
||||
end
|
||||
|
||||
--this actor isn't in the pet cache
|
||||
elseif (not petBlackList[actorSerial]) then --check if is a pet
|
||||
petBlackList[actorSerial] = true
|
||||
|
||||
--try to find the owner
|
||||
if (actorFlags and bitBand(actorFlags, OBJECT_TYPE_PETGUARDIAN) ~= 0) then
|
||||
local ownerName, ownerGUID, ownerFlags = Details222.Pets.GetPetOwner(actorSerial, actorName)
|
||||
if (ownerName and ownerGUID) then
|
||||
--Don't pass ownerFlags just in case the cached owner happens to be an enemy last combat, but ally now.
|
||||
local newPetName, ownerObject = petOwnerFound(ownerName, actorSerial, actorName, actorFlags, self, ownerGUID)
|
||||
local ownerName, ownerGuid, ownerFlags = petContainer.GetOwner(actorSerial, actorName)
|
||||
if (ownerName and ownerGuid) then
|
||||
--don't pass ownerFlags just in case the cached owner happens to be an enemy from last combat, but ally now.
|
||||
local newPetName, ownerObject = petOwnerFound(ownerName, actorSerial, actorName, actorFlags, self, ownerGuid)
|
||||
if (newPetName and ownerObject) then
|
||||
actorName, petOwnerObject = newPetName, ownerObject
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
petBlackList[actorSerial] = true
|
||||
end
|
||||
|
||||
--get the actor index in the hash map
|
||||
@@ -755,19 +760,6 @@ end
|
||||
if (petOwnerObject) then
|
||||
AddUnique(petOwnerObject.pets, actorName)
|
||||
end
|
||||
|
||||
elseif (self.tipo == container_energy_target) then --deprecated
|
||||
newActor.mana = 0
|
||||
newActor.e_rage = 0
|
||||
newActor.e_energy = 0
|
||||
newActor.runepower = 0
|
||||
print("111111111111111111")
|
||||
|
||||
elseif (self.tipo == container_enemydebufftarget_target) then --deprecated
|
||||
newActor.uptime = 0
|
||||
newActor.actived = false
|
||||
newActor.activedamt = 0
|
||||
print("222222222222222222")
|
||||
end
|
||||
|
||||
--sanguine affix
|
||||
@@ -818,11 +810,6 @@ end
|
||||
end
|
||||
end
|
||||
|
||||
function Details:UpdatePetCache()
|
||||
container_pets = Details.tabela_pets.pets
|
||||
Details:UpdatePetsOnParser()
|
||||
end
|
||||
|
||||
function Details:ClearCCPetsBlackList()
|
||||
Details:Destroy(petBlackList)
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user