forked from NerdEgghead/WotLK_cat_sim
-
Notifications
You must be signed in to change notification settings - Fork 4
/
trinkets.py
1397 lines (1260 loc) · 50.7 KB
/
trinkets.py
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
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
"""Code for modeling non-static trinkets in feral DPS simulation."""
import numpy as np
import wotlk_cat_sim as ccs
import sim_utils
class Trinket():
"""Keeps track of activation times and cooldowns for an equipped trinket,
updates Player and Simulation parameters when the trinket is active, and
determines when procs or trinket activations occur."""
def __init__(
self, stat_name, stat_increment, proc_name, proc_duration, cooldown
):
"""Initialize a generic trinket with key parameters.
Arguments:
stat_name (str or list): Name of the Player attribute that will be
modified by the trinket activation. Must be a valid attribute
of the Player class that can be modified. The one exception is
haste_rating, which is separately handled by the Simulation
object when updating timesteps for the sim. A list of strings
can be provided instead, in which case every stat in the list
will be modified during the trinket activation.
stat_increment (float or np.ndarray): Amount by which the Player
attribute is changed when the trinket is active. If multiple
stat names are specified, then this must be a numpy array of
equal length to the number of stat names.
proc_name (str): Name of the buff that is applied when the trinket
is active. Used for combat logging.
proc_duration (int): Duration of the buff, in seconds.
cooldown (int): Internal cooldown before the trinket can be
activated again, either via player use or procs.
"""
self.stat_name = stat_name
self.stat_increment = stat_increment
self.proc_name = proc_name
self.proc_duration = proc_duration
self.cooldown = cooldown
self.reset()
def reset(self):
"""Set trinket to fresh inactive state with no cooldown remaining."""
self.activation_time = -np.inf
self.active = False
self.can_proc = True
self.num_procs = 0
self.uptime = 0.0
self.last_update = 0.0
def modify_stat(self, time, player, sim, increment):
"""Change a player stat when a trinket is activated or deactivated.
Arguments:
time (float): Simulation time, in seconds, of activation.
player (tbc_cat_sim.Player): Player object whose attributes will be
modified.
sim (tbc_cat_sim.Simulation): Simulation object controlling the
fight execution.
increment (float or np.ndarray): Quantity to add to the player's
existing stat value(s).
"""
# Convert stat name and stat increment to arrays if they are scalars
stat_names = np.atleast_1d(self.stat_name)
increments = np.atleast_1d(increment)
for index, stat_name in enumerate(stat_names):
self._modify_stat(time, player, sim, stat_name, increments[index])
@staticmethod
def _modify_stat(time, player, sim, stat_name, increment):
"""Contains the actual stat modification functionality for a single
stat. Called by the wrapper function, which handles potentially
iterating through multiple stats to be modified."""
# Haste procs get handled separately from other raw stat buffs
if stat_name == 'haste_rating':
sim.apply_haste_buff(time, increment)
else:
old_value = getattr(player, stat_name)
setattr(player, stat_name, old_value + increment)
# Recalculate damage parameters when player stats change
player.calc_damage_params(**sim.params)
def activate(self, time, player, sim):
"""Activate the trinket buff upon player usage or passive proc.
Arguments:
time (float): Simulation time, in seconds, of activation.
player (tbc_cat_sim.Player): Player object whose attributes will be
modified by the trinket proc.
sim (tbc_cat_sim.Simulation): Simulation object controlling the
fight execution.
Returns:
damage_done (float): Any instant damage that is dealt when the
trinket is activated. Defaults to 0 for standard trinkets, but
custom subclasses can implement fixed damage procs that would
be calculated in this method.
"""
self.activation_time = time
self.deactivation_time = time + self.proc_duration
self.modify_stat(time, player, sim, self.stat_increment)
sim.proc_end_times.append(self.deactivation_time)
# In the case of a second trinket being used, the proc end time can
# sometimes be earlier than that of the first trinket, so the list of
# end times needs to be sorted.
sim.proc_end_times.sort()
# Mark trinket as active
self.active = True
self.can_proc = False
self.num_procs += 1
# Log if requested
if sim.log:
sim.combat_log.append(sim.gen_log(time, self.proc_name, 'applied'))
# Return default damage dealt of 0
return 0.0
def deactivate(self, player, sim, time=None):
"""Deactivate the trinket buff when the duration has expired.
Arguments:
player (tbc_cat_sim.Player): Player object whose attributes will be
restored to their original values.
sim (tbc_cat_sim.Simulation): Simulation object controlling the
fight execution.
time (float): Time at which the trinket is deactivated. Defaults to
the stored time for automatic deactivation.
"""
if time is None:
time = self.deactivation_time
self.modify_stat(time, player, sim, -self.stat_increment)
self.active = False
if sim.log:
sim.combat_log.append(
sim.gen_log(time, self.proc_name, 'falls off')
)
def update(self, time, player, sim, allow_activation=True):
"""Check for a trinket activation or deactivation at the specified
simulation time, and perform associated bookkeeping.
Arguments:
time (float): Simulation time, in seconds.
player (tbc_cat_sim.Player): Player object whose attributes will be
modified by the trinket proc.
sim (tbc_cat_sim.Simulation): Simulation object controlling the
fight execution.
allow_activation (bool): Allow the trinket to be activated
automatically if the appropriate conditions are met. Defaults
True, but can be set False if the user wants to control
trinket activations manually.
Returns:
damage_done (float): Any instant damage that is dealt if the
trinket is activated at the specified time. Defaults to 0 for
standard trinkets, but custom subclasses can implement fixed
damage procs that would be returned on each update.
"""
# Update average proc uptime value
if time > self.last_update:
dt = time - self.last_update
self.uptime = (
(self.uptime * self.last_update + dt * self.active) / time
)
self.last_update = time
# First check if an existing buff has fallen off
if self.active and (time > self.deactivation_time - 1e-9):
self.deactivate(player, sim)
# Then check whether the trinket is off CD and can now proc
if (not self.can_proc
and (time - self.activation_time > self.cooldown - 1e-9)):
self.can_proc = True
# Now decide whether a proc actually happens
if allow_activation and self.apply_proc():
return self.activate(time, player, sim)
# Return default damage dealt of 0
return 0.0
def apply_proc(self):
"""Determine whether or not the trinket is activated at the current
time. This method must be implemented by Trinket subclasses.
Returns:
proc_applied (bool): Whether or not the activation occurs.
"""
return NotImplementedError(
'Logic for trinket activation must be implemented by Trinket '
'subclasses.'
)
class ActivatedTrinket(Trinket):
"""Models an on-use trinket that is activated on cooldown as often as
possible."""
def __init__(
self, stat_name, stat_increment, proc_name, proc_duration, cooldown,
delay=0.0
):
"""Initialize a generic activated trinket with key parameters.
Arguments:
stat_name (str): Name of the Player attribute that will be
modified by the trinket activation. Must be a valid attribute
of the Player class that can be modified. The one exception is
haste_rating, which is separately handled by the Simulation
object when updating timesteps for the sim.
stat_increment (float): Amount by which the Player attribute is
changed when the trinket is active.
proc_name (str): Name of the buff that is applied when the trinket
is active. Used for combat logging.
proc_duration (int): Duration of the buff, in seconds.
cooldown (int): Internal cooldown before the trinket can be
activated again.
delay (float): Optional time delay (in seconds) before the first
trinket activation in the fight. Can be used to enforce a
shared cooldown between two activated trinkets, or to delay the
activation for armor debuffs etc. Defaults to 0.0 .
"""
self.delay = delay
Trinket.__init__(
self, stat_name, stat_increment, proc_name, proc_duration,
cooldown
)
def reset(self):
"""Set trinket to fresh inactive state at the start of a fight."""
if self.delay:
# We put in a hack to set the "activation time" such that the
# trinket is ready after precisely the delay
self.activation_time = self.delay - self.cooldown
else:
# Otherwise, the initial activation time is set infinitely in the
# past so that the trinket is immediately ready for activation.
self.activation_time = -np.inf
self.active = False
self.can_proc = not self.delay
self.num_procs = 0
self.uptime = 0.0
self.last_update = 0.0
def apply_proc(self):
"""Determine whether or not the trinket is activated at the current
time.
Returns:
proc_applied (bool): Whether or not the activation occurs.
"""
# Activated trinkets follow the simple logic of being used as soon as
# they are available.
if self.can_proc:
return True
return False
class HastePotion(ActivatedTrinket):
"""Haste pots can be easily modeled within the same trinket class structure
without the need for custom code."""
def __init__(self, delay=0.0):
"""Initialize object at the start of a fight.
Arguments:
delay (float): Minimum elapsed time in the fight before the potion
can be used. Can be used to delay the potion activation for
armor debuffs going up, etc. Defaults to 0.0
"""
ActivatedTrinket.__init__(
self, 'haste_rating', 500, 'Speed', 15, 60, delay=delay
)
self.max_procs = 1 if delay > 1e-9 else 2 # 1 pot per combat in WotLK
def apply_proc(self):
"""Determine whether or not the trinket is activated at the current
time.
Returns:
proc_applied (bool): Whether or not the activation occurs.
"""
# Adjust standard ActivatedTrinket logic to prevent multiple Haste
# Potion activations once combat has commenced.
if self.can_proc and (self.num_procs < self.max_procs):
return True
return False
class Bloodlust(ActivatedTrinket):
"""Similar to haste pots, the trinket framework works perfectly for Lust as
well, just that the percentage haste buff is handled a bit differently."""
def __init__(self, delay=0.0):
"""Initialize object at the start of a fight.
Arguments:
delay (float): Minimum elapsed time in the fight before Lust is
used. Can be used to delay lusting for armor debuffs going up,
etc. Defaults to 0.0
"""
ActivatedTrinket.__init__(
self, None, 0.0, 'Bloodlust', 40, 600, delay=delay
)
def modify_stat(self, time, player, sim, *args):
"""Change swing timer when Bloodlust is applied or falls off.
Arguments:
time (float): Simulation time, in seconds, of activation.
player (tbc_cat_sim.Player): Player object whose attributes will be
modified.
sim (tbc_cat_sim.Simulation): Simulation object controlling the
fight execution.
"""
old_multi = sim.haste_multiplier
not_bear = not player.bear_form
haste_rating = sim_utils.calc_haste_rating(
sim.swing_timer, multiplier=old_multi, cat_form=not_bear
)
multi_fac = 1./1.3 if self.active else 1.3
new_multi = old_multi * multi_fac
new_swing_timer = sim_utils.calc_swing_timer(
haste_rating, multiplier=new_multi, cat_form=not_bear
)
sim.update_swing_times(time, new_swing_timer)
sim.haste_multiplier = new_multi
player.update_spell_gcd(
haste_rating, multiplier=player.spell_haste_multiplier * multi_fac
)
class UnholyFrenzy(ActivatedTrinket):
"""Models the external damage buff provided by Blood Death Knights."""
def __init__(self, delay=0.0):
"""Initialize controller for Unholy Frenzy buff.
Arguments:
delay (float): Time delay, in seconds, before first buff
application. Defaults to 0.
"""
ActivatedTrinket.__init__(
self, None, 0.0, 'Unholy Frenzy', 30, 180, delay=delay
)
def modify_stat(self, time, player, sim, *args):
"""Change global damage modifier when Unholy Frenzy is applied or falls
off.
Arguments:
time (float): Simulation time, in seconds, of buff activation or
deactivation.
player (wotlk_cat_sim.Player): Player object whose attributes will
be modified.
sim (wotlk_cat_sim.Simulation): Simulation object controlling the
fight execution.
"""
damage_mod = 1./1.2 if self.active else 1.2
player.damage_multiplier *= damage_mod
player.calc_damage_params(**sim.params)
class ShatteringThrow(ActivatedTrinket):
"""Models the external armor penetration cooldown provided by Warriors."""
def __init__(self, delay=0.0):
"""Inititalize controller for Shattering Throw debuff.
Arguments:
delay (float): Time delay, in seconds, before first usage. Defaults
to 0.
"""
ActivatedTrinket.__init__(
self, None, 0.0, 'Shattering Throw', 10, 300, delay=delay
)
def modify_stat(self, time, player, sim, *args):
"""Change residual boss armor when Shattering Throw is applied or falls
off.
Arguments:
time (float): Simulation time, in seconds.
player (wotlk_cat_sim.Player): Player object whose damage values
will be modified.
sim (wotlk_cat_sim.Simulation): Simulation object controlling the
fight execution.
"""
sim.params['shattering_throw'] = not self.active
player.calc_damage_params(**sim.params)
class ProcTrinket(Trinket):
"""Models a passive trinket with a specified proc chance on hit or crit."""
def __init__(
self, stat_name, stat_increment, proc_name, chance_on_hit,
proc_duration, cooldown, chance_on_crit=0.0, yellow_chance_on_hit=None,
mangle_only=False, cat_mangle_only=False, shred_only=False,
swipe_only=False, periodic_only=False, icd_precombat=0.0
):
"""Initialize a generic proc trinket with key parameters.
Arguments:
stat_name (str): Name of the Player attribute that will be
modified by the trinket activation. Must be a valid attribute
of the Player class that can be modified. The one exception is
haste_rating, which is separately handled by the Simulation
object when updating timesteps for the sim.
stat_increment (float): Amount by which the Player attribute is
changed when the trinket is active.
proc_name (str): Name of the buff that is applied when the trinket
is active. Used for combat logging.
chance_on_hit (float): Probability of a proc on a successful normal
hit, between 0 and 1.
chance_on_crit (float): Probability of a proc on a critical strike,
between 0 and 1. Defaults to 0.
yellow_chance_on_hit (float): If supplied, use a separate proc rate
for special abilities. In this case, chance_on_hit will be
interpreted as the proc rate for white attacks. Used for ppm
trinkets where white and yellow proc rates are normalized
differently.
proc_duration (int): Duration of the buff, in seconds.
cooldown (int): Internal cooldown before the trinket can proc
again.
mangle_only (bool): If True, then designate this trinket as being
able to proc exclusively on the Mangle ability. Defaults False.
cat_mangle_only (bool): If True, then designate this trinket as
being able to proc exclusively on the Cat Mangle ability.
Defaults False.
shred_only (bool): If True, then designate this trinket as being
able to proc exclusively on the Shred ability. Defaults False.
swipe_only (bool): If True, then designate this trinket as being
able to proc exclusively on the Swipe ability. Defaults False.
periodic_only (bool): If True, then designate this trinket as being
able to proc exclusively on periodic damage. Defaults False.
icd_precombat (float): Optional time (in seconds) of resetting the
trinket's internal cooldown before the fight. For example,
equipping trinkets before pull. Defaults to 0.0.
"""
self.icd_precombat = icd_precombat
Trinket.__init__(
self, stat_name, stat_increment, proc_name, proc_duration,
cooldown
)
if yellow_chance_on_hit is not None:
self.rates = {
'white': chance_on_hit, 'yellow': yellow_chance_on_hit
}
self.separate_yellow_procs = True
else:
self.chance_on_hit = chance_on_hit
self.chance_on_crit = chance_on_crit
self.separate_yellow_procs = False
self.mangle_only = mangle_only
self.cat_mangle_only = cat_mangle_only
self.shred_only = shred_only
self.swipe_only = swipe_only
self.periodic_only = periodic_only
self.special_proc_conditions = (
mangle_only or cat_mangle_only or shred_only or swipe_only
or periodic_only
)
def check_for_proc(self, crit, yellow):
"""Perform random roll for a trinket proc upon a successful attack.
Arguments:
crit (bool): Whether the attack was a critical strike.
yellow (bool): Whether the attack was a special ability rather
than a melee attack.
"""
if not self.can_proc:
return
proc_roll = np.random.rand()
if self.separate_yellow_procs:
rate = self.rates['yellow'] if yellow else self.rates['white']
else:
rate = self.chance_on_crit if crit else self.chance_on_hit
if proc_roll < rate:
self.proc_happened = True
def apply_proc(self):
"""Determine whether or not the trinket is activated at the current
time. For a proc trinket, it is assumed that a check has already been
made for the proc when the most recent attack occurred.
Returns:
proc_applied (bool): Whether or not the activation occurs.
"""
if self.can_proc and self.proc_happened:
self.proc_happened = False
return True
return False
def reset(self):
"""Set trinket to fresh inactive state with no cooldown remaining."""
Trinket.reset(self)
self.can_proc = self.icd_precombat > self.cooldown - 1e-9 if self.icd_precombat else True
self.activation_time = -self.icd_precombat if self.icd_precombat else -np.inf
self.proc_happened = False
def activate(self, time, player, sim):
"""Perform normal trinket activation, but then additionally schedule a
rotation action in case the agent was pooling Energy in anticipation of
a proc.
Arguments:
time (float): Simulation time, in seconds, of activation.
player (wotlk_cat_sim.Player): Player object whose attributes will
be modified by the trinket proc.
sim (wotlk_cat_sim.Simulation): Simulation object controlling the
fight execution.
Returns:
damage_done (float): Any instant damage that is dealt when the
trinket is activated. Defaults to 0 for standard trinkets, but
custom subclasses can implement fixed damage procs that would
be calculated in this method.
"""
if not self.special_proc_conditions:
sim.next_action = min(sim.next_action, time + sim.latency)
return Trinket.activate(self, time, player, sim)
class IdolOfTheCorruptor(ProcTrinket):
"""Custom class to model the Mangle proc from Idol of the Corruptor, which
has different proc rates in Cat Form vs. Dire Bear Form and which can be
dynamically unequipped and re-equipped in combat as an advanced tactic."""
def __init__(self, stat_mod, ap_mod):
"""Initialize Idol with default state set to "equipped" with Cat Form
proc rate.
Arguments:
stat_mod (float): Multiplicative scaling factor for primary stats
from talents and raid buffs.
ap_mod (float): Multiplicative scaling factor for Attack Power in
Cat Form from talents and raid buffs.
"""
agi_gain = 162. * stat_mod
ProcTrinket.__init__(
self, ['agility', 'attack_power', 'crit_chance'],
np.array([agi_gain, agi_gain * ap_mod, agi_gain / 83.33 / 100.]),
'Primal Wrath', 1.0, 12, 0, mangle_only=True
)
self.equipped = True
def update(self, time, player, sim):
"""Adjust Idol proc chance based on whether it is currently equipped
and the player's current form, then call normal Trinket update loop.
Arguments:
time (float): Simulation time, in seconds.
player (player.Player): Player object whose attributes will be
modified by the Idol proc.
sim (wotlk_cat_sim.Simulation): Simulation object controlling the
fight execution.
Returns:
damage_done (float): Any instant damage that is dealt if the
proc is activated at the specified time. Always 0 for Idol of
the Corruptor.
"""
if self.equipped:
self.chance_on_hit = 1.0 if player.cat_form else 0.5
else:
self.chance_on_hit = 0.0
return ProcTrinket.update(self, time, player, sim)
class DeathbringersWill(ProcTrinket):
"""Custom class to model the random transformations from DBW procs."""
def __init__(self, stat_mod, ap_mod, **kwargs):
"""Initialize trinket with static parameters that won't change.
Arguments:
stat_mod (float): Multiplicative scaling factor for primary stats
from talents and raid buffs.
ap_mod (float): Multiplicative scaling factor for Attack Power in
Cat Form from talents and raid buffs.
kwargs (dict): Standard arguments to pass to ProcTrinket.
"""
self.stat_mod = stat_mod
self.ap_mod = ap_mod
ProcTrinket.__init__(self, **kwargs)
def activate(self, time, player, sim):
"""Roll for which transformation will be applied, then call normal
trinket activation loop."""
roll = np.random.rand()
if roll < 1.0/3.0:
self.proc_name = 'Strength of the Vrykul'
self.stat_name = 'attack_power'
self.stat_increment = 2 * self.stat_mod * self.ap_mod * 700
elif roll < 2.0/3.0:
self.proc_name = 'Agility of the Wolvar'
self.stat_name = ['agility', 'attack_power', 'crit_chance']
self.stat_increment = np.array([
self.stat_mod * 700, self.stat_mod * 700 * self.ap_mod,
self.stat_mod * 700 / 83.33 / 100.
])
else:
self.proc_name = 'Speed of the Gurloc'
self.stat_name = 'haste_rating'
self.stat_increment = 700
return ProcTrinket.activate(self, time, player, sim)
def deactivate(self, player, sim, time=None):
"""Call normal trinket deactivation loop, then reset proc name."""
ProcTrinket.deactivate(self, player, sim, time=time)
self.proc_name = "Deathbringer's Will"
class StackingProcTrinket(ProcTrinket):
"""Models trinkets that provide temporary stacking buffs to the player
after an initial proc or activation."""
def __init__(
self, stat_name, stat_increment, max_stacks, aura_name, stack_name,
chance_on_hit, yellow_chance_on_hit, aura_duration, cooldown,
aura_type='activated', aura_proc_rates=None
):
"""Initialize a generic stacking proc trinket with key parameters.
Arguments:
stat_name (str): Name of the Player attribute that will be
modified when stacks are accumulated. Must be a valid attribute
of the Player class that can be modified. The one exception is
haste_rating, which is separately handled by the Simulation
object when updating timesteps for the sim.
stat_increment (int): Amount by which the Player attribute is
changed from one additional stack of the trinket buff.
max_stacks (int): Maximum number of stacks that can be accumulated.
aura_name (str): Name of the aura that is applied when the trinket
is active, allowing for stack accumulation. Used for combat
logging.
stack_name (str): Name of the actual stacking buff that procs when
the above aura is active.
chance_on_hit (float): Probability of applying a new stack of the
buff when the aura is active upon a successful normal hit,
between 0 and 1.
yellow_chance_on_hit (float): Same as above, but for special
abilities.
aura_duration (float): Duration of the trinket aura as well as any
buff stacks that are accumulated when the aura is active.
cooldown (float): Internal cooldown before the aura can be applied
again once it falls off.
aura_type (str): Either "activated" or "proc", specifying whether
the overall stack accumulation aura is applied via player
activation of the trinket or via another proc mechanic.
aura_proc_rates (dict): Dictionary containing "white" and "yellow"
keys specifying the chance on hit for activating the aura and
enabling subsequent stack accumulation. Required and used only
when aura_type is "proc".
"""
self.stack_increment = stat_increment
self.default_increment = np.zeros_like(stat_name, dtype=int)
self.max_stacks = max_stacks
self.aura_name = aura_name
self.stack_name = stack_name
self.stack_proc_rates = {
'white': chance_on_hit, 'yellow': yellow_chance_on_hit
}
self.activated_aura = (aura_type == 'activated')
self.aura_proc_rates = aura_proc_rates
ProcTrinket.__init__(
self, stat_name=stat_name, stat_increment=self.default_increment,
proc_name=aura_name, proc_duration=aura_duration,
cooldown=cooldown, chance_on_hit=self.stack_proc_rates['white'],
yellow_chance_on_hit=self.stack_proc_rates['yellow']
)
def reset(self):
"""Full reset of the trinket at the start of a fight."""
self.activation_time = -np.inf
self._reset()
self.stat_increment = self.default_increment
self.num_procs = 0
self.uptime = 0.0
self.last_update = 0.0
def _reset(self):
self.active = False
self.can_proc = False
self.proc_happened = False
self.num_stacks = 0
self.proc_name = self.aura_name
if not self.activated_aura:
self.rates = self.aura_proc_rates
def deactivate(self, player, sim, time=None):
"""Deactivate the trinket buff when the duration has expired.
Arguments:
player (tbc_cat_sim.Player): Player object whose attributes will be
restored to their original values.
sim (tbc_cat_sim.Simulation): Simulation object controlling the
fight execution.
time (float): Time at which the trinket is deactivated. Defaults to
the stored time for automatic deactivation.
"""
# Temporarily change the stat increment to the total value gained while
# the trinket was active
self.stat_increment = self.stack_increment * self.num_stacks
# Reset trinket to inactive state
self._reset()
Trinket.deactivate(self, player, sim, time=time)
self.stat_increment = self.default_increment
def apply_proc(self):
"""Determine whether a new trinket activation takes place, or whether
a new stack is applied to an existing activation."""
# If can_proc is True but the stat increment is 0, it means that the
# last event was a trinket deactivation, so we activate the trinket.
if (self.activated_aura and (not self.active) and self.can_proc
and (np.sum(self.stat_increment) == 0)):
return True
# Ignore procs when at max stacks, and prevent future proc checks
if self.num_stacks == self.max_stacks:
self.can_proc = False
return False
return ProcTrinket.apply_proc(self)
def activate(self, time, player, sim):
"""Activate the trinket when off cooldown. If already active and a
trinket proc just occurred, then add a new stack of the buff.
Arguments:
time (float): Simulation time, in seconds, of activation.
player (tbc_cat_sim.Player): Player object whose attributes will be
modified by the trinket proc.
sim (tbc_cat_sim.Simulation): Simulation object controlling the
fight execution.
"""
if not self.active:
# Activate the trinket on a fresh use
Trinket.activate(self, time, player, sim)
self.can_proc = True
self.proc_name = self.stack_name
self.stat_increment = self.stack_increment
self.rates = self.stack_proc_rates
else:
# Apply a new buff stack. We do this "manually" rather than in the
# parent method because a new stack doesn't count as an actual
# activation.
self.modify_stat(time, player, sim, self.stat_increment)
self.num_stacks += 1
# Log if requested
if sim.log:
sim.combat_log.append(
sim.gen_log(time, self.proc_name, 'applied')
)
return 0.0
class InstantDamageProc(ProcTrinket):
"""Custom class to handle instant damage procs."""
def __init__(
self, proc_name, min_damage, damage_range, cooldown, chance_on_hit,
chance_on_crit, icd_precombat=0.0, **kwargs
):
"""Initialize Trinket object.
Arguments:
proc_name (str): Name of the spell that is cast when the trinket
procs. Used for combat logging.
min_damage (float): Low roll damage of the proc, before partial
resists.
damage_range (float): Damage range of the proc.
cooldown (int): Internal cooldown before the trinket can proc
again.
chance_on_hit (float): Probability of a proc on a successful normal
hit, between 0 and 1.
chance_on_crit (float): Probability of a proc on a critical strike,
between 0 and 1.
"""
ProcTrinket.__init__(
self, stat_name='attack_power', stat_increment=0,
proc_name=proc_name, proc_duration=0, cooldown=cooldown,
chance_on_hit=chance_on_hit, chance_on_crit=chance_on_crit,
periodic_only=kwargs.get('periodic_only', False),
icd_precombat=icd_precombat
)
self.min_damage = min_damage
self.damage_range = damage_range
def activate(self, time, player, sim):
"""Deal damage when the trinket procs.
Arguments:
time (float): Simulation time, in seconds, of activation.
player (player.Player): Player object whose stats will be used for
determining the proc damage.
sim (wotlk_cat_sim.Simulation): Simulation object controlling the
fight execution.
Returns:
damage_done (float): Damage dealt by the proc.
"""
ProcTrinket.activate(self, time, player, sim)
# First roll for miss. Infer spell miss chance from player's melee miss
# chance. Assume Improved Faerie Fire / Misery debuffs.
miss_chance = 0.14 - (
(8. - (player.miss_chance - player.dodge_chance) * 100)
* 32.79 / 26.23 / 100
)
miss_roll = np.random.rand()
if miss_roll < miss_chance:
if sim.log:
sim.combat_log.append(
sim.gen_log(time, self.proc_name, 'miss')
)
return 0.0
# Now roll the base damage done by the proc
base_damage = self.min_damage + np.random.rand() * self.damage_range
base_damage *= 1.03 * 1.13 # assume Santified Retribution / CoE
# Now roll for partial resists. Assume that the boss has no nature
# resistance, so the only source of partials is the level based
# resistance of 24 for a boss mob. The partial resist table for this
# condition was taken from this calculator:
# https://royalgiraffe.github.io/legacy-sim/#/resistances
resist_roll = np.random.rand()
if resist_roll < 0.84:
dmg_done = base_damage
elif resist_roll < 0.95:
dmg_done = 0.75 * base_damage
elif resist_roll < 0.99:
dmg_done = 0.5 * base_damage
else:
dmg_done = 0.25 * base_damage
if sim.log:
sim.combat_log.append(
sim.gen_log(time, self.proc_name, '%d' % dmg_done)
)
return dmg_done
class RefreshingProcTrinket(ProcTrinket):
"""Handles trinkets that can proc when already active to refresh the buff
duration."""
def activate(self, time, player, sim):
"""Activate the trinket buff upon player usage or passive proc.
Arguments:
time (float): Simulation time, in seconds, of activation.
player (tbc_cat_sim.Player): Player object whose attributes will be
modified by the trinket proc.
sim (tbc_cat_sim.Simulation): Simulation object controlling the
fight execution.
"""
# The only difference between a standard and repeating proc is that
# we want to make sure that the buff doesn't stack and merely
# refreshes. This is accomplished by deactivating the previous buff and
# then re-applying it.
if self.active:
self.deactivate(player, sim, time=time)
return ProcTrinket.activate(self, time, player, sim)
# Library of recognized trinkets and associated parameters
trinket_library = {
'berserkers_call': {
'type': 'activated',
'passive_stats': {
'attack_power': 90,
},
'active_stats': {
'stat_name': 'attack_power',
'stat_increment': 360,
'proc_name': 'Call of the Berserker',
'proc_duration': 20,
'cooldown': 120,
},
},
'sphere': {
'type': 'activated',
'passive_stats': {
'hit_chance': 55./32.79/100,
'spell_hit_chance': 55./26.23/100,
},
'active_stats': {
'stat_name': 'attack_power',
'stat_increment': 670,
'proc_name': 'Heart of a Dragon',
'proc_duration': 20,
'cooldown': 120,
},
},
'incisor_fragment': {
'type': 'activated',
'passive_stats': {
'attack_power': 148,
},
'active_stats': {
'stat_name': 'armor_pen_rating',
'stat_increment': 291,
'proc_name': 'Incisor Fragment',
'proc_duration': 20,
'cooldown': 120,
},
},
'fezzik': {
'type': 'activated',
'passive_stats': {
'haste_rating': 60,
},
'active_stats': {
'stat_name': 'attack_power',
'stat_increment': 432,
'proc_name': 'Argent Heroism',
'proc_duration': 15,
'cooldown': 120,
},
},
'norgannon': {
'type': 'activated',
'passive_stats': {
'expertise_rating': 69,
},
'active_stats': {
'stat_name': 'haste_rating',
'stat_increment': 491,
'proc_name': 'Mark of Norgannon',
'proc_duration': 20,
'cooldown': 120,
},
},
'loatheb': {
'type': 'activated',
'passive_stats': {
'crit_chance': 84./45.91/100,
'spell_crit_chance': 84./45.91/100,
},
'active_stats': {
'stat_name': 'attack_power',
'stat_increment': 670,
'proc_name': "Loatheb's Shadow",
'proc_duration': 20,
'cooldown': 120,
},
},
'whetstone': {
'type': 'proc',
'passive_stats': {
'crit_chance': 74./45.91/100,
'spell_crit_chance': 74./45.91/100,
},
'active_stats': {
'stat_name': 'haste_rating',
'stat_increment': 444,
'proc_name': 'Meteorite Whetstone',
'proc_duration': 10,
'cooldown': 45,
'proc_type': 'chance_on_hit',
'proc_rate': 0.15,
},
},
'mirror': {
'type': 'proc',
'passive_stats': {
'crit_chance': 84./45.91/100,