Skip to content

Commit

Permalink
fix: 修复报历史协议请求数据逻辑未生效
Browse files Browse the repository at this point in the history
  • Loading branch information
DengSir committed Sep 1, 2024
1 parent 7585682 commit f477868
Show file tree
Hide file tree
Showing 24 changed files with 1,269 additions and 130 deletions.
8 changes: 8 additions & 0 deletions Addon.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ local ns = select(2, ...)

local ShowUIPanel = LibStub('LibShowUIPanel-1.0').ShowUIPanel

---@class UI
---@field BaseItem UI.BaseItem
---@field GearItem UI.GearItem
---@field GearFrame UI.GearFrame
---@field GemItem UI.GemItem
---@field EnchantItem UI.EnchantItem
---@field InspectFrame UI.InspectFrame
---@field InspectGearFrame UI.InspectGearFrame
ns.UI = {}
ns.L = LibStub('AceLocale-3.0'):GetLocale('tdInspect')

Expand Down
23 changes: 23 additions & 0 deletions Api.lua
Original file line number Diff line number Diff line change
Expand Up @@ -150,3 +150,26 @@ function ns.ResolveTalent(class, data)
local talent = ns.Talent:New(class, data)
return talent:ToString()
end

local function FlagTest(value, flag)
return bit.band(value, bit.lshift(1, flag)) > 0
end

function ns.GetItemEnchantInfo(link)
if not link then
return
end
local enchantId = tonumber(link:match('item:%d+:(%d*)'))
if enchantId then
local itemId, _, _, _, _, classId, subClassId = GetItemInfoInstant(link)
local invType = C_Item.GetItemInventoryTypeByID(itemId)

for _, v in ipairs(ns.ItemEnchants) do
if v.enchantId == enchantId and v.classId == classId and
(not v.subClassMask or FlagTest(v.subClassMask, subClassId)) and
(not v.invTypeMask or FlagTest(v.invTypeMask, invType)) then
return v
end
end
end
end
129 changes: 102 additions & 27 deletions Core/Inspect.lua
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,14 @@ function Inspect:SetUnit(unit, name)
end
end

function Inspect:GetUnitName()
if self.unit then
return ns.UnitName(self.unit)
else
return Ambiguate(self.unitName, 'none')
end
end

function Inspect:Clear()
ClearInspectPlayer()
self.unitName = nil
Expand Down Expand Up @@ -177,6 +185,73 @@ function Inspect:IsItemEquipped(itemId)
end
end

local function GetSlotItemLevel(slot)
local itemId = Inspect:GetItemLink(slot)
if not itemId then
return 0
end

local itemLevel = select(4, GetItemInfo(itemId))
if itemLevel then
return itemLevel
end
end

local function GetMainhandItemLevel(slot)
local itemId = Inspect:GetItemLink(slot)
if not itemId then
return 0
end
local itemLevel, _, _, _, _, itemEquipLoc = select(4, GetItemInfo(itemId))
if itemEquipLoc == 'INVTYPE_2HWEAPON' then
return itemLevel * 2
end
return itemLevel
end

local function GetRangedItemLevel(slot)
if UnitClassBase('player') ~= 'HUNTER' then
return 0, true
end
return GetSlotItemLevel(slot)
end

local SLOTS = {
[INVSLOT_HEAD] = GetSlotItemLevel,
[INVSLOT_NECK] = GetSlotItemLevel,
[INVSLOT_SHOULDER] = GetSlotItemLevel,
[INVSLOT_CHEST] = GetSlotItemLevel,
[INVSLOT_WAIST] = GetSlotItemLevel,
[INVSLOT_LEGS] = GetSlotItemLevel,
[INVSLOT_FEET] = GetSlotItemLevel,
[INVSLOT_WRIST] = GetSlotItemLevel,
[INVSLOT_HAND] = GetSlotItemLevel,
[INVSLOT_FINGER1] = GetSlotItemLevel,
[INVSLOT_FINGER2] = GetSlotItemLevel,
[INVSLOT_TRINKET1] = GetSlotItemLevel,
[INVSLOT_TRINKET2] = GetSlotItemLevel,
[INVSLOT_BACK] = GetSlotItemLevel,
[INVSLOT_MAINHAND] = GetMainhandItemLevel,
[INVSLOT_OFFHAND] = GetSlotItemLevel,
[INVSLOT_RANGED] = GetRangedItemLevel,
}

function Inspect:GetItemLevel()
local total, count = 0, 0

for slot, f in pairs(SLOTS) do
local itemLevel, ignore = f(slot)
if not itemLevel then
return
end
if not ignore then
count = count + 1
total = total + itemLevel
end
end
return total / count
end

-- @build>2@
local GEM_COLORS = {
[Enum.ItemGemSubclass.Red] = {Enum.ItemGemSubclass.Red},
Expand Down Expand Up @@ -226,40 +301,23 @@ end
-- @end-build>2@

function Inspect:GetEquippedSetItems(id)
local count = 0
local items = {}
local overrideNames = {}
local slotItems = ns.ItemSets[id].slots

local count = 0
for slot = 1, 18 do
local link = self:GetItemLink(slot)
if link then
local name, _, _, _, _, _, _, _, equipLoc, _, _, _, _, _, _, setId = GetItemInfo(link)
if name and setId and setId == id then
local baseName
local itemId = ns.ItemLinkToId(link)

if equipLoc == 'INVTYPE_ROBE' then
equipLoc = 'INVTYPE_CHEST'
end

local isBaseItem = slotItems[equipLoc][itemId]
if not isBaseItem then
local baseItemId = next(slotItems[equipLoc])
baseName = GetItemInfo(baseItemId)
if baseName then
overrideNames[baseName] = name
end
items[name] = (items[name] or 0) + 1
end

items[equipLoc] = itemId
count = count + 1
baseName = baseName or name
items[baseName] = (items[baseName] or 0) + 1
end
end
end
return count, items, overrideNames
return count, items
end

function Inspect:GetUnitClassFileName()
Expand Down Expand Up @@ -302,6 +360,17 @@ function Inspect:GetUnitLevel()
end
end

function Inspect:GetDataSource()
if self.db.proto then
if self.db.proto.tdInspect then
return 'tdInspect'
elseif self.db.proto.TalentEmu then
return 'TalentEmu'
end
end
return 'Blizzard'
end

function Inspect:GetNumTalentGroups()
return self.db.numGroups or 0
end
Expand Down Expand Up @@ -399,31 +468,31 @@ function Inspect:Query(unit, name)
if queryEquip or queryTalent or queryGlyph or queryRune then

local co = coroutine.create(function()
local me = self:IsCharacterHasProto('tdInspect')
local ala = self:IsCharacterHasProto('TalentEmu')
local unitName = self.unitName
local me = self:IsCharacterHasProto(unitName, 'tdInspect')
local ala = self:IsCharacterHasProto(unitName, 'TalentEmu')


self:ClearCharacterProto(self.unitName, 'tdInspect')
self:ClearCharacterProto(unitName, 'tdInspect')
self:SendCommMessage(PROTO_PREFIX, Serializer:Serialize('Q', queryTalent, queryEquip, PROTO_VERSION,
queryGlyph, queryRune), 'WHISPER', self.unitName)

if me then
sleep(1)
end

if self:IsCharacterHasProto('tdInspect') then
if self:IsCharacterHasProto(unitName, 'tdInspect') then
return
end

self:ClearCharacterProto(self.unitName, 'TalentEmu')
self:ClearCharacterProto(unitName, 'TalentEmu')
self:SendCommMessage(ALA_PREFIX, ns.Ala:PackQuery(queryEquip, queryTalent, queryGlyph, queryRune),
'WHISPER', self.unitName)

if ala then
sleep(1)
end

if self:IsCharacterHasProto('TalentEmu') then
if self:IsCharacterHasProto(unitName, 'TalentEmu') then
return
end

Expand Down Expand Up @@ -510,6 +579,12 @@ end

function Inspect:UpdateCharacter(sender, data)
local name = ns.GetFullName(sender)

if self:IsCharacterHasProto(name, 'tdInspect') and self.userCache[name] and self.userCache[name].timestamp and
time() - self.userCache[name].timestamp < 5 then
return
end

local db = self:BuildCharacterDb(name)

if data.class then
Expand Down
22 changes: 19 additions & 3 deletions Data/DataLoader.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ ns.ItemSets = {}
ns.Glyphes = {}
ns.SpellGlyphes = {}
ns.GlyphSlots = {}
ns.ItemEnchants = {}

local strsplittable = strsplittable or function(delimiter, str, pieces)
return {strsplit(delimiter, str, pieces)}
Expand Down Expand Up @@ -131,9 +132,7 @@ function ns.ItemSetMake()
end

local function SetItemSetSlotItem(slot, itemId)
slot = SLOTS[slot]
CURRENT.slots[slot] = CURRENT.slots[slot] or {}
CURRENT.slots[slot][itemId] = true
tinsert(CURRENT.slots, {slot = SLOTS[slot], itemId = itemId})
end

setfenv(2, { --
Expand Down Expand Up @@ -162,3 +161,20 @@ function ns.GlyphMake()

setfenv(2, {D = Data, S = Slot})
end

function ns.ItemEnchantMake()
ns.ItemEnchantMake = nil

local Data = function(enchantId, spellId, itemId, classId, subClassMask, invTypeMask)
tinsert(ns.ItemEnchants, {
enchantId = enchantId,
spellId = spellId,
itemId = itemId,
classId = classId,
subClassMask = subClassMask,
invTypeMask = invTypeMask,
})
end

setfenv(2, {D = Data})
end
Loading

0 comments on commit f477868

Please sign in to comment.