-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.lua
143 lines (112 loc) · 3.89 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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
--[[
Copyright (c) 2014 by Adam Hellberg.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
]]
local NAME, T = ...
T.Frame = CreateFrame("Frame")
T.Events = {}
local VELLUM_ID = 38682
local db
local cdb
local bank_open = false
function T:IsEnabled()
return cdb.Enabled and db.Enabled
end
function T:RunCheck()
if not bank_open or not self:IsEnabled() then return end
for i = 1, GetContainerNumSlots(REAGENTBANK_CONTAINER) do
local id = GetContainerItemID(REAGENTBANK_CONTAINER, i)
if id == VELLUM_ID or db.Items[id] or cdb.Items[id] then
UseContainerItem(REAGENTBANK_CONTAINER, i)
end
end
end
function T.Events.ADDON_LOADED(name)
if name ~= NAME then return end
if type(VellumWithdrawerDB) ~= "table" then
VellumWithdrawerDB = {}
end
T.DB = VellumWithdrawerDB
db = T.DB
if type(db.Enabled) ~= "boolean" then
db.Enabled = true
end
if type(db.Items) ~= "table" then
db.Items = {}
end
if type(db.AutoDeposit) ~= "boolean" then
db.AutoDeposit = false
end
if type(VellumWithdrawerCharDB) ~= "table" then
VellumWithdrawerCharDB = {}
end
T.CDB = VellumWithdrawerCharDB
cdb = T.CDB
if type(cdb.Enabled) ~= "boolean" then
cdb.Enabled = db.Enabled
end
if type(cdb.Items) ~= "table" then
cdb.Items = {}
end
if type(cdb.AutoDeposit) ~= "boolean" then
cdb.AutoDeposit = false
end
end
function T.Events.BANKFRAME_OPENED()
bank_open = true
if db.AutoDeposit and cdb.AutoDeposit then
DepositReagentBank()
else
T:RunCheck()
end
end
function T.Events.BANKFRAME_CLOSED()
bank_open = false
end
function T.Events.BAG_UPDATE_DELAYED()
T:RunCheck()
end
T.Frame:SetScript("OnEvent", function(self, event, ...)
if T.Events[event] then T.Events[event](...) end
end)
for k, _ in pairs(T.Events) do
T.Frame:RegisterEvent(k)
end
SLASH_VELLUMWITHDRAWER1 = "/vellumwithdrawer"
SLASH_VELLUMWITHDRAWER2 = "/vw"
local function log(f, ...)
DEFAULT_CHAT_FRAME:AddMessage(("|cff00FF00[VellumWithdrawer]|r %s"):format(tostring(f):format(...)))
end
SlashCmdList.VELLUMWITHDRAWER = function(msg, editBox)
if msg:match("^c") then
cdb.Enabled = not cdb.Enabled
log("%s for this character", cdb.Enabled and "Enabled" or "Disabled")
elseif msg:match("^n") then
T:RunCheck()
elseif msg:match("^o") then
T.Options:Open()
elseif msg:match("^d") then
db.AutoDeposit = not db.AutoDeposit
log("Auto deposit %s", db.AutoDeposit and "enabled" or "disabled")
elseif msg:match("^d[%w%s]-c") then
cdb.AutoDeposit = not cdb.AutoDeposit
log("Auto deposit %s for this character", cdb.AutoDeposit and "enabled" or "disabled")
else
db.Enabled = not db.Enabled
log("%s", db.Enabled and "Enabled" or "Disabled")
end
end