-
Notifications
You must be signed in to change notification settings - Fork 0
/
Classes.lua
653 lines (454 loc) · 15.2 KB
/
Classes.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
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
-- Classes.lua
-- July 2014
local addon, ns = ...
local Hekili = _G[ addon ]
local class = ns.class
local state = ns.state
local getResourceID = ns.getResourceID
local getSpecializationKey = ns.getSpecializationKey
ns.initializeClassModule = function()
-- do nothing, overwrite this stub with a class module.
end
ns.addExclusion = function( spellID )
class.exclusions[ spellID ] = true
end
ns.addHook = function( hook, func )
class.hooks[ hook ] = func
end
ns.callHook = function( hook, ... )
if class.hooks[ hook ] then
class.hooks[ hook ] ( ... )
end
end
-- Metatable to return modified information about an ability, if available.
local mt_modifiers = {
__index = function(t, k)
if not t.mods[ k ] then
return t.elem[ k ]
else
return t.mods[ k ] ( t.elem[ k ] )
end
end
}
ns.setClass = function( name ) class.file = name end
local function storeAbilityElements( key, values )
local ability = class.abilities[ key ]
if not ability then
ns.Error( "storeAbilityElements( " .. key .. " ) - no such ability in abilities table." )
return
end
for k, v in pairs( values ) do
ability.elem[ k ] = type( v ) == 'function' and setfenv( v, state ) or v
end
end
ns.storeAbilityElements = storeAbilityElements
local function modifyElement( t, k, elem, value )
local entry = class[ t ][ k ]
if not entry then
ns.Error( "modifyElement() - no such key '" .. k .. "' in '" .. t .. "' table." )
return
end
if type( value ) == 'function' then
entry.mods[ elem ] = setfenv( value, ns.state )
else
entry.elem[ elem ] = value
end
end
ns.modifyElement = modifyElement
-- Wrapper for the ability table.
local function modifyAbility( k, elem, value )
modifyElement( 'abilities', k, elem, value )
end
ns.modifyAbility = modifyAbility
local function addAbility( key, values, ... )
if not values.id then
ns.Error( "addAbility( " .. key .. " ) - values table is missing 'id' element." )
return
end
local name = GetSpellInfo( values.id )
if not name and values.id > 0 then
ns.Error( "addAbility( " .. key .. " ) - unable to get name of spell #" .. values.id .. "." )
return
end
class.abilities[ key ] = setmetatable( {
name = name,
elem = {}, -- storage for each attribute
mods = {} -- storage for attribute modifiers
}, mt_modifiers )
class.abilities[ values.id ] = class.abilities[ key ]
for i = 1, select( "#", ... ) do
class.abilities[ select( i, ... ) ] = class.abilities[ key ]
end
ns.commitKey( key )
storeAbilityElements( key, values )
class.searchAbilities[ key ] = '|T' .. ( GetSpellTexture( values.id ) or 'Interface\\ICONS\\Spell_Nature_BloodLust' ) .. ':O|t ' .. class.abilities[ key ].name
end
ns.addAbility = addAbility
local storeAuraElements = function( key, ... )
local aura = class.auras[ key ]
if not aura then
ns.Error( "storeAuraElements() - no aura '" .. key .. "' in auras table." )
return
end
for i = 1, select( "#", ... ), 2 do
local k, v = select( i, ... ), select( i+1, ... )
if k and v then
if k == 'id' then aura[k] = v
else aura.elem[k] = v end
end
end
end
ns.storeAuraElements = storeAuraElements
local function modifyAura( key, elem, func )
modifyElement( 'auras', key, elem, func )
end
ns.modifyAura = modifyAura
local function addAura( key, id, ... )
local name = GetSpellInfo( id )
class.auras[ key ] = setmetatable( {
id = id,
key = key,
name = name,
elem = {},
mods = {}
}, mt_modifiers )
ns.commitKey( key )
-- Allow reference by ID as well.
class.auras[ id ] = class.auras[ key ]
-- Add the elements, front-loading defaults and just overriding them if something else is specified.
storeAuraElements( key, 'duration', 30, 'max_stack', 1, ... )
end
ns.addAura = addAura
local function addGlyph( key, id )
local name = GetSpellInfo( id )
if not name then
ns.Error( "addGlyph() - unable to get glyph name from id#" .. id .. "." )
return
end
class.glyphs[ key ] = {
id = id,
name = name
}
ns.commitKey( key )
end
ns.addGlyph = addGlyph
local function addPerk( key, id )
local name = GetSpellInfo( id )
if not name then
ns.Error( "addPerk( " .. key .. " ) - unable to get perk name from id#" .. id .. "." )
return
end
class.perks[ key ] = {
id = id,
key = key,
name = name
}
ns.commitKey( key )
end
ns.addPerk = addPerk
local function addTalent( key, id, ... )
local name = GetSpellInfo( id )
if not name then
ns.Error( "addTalent() - unable to get talent name from id #" .. id .. "." )
return
end
class.talents[ key ] = {
id = id,
name = name
}
ns.commitKey( key )
end
ns.addTalent = addTalent
local function addResource( resource, primary )
class.resources[ resource ] = true
if primary or #class.resources == 1 then class.primaryResource = resource end
ns.commitKey( resource )
end
ns.addResource = addResource
local function removeResource( resource )
class.resources[ resource ] = nil
if class.primaryResource == resource then class.primaryResource = nil end
end
ns.removeResource = removeResource
local function addGearSet( name, ... )
class.gearsets[ name ] = class.gearsets[ name ] or {}
for i = 1, select( '#', ... ) do
class.gearsets[ name ][ select( i, ... ) ] = 1
end
ns.commitKey( name )
end
ns.addGearSet = addGearSet
local function setGCD( key )
class.gcd = key
end
ns.setGCD = setGCD
local function addHandler( key, func )
local ability = class.abilities[ key ]
if not ability then
ns.Error( "addHandler() attempting to store handler for non-existant ability '" .. key .. "'." )
return
end
ability.elem[ 'handler' ] = setfenv( func, state )
end
ns.addHandler = addHandler
local function runHandler( key )
local ability = class.abilities[ key ]
if not ability then
-- ns.Error( "runHandler() attempting to run handler for non-existant ability '" .. key .. "'." )
return
end
if ability.elem[ 'handler' ] then
ability.elem[ 'handler' ] ()
end
if not ability.passive and state.time == 0 then
state.false_start = state.now + state.offset
end
state.cast_start = 0
ns.callHook( 'runHandler', key )
end
ns.runHandler = runHandler
local function addStance( key, ... )
class.stances[ key ] = class.stances[ key ] or {}
for i = 1, select( '#', ... ), 2 do
class.stances[ key ][ select( i, ... ) ] = select( i + 1, ... )
end
ns.commitKey( key )
end
ns.addStance = addStance
ns.specializationChanged = function()
for k, _ in pairs( state.spec ) do
state.spec[ k ] = nil
end
if GetSpecialization() then
state.spec.id, state.spec.name = GetSpecializationInfo( GetSpecialization() )
state.spec.key = getSpecializationKey( state.spec.id )
state.spec[ state.spec.key ] = true
end
state.GUID = UnitGUID( 'player' )
ns.updateGlyphs()
ns.updateTalents()
ns.updateGear()
ns.callHook( 'specializationChanged' )
ns.cacheCriteria()
for i, v in ipairs( ns.queue ) do
for j = 1, #v do
ns.queue[i][j] = nil
end
ns.queue[i] = nil
end
end
------------------------------
-- SHARED SPELLS/BUFFS/ETC. --
------------------------------
-- Bloodlust.
addAura( 'ancient_hysteria', 90355, 'duration', 40 )
addAura( 'bloodlust', 2825 , 'duration', 40 )
addAura( 'heroism', 32182, 'duration', 40 )
addAura( 'time_warp', 80353, 'duration', 40 )
-- Sated.
addAura( 'exhaustion', 57723, 'duration', 600 )
addAura( 'insanity', 95809, 'duration', 600 )
addAura( 'sated', 57724, 'duration', 600 )
addAura( 'temporal_displacement', 80354, 'duration', 600 )
-- Enchants.
addAura( 'dancing_steel', 104434, 'duration', 12, 'max_stack', 2 )
-- Potions.
addAura( 'jade_serpent_potion', 105702, 'duration', 25 )
addAura( 'mogu_power_potion', 105706, 'duration', 25 )
addAura( 'virmens_bite_potion', 105697, 'duration', 25 )
-- Trinkets.
addAura( 'dextrous', 146308, 'duration', 20 )
addAura( 'vicious', 148903, 'duration', 10 )
-- Raid Buffs
addAura( 'str_agi_int', -1, 'duration', 3600 )
addAura( 'stamina', -2, 'duration', 3600 )
addAura( 'attack_power_multiplier', -3, 'duration', 3600 )
addAura( 'haste', -4, 'duration', 3600 )
addAura( 'spell_power_multiplier', -5, 'duration', 3600 )
addAura( 'critical_strike', -6, 'duration', 3600 )
addAura( 'mastery', -7, 'duration', 3600 )
addAura( 'multistrike', -8, 'duration', 3600 )
addAura( 'versatility', -9, 'duration', 3600 )
-- Racials.
-- AddSpell( 26297, "berserking", 10 )
addAbility( 'berserking',
{
id = 26297,
spend = 0,
cast = 0,
gcdType = 'off',
cooldown = 180
} )
addHandler( 'berserking', function ()
applyBuff( 'berserking' )
end )
addAura( 'berserking', 26297, 'duration', 10 )
-- AddSpell( 20572, "blood_fury", 15 )
addAbility( 'blood_fury',
{
id = 20572,
spend = 0,
cast = 0,
gcdType = 'off',
cooldown = 120
}, 33697, 33702 )
modifyAbility( 'blood_fury', 'id', function( x )
if class.file == 'MONK' or class.file == 'SHAMAN' then return 33697 end
return x
end )
addHandler( 'blood_fury', function ()
applyBuff( 'blood_fury', 15 )
end )
addAura( 'blood_fury', 20572, 'duration', 15 )
addAbility( 'arcane_torrent', {
id = 28730,
spend = 0,
cast = 0,
gcdType = 'spell',
cooldown = 120
}, 50613, 80483, 129597, 155145, 25046, 69179 )
modifyAbility( 'arcane_torrent', 'id', function( x )
if class.file == 'PALADIN' then return 155145
elseif class.file == 'MONK' then return 129597 end
return x
end )
addHandler( 'arcane_torrent', function ()
interrupt()
if class.death_knight then gain( 20, "runic_power" )
elseif class.hunter then gain( 15, "focus" )
elseif class.monk then gain( 1, "chi" )
elseif class.paladin then gain( 1, "holy_power" )
elseif class.rogue then gain( 15, "energy" )
elseif class.warrior then gain( 15, "rage" ) end
end )
-- Special Instructions
addAbility( 'wait', {
id = -1,
name = 'Wait',
spend = 0,
cast = 0,
gcdType = 'off',
cooldown = 0
} )
-- DEFAULTS
ns.storeDefault = function( name, category, version, import )
if not ( name and category and version and import ) then
return
end
class.defaults[ #class.defaults + 1 ] = {
name = name,
type = category,
version = version,
import = import:gsub("([^|])|([^|])", "%1||%2")
}
end
ns.restoreDefaults = function( category )
local profile = Hekili.DB.profile
-- By default, restore action lists.
if not category or category == 'actionLists' then
for i, default in ipairs( class.defaults ) do
if default.type == 'actionLists' then
local reload = true
local index
for j, list in ipairs( profile.actionLists ) do
if list.Name == default.name then
reload = list.Default and ( list.Release < default.version )
index = j
break
end
end
if reload then
local import = ns.deserializeActionList( default.import )
if import and type( import ) == 'table' then
import.Name = default.name
import.Release = default.version
import.Default = true
if not index then index = #profile.actionLists + 1 end
ns.Error( "rD() - putting " .. default.name .. " at index " .. index .. "." )
profile.actionLists[ index ] = import
else
ns.Error( "restoreDefaults() - unable to import actionList " .. default.name .. "." )
end
end
end
end
end
if not category or category == 'displays' then
for i, default in ipairs( class.defaults ) do
if default.type == 'displays' then
local reload = true
local index
for j, display in ipairs( profile.displays ) do
if display.Name == default.name then
index = j
reload = display.Default and ( display.Release < default.version )
break
end
end
if reload then
ns.Error( "restoreDefaults() - didn't find " .. default.name .. "." )
local import = ns.deserializeDisplay( default.import )
if import and type( import ) == 'table' then
import.Name = default.name
import.Release = default.version
import.Default = true
if index then
local existing = profile.displays[index]
import.Enabled = existing.Enabled
import['Use SpellFlash'] = existing['Use SpellFlash']
import['SpellFlash Color'] = existing['SpellFlash Color']
import['PvE Visibility'] = existing['PvE Visibility']
import['PvE Visibility'] = existing['PvE Visibility']
import.x = existing.x
import.y = existing.y
import.rel = existing.rel
import['Icons Shown'] = existing['Icons Shown']
import['Spacing'] = existing['Spacing']
import['Queue Direction'] = existing['Queue Direction']
import['Primary Icon Size'] = existing['Primary Icon Size']
import['Queued Icon Size'] = existing['Queued Icon Size']
import['Font'] = existing['Font']
import['Primary Font Size'] = existing['Primary Font Size']
import['Queued Font Size'] = existing['Queued Font Size']
import['Action Captions'] = existing['Action Captions']
import['Primary Caption'] = existing['Primary Caption']
import['Primary Caption Aura'] = existing['Primary Caption Aura']
else
index = #profile.displays + 1
end
profile.displays[ index ] = import
for j, hook in ipairs( profile.displays[ #profile.displays ].Queues ) do
if type( hook['Action List'] ) == 'string' then
for k, list in ipairs( profile.actionLists ) do
if list.Name == hook['Action List'] then
hook['Action List'] = k
break
end
end
if type( hook['Action List'] ) == 'string' then
-- The list wasn't found.
hook['Action List'] = 0
end
end
end
else
ns.Error( "restoreDefaults() - unable to import '" .. default.name .. "' display." )
end
end
end
end
end
ns.refreshOptions()
ns.loadScripts()
end
ns.isDefault = function( name, category )
if not name or not category then
return false
end
for i, default in ipairs( class.defaults ) do
if default.type == category and default.name == name then
return true, i
end
end
return false
end