-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.lua
executable file
·120 lines (102 loc) · 3.73 KB
/
main.lua
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
Addon('JunkFilters', function()
local Bag = Require('Bag')
local Contains = Require('Contains')
local SortInsert = Require('SortInsert')
local Settings = Require('Settings')
local Backpack = Bag(BAG_BACKPACK)
local Filters = {}
local function LoadFilters ()
Filters = {}
for name, Filter in pairs(Data.Filters) do
SortInsert(Filters, {
Name = name,
Priority = Filter.Priority,
Test = LoadString('return '..Filter.Test),
}, function(A, B) return A.Priority < B.Priority end)
end
end
local function SaveFilter (name, priority, test)
Data.Filters[name] = { Priority = priority, Test = test }
LoadFilters()
end
local function DeleteFilter (name)
Data.Filters[name] = nil
LoadFilters()
end
local function FilterItem (code, bag, slot)
local Item = Backpack.Item(slot)
if Item.IsLocked() or Item.Quality() > 4 then return end
local function FilterType (...)
local nums = Item.FilterTypes()
local names = Item.FilterNames()
return Contains({...}, unpack(nums)) or Contains({...}, unpack(names))
end
local API = {
stat = Item.Stat,
level = Item.Level,
cp = Item.CP,
quality = Item.Quality,
condition = Item.Condition,
craftRank = Item.CraftRank,
stack = Item.Stack,
maxStack = Item.MaxStack,
inBackpack = Item.InBackpack,
inBank = Item.InBank,
inCraftbag = Item.InCraftbag,
hasSet = Item.HasSet,
isResearchable = Item.IsResearchable,
isBound = Item.IsBound,
isCrafted = Item.IsCrafted,
isStolen = Item.IsStolen,
isQuickslotted = Item.IsQuickslotted,
isKnown = Item.IsKnown,
ftype = FilterType,
id = function(...) return Contains({...}, Item.ID()) end,
set = function(...) return Contains({...}, Item.Set()) end,
name = function(...) return Contains({...}, Item.Name()) end,
trait = function(...) return Contains({...}, Item.Trait()) end,
type = function(...) return Contains({...}, Item.Type()) end,
stype = function(...) return Contains({...}, Item.SpecialType()) end,
armortype = function(...) return Contains({...}, Item.ArmorType()) end,
weapontype = function(...) return Contains({...}, Item.WeaponType()) end,
}
for _, Filter in pairs(Filters) do
local Filter = setfenv(Filter.Test, API)
local ok, result = pcall(Filter)
if ok then if result then Item.Junk(true) end
else Print('Error Running Junk Filter') end
end
end
-- On Addon Loaded
Event.OnLoad(function()
Data.Filters = Data.Filters or {
['General'] = {
['Priority'] = 1,
['Test'] = "type('Trash')"
}
}
Data.Options = Data.Options or {
AutoSell = true
}
Settings(SaveFilter, DeleteFilter)
LoadFilters()
end)
-- On Store Open
Event.On(EVENT_OPEN_STORE, function()
if Data.Options.AutoSell then
if Backpack.SellJunk()
then Print('Junk Items Sold') end
end
end)
-- Filter Now Command
SLASH_COMMANDS['/filternow'] = function()
for slot = 0, Backpack.Size() do
if Backpack.IsFilled(slot)
then FilterItem(nil, nil, slot) end
end
Print('Inventory Filtered')
end
Event.On(EVENT_INVENTORY_SINGLE_SLOT_UPDATE, FilterItem)
.Filter(REGISTER_FILTER_BAG_ID, BAG_BACKPACK)
.Filter(REGISTER_FILTER_INVENTORY_UPDATE_REASON, INVENTORY_UPDATE_REASON_DEFAULT)
end)