Skip to content

Commit

Permalink
feat: 装等计算
Browse files Browse the repository at this point in the history
  • Loading branch information
DengSir committed Sep 3, 2024
1 parent 57035f6 commit 145ea8e
Showing 1 changed file with 36 additions and 23 deletions.
59 changes: 36 additions & 23 deletions Core/Inspect.lua
Original file line number Diff line number Diff line change
Expand Up @@ -191,29 +191,47 @@ local function GetSlotItemLevel(slot)
return 0
end

local itemLevel = select(4, GetItemInfo(itemId))
local itemLevel, _, _, _, _, itemEquipLoc, _, _, _, subClassId = select(4, GetItemInfo(itemId))
if itemLevel then
return itemLevel
return itemLevel, itemEquipLoc, subClassId
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))
local function GetHandItemLevel()
local itemLevel, itemEquipLoc = GetSlotItemLevel(INVSLOT_MAINHAND)
if itemEquipLoc == 'INVTYPE_2HWEAPON' then
return itemLevel * 2
else
local itemLevelOff = GetSlotItemLevel(INVSLOT_OFFHAND)
return itemLevel + itemLevelOff
end
return itemLevel
end

local function GetRangedItemLevel(slot)
if UnitClassBase('player') ~= 'HUNTER' then
return 0, true
local DOUBLE_ITEM_LEVEL_RANGED = {
[Enum.ItemWeaponSubclass.Guns] = true,
[Enum.ItemWeaponSubclass.Bows] = true,
[Enum.ItemWeaponSubclass.Crossbow] = true,
}

local function GetRangedItemLevel()
local itemLevel, itemEquipLoc, subClassId = GetSlotItemLevel(INVSLOT_RANGED)
if itemEquipLoc == 'INVTYPE_THROWN' then
return itemLevel
elseif itemEquipLoc == 'INVTYPE_RANGED' or itemEquipLoc == 'INVTYPE_RANGEDRIGHT' then
if DOUBLE_ITEM_LEVEL_RANGED[subClassId] then
return itemLevel * 2
else
return itemLevel
end
else
return 0
end
return GetSlotItemLevel(slot)
end

local function GetWeaponItemLevel()
local itemLevelHand = GetHandItemLevel()
local itemLevelRanged = GetRangedItemLevel()
return max(itemLevelHand, itemLevelRanged)
end

local SLOTS = {
Expand All @@ -231,25 +249,20 @@ local SLOTS = {
[INVSLOT_TRINKET1] = GetSlotItemLevel,
[INVSLOT_TRINKET2] = GetSlotItemLevel,
[INVSLOT_BACK] = GetSlotItemLevel,
[INVSLOT_MAINHAND] = GetMainhandItemLevel,
[INVSLOT_OFFHAND] = GetSlotItemLevel,
[INVSLOT_RANGED] = GetRangedItemLevel,
[INVSLOT_MAINHAND] = GetWeaponItemLevel,
}

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

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

-- @build>2@
Expand Down

0 comments on commit 145ea8e

Please sign in to comment.