-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathCore.lua
371 lines (324 loc) · 13.2 KB
/
Core.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
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
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
local L = ME_GetLocale()
MacroExtender_Options = nil
MacroExtender_OptionsDefaults = {
MacroUI = true,
ActionBars = true,
Inventory = true
}
local ME_OptionOps = {
['+d'] = function(str) return string.find(str,"%d+") end,
['+a'] = function(str) return string.find(str,"%a+") end,
['+w'] = function(str) return string.find(str,"%w+") end,
}
--TODO: Implement help / settings to control Macro Extender
--Currently being used for debugging
--Do not use these
local function IsOptionEnabled( option )
if option then
return L["ENABLED"]
end
return L["DISABLED"]
end
function InitAddon( ... )
if not MacroExtender_Options then
MacroExtender_Options = ME_ShallowCopy(MacroExtender_OptionsDefaults)
end
end
function CheckOptionSyntax(args, params)
if not args then return end
local count = 0
for k,v in splitIter(",", params) do
count = count + 1
end
local argc = (table.getn(args) - 1)
if argc < count then
return false
end
local i = 2
local found = 0
local num_params = 0
local invalidArgs = { index = {}, args = {}}
for k,v in splitIter(",", params) do
local option = args[i]
if option then
if ME_OptionOps[v] then
if ME_OptionOps[v](option) then
found = found + 1
else
table.insert(invalidArgs["index"], i - 1)
table.insert(invalidArgs["args"], option)
end
else
local correct_arg
if string.find(v,"/") then
for _,y in splitIter("/",v) do
if y == option then
found = found + 1
correct_arg = true
end
end
if not correct_arg then
table.insert(invalidArgs["index"], i - 1)
table.insert(invalidArgs["args"], option)
end
end
end
else
break
end
i = i + 1
num_params = num_params + 1
end
return found == count, invalidArgs, num_params
end
function ME_Usage( args, help, usage, params, option)
if not args then return end
local function UnpackArgs( tbl, num_params )
local t={}
num_params = num_params or table.getn(tbl)
for i=2, num_params + 1 do
if not tbl[i] then
break
end
table.insert(t,tbl[i])
end
return unpack(t)
end
if type(help) == "table" then
-- future development? May not be worth doing
else
if not args[2] then
ME_Print(help)
ME_Print(L["Usage"]..": /%s %s",args[1], usage)
return nil
else
local results, invalidArgs, numArgs = CheckOptionSyntax(args,params)
if not results then
if invalidArgs then
local param_idx, param_args = invalidArgs["index"][1],invalidArgs["args"][1]
if table.getn(invalidArgs["index"]) > 1 then
param_idx = table.concat(invalidArgs["index"],", ")
param_args = table.concat(invalidArgs["args"],", ")
else
end
ME_Print("")
ME_Print(L["Usage"]..": /%s %s",args[1], usage)
ME_Print(L["Unknown Option"]..": Args(%s) -> %s",param_idx,param_args)
end
end
return UnpackArgs(args, numArgs)
end
end
return nil
end
local function ProxMacro_Handler(msg,editbox)
if msg or msg ~= "" then
local args = {};
local word;
for word in string.gfind(msg, "[^%s]+") do
table.insert(args, word);
end
local cmd = ME_StringLower(args[1])
if cmd == "macroui" then
local option = ME_Usage(args, "MacroUI "..L["interface improvement"], "on/off","on/off", MacroExtender_Options.MacroUI)
if option then
local option = ME_StringLower(option)
local show = true
if option == "on" then
MacroExtender_Options.MacroUI = true
elseif option == "off" then
MacroExtender_Options.MacroUI = nil
end
else
ME_Print("MacroUI "..L["is currently"].." %s",IsOptionEnabled(MacroExtender_Options.MacroUI))
end
elseif cmd == "actionbars" then
local option = ME_Usage(args, "ActionBars "..L["interface improvement"], "on/off","on/off", MacroExtender_Options.ActionBars)
if option then
local option = ME_StringLower(option)
local show = true
if option == "on" then
MacroExtender_Options.ActionBars = true
elseif option == "off" then
MacroExtender_Options.ActionBars = nil
end
else
ME_Print("ActionBars "..L["is currently"].." %s",IsOptionEnabled(MacroExtender_Options.ActionBars))
end
elseif cmd == "inventory" then
local option = ME_Usage(args, "InventorySlots "..L["interface improvement"], "on/off","on/off", MacroExtender_Options.Inventory)
if option then
local option = ME_StringLower(option)
local show = true
if option == "on" then
MacroExtender_Options.Inventory = true
elseif option == "off" then
MacroExtender_Options.Inventory = nil
end
else
ME_Print("InventorySlots "..L["is currently"].." %s",IsOptionEnabled(MacroExtender_Options.Inventory))
end
end
end
end
SLASH_PXMACRO1 = "/mex"
SlashCmdList["PXMACRO"] = ProxMacro_Handler
--Save the old cast macro command
SLASH_PXOLDCAST1 = "/oldcast"
SlashCmdList["PXOLDCAST"] = SlashCmdList["CAST"]
-- Macros
-- /castx will remain stay for compatability issues
SLASH_PXCASTX1 = "/castx"
SLASH_PXCASTX2 = "/use"
SlashCmdList["PXCASTX"] = function (msg,editbox)
if msg or msg ~= "" then
ME_CastSpell(msg)
end
end
-- Replace the old /cast with the new casting spell
SlashCmdList["CAST"] = SlashCmdList["PXCASTX"]
SLASH_PXCASTSEQUENCE1 = "/castsequence"
SLASH_PXCASTSEQUENCE2 = "/castseq"
SlashCmdList["PXCASTSEQUENCE"] = function (msg,editbox)
if msg or msg ~= "" then
ME_CastSequence(msg)
end
end
SLASH_PXCASTRANDOM1 = "/castrandom"
SLASH_PXCASTRANDOM2 = "/userandom"
SlashCmdList["PXCASTRANDOM"] = function (msg,editbox)
if msg or msg ~= "" then
ME_CastRandom(msg)
end
end
SLASH_PXCLICK1 = "/click"
SlashCmdList["PXCLICK"] = function (msg,editbox)
if msg or msg ~= "" then
ME_Click(msg)
end
end
SLASH_PXPICK1 = "/pick"
SlashCmdList["PXPICK"] = function (msg,editbox)
if msg or msg ~= "" then
ME_PickItem(msg)
end
end
SLASH_PXEQUIP1 = "/equip"
SLASH_PXEQUIP2 = "/eq"
SlashCmdList["PXEQUIP"] = function (msg,editbox)
if msg or msg ~= "" then
ME_EquipItem(msg)
end
end
SLASH_PXDISMOUNT1 = "/dismount"
SlashCmdList["PXDISMOUNT"] = function (msg,editbox)
if msg or msg ~= "" then
ME_GenericFunction(msg,function()
Dismount()
end)
else
Dismount()
end
end
SLASH_PXCANCELFORM1 = "/cancelform"
SlashCmdList["PXCANCELFORM"] = function (msg,editbox)
if msg or msg ~= "" then
ME_GenericFunction(msg,function()
CancelForm()
end)
else
CancelForm()
end
end
SLASH_PXSTOPCASTING1 = "/stopcasting"
SlashCmdList["PXSTOPCASTING"] = function (msg,editbox)
if msg or msg ~= "" then
ME_GenericFunction(msg,function()
SpellStopCasting()
end)
else
SpellStopCasting()
end
end
SLASH_PXMACRORELOADUI1 = "/reload"
SlashCmdList["PXMACRORELOADUI"] = function (msg,editbox)
ReloadUI()
end
--- PET
SLASH_PXPETASSIST1 = "/petassist"
SlashCmdList["PXPETASSIST"] = function (msg,editbox)
if msg or msg ~= "" then
ME_GenericFunction(msg,function() if UnitExists("pet") then AssistUnit("pet") end end)
end
end
SLASH_PXPETATTACK1 = "/petattack"
SlashCmdList["PXPETATTACK"] = function (msg,editbox)
if msg or msg ~= "" then
ME_GenericFunction(msg,function() if UnitExists("pet") then PetAttack() end end)
end
end
SLASH_PXPETPASSIVE1 = "/petpassive"
SlashCmdList["PXPETPASSIVE"] = function (msg,editbox)
if msg or msg ~= "" then
ME_GenericFunction(msg,function() if UnitExists("pet") then PetPassiveMode() end end)
end
end
SLASH_PXPETDEFENSIVE1 = "/petdefensive"
SlashCmdList["PXPETDEFENSIVE"] = function (msg,editbox)
if msg or msg ~= "" then
ME_GenericFunction(msg,function() if UnitExists("pet") then PetDefensiveMode() end end)
end
end
SLASH_PXPETAGGRESSIVE1 = "/petaggressive"
SlashCmdList["PXPETAGGRESSIVE"] = function (msg,editbox)
if msg or msg ~= "" then
ME_GenericFunction(msg,function() if UnitExists("pet") then PetAggressiveMode() end end)
end
end
SLASH_PXPETFOLLOW1 = "/petfollow"
SlashCmdList["PXPETFOLLOW"] = function (msg,editbox)
if msg or msg ~= "" then
ME_GenericFunction(msg,function() if UnitExists("pet") then PetFollow() end end)
end
end
SLASH_PXPETSTAY1 = "/petstay"
SlashCmdList["PXPETSTAY"] = function (msg,editbox)
if msg or msg ~= "" then
ME_GenericFunction(msg,function() if UnitExists("pet") then PetWait() end end)
end
end
SLASH_PXHEARTHSTONE1 = "/hearth"
SlashCmdList["PXHEARTHSTONE"] = function (msg,editbox)
if msg or msg ~= "" then
ME_GenericFunction(msg,function()
local found,item = ME_HasItem("hearthstone")
if found and item then
local startTime = GetContainerItemCooldown(item[1].bag,item[1].slot)
if startTime == 0 then
UseContainerItem(item[1].bag,item[1].slot)
else
Stuck()
end
end
end)
end
end
SLASH_PXMOUNT1 = "/mount"
SlashCmdList["PXMOUNT"] = function (msg,editbox)
if msg or msg ~= "" then
ME_GenericFunction(msg,function(action)
ME_CallMount(action)
end)
end
end
SLASH_PXTRADEITEM1 = "/tradeitem"
SlashCmdList["PXTRADEITEM"] = function (msg,editbox)
if msg or msg ~= "" then
ME_TradeItem(msg)
end
end
SLASH_PXSTOPMACRO1 = "/stopmacro"
SlashCmdList["PXSTOPMACRO"] = function (msg,editbox)
-- This is a dummy macro all work is done via Chat Hook
-- Not implemented yet
end