Skip to content

Commit

Permalink
fix: 修复按需请求协议未生效
Browse files Browse the repository at this point in the history
  • Loading branch information
DengSir committed Sep 4, 2024
1 parent 16464bc commit 16475c5
Show file tree
Hide file tree
Showing 3 changed files with 132 additions and 43 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
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
38 changes: 22 additions & 16 deletions Tooltip/FixItemSet.lua
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,14 @@ function ns.FixItemSets(tip, id)
return
end

local equippedCount, itemNames, overrideNames = ns.Inspect:GetEquippedSetItems(setId)
local equippedCount, equippedSetItems = ns.Inspect:GetEquippedSetItems(setId)
local setNameLinePattern = '^(' .. setName .. '.+)(%d+)/(%d+)(.+)$'

local setLine
local firstBonusLine
local inSetLine = true
local bonus = ns.ItemSets[setId].bouns
local slots = ns.ItemSets[setId].slots
local setLineFinished = false

for i = 2, tip:NumLines() do
local textLeft = tip:GetFontStringLeft(i)
Expand All @@ -47,26 +48,31 @@ function ns.FixItemSets(tip, id)
setLine = i
textLeft:SetText(prefix .. equippedCount .. '/' .. maxCount .. suffix)
end
elseif inSetLine then
elseif setLine and not setLineFinished then
local line = text:trim()
local setSlotIndex = i - setLine
local slotItem = slots[setSlotIndex]

if line == '' then
inSetLine = false
if not slotItem or line == '' then
setLineFinished = true
else
local n = itemNames[line]
if n and n > 0 then
local overrideName = overrideNames[line]
if overrideName and line ~= overrideName then
textLeft:SetText(text:sub(1, #text - #line) .. overrideName)
end
local item = equippedSetItems[slotItem.slot]
local hasItem = item
if not item then
item = slotItem.itemId
end

textLeft:SetTextColor(1, 1, 0.6)
itemNames[line] = n > 1 and n - 1 or nil
else
textLeft:SetTextColor(0.5, 0.5, 0.5)
local name = GetItemInfo(item)
if name then
textLeft:SetText(' ' .. name)
if hasItem then
textLeft:SetTextColor(1, 1, 0.6)
else
textLeft:SetTextColor(0.5, 0.5, 0.5)
end
end
end
else
elseif setLineFinished then
local summary, count = MatchBonus(text)
if summary then
if not firstBonusLine then
Expand Down

0 comments on commit 16475c5

Please sign in to comment.