-
Notifications
You must be signed in to change notification settings - Fork 32
/
Mote-SelfCommands.lua
466 lines (374 loc) · 14.6 KB
/
Mote-SelfCommands.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
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
-------------------------------------------------------------------------------------------------------------------
-- General functions for manipulating state values via self-commands.
-- Only handles certain specific states that we've defined, though it
-- allows the user to hook into the cycle command.
-------------------------------------------------------------------------------------------------------------------
-- Routing function for general known self_commands. Mappings are at the bottom of the file.
-- Handles splitting the provided command line up into discrete words, for the other functions to use.
function self_command(commandArgs)
local commandArgs = commandArgs
if type(commandArgs) == 'string' then
commandArgs = T(commandArgs:split(' '))
if #commandArgs == 0 then
return
end
end
-- init a new eventArgs
local eventArgs = {handled = false}
-- Allow jobs to override this code
if job_self_command then
job_self_command(commandArgs, eventArgs)
end
if not eventArgs.handled then
-- Of the original command message passed in, remove the first word from
-- the list (it will be used to determine which function to call), and
-- send the remaining words as parameters for the function.
local handleCmd = table.remove(commandArgs, 1)
if selfCommandMaps[handleCmd] then
selfCommandMaps[handleCmd](commandArgs)
end
end
end
-------------------------------------------------------------------------------------------------------------------
-- Functions for manipulating state vars.
-------------------------------------------------------------------------------------------------------------------
-- Function to set various states to specific values directly.
-- User command format: gs c set [field] [value]
-- If a boolean [field] is used, but not given a [value], it will be set to true.
function handle_set(cmdParams)
if #cmdParams == 0 then
add_to_chat(123,'Mote-Libs: Set parameter failure: field not specified.')
return
end
local state_var = get_state(cmdParams[1])
if state_var then
local oldVal = state_var.value
state_var:set(cmdParams[2])
local newVal = state_var.value
local descrip = state_var.description or cmdParams[1]
if job_state_change then
job_state_change(descrip, newVal, oldVal)
end
local msg = descrip..' is now '..state_var.current
if state_var == state.DefenseMode and newVal ~= 'None' then
msg = msg .. ' (' .. state[newVal .. 'DefenseMode'].current .. ')'
end
msg = msg .. '.'
add_to_chat(122, msg)
handle_update({'auto'})
else
add_to_chat(123,'Mote-Libs: Set: Unknown field ['..cmdParams[1]..']')
end
-- handle string states: CombatForm, CombatWeapon, etc
end
-- Function to reset values to their defaults.
-- User command format: gs c reset [field]
-- Or: gs c reset all
function handle_reset(cmdParams)
if #cmdParams == 0 then
if _global.debug_mode then add_to_chat(123,'handle_reset: parameter failure: reset type not specified') end
return
end
local state_var = get_state(cmdParams[1])
local oldVal
local newVal
local descrip
if state_var then
oldVal = state_var.value
state_var:reset()
newVal = state_var.value
local descrip = state_var.description or cmdParams[1]
if job_state_change then
job_state_change(descrip, newVal, oldVal)
end
add_to_chat(122,descrip..' is now '..state_var.current..'.')
handle_update({'auto'})
elseif cmdParams[1]:lower() == 'all' then
for k,v in pairs(state) do
if v._type == 'mode' then
oldVal = v.value
v:reset()
newVal = v.value
descrip = state_var.description
if descrip and job_state_change then
job_state_change(descrip, newVal, oldVal)
end
end
end
if job_reset_state then
job_reset_state('all')
end
if job_state_change then
job_state_change('Reset All')
end
add_to_chat(122,"All state vars have been reset.")
handle_update({'auto'})
elseif job_reset_state then
job_reset_state(cmdParams[1])
else
add_to_chat(123,'Mote-Libs: Reset: Unknown field ['..cmdParams[1]..']')
end
end
-- Handle cycling through the options list of a state var.
-- User command format: gs c cycle [field]
function handle_cycle(cmdParams)
if #cmdParams == 0 then
add_to_chat(123,'Mote-Libs: Cycle parameter failure: field not specified.')
return
end
local state_var = get_state(cmdParams[1])
if state_var then
local oldVal = state_var.value
if cmdParams[2] and S{'reverse', 'backwards', 'r'}:contains(cmdParams[2]:lower()) then
state_var:cycleback()
else
state_var:cycle()
end
local newVal = state_var.value
local descrip = state_var.description or cmdParams[1]
if job_state_change then
job_state_change(descrip, newVal, oldVal)
end
add_to_chat(122,descrip..' is now '..state_var.current..'.')
handle_update({'auto'})
else
add_to_chat(123,'Mote-Libs: Cycle: Unknown field ['..cmdParams[1]..']')
end
end
-- Handle cycling backwards through the options list of a state var.
-- User command format: gs c cycleback [field]
function handle_cycleback(cmdParams)
cmdParms[2] = 'reverse'
handle_cycle(cmdParams)
end
-- Handle toggling of boolean mode vars.
-- User command format: gs c toggle [field]
function handle_toggle(cmdParams)
if #cmdParams == 0 then
add_to_chat(123,'Mote-Libs: Toggle parameter failure: field not specified.')
return
end
local state_var = get_state(cmdParams[1])
if state_var then
local oldVal = state_var.value
state_var:toggle()
local newVal = state_var.value
local descrip = state_var.description or cmdParams[1]
if job_state_change then
job_state_change(descrip, newVal, oldVal)
end
add_to_chat(122,descrip..' is now '..state_var.current..'.')
handle_update({'auto'})
else
add_to_chat(123,'Mote-Libs: Toggle: Unknown field ['..cmdParams[1]..']')
end
end
-- Function to force a boolean field to false.
-- User command format: gs c unset [field]
function handle_unset(cmdParams)
if #cmdParams == 0 then
add_to_chat(123,'Mote-Libs: Unset parameter failure: field not specified.')
return
end
local state_var = get_state(cmdParams[1])
if state_var then
local oldVal = state_var.value
state_var:unset()
local newVal = state_var.value
local descrip = state_var.description or cmdParams[1]
if job_state_change then
job_state_change(descrip, newVal, oldVal)
end
add_to_chat(122,descrip..' is now '..state_var.current..'.')
handle_update({'auto'})
else
add_to_chat(123,'Mote-Libs: Toggle: Unknown field ['..cmdParams[1]..']')
end
end
-------------------------------------------------------------------------------------------------------------------
-- User command format: gs c update [option]
-- Where [option] can be 'user' to display current state.
-- Otherwise, generally refreshes current gear used.
function handle_update(cmdParams)
-- init a new eventArgs
local eventArgs = {handled = false}
reset_buff_states()
-- Allow jobs to override this code
if job_update then
job_update(cmdParams, eventArgs)
end
if not eventArgs.handled then
if handle_equipping_gear then
handle_equipping_gear(player.status)
end
end
if cmdParams[1] == 'user' then
display_current_state()
end
end
-- showtp: equip the current TP set for examination.
function handle_showtp(cmdParams)
local msg = 'Showing current TP set: ['.. state.OffenseMode.value
if state.HybridMode.value ~= 'Normal' then
msg = msg .. '/' .. state.HybridMode.value
end
msg = msg .. ']'
if #classes.CustomMeleeGroups > 0 then
msg = msg .. ' ['
for i = 1,#classes.CustomMeleeGroups do
msg = msg .. classes.CustomMeleeGroups[i]
if i < #classes.CustomMeleeGroups then
msg = msg .. ', '
end
end
msg = msg .. ']'
end
add_to_chat(122, msg)
equip(get_melee_set())
end
-- Minor variation on the GearSwap "gs equip naked" command, that ensures that
-- all slots are enabled before removing gear.
-- Command: "gs c naked"
function handle_naked(cmdParams)
enable('main','sub','range','ammo','head','neck','lear','rear','body','hands','lring','rring','back','waist','legs','feet')
equip(sets.naked)
end
-------------------------------------------------------------------------------------------------------------------
-- Get the state var that matches the requested name.
-- Only returns mode vars.
function get_state(name)
if state[name] then
return state[name]._class == 'mode' and state[name] or nil
else
local l_name = name:lower()
for key,var in pairs(state) do
if key:lower() == l_name then
return var._class == 'mode' and var or nil
end
end
end
end
-- Function to reset state.Buff values (called from update).
function reset_buff_states()
if state.Buff then
for buff,present in pairs(state.Buff) do
if mote_vars.res_buffs:contains(buff) then
state.Buff[buff] = buffactive[buff] or false
end
end
end
end
-- Function to display the current relevant user state when doing an update.
-- Uses display_current_job_state instead if that is defined in the job lua.
function display_current_state()
local eventArgs = {handled = false}
if display_current_job_state then
display_current_job_state(eventArgs)
end
if not eventArgs.handled then
local msg = 'Melee'
if state.CombatForm.has_value then
msg = msg .. ' (' .. state.CombatForm.value .. ')'
end
msg = msg .. ': '
msg = msg .. state.OffenseMode.value
if state.HybridMode.value ~= 'Normal' then
msg = msg .. '/' .. state.HybridMode.value
end
msg = msg .. ', WS: ' .. state.WeaponskillMode.value
if state.DefenseMode.value ~= 'None' then
msg = msg .. ', Defense: ' .. state.DefenseMode.value .. ' (' .. state[state.DefenseMode.value .. 'DefenseMode'].value .. ')'
end
if state.Kiting.value == true then
msg = msg .. ', Kiting'
end
if state.PCTargetMode.value ~= 'default' then
msg = msg .. ', Target PC: '..state.PCTargetMode.value
end
if state.SelectNPCTargets.value == true then
msg = msg .. ', Target NPCs'
end
add_to_chat(122, msg)
end
if state.EquipStop.value ~= 'off' then
add_to_chat(122,'Gear equips are blocked after ['..state.EquipStop.value..']. Use "//gs c reset equipstop" to turn it off.')
end
end
-- Generic version of this for casters
function display_current_caster_state()
local msg = ''
if state.OffenseMode.value ~= 'None' then
msg = msg .. 'Melee'
if state.CombatForm.has_value then
msg = msg .. ' (' .. state.CombatForm.value .. ')'
end
msg = msg .. ', '
end
msg = msg .. 'Casting ['..state.CastingMode.value..'], Idle ['..state.IdleMode.value..']'
if state.DefenseMode.value ~= 'None' then
msg = msg .. ', ' .. 'Defense: ' .. state.DefenseMode.value .. ' (' .. state[state.DefenseMode.value .. 'DefenseMode'].value .. ')'
end
if state.Kiting.value == true then
msg = msg .. ', Kiting'
end
if state.PCTargetMode.value ~= 'default' then
msg = msg .. ', Target PC: '..state.PCTargetMode.value
end
if state.SelectNPCTargets.value == true then
msg = msg .. ', Target NPCs'
end
add_to_chat(122, msg)
end
-------------------------------------------------------------------------------------------------------------------
-- Function to show what commands are available, and their syntax.
-- Syntax: gs c help
-- Or: gs c
function handle_help(cmdParams)
if cmdParams[1] and cmdParams[1]:lower():startswith('field') then
print('Predefined Library Fields:')
print('--------------------------')
print('OffenseMode, HybridMode, RangedMode, WeaponskillMode')
print('CastingMode, IdleMode, RestingMode, Kiting')
print('DefenseMode, PhysicalDefenseMode, MagicalDefenseMode')
print('SelectNPCTargets, PCTargetMode')
print('EquipStop (precast, midcast, pet_midcast)')
else
print('Custom Library Self-commands:')
print('-----------------------------')
print('Show TP Set: gs c showtp')
print('Toggle bool: gs c toggle [field]')
print('Cycle list: gs c cycle [field] [(r)everse]')
print('Cycle list back: gs c cycleback [field]')
print('Reset a state: gs c reset [field]')
print('Reset all states: gs c reset all')
print('Set state var: gs c set [field] [value]')
print('Set bool true: gs c set [field]')
print('Set bool false: gs c unset [field]')
print('Remove gear: gs c naked')
print('Show TP Set: gs c showtp')
print('State vars: gs c help field')
end
end
-- A function for testing lua code. Called via "gs c test".
function handle_test(cmdParams)
if user_test then
user_test(cmdParams)
elseif job_test then
job_test(cmdParams)
end
end
-------------------------------------------------------------------------------------------------------------------
-- The below table maps text commands to the above handler functions.
-------------------------------------------------------------------------------------------------------------------
selfCommandMaps = {
['toggle'] = handle_toggle,
['cycle'] = handle_cycle,
['cycleback']= handle_cycleback,
['set'] = handle_set,
['reset'] = handle_reset,
['unset'] = handle_unset,
['update'] = handle_update,
['showtp'] = handle_showtp,
['naked'] = handle_naked,
['help'] = handle_help,
['test'] = handle_test}