-
Notifications
You must be signed in to change notification settings - Fork 36
/
spell_mod.go
521 lines (420 loc) · 11.3 KB
/
spell_mod.go
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
package core
import (
"strconv"
"time"
)
/*
SpellMod implementation.
*/
type SpellModConfig struct {
ClassMask int64
Kind SpellModType
School SpellSchool
ProcMask ProcMask
IntValue int64
TimeValue time.Duration
FloatValue float64
}
type SpellMod struct {
ClassMask int64
Kind SpellModType
School SpellSchool
ProcMask ProcMask
floatValue float64
intValue int64
timeValue time.Duration
Apply SpellModApply
Remove SpellModRemove
IsActive bool
AffectedSpells []*Spell
}
type SpellModApply func(mod *SpellMod, spell *Spell)
type SpellModRemove func(mod *SpellMod, spell *Spell)
type SpellModFunctions struct {
Apply SpellModApply
Remove SpellModRemove
}
func buildMod(unit *Unit, config SpellModConfig) *SpellMod {
functions := spellModMap[config.Kind]
if functions == nil {
panic("SpellMod " + strconv.Itoa(int(config.Kind)) + " not implmented")
}
mod := &SpellMod{
ClassMask: config.ClassMask,
Kind: config.Kind,
School: config.School,
ProcMask: config.ProcMask,
floatValue: config.FloatValue,
intValue: config.IntValue,
timeValue: config.TimeValue,
Apply: functions.Apply,
Remove: functions.Remove,
IsActive: false,
}
unit.OnSpellRegistered(func(spell *Spell) {
if shouldApply(spell, mod) {
mod.AffectedSpells = append(mod.AffectedSpells, spell)
if mod.IsActive {
mod.Apply(mod, spell)
}
}
})
return mod
}
func (unit *Unit) AddStaticMod(config SpellModConfig) {
mod := buildMod(unit, config)
mod.Activate()
}
// Never use dynamic mods for Auras that have ExpireNever and activate on reset
// Those mods will be overwritten potentilly during sim reset
func (unit *Unit) AddDynamicMod(config SpellModConfig) *SpellMod {
return buildMod(unit, config)
}
func shouldApply(spell *Spell, mod *SpellMod) bool {
if spell.Flags.Matches(SpellFlagNoSpellMods) {
return false
}
if mod.ClassMask > 0 && mod.ClassMask&spell.ClassSpellMask == 0 {
return false
}
if mod.School > 0 && !mod.School.Matches(spell.SpellSchool) {
return false
}
if mod.ProcMask > 0 && !mod.ProcMask.Matches(spell.ProcMask) {
return false
}
return true
}
func (mod *SpellMod) UpdateIntValue(value int64) {
if mod.IsActive {
mod.Deactivate()
mod.intValue = value
mod.Activate()
} else {
mod.intValue = value
}
}
func (mod *SpellMod) UpdateTimeValue(value time.Duration) {
if mod.IsActive {
mod.Deactivate()
mod.timeValue = value
mod.Activate()
} else {
mod.timeValue = value
}
}
func (mod *SpellMod) UpdateFloatValue(value float64) {
if mod.IsActive {
mod.Deactivate()
mod.floatValue = value
mod.Activate()
} else {
mod.floatValue = value
}
}
func (mod *SpellMod) GetIntValue() int64 {
return mod.intValue
}
func (mod *SpellMod) GetFloatValue() float64 {
return mod.floatValue
}
func (mod *SpellMod) GetTimeValue() time.Duration {
return mod.timeValue
}
func (mod *SpellMod) Activate() {
if mod.IsActive {
return
}
for _, spell := range mod.AffectedSpells {
mod.Apply(mod, spell)
}
mod.IsActive = true
}
func (mod *SpellMod) Deactivate() {
if !mod.IsActive {
return
}
for _, spell := range mod.AffectedSpells {
mod.Remove(mod, spell)
}
mod.IsActive = false
}
// Mod implmentations
type SpellModType uint32
const (
// Will multiply the spell.DamageDoneMultiplier. +5% = 0.05
// Uses FloatValue
SpellMod_DamageDone_Pct SpellModType = 1 << iota
// Will add the value spell.DamageDoneAddMultiplier
// Uses FloatValue
SpellMod_DamageDone_Flat
// Will reduce spell.DefaultCast.Cost by % amount. -5% = -0.05
// Uses FloatValue
SpellMod_PowerCost_Pct
// Increases or decreases spell.DefaultCast.Cost by flat amount
// Uses FloatValue
SpellMod_PowerCost_Flat
// Increases or decreases RuneCost.RunicPowerCost by flat amount
// Uses FloatValue
SpellMod_RunicPowerCost_Flat
// Will add time.Duration to spell.CD.Duration
// Uses TimeValue
SpellMod_Cooldown_Flat
// Increases or decreases spell.CD.Multiplier by flat amount
// Uses FloatValue
SpellMod_Cooldown_Multiplier
// Will increase the CritMultiplier. +100% = 1.0
// Uses FloatValue
SpellMod_CritMultiplier_Pct
// Will add / substract % amount from the cast time multiplier.
// Ueses: FloatValue
SpellMod_CastTime_Pct
// Will add / substract time from the cast time.
// Ueses: TimeValue
SpellMod_CastTime_Flat
// Add/subtract bonus crit rating
// Uses: FloatValue
SpellMod_BonusCrit_Rating
// Add/subtract bonus hit rating
// Uses: FloatValue
SpellMod_BonusHit_Rating
// Add/subtract to the dots max ticks
// Uses: IntValue
SpellMod_DotNumberOfTicks_Flat
// Add/subtract to the casts gcd
// Uses: TimeValue
SpellMod_GlobalCooldown_Flat
// Add/substrct to the base tick frequency
// Uses: TimeValue
SpellMod_DotTickLength_Flat
// Add/subtract bonus coefficient
// Uses: FloatValue
SpellMod_BonusCoeffecient_Flat
// Enables casting while moving
SpellMod_AllowCastWhileMoving
// Add/subtract bonus spell power
// Uses: FloatValue
SpellMod_BonusSpellPower_Flat
)
var spellModMap = map[SpellModType]*SpellModFunctions{
SpellMod_DamageDone_Pct: {
Apply: applyDamageDonePercent,
Remove: removeDamageDonePercent,
},
SpellMod_DamageDone_Flat: {
Apply: applyDamageDoneAdd,
Remove: removeDamageDonAdd,
},
SpellMod_PowerCost_Pct: {
Apply: applyPowerCostPercent,
Remove: removePowerCostPercent,
},
SpellMod_PowerCost_Flat: {
Apply: applyPowerCostFlat,
Remove: removePowerCostFlat,
},
SpellMod_RunicPowerCost_Flat: {
Apply: applyRunicPowerCostFlat,
Remove: removeRunicPowerCostFlat,
},
SpellMod_Cooldown_Flat: {
Apply: applyCooldownFlat,
Remove: removeCooldownFlat,
},
SpellMod_Cooldown_Multiplier: {
Apply: applyCooldownMultiplier,
Remove: removeCooldownMultiplier,
},
SpellMod_CritMultiplier_Pct: {
Apply: applyCritMultiplier,
Remove: removeCritMultiplier,
},
SpellMod_CastTime_Pct: {
Apply: applyCastTimePercent,
Remove: removeCastTimePercent,
},
SpellMod_CastTime_Flat: {
Apply: applyCastTimeFlat,
Remove: removeCastTimeFlat,
},
SpellMod_BonusCrit_Rating: {
Apply: applyBonusCritRating,
Remove: removeBonusCritRating,
},
SpellMod_BonusHit_Rating: {
Apply: applyBonusHitRating,
Remove: removeBonusHitRating,
},
SpellMod_DotNumberOfTicks_Flat: {
Apply: applyDotNumberOfTicks,
Remove: removeDotNumberOfTicks,
},
SpellMod_GlobalCooldown_Flat: {
Apply: applyGlobalCooldownFlat,
Remove: removeGlobalCooldownFlat,
},
SpellMod_DotTickLength_Flat: {
Apply: applyDotTickLengthFlat,
Remove: removeDotTickLengthFlat,
},
SpellMod_BonusCoeffecient_Flat: {
Apply: applyBonusCoefficientFlat,
Remove: removeBonusCoefficientFlat,
},
SpellMod_AllowCastWhileMoving: {
Apply: applyAllowCastWhileMoving,
Remove: removeAllowCastWhileMoving,
},
SpellMod_BonusSpellPower_Flat: {
Apply: applyBonusSpellPowerFlat,
Remove: removeBonusSpellPowerFlat,
},
}
func applyDamageDonePercent(mod *SpellMod, spell *Spell) {
spell.DamageMultiplier *= 1 + mod.floatValue
}
func removeDamageDonePercent(mod *SpellMod, spell *Spell) {
spell.DamageMultiplier /= 1 + mod.floatValue
}
func applyDamageDoneAdd(mod *SpellMod, spell *Spell) {
spell.DamageMultiplierAdditive += mod.floatValue
}
func removeDamageDonAdd(mod *SpellMod, spell *Spell) {
spell.DamageMultiplierAdditive -= mod.floatValue
}
func applyPowerCostPercent(mod *SpellMod, spell *Spell) {
spell.CostMultiplier += mod.floatValue
}
func removePowerCostPercent(mod *SpellMod, spell *Spell) {
spell.CostMultiplier -= mod.floatValue
}
func applyPowerCostFlat(mod *SpellMod, spell *Spell) {
spell.DefaultCast.Cost += mod.floatValue
}
func removePowerCostFlat(mod *SpellMod, spell *Spell) {
spell.DefaultCast.Cost -= mod.floatValue
}
func applyRunicPowerCostFlat(mod *SpellMod, spell *Spell) {
cost := spell.RuneCostImpl()
cost.RunicPowerCost += mod.floatValue
spell.Cost = newRuneCost(spell, cost.GetConfig())
}
func removeRunicPowerCostFlat(mod *SpellMod, spell *Spell) {
cost := spell.RuneCostImpl()
cost.RunicPowerCost -= mod.floatValue
spell.Cost = newRuneCost(spell, cost.GetConfig())
}
func applyCooldownFlat(mod *SpellMod, spell *Spell) {
spell.CD.Duration += mod.timeValue
}
func removeCooldownFlat(mod *SpellMod, spell *Spell) {
spell.CD.Duration -= mod.timeValue
}
func applyCooldownMultiplier(mod *SpellMod, spell *Spell) {
spell.CdMultiplier += mod.floatValue
}
func removeCooldownMultiplier(mod *SpellMod, spell *Spell) {
spell.CdMultiplier -= mod.floatValue
}
func applyCritMultiplier(mod *SpellMod, spell *Spell) {
spell.CritMultiplier = 1 + (spell.CritMultiplier-1)*(mod.floatValue+1)
}
func removeCritMultiplier(mod *SpellMod, spell *Spell) {
spell.CritMultiplier = 1 + (spell.CritMultiplier-1)/(mod.floatValue+1)
}
func applyCastTimePercent(mod *SpellMod, spell *Spell) {
spell.CastTimeMultiplier += mod.floatValue
}
func removeCastTimePercent(mod *SpellMod, spell *Spell) {
spell.CastTimeMultiplier -= mod.floatValue
}
func applyCastTimeFlat(mod *SpellMod, spell *Spell) {
spell.DefaultCast.CastTime += mod.timeValue
}
func removeCastTimeFlat(mod *SpellMod, spell *Spell) {
spell.DefaultCast.CastTime -= mod.timeValue
}
func applyBonusCritRating(mod *SpellMod, spell *Spell) {
spell.BonusCritRating += mod.floatValue
}
func removeBonusCritRating(mod *SpellMod, spell *Spell) {
spell.BonusCritRating -= mod.floatValue
}
func applyBonusHitRating(mod *SpellMod, spell *Spell) {
spell.BonusHitRating += mod.floatValue
}
func removeBonusHitRating(mod *SpellMod, spell *Spell) {
spell.BonusHitRating -= mod.floatValue
}
func applyDotNumberOfTicks(mod *SpellMod, spell *Spell) {
if spell.dots != nil {
for _, dot := range spell.dots {
if dot != nil {
dot.AddTicks(int32(mod.intValue))
}
}
}
if spell.aoeDot != nil {
spell.aoeDot.AddTicks(int32(mod.intValue))
}
}
func removeDotNumberOfTicks(mod *SpellMod, spell *Spell) {
if spell.dots != nil {
for _, dot := range spell.dots {
if dot != nil {
dot.AddTicks(-int32(mod.intValue))
}
}
}
if spell.aoeDot != nil {
spell.aoeDot.AddTicks(-int32(mod.intValue))
}
}
func applyGlobalCooldownFlat(mod *SpellMod, spell *Spell) {
spell.DefaultCast.GCD += mod.timeValue
}
func removeGlobalCooldownFlat(mod *SpellMod, spell *Spell) {
spell.DefaultCast.GCD -= mod.timeValue
}
func applyDotTickLengthFlat(mod *SpellMod, spell *Spell) {
if spell.dots != nil {
for _, dot := range spell.dots {
if dot != nil {
dot.TickLength += mod.timeValue
}
}
}
if spell.aoeDot != nil {
spell.aoeDot.TickLength += mod.timeValue
}
}
func removeDotTickLengthFlat(mod *SpellMod, spell *Spell) {
if spell.dots != nil {
for _, dot := range spell.dots {
if dot != nil {
dot.TickLength -= mod.timeValue
}
}
}
if spell.aoeDot != nil {
spell.aoeDot.TickLength -= mod.timeValue
}
}
func applyBonusCoefficientFlat(mod *SpellMod, spell *Spell) {
spell.BonusCoefficient += mod.floatValue
}
func removeBonusCoefficientFlat(mod *SpellMod, spell *Spell) {
spell.BonusCoefficient -= mod.floatValue
}
func applyAllowCastWhileMoving(mod *SpellMod, spell *Spell) {
spell.Flags |= SpellFlagCanCastWhileMoving
}
func removeAllowCastWhileMoving(mod *SpellMod, spell *Spell) {
spell.Flags ^= SpellFlagCanCastWhileMoving
}
func applyBonusSpellPowerFlat(mod *SpellMod, spell *Spell) {
spell.BonusSpellPower += mod.floatValue
}
func removeBonusSpellPowerFlat(mod *SpellMod, spell *Spell) {
spell.BonusSpellPower -= mod.floatValue
}