Quicklog/GuidInfo.lua

356 lines
9.8 KiB
Lua

local name, addon = ...
local GetPlayerInfoByGUID, UnitFullName, UnitClassification, UnitGUID, GetNormalizedRealmName, UnitClass = GetPlayerInfoByGUID, UnitFullName, UnitClassification, UnitGUID, GetNormalizedRealmName, UnitClass
local MAX_RAID_MEMBERS, COMBATLOG_OBJECT_TYPE_PLAYER = MAX_RAID_MEMBERS, COMBATLOG_OBJECT_TYPE_PLAYER
local guidInfo = {}
--[[
UNITNAME_SUMMON_TITLE1 = "Begleiter von %s";
UNITNAME_SUMMON_TITLE10 = "Reittier von %s";
UNITNAME_SUMMON_TITLE11 = "Lichtbrunnen von %s";
UNITNAME_SUMMON_TITLE12 = "Butler von %s";
UNITNAME_SUMMON_TITLE13 = "%s'aka";
UNITNAME_SUMMON_TITLE14 = "Portal von %s";
UNITNAME_SUMMON_TITLE15 = "Hass von %s";
UNITNAME_SUMMON_TITLE16 = "Statue von %s";
UNITNAME_SUMMON_TITLE17 = "Geist von %s";
UNITNAME_SUMMON_TITLE18 = "Kriegsbanner von %s";
UNITNAME_SUMMON_TITLE19 = "Herzerwärmer von %s";
UNITNAME_SUMMON_TITLE2 = "Wächter von %s";
UNITNAME_SUMMON_TITLE20 = "Angeheuert von %s";
UNITNAME_SUMMON_TITLE21 = "Gekauft von %s";
UNITNAME_SUMMON_TITLE22 = "Stolz von %s";
UNITNAME_SUMMON_TITLE23 = "Verzerrtes Abbild von %s";
UNITNAME_SUMMON_TITLE24 = "Nudelwagen von %s";
UNITNAME_SUMMON_TITLE25 = "Innerer Dämon von %s";
UNITNAME_SUMMON_TITLE26 = "Leibwächter von %s";
UNITNAME_SUMMON_TITLE27 = "%s";
UNITNAME_SUMMON_TITLE28 = "Knappe von %s";
UNITNAME_SUMMON_TITLE29 = "Champion von %s";
UNITNAME_SUMMON_TITLE3 = "Diener von %s";
UNITNAME_SUMMON_TITLE30 = "Der Verräter";
UNITNAME_SUMMON_TITLE31 = "Eruptive Reflexion von %s";
UNITNAME_SUMMON_TITLE32 = "Hoffnungslose Reflexion von %s";
UNITNAME_SUMMON_TITLE33 = "Bösartige Reflexion von %s";
UNITNAME_SUMMON_TITLE34 = "Klagende Reflexion von %s";
UNITNAME_SUMMON_TITLE35 = "Assistentin von %s";
UNITNAME_SUMMON_TITLE36 = "Vollstrecker von %s";
UNITNAME_SUMMON_TITLE37 = "Rekrut von %s";
UNITNAME_SUMMON_TITLE38 = "Fan von %s";
UNITNAME_SUMMON_TITLE39 = "Böser Zwilling von %s";
UNITNAME_SUMMON_TITLE4 = "Totem von %s";
UNITNAME_SUMMON_TITLE40 = "Gier von %s";
UNITNAME_SUMMON_TITLE41 = "Verlorener Verstand von %s";
UNITNAME_SUMMON_TITLE42 = "Paktgebundener Beschützer von %s";
UNITNAME_SUMMON_TITLE43 = "Mechanoid von %s";
UNITNAME_SUMMON_TITLE44 = "%s, Diener von N'Zoth";
UNITNAME_SUMMON_TITLE45 = "Assassine von %s";
UNITNAME_SUMMON_TITLE46 = "Wildsamen von %s";
UNITNAME_SUMMON_TITLE47 = "Provost von %s";
UNITNAME_SUMMON_TITLE48 = "Repariert von %s";
UNITNAME_SUMMON_TITLE5 = "Gefährte von %s";
UNITNAME_SUMMON_TITLE6 = "Runenklinge von %s";
UNITNAME_SUMMON_TITLE7 = "Konstrukt von %s";
UNITNAME_SUMMON_TITLE8 = "Gegner von %s";
UNITNAME_SUMMON_TITLE9 = "Fahrzeug von %s";
]]
local LibGUID = LibStub("LibGUID")
addon['LibGUID'] = LibGUID
local methods_guid = {}
local scanIds = { 1, 2, 3, 7, 9, 26, 29}
local scanTip = CreateFrame("GameTooltip", format("%s_ScanTooltip",name), nil, "GameTooltipTemplate")
scanTip:SetOwner( WorldFrame, "ANCHOR_NONE" )
function methods_guid:scanTooltip()
if(self:HasOwner()) then return end
local guid = self[1]
local text = _G[format("%s_ScanTooltipTextLeft2",name)]
scanTip:SetOwner(WorldFrame, 'ANCHOR_NONE')
scanTip:SetHyperlink('unit:' .. guid or '')
if(guid and text) then
local text2 = text:GetText()
if(text2) then
for i = 1, #scanIds do
local check = _G[format("UNITNAME_SUMMON_TITLE%i",scanIds[i])]:gsub("%%s", "(.+)"):gsub("[%[%]]", "%%%1")
self['tooltip'] = text2
if(string.find(text2, check)) then
self['tooltip'] = text2
local a,b,c = string.find(text2, check)
if(c) then
local g = UnitGUID(c)
if(g) then
local gio = addon:GetGuidInfo(g)
-- local gip = addon:GetGuidInfo(guid)
self:SetOwner(gio)
return
-- print('found',c,gio['name'], gip['name'])
end
end
end
-- print(text:GetText(), check, guid)
end
end
end
end
local function GetGuid(unit)
if(unit) then
local guid = UnitGUID(unit)
if(guid and guid ~= "") then
return guid
end
end
end
function methods_guid:IsParty()
if(self['isParty'] ~= nil) then
-- return self['isParty']
end
if(self[3] and bit.band(self[3], COMBATLOG_OBJECT_AFFILIATION_OUTSIDER) == 0) then
self['isParty'] = true
else
self['isParty'] = false
end
return self['isParty']
end
function methods_guid:SetName(newName)
self[2] = newName
local nameSplit, serverSplit = strsplit('-',self[2],2)
if(not serverSplit) then
serverSplit = GetNormalizedRealmName()
end
self['shortName'] = nameSplit
self['shortRealm'] = serverSplit
end
local function processPet(self, clot)
if(guid) then
local gi = addon:GetGuidInfo(guid, UnitFlag, UnitName)
if(gi['isPet'] ~= nil) then
return gi['isPet']
end
if(UnitFlag and bit.band(UnitFlag, COMBATLOG_OBJECT_TYPE_PET) > 0) then
gi['isPet'] = true
return true
else
gi['isPet'] = false
end
end
end
local pet_clots = {COMBATLOG_OBJECT_TYPE_PET, COMBATLOG_OBJECT_TYPE_GUARDIAN, COMBATLOG_OBJECT_TYPE_OBJECT}
function methods_guid:IsPet()
if(self['isPet'] ~= nil) then
return self['isPet']
end
if(self[2]) then
for i = 1, #pet_clots do
if(UnitFlag and bit.band(self[2], COMBATLOG_OBJECT_TYPE_PET) > 0) then
self['isPet'] = true
break
else
self['isPet'] = false
end
end
end
return self['isPet']
end
function methods_guid:HasOwner()
return self['ownerGuid'] or false
end
function methods_guid:SetOwner(gi)
-- print("set owner", self['name'], gi['name'])
self['isPet'] = true
if(gi) then
self['ownerName'] = gi[2]
self['ownerGuid'] = gi[1]
if(gi:IsParty())then
self['isParty'] = true
end
end
end
local function checkPet(unit)
local guid = GetGuid(unit)
if(guid) then
local o = addon:GetGuidInfo2(guid)
o:SetUnit(unit)
o['isParty'] = true
local pet = format("%sPET", unit)
local pguid = GetGuid(pet)
if(pguid) then
local p = addon:GetGuidInfo2(pguid)
p['isParty'] = true
p:SetOwner(o)
end
return guid
end
end
local function assocOwner(guid, petguid)
local gio = addon:GetGuidInfo2(guid)
local gip = addon:GetGuidInfo2(petguid)
gip:SetOwner(gio)
end
local function group_helper(guids, endcount, unitbase)
for i = 1, endcount do
local guid = UnitGUID(format("%s%i", unitbase, i))
if(guid) then
guids[guid] = true
local petguid = UnitGUID(format("%s%ipet", unitbase, i))
if(petguid) then
assocOwner(guid, petguid)
guids[petguid] = true
end
end
end
return guids
end
function addon:GetGroupGuid(guids)
guids = guids or {}
if(IsInRaid()) then
guids = group_helper(guids, MAX_RAID_MEMBERS, 'raid')
elseif(IsInGroup()) then
guids = group_helper(guids, 4, 'party')
local guid = UnitGUID('player')
if(guid) then
guids[guid] = true
local petguid = UnitGUID('pet')
if(petguid) then
assocOwner(guid, petguid)
guids[petguid] = true
end
end
else
local guid = UnitGUID('player')
if(guid) then
guids[guid] = true
local petguid = UnitGUID('pet')
if(petguid) then
assocOwner(guid, petguid)
guids[petguid] = true
end
end
end
return guids
end
function addon:CheckUnit(unit)
if(unit) then
return checkPet(unit)
end
end
function addon:UNIT_TARGET(event, unit)
local trg = format("%starget", unit)
local guid = GetGuid(trg)
if(guid) then
local _, class = UnitClass(trg)
local fullName, realm = UnitFullName(trg)
local gi = addon:GetGuidInfo2(guid, class)
local clf = UnitClassification(trg)
-- print(trg, clf, UnitLevel(trg))
if(clf == 'elite') then
if(UnitLevel(trg) == -1) then
gi['isBoss'] = true
end
end
-- print('gi',gi['class'])
if(not gi['class']) then
-- print('find class')
local _, class = UnitClass(trg)
if(class) then
-- print('found class',class)
gi['class'] = class
end
end
end
end
local function purgeGroupMember()
-- if(true) then return end -- dont purge to keep data intact
local guids = addon:GetGroupGuid()
guids = addon:GetSegmentsGuid(guids)
for guid, v in pairs(guidInfo) do
if(not guids[k]) then
guidInfo[guid]['isParty'] = nil
end
end
end
function addon:RAID_ROSTER_UPDATE()
purgeGroupMember()
for i = 1, MAX_RAID_MEMBERS do
checkPet(format("raid%i", i))
end
end
function addon:GROUP_ROSTER_UPDATE()
purgeGroupMember()
for i = 1, 4 do
checkPet(format('party%i', i))
end
checkPet('player')
end
local purgeTime = {
['Player'] = 3600 * 24,
['Pet'] = 3600,
['Creature'] = 3600
}
function addon:PurgeGuidInfo()
local guids = addon:GetGroupGuid()
--[[ for k, v in pairs(guids) do
local gi = addon:GetGuidInfo(k)
if(gi) then
local localizedClass, englishClass, localizedRace, englishRace, sexGuid, nameGuid, realmGuid = GetPlayerInfoByGUID(k)
-- print(nameGuid, englishClass, k, gi:IsPet())
end
end]]
guids = addon:GetSegmentsGuid(guids)
for k, v in pairs(guidInfo) do
if(not guids[k]) then
-- print(guidInfo[k]['name'],'purged')
guidInfo[k] = nil
else
guidInfo[k]:Touch()
end
end
return guidInfo
end
function rebuildGI()
local guids = addon:GetGroupGuid()
guids = addon:GetSegmentsGuid(guids)
for i = 1,#QuicklogDB['segments'] do
local store = addon:GetStore(addon:GetSegment(i))
for guid, data in pairs(store['source']) do
local obj = addon:GetGuidInfo2(data)
for dguid, ddata in pairs(data['dest']) do
local obj2 = addon:GetGuidInfo2(ddata)
end
end
end
end
function addon:GetGuidInfoDB()
return guidInfo
end
function addon:SetGuidInfoDB(db)
if(db and type(db) == 'table') then
guidInfo = db
end
for guid, data in pairs(guidInfo) do
guidInfo[guid] = LibGUID:UpdateGUID(guid, data)
end
rebuildGI()
return guidInfo
end
function addon:GetGuidInfo2(obj, unitClass)
obj = LibGUID:CreateGUIDObject(obj)
if(not obj) then return end
-- local objDB = obj:GetNamespace(name)
for k, v in pairs(methods_guid) do
obj[k] = v
end
if(obj[2]) then
obj:SetName(obj[2])
end
if(unitClass) then
obj['class'] = unitClass
end
if(obj['class'] and not obj['classColor']) then
obj['classColor'] = addon:GetClassColors(obj['class'])
end
guidInfo[obj[1]] = obj
return obj
end
LibGUID:RegisterPrune(function(self)
addon:PurgeGuidInfo()
end)