-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsmart.lua
340 lines (290 loc) · 8.99 KB
/
smart.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
--luacheck: globals gFunc gData gSettings gProfile chat T
---@type skills?
local skills = gFunc.LoadFile('smart.lac/data/skills.lua')
---@type playerData?
local validData = gFunc.LoadFile('smart.lac/data/index.lua')
---@type helpers?
local helpers = gFunc.LoadFile('smart.lac/helpers.lua')
if helpers == nil then
print("Smart.LAC [FATAL]: failed to load helpers.")
return nil
end
helpers.CreateRequiredFiles()
AugmentTypes = gFunc.LoadFile('smart.lac/AugmentTypes.lua')
---@type playerData?
local data = gFunc.LoadFile('index.lua')
---@type globals?
local globals = gFunc.LoadFile('globals.lua')
---@type accessories?
local accessories = gFunc.LoadFile('smart.lac/accessories.lua')
---@type jobHandlers?
local jobHandlers = gFunc.LoadFile('smart.lac/handlers/JOB/index.lua')
---@diagnostic disable-next-line: lowercase-global
if(skills==nil or data==nil or validData==nil or globals == nil or jobHandlers == nil or accessories == nil) then
print ("Failed to load a file.")
print("--------------------\nGlobals")
print (globals)
print("--------------------\nSkills")
print (skills)
print("--------------------\nindex.lua")
print (data)
print("--------------------\nindex.lua for validation")
print (validData)
print("--------------------\nhelper functions")
print (helpers)
print("--------------------\naccessories table for validation")
print (accessories)
print("--------------------\nSpecialized Job handlers")
print (jobHandlers)
return nil
end
---@type modes?
---@diagnostic disable-next-line: lowercase-global
modes = gFunc.LoadFile('smart.lac/modes.lua')
assert(modes ~= nil, "[Fatal] Modes is unexpectedly nil.")
if not modes then return nil end
local load = function()
local success = true
helpers.PerformUpdateCheck()
AugmentTypes = nil
local sub = gData.GetPlayer().SubJob
gSettings.AllowAddSet = true
print(chat.colors.SpringGreen..'Welcome to Smart.LAC!'..chat.colors.Reset)
data.ownedBelts = helpers.EnsureSugaredTable(data.ownedBelts)
data.ownedGorgets = helpers.EnsureSugaredTable(data.ownedGorgets)
if globals and globals.debug then
print(data.ownedBelts.contains ~= nil
and chat.success(" Tables have been sugared")
or chat.error(" Table sugaring failed."))
end
if not helpers.ValidatePlayerData(data) then
print(helpers.AddModHeader(chat.warning('Failed to validate index.lua')))
success = false
end
local sets = modes.getSets()
local validator = gFunc.LoadFile('smart.lac/handlers/validations.lua')
assert(validator ~= nil, "Validator unexpectedly nil.")
validator(sets)
if not helpers.ValidateSets(sets) then
print(helpers.AddModHeader(chat.warning('Failed to validate sets')))
success = false
end
if sets.general and sets.general.Idle then
gFunc.EquipSet(sets.general.Idle)
else
print(helpers.AddModHeader(helpers.SucceedOrWarn(false, "",
"Failed to equip default idle set, please check your gear.")))
success = false
end
gProfile.Sets = sets
modes.initializeWindow()
modes.registerKeybinds()
print(helpers.AddModHeader(helpers.SucceedOrWarn(success, 'All validations passed', 'Some validations failed, check chat output for info.')))
end
local unload = function()
modes.setWindowVisibility(false)
end
-- This is the only callback that natively accepts an argument
local command = function(args)
local switch = {
equip = function(args)
local switch = {
function(_) print("equip requires at least 2 arguments") end,
function(_) print("equip requires at least 2 arguments") end,
function(a)
local sets = modes.getSets()
gFunc.LockSet(sets[a[2]][a[3]], 15)
end,
function(a)
local sets = modes.getSets()
gFunc.LockSet(sets[a[2]][a[3]][a[4]], 15)
end,
function(a)
local sets = modes.getSets()
gFunc.LockSet(sets[a[2]][a[3]][a[4]][a[5]], 15)
end,
function(a)
local sets = modes.getSets()
gFunc.LockSet(sets[a[2]][a[3]][a[4]][a[5]][a[6]], 15)
end
}
switch[#args](args)
end,
setMode = function(args)
if #args ~= 2 then
print(helpers.AddModHeader("setMode requires exactly 1 argument."))
else
modes.setActiveMode(args[2])
end
end,
setWeaponGroup = function(args)
if #args ~= 2 then
print(helpers.AddModHeader(chat.error('setWeaponGroup requires exactly 1 argument')))
else
modes.setActiveMode(args[2])
end
end,
setWindowLocation = function(args)
if #args ~= 3 then
print(helpers.AddModHeader("setWindowLocation requires exactly 3 arguments"))
elseif string.lower(args[2]) == 'x' then
modes.setWindowPosX(tonumber(args[3]) or ModeTable.imgui.windowPosX)
elseif string.lower(args[2]) == 'y' then
modes.setWindowPosY(tonumber(args[3]) or ModeTable.imgui.windowPosY)
else
print(helpers.AddModHeader("second argument must be either x or y"))
end
end,
nextMode = function()
modes.nextMode()
end,
nextWeaponGroup = function()
modes.nextWeaponGroup()
end,
nextSecondaryGroup = function()
modes.nextSecondaryGroup()
end,
nextOverride = function(args)
if #args ~= 2 then
print(helpers.AddModHeader(chat.error('nextOverride requires a layer index')))
else
modes.nextOverrideState(args[2])
end
end,
subjobPalette = function()
local subjob = gData.GetPlayer().SubJob
AshitaCore:GetChatManager():QueueCommand(-1, "/tc palette change \""..subjob.." JAs\"")
end
}
switch[args[1]](args)
end
local default = function()
-- return nil
local player = gData.GetPlayer()
local sets = modes.getSets()
if(sets['general']) then
---@type EntityStatus
local status = player.Status
if(not status) then return end
local set = {}
if(sets.general[status] ~= nil) then
set = gFunc.Combine(set, sets.general[status])
end
if ModeTable.weaponsEnabled then
set = gFunc.Combine(set, modes.getWeaponGroup())
end
if ModeTable.secondaryEnabled then
set = gFunc.Combine(set, modes.getSecondaryGroup())
end
if jobHandlers[player.MainJob] ~= nil and jobHandlers[player.MainJob].default ~= nil then
local mainJobOverride = jobHandlers[player.MainJob].default(sets, status)
if mainJobOverride then
set = gFunc.Combine(set, mainJobOverride)
end
end
if jobHandlers[player.SubJob] ~= nil and jobHandlers[player.SubJob].default ~= nil then
local subJobOverride = jobHandlers[player.SubJob].default(sets, status)
if subJobOverride then
set = gFunc.Combine(set, subJobOverride)
end
end
set = modes.applyOverrides(set, "general", status)
if (sets.general.buffs) then
for k, v in pairs(sets.general.buffs) do
if gData.GetBuffCount(k) > 0 then
set = gFunc.Combine(set, v)
set = modes.applyOverrides(set, 'general', 'buffs', k)
end
end
end
gFunc.EquipSet(set)
end
end
local ability = function()
local sets = modes.getSets()
return helpers.GenericAbilityHandler(sets, "ability")
end
local item = function()
local sets = modes.getSets()
return helpers.GenericAbilityHandler(sets, "item")
end
local precast = function()
local sets = modes.getSets()
return helpers.GenericAbilityHandler(sets, "precast")
end
local midcast = function()
local sets = modes.getSets()
return helpers.GenericAbilityHandler(sets, "midcast")
end
local preshot = function()
local sets = modes.getSets()
return helpers.GenericAbilityHandler(sets, "preshot")
end
local midshot = function()
local sets = modes.getSets()
return helpers.GenericAbilityHandler(sets, 'midshot')
end
local weaponskill = function()
local sets = modes.getSets()
helpers.GenericAbilityHandler(sets, 'weaponskill')
if(sets.settings ~= nil and sets.settings.allowElementalAccessories == true) then
---@type Action?
local action = gData.GetAction()
if action == nil then return nil end
accessories.DoBeltAndGorget(helpers.GetWeaponskillProperty(action), data)
end
end
return (function()
---@return smartProfile
local retFunc = function()
---@class smartProfile
local returnTable = T{
Packer = modes.generatePackerConfig(),
OnLoad = load,
OnUnload = unload,
HandleCommand = command,
HandleDefault = default,
HandleAbility = ability,
HandleItem = item,
HandlePrecast = precast,
HandleMidcast = midcast,
HandlePreshot = preshot,
HandleMidshot = midshot,
HandleWeaponskill = weaponskill
}
function returnTable:withPacker(packerData)
self.Packer = packerData
return self
end
function returnTable:appendPacker(t)
self.Packer[#self.Packer] = t
return self
end
function returnTable:aAppendPacker(array)
for _, v in ipairs(array) do
self.Packer[#self.Packer + 1] = v
end
return self
end
return returnTable
end
local shared = gFunc.LoadFile('shared.lua')
if shared ~= nil then
if shared.overrides ~= nil then
modes.enableOverrideLayers()
for k, v in pairs(shared.overrides) do
modes.registerOverride(k, v)
end
end
end
return (function()
---@param sets sets
return function(sets)
if sets ~= nil then
modes.registerSets('default', (shared ~= nil and shared.defaults ~= nil) and sets:merge(shared.defaults) or sets)
modes.setActiveMode('default')
end
return retFunc()
end
end)()
end)()