-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathparcel_inv.lua
More file actions
133 lines (109 loc) · 3.57 KB
/
parcel_inv.lua
File metadata and controls
133 lines (109 loc) · 3.57 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
local mq = require('mq')
local ICONS = require('mq.Icons')
local parcel_inv = {}
parcel_inv.sendSources = {}
parcel_inv.items = {}
parcel_inv.currentSendItemIdx = 0
local inventoryOffset = 22
parcel_inv.genericSources = {
{
name = "All TS Items",
filter = function(item)
return item.Tradeskills() and item.Stackable()
end,
},
{
name = "All Collectible Items",
filter = function(item)
return item.Collectible() and item.Stackable()
end,
},
}
parcel_inv.customSources = {}
--[[
Sample Custom Source in config/parcel_sources.lua
return {
{
name = "Tradable Armor",
filter = function(item)
return item.Type() == "Armor"
end,
},
}
]]
---@param additionalSource table
---@return table
function parcel_inv:new(additionalSource)
local newInv = setmetatable({}, self)
self.__index = self
newInv.customSources = additionalSource or {}
return newInv
end
function parcel_inv:createContainerInventory()
self.sendSources = {}
for _, v in ipairs(self.genericSources) do table.insert(self.sendSources, v) end
for _, v in ipairs(self.customSources) do table.insert(self.sendSources, v) end
for i = 23, 34, 1 do
local slot = mq.TLO.Me.Inventory(i)
if slot.Container() and slot.Container() > 0 then
local bagName = string.format("%s (%d)", slot.Name(), slot.ItemSlot() - inventoryOffset)
table.insert(self.sendSources, { name = bagName, slot = slot, })
end
end
end
-- Converts between ItemSlot and /itemnotify pack numbers
function parcel_inv.toPack(slot_number)
return "pack" .. tostring(slot_number - 22)
end
-- Converts between ItemSlot2 and /itemnotify numbers
function parcel_inv.toBagSlot(slot_number)
return slot_number + 1
end
function parcel_inv:resetState()
self.currentSendItemIdx = 0
end
function parcel_inv:getNextItem()
self.currentSendItemIdx = self.currentSendItemIdx + 1
if self.currentSendItemIdx > #self.items then
self.currentSendItemIdx = 0
return nil
end
return self.items[self.currentSendItemIdx]
end
function parcel_inv:getFilteredItems(filterFn)
self.items = {}
for i = 23, 34, 1 do
local slot = mq.TLO.Me.Inventory(i)
if slot.Container() and slot.Container() > 0 then
for j = 1, (slot.Container()), 1 do
if (slot.Item(j)() and not slot.Item(j).NoDrop() and not slot.Item(j).NoRent()) and
filterFn(slot.Item(j)) then
table.insert(self.items, { Item = slot.Item(j), Sent = ICONS.MD_CLOUD_QUEUE, })
end
end
else
if (slot() and not slot.NoDrop() and not slot.NoRent()) and
filterFn(slot) then
table.insert(self.items, { Item = slot, Sent = ICONS.MD_CLOUD_QUEUE, })
end
end
end
end
---@param index number
function parcel_inv:getItems(index)
local data = self.sendSources[index]
if not data then return end
if data.filter ~= nil then
self:getFilteredItems(data.filter)
else
self.items = {}
local slot = data.slot
for j = 1, (slot.Container()), 1 do
if (slot.Item(j)() and not slot.Item(j).NoDrop() and not slot.Item(j).NoRent()) then
table.insert(self.items, { Item = slot.Item(j), Sent = ICONS.MD_CLOUD_QUEUE, })
end
end
end
self.currentSendItemIdx = 0
end
return parcel_inv