You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

262 lines
7.8 KiB

local Details = _G.Details
local container_pets = Details.container_pets
local _
local addonName, Details222 = ...
4 years ago
3 years ago
local UnitGUID = _G.UnitGUID
local UnitName = _G.UnitName
local GetUnitName = _G.GetUnitName
3 years ago
local IsInRaid = _G.IsInRaid
local IsInGroup = _G.IsInGroup
local GetNumGroupMembers = _G.GetNumGroupMembers
local setmetatable = setmetatable
local bitBand = bit.band --lua local
3 years ago
local pairs = pairs
4 years ago
--details locals
local bIsIgnored = Details.pets_ignored
4 years ago
function container_pets:NovoContainer()
local newPetContainer = {}
setmetatable(newPetContainer, Details.container_pets)
---@type petinfo
local newPetCacheTable = {}
newPetContainer.pets = newPetCacheTable
newPetContainer._ActorTable = {}
return newPetContainer
4 years ago
end
local OBJECT_TYPE_PET = 0x00001000
local OBJECT_IN_GROUP = 0x00000007
4 years ago
function container_pets:PegaDono(petGUID, petName, petFlags)
3 years ago
--sair se o pet estiver na ignore
if (bIsIgnored[petGUID]) then
4 years ago
return
end
3 years ago
--buscar pelo pet no container de pets
local busca = self.pets[petGUID]
4 years ago
if (busca) then
--in merging operations, make sure to not add the owner name a second time in the name
4 years ago
--check if the pet name already has the owner name in, if not, add it
if (not petName:find("<")) then
4 years ago
--get the owner name
local ownerName = busca[1]
--add the owner name to the pet name
petName = petName .. " <".. ownerName ..">"
4 years ago
end
3 years ago
--return busca[6] or pet_nome, busca[1], busca[2], busca[3] --busca[6] poderia estar causando problemas
return petName, busca[1], busca[2], busca[3] --[1] dono nome[2] dono serial[3] dono flag
4 years ago
end
3 years ago
--buscar pelo pet na raide
4 years ago
local dono_nome, dono_serial, dono_flags
3 years ago
if (IsInRaid()) then
for i = 1, GetNumGroupMembers() do
if (petGUID == UnitGUID("raidpet"..i)) then
3 years ago
dono_serial = UnitGUID("raid"..i)
dono_flags = 0x00000417 --emulate sourceflag flag
local nome, realm = UnitName("raid"..i)
4 years ago
if (realm and realm ~= "") then
nome = nome.."-"..realm
end
dono_nome = nome
end
end
3 years ago
elseif (IsInGroup()) then
for i = 1, GetNumGroupMembers()-1 do
if (petGUID == UnitGUID("partypet"..i)) then
3 years ago
dono_serial = UnitGUID("party"..i)
dono_flags = 0x00000417 --emulate sourceflag flag
local nome, realm = UnitName("party"..i)
4 years ago
if (realm and realm ~= "") then
nome = nome.."-"..realm
end
4 years ago
dono_nome = nome
end
end
end
4 years ago
if (not dono_nome) then
if (petGUID == UnitGUID("pet")) then
dono_nome = GetUnitName("player")
3 years ago
dono_serial = UnitGUID("player")
if (IsInGroup() or IsInRaid()) then
dono_flags = 0x00000417 --emulate sourceflag flag
4 years ago
else
3 years ago
dono_flags = 0x00000411 --emulate sourceflag flag
4 years ago
end
end
end
4 years ago
if (dono_nome) then
self.pets[petGUID] = {dono_nome, dono_serial, dono_flags, Details._tempo, true, petName, petGUID} --adicionada a flag emulada
if (not petName:find("<")) then
petName = petName .. " <".. dono_nome ..">"
4 years ago
end
return petName, dono_nome, dono_serial, dono_flags
4 years ago
else
if (petFlags and bitBand(petFlags, OBJECT_TYPE_PET) ~= 0) then --� um pet
if (not Details.pets_no_owner[petGUID] and bitBand(petFlags, OBJECT_IN_GROUP) ~= 0) then
Details.pets_no_owner[petGUID] = {petName, petFlags}
Details:Msg("couldn't find the owner of the pet:", petName)
4 years ago
end
else
bIsIgnored[petGUID] = true
4 years ago
end
end
return
end
function container_pets:Unpet(...)
4 years ago
local unitid = ...
3 years ago
local owner_serial = UnitGUID(unitid)
4 years ago
if (owner_serial) then
--tira o pet existente da tabela de pets e do cache do core
local existing_pet_serial = Details.pets_players[owner_serial]
4 years ago
if (existing_pet_serial) then
Details.parser:RevomeActorFromCache(existing_pet_serial)
container_pets:Remover(existing_pet_serial)
Details.pets_players[owner_serial] = nil
4 years ago
end
--verifica se h� um pet novo deste jogador
3 years ago
local pet_serial = UnitGUID(unitid .. "pet")
4 years ago
if (pet_serial) then
if (not Details.tabela_pets.pets[pet_serial]) then
local nome, realm = UnitName(unitid)
4 years ago
if (realm and realm ~= "") then
nome = nome.."-"..realm
end
Details.tabela_pets:Adicionar(pet_serial, UnitName(unitid .. "pet"), 0x1114, owner_serial, nome, 0x514)
4 years ago
end
Details.parser:RevomeActorFromCache(pet_serial)
container_pets:PlayerPet(owner_serial, pet_serial)
4 years ago
end
end
end
function container_pets:PlayerPet(player_serial, pet_serial)
Details.pets_players[player_serial] = pet_serial
4 years ago
end
function container_pets:BuscarPets()
3 years ago
if (IsInRaid()) then
for i = 1, GetNumGroupMembers(), 1 do
3 years ago
local pet_serial = UnitGUID("raidpet"..i)
4 years ago
if (pet_serial) then
if (not Details.tabela_pets.pets[pet_serial]) then
local nome, realm = UnitName("raid"..i)
4 years ago
if (realm and realm ~= "") then
nome = nome.."-"..realm
end
3 years ago
local owner_serial = UnitGUID("raid"..i)
Details.tabela_pets:Adicionar(pet_serial, UnitName("raidpet"..i), 0x1114, owner_serial, nome, 0x514)
Details.parser:RevomeActorFromCache(pet_serial)
container_pets:PlayerPet(owner_serial, pet_serial)
4 years ago
end
end
end
3 years ago
elseif (IsInGroup()) then
for i = 1, GetNumGroupMembers()-1, 1 do
3 years ago
local pet_serial = UnitGUID("partypet"..i)
4 years ago
if (pet_serial) then
if (not Details.tabela_pets.pets[pet_serial]) then
local nome, realm = UnitName("party"..i)
4 years ago
if (realm and realm ~= "") then
nome = nome.."-"..realm
end
Details.tabela_pets:Adicionar(pet_serial, UnitName("partypet"..i), 0x1114, UnitGUID("party"..i), nome, 0x514)
4 years ago
end
end
end
3 years ago
local pet_serial = UnitGUID("pet")
4 years ago
if (pet_serial) then
if (not Details.tabela_pets.pets[pet_serial]) then
Details.tabela_pets:Adicionar(pet_serial, UnitName("pet"), 0x1114, UnitGUID("player"), Details.playername, 0x514)
4 years ago
end
end
4 years ago
else
3 years ago
local pet_serial = UnitGUID("pet")
4 years ago
if (pet_serial) then
if (not Details.tabela_pets.pets[pet_serial]) then
Details.tabela_pets:Adicionar(pet_serial, UnitName("pet"), 0x1114, UnitGUID("player"), Details.playername, 0x514)
4 years ago
end
end
end
end
function container_pets:Remover(pet_serial)
if (Details.tabela_pets.pets[pet_serial]) then
Details:Destroy(Details.tabela_pets.pets[pet_serial])
4 years ago
end
Details.tabela_pets.pets[pet_serial] = nil
4 years ago
end
function container_pets:Adicionar(pet_serial, pet_nome, pet_flags, dono_serial, dono_nome, dono_flags)
if (pet_flags and bitBand(pet_flags, OBJECT_TYPE_PET) ~= 0 and bitBand(pet_flags, OBJECT_IN_GROUP) ~= 0) then
self.pets[pet_serial] = {dono_nome, dono_serial, dono_flags, Details._tempo, true, pet_nome, pet_serial}
4 years ago
else
self.pets[pet_serial] = {dono_nome, dono_serial, dono_flags, Details._tempo, false, pet_nome, pet_serial}
4 years ago
end
end
function Details:WipePets()
return Details:Destroy(Details.tabela_pets.pets)
4 years ago
end
function Details222.Pets.PetContainerCleanup()
3 years ago
--erase old pet table by creating a new one
4 years ago
local newPetTable = {}
3 years ago
--minimum of 90 minutes to clean a pet from the pet table data
for petGUID, petTable in pairs(Details.tabela_pets.pets) do
if ((petTable[4] + 5400 > Details._tempo + 1) or (petTable[5] and petTable[4] + 43200 > Details._tempo)) then
newPetTable[petGUID] = petTable
4 years ago
end
end
Details.tabela_pets.pets = newPetTable
Details:UpdatePetCache()
4 years ago
end
local have_schedule = false
function Details:UpdatePets()
4 years ago
have_schedule = false
return container_pets:BuscarPets()
end
function Details:SchedulePetUpdate(seconds)
4 years ago
if (have_schedule) then
return
end
have_schedule = true
3 years ago
--_detalhes:ScheduleTimer("UpdatePets", seconds or 5)
4 years ago
Details.Schedules.NewTimer(seconds or 5, Details.UpdatePets, Details)
end
function Details.refresh:r_container_pets(container)
setmetatable(container, container_pets)
4 years ago
end