-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFilterSystem.lua
More file actions
222 lines (188 loc) · 4.86 KB
/
FilterSystem.lua
File metadata and controls
222 lines (188 loc) · 4.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
---@class LibsDisenchantAssist
local LibsDisenchantAssist = LibStub('AceAddon-3.0'):GetAddon('LibsDisenchantAssist')
---@class LibsDisenchantAssist.FilterSystem : AceModule
local FilterSystem = LibsDisenchantAssist:NewModule('FilterSystem')
LibsDisenchantAssist.FilterSystem = FilterSystem
local slotMap = {
['INVTYPE_HEAD'] = { 1 },
['INVTYPE_NECK'] = { 2 },
['INVTYPE_SHOULDER'] = { 3 },
['INVTYPE_BODY'] = { 4 },
['INVTYPE_CHEST'] = { 5 },
['INVTYPE_WAIST'] = { 6 },
['INVTYPE_LEGS'] = { 7 },
['INVTYPE_FEET'] = { 8 },
['INVTYPE_WRIST'] = { 9 },
['INVTYPE_HAND'] = { 10 },
['INVTYPE_FINGER'] = { 11, 12 },
['INVTYPE_TRINKET'] = { 13, 14 },
['INVTYPE_WEAPON'] = { 16, 17 },
['INVTYPE_SHIELD'] = { 17 },
['INVTYPE_RANGED'] = { 18 },
['INVTYPE_CLOAK'] = { 15 },
['INVTYPE_2HWEAPON'] = { 16, 17 },
['INVTYPE_WEAPONMAINHAND'] = { 16 },
['INVTYPE_WEAPONOFFHAND'] = { 17 },
['INVTYPE_HOLDABLE'] = { 17 },
['INVTYPE_THROWN'] = { 18 },
['INVTYPE_RANGEDRIGHT'] = { 18 },
}
---@return table[]
function FilterSystem:GetFilteredItems()
local allItems = LibsDisenchantAssist.ItemScanner:GetDisenchantableItems()
return self:FilterItems(allItems)
end
---@param items table[]
---@return table[]
function FilterSystem:FilterItems(items)
local filtered = {}
local options = LibsDisenchantAssist.DB
for _, item in ipairs(items) do
if self:PassesAllFilters(item, options) then
table.insert(filtered, item)
end
end
table.sort(filtered, function(a, b)
if a.itemLevel ~= b.itemLevel then
return a.itemLevel < b.itemLevel
end
return a.itemName < b.itemName
end)
return filtered
end
---@param item table
---@param options LibsDisenchantAssistOptions
---@return boolean
function FilterSystem:PassesAllFilters(item, options)
if not options.enabled then
return false
end
if LibsDisenchantAssist:IsItemIgnored(item.itemID) then
return false
end
if not self:PassesDisenchantFilters(item, options) then
return false
end
if options.excludeToday and item.seenToday then
return false
end
return true
end
---@param item table
---@param options LibsDisenchantAssistOptions
---@return boolean
function FilterSystem:PassesDisenchantFilters(item, options)
if item.quality > options.deMaxQuality then
return false
end
if item.itemLevel < options.minIlvl or item.itemLevel > options.maxIlvl then
return false
end
if options.excludeHigherIlvl and self:IsHigherThanEquipped(item) then
return false
end
if options.excludeGearSets and self:IsInGearSet(item) then
return false
end
if options.excludeWarbound and self:IsWarbound(item) then
return false
end
if options.excludeBOE and self:IsBOE(item) then
return false
end
if options.excludePawnUpgrades and self:IsPawnUpgrade(item) then
return false
end
return true
end
---@param item table
---@return boolean
function FilterSystem:IsHigherThanEquipped(item)
if not item.equipLoc or item.equipLoc == '' then
return false
end
local slots = slotMap[item.equipLoc]
if not slots then
return false
end
for _, slotID in ipairs(slots) do
local equippedLink = GetInventoryItemLink('player', slotID)
if equippedLink then
local equippedIlvl = C_Item.GetDetailedItemLevelInfo(equippedLink)
if equippedIlvl and item.itemLevel > equippedIlvl then
return true
end
end
end
return false
end
---@param item table
---@return boolean
function FilterSystem:IsInGearSet(item)
local setIDs = C_EquipmentSet.GetEquipmentSetIDs()
for _, setID in ipairs(setIDs) do
local itemIDs = C_EquipmentSet.GetItemIDs(setID)
if itemIDs then
for _, id in pairs(itemIDs) do
if id == item.itemID then
return true
end
end
end
end
return false
end
---@param item table
---@return boolean
function FilterSystem:IsWarbound(item)
local tooltipData = C_TooltipInfo.GetBagItem(item.bag, item.slot)
if not tooltipData then
return false
end
for _, line in ipairs(tooltipData.lines) do
if line.leftText then
if string.find(line.leftText, 'Warbound') then
return true
end
end
end
return false
end
---@param item table
---@return boolean
function FilterSystem:IsBOE(item)
local tooltipData = C_TooltipInfo.GetBagItem(item.bag, item.slot)
if not tooltipData then
return false
end
for _, line in ipairs(tooltipData.lines) do
if line.leftText and string.find(line.leftText, 'Binds when equipped') then
return true
end
end
return false
end
---@param item table
---@return boolean
function FilterSystem:IsPawnUpgrade(item)
if not PawnIsReady or not PawnIsReady() then
return false
end
if not PawnGetItemData or not PawnIsItemAnUpgrade then
return false
end
local pawnItem = PawnGetItemData(item.itemLink)
if not pawnItem then
return false
end
local upgradeTable = PawnIsItemAnUpgrade(pawnItem)
if upgradeTable and #upgradeTable > 0 then
return true
end
return false
end
---@return number
function FilterSystem:GetItemCount()
local items = self:GetFilteredItems()
return #items
end