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.

263 lines
8.2 KiB

local _detalhes = _G.Details
4 years ago
local gump = _detalhes.gump
local container_pets = _detalhes.container_pets
local _
local addonName, Details222 = ...
4 years ago
-- api locals
3 years ago
local UnitGUID = _G.UnitGUID
4 years ago
local _UnitName = _G.UnitName
local _GetUnitName = _G.GetUnitName
3 years ago
local IsInRaid = _G.IsInRaid
local IsInGroup = _G.IsInGroup
local GetNumGroupMembers = _G.GetNumGroupMembers
4 years ago
-- lua locals
local setmetatable = setmetatable
4 years ago
local _bit_band = bit.band --lua local
3 years ago
local pairs = pairs
local wipe = table.wipe
4 years ago
--details locals
local is_ignored = _detalhes.pets_ignored
function container_pets:NovoContainer()
local esta_tabela = {}
setmetatable(esta_tabela, _detalhes.container_pets)
3 years ago
esta_tabela.pets = {} --armazena a pool -> uma dictionary com o [serial do pet] -> nome do dono
esta_tabela._ActorTable = {} --armazena os 15 ultimos pets do jogador -> [jogador nome] -> {nil, nil, nil, ...}
4 years ago
return esta_tabela
end
local OBJECT_TYPE_PET = 0x00001000
local EM_GRUPO = 0x00000007
local PET_EM_GRUPO = 0x00001007
function container_pets:PegaDono (pet_serial, pet_nome, pet_flags)
3 years ago
--sair se o pet estiver na ignore
4 years ago
if (is_ignored [pet_serial]) then
return
end
3 years ago
--buscar pelo pet no container de pets
4 years ago
local busca = self.pets [pet_serial]
if (busca) then
--in merging operations, make sure to not add the owner name a second time in the name
--check if the pet name already has the owner name in, if not, add it
3 years ago
if (not pet_nome:find("<")) then
4 years ago
--get the owner name
local ownerName = busca[1]
--add the owner name to the pet name
pet_nome = pet_nome .. " <".. ownerName ..">"
end
3 years ago
--return busca[6] or pet_nome, busca[1], busca[2], busca[3] --busca[6] poderia estar causando problemas
return pet_nome, 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 (pet_serial == UnitGUID("raidpet"..i)) then
dono_serial = UnitGUID("raid"..i)
dono_flags = 0x00000417 --emulate sourceflag flag
4 years ago
local nome, realm = _UnitName ("raid"..i)
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 (pet_serial == UnitGUID("partypet"..i)) then
dono_serial = UnitGUID("party"..i)
dono_flags = 0x00000417 --emulate sourceflag flag
4 years ago
local nome, realm = _UnitName ("party"..i)
if (realm and realm ~= "") then
nome = nome.."-"..realm
end
dono_nome = nome
end
end
end
if (not dono_nome) then
3 years ago
if (pet_serial == UnitGUID("pet")) then
4 years ago
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
if (dono_nome) then
3 years ago
self.pets [pet_serial] = {dono_nome, dono_serial, dono_flags, _detalhes._tempo, true, pet_nome, pet_serial} --adicionada a flag emulada
4 years ago
3 years ago
if (not pet_nome:find("<")) then
4 years ago
pet_nome = pet_nome .. " <".. dono_nome ..">"
end
return pet_nome, dono_nome, dono_serial, dono_flags
else
3 years ago
if (pet_flags and _bit_band (pet_flags, OBJECT_TYPE_PET) ~= 0) then --� um pet
4 years ago
if (not _detalhes.pets_no_owner [pet_serial] and _bit_band (pet_flags, EM_GRUPO) ~= 0) then
_detalhes.pets_no_owner [pet_serial] = {pet_nome, pet_flags}
3 years ago
_detalhes:Msg("couldn't find the owner of the pet:", pet_nome)
4 years ago
end
else
is_ignored [pet_serial] = true
end
end
return
end
function container_pets:Unpet (...)
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 = _detalhes.pets_players [owner_serial]
if (existing_pet_serial) then
_detalhes.parser:RevomeActorFromCache (existing_pet_serial)
container_pets:Remover (existing_pet_serial)
_detalhes.pets_players [owner_serial] = nil
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 _detalhes.tabela_pets.pets [pet_serial]) then
local nome, realm = _UnitName (unitid)
if (realm and realm ~= "") then
nome = nome.."-"..realm
end
_detalhes.tabela_pets:Adicionar (pet_serial, _UnitName (unitid .. "pet"), 0x1114, owner_serial, nome, 0x514)
end
_detalhes.parser:RevomeActorFromCache (pet_serial)
container_pets:PlayerPet (owner_serial, pet_serial)
end
end
end
function container_pets:PlayerPet (player_serial, pet_serial)
_detalhes.pets_players [player_serial] = pet_serial
end
function container_pets:BuscarPets()
3 years ago
if (IsInRaid()) then
for i = 1, GetNumGroupMembers(), 1 do
local pet_serial = UnitGUID("raidpet"..i)
4 years ago
if (pet_serial) then
if (not _detalhes.tabela_pets.pets [pet_serial]) then
local nome, realm = _UnitName ("raid"..i)
if (realm and realm ~= "") then
nome = nome.."-"..realm
end
3 years ago
local owner_serial = UnitGUID("raid"..i)
4 years ago
_detalhes.tabela_pets:Adicionar (pet_serial, _UnitName ("raidpet"..i), 0x1114, owner_serial, nome, 0x514)
_detalhes.parser:RevomeActorFromCache (pet_serial)
container_pets:PlayerPet (owner_serial, pet_serial)
end
end
end
3 years ago
elseif (IsInGroup()) then
for i = 1, GetNumGroupMembers()-1, 1 do
local pet_serial = UnitGUID("partypet"..i)
4 years ago
if (pet_serial) then
if (not _detalhes.tabela_pets.pets [pet_serial]) then
local nome, realm = _UnitName ("party"..i)
if (realm and realm ~= "") then
nome = nome.."-"..realm
end
3 years ago
_detalhes.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 _detalhes.tabela_pets.pets [pet_serial]) then
3 years ago
_detalhes.tabela_pets:Adicionar (pet_serial, _UnitName ("pet"), 0x1114, UnitGUID("player"), _detalhes.playername, 0x514)
4 years ago
end
end
else
3 years ago
local pet_serial = UnitGUID("pet")
4 years ago
if (pet_serial) then
if (not _detalhes.tabela_pets.pets [pet_serial]) then
3 years ago
_detalhes.tabela_pets:Adicionar (pet_serial, _UnitName ("pet"), 0x1114, UnitGUID("player"), _detalhes.playername, 0x514)
4 years ago
end
end
end
end
function container_pets:Remover (pet_serial)
if (_detalhes.tabela_pets.pets [pet_serial]) then
3 years ago
table.wipe(_detalhes.tabela_pets.pets [pet_serial])
4 years ago
end
_detalhes.tabela_pets.pets [pet_serial] = nil
end
function container_pets:Adicionar (pet_serial, pet_nome, pet_flags, dono_serial, dono_nome, dono_flags)
if (pet_flags and _bit_band (pet_flags, OBJECT_TYPE_PET) ~= 0 and _bit_band (pet_flags, EM_GRUPO) ~= 0) then
self.pets [pet_serial] = {dono_nome, dono_serial, dono_flags, _detalhes._tempo, true, pet_nome, pet_serial}
else
self.pets [pet_serial] = {dono_nome, dono_serial, dono_flags, _detalhes._tempo, false, pet_nome, pet_serial}
end
end
function _detalhes:WipePets()
3 years ago
return wipe(_detalhes.tabela_pets.pets)
4 years ago
end
function _detalhes: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 PetSerial, PetTable in pairs(_detalhes.tabela_pets.pets) do
4 years ago
if ( (PetTable[4] + 5400 > _detalhes._tempo + 1) or (PetTable[5] and PetTable[4] + 43200 > _detalhes._tempo) ) then
newPetTable [PetSerial] = PetTable
end
end
_detalhes.tabela_pets.pets = newPetTable
_detalhes:UpdateContainerCombatentes()
end
local have_schedule = false
function _detalhes:UpdatePets()
have_schedule = false
return container_pets:BuscarPets()
end
3 years ago
function _detalhes: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 _detalhes.refresh:r_container_pets (container)
setmetatable(container, container_pets)
4 years ago
end