-
Notifications
You must be signed in to change notification settings - Fork 0
/
classic_cat_sim.py
1710 lines (1404 loc) · 62.1 KB
/
classic_cat_sim.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 simulating the classic WoW feral cat DPS rotation."""
import numpy as np
import copy
import collections
import urllib
import multiprocessing
import psutil
def calc_white_damage(low_end, high_end, miss_chance, crit_chance):
"""Execute single roll table for a melee white attack.
Arguments:
low_end (float): Low end base damage of the swing.
high_end (float): High end base damage of the swing.
miss_chance (float): Probability that the swing is avoided.
crit_chance (float): Probability of a critical strike.
Returns:
damage_done (float): Damage done by the swing.
miss (bool): True if the attack was avoided.
crit (bool): True if the attack was a critical strike.
"""
outcome_roll = np.random.rand()
if outcome_roll < miss_chance:
return 0.0, True, False
base_dmg = low_end + np.random.rand() * (high_end - low_end)
if outcome_roll < miss_chance + 0.4:
glance_reduction = 0.35
return (1.0 - glance_reduction) * base_dmg, False, False
if outcome_roll < miss_chance + 0.4 + crit_chance:
return 2 * base_dmg, False, True
return base_dmg, False, False
def calc_yellow_damage(low_end, high_end, miss_chance, crit_chance):
"""Execute 2-roll table for a melee spell.
Arguments:
low_end (float): Low end base damage of the ability.
high_end (float): High end base damage of the ability.
miss_chance (float): Probability that the ability is avoided.
crit_chance (float): Probability of a critical strike.
Returns:
damage_done (float): Damage done by the ability.
miss (bool): True if the attack was avoided.
crit (bool): True if the attack was a critical strike.
"""
miss_roll = np.random.rand()
if miss_roll < miss_chance:
return 0.0, True, False
base_dmg = low_end + np.random.rand() * (high_end - low_end)
crit_roll = np.random.rand()
if crit_roll < crit_chance:
return 2 * base_dmg, False, True
return base_dmg, False, False
def piecewise_eval(t_fine, times, values):
"""Evaluate a piecewise constant function on a finer time mesh.
Arguments:
t_fine (np.ndarray): Desired mesh for evaluation.
times (np.ndarray): Breakpoints of piecewise function.
values (np.ndarray): Function values at the breakpoints.
Returns:
y_fine (np.ndarray): Function evaluated on the desired mesh.
"""
result = np.zeros_like(t_fine)
for i in range(len(times) - 1):
result += values[i] * ((t_fine >= times[i]) & (t_fine < times[i + 1]))
result += values[-1] * (t_fine >= times[-1])
return result
def calc_swing_timer(haste_buffs):
"""Calculate cat swing timer given a list of haste buffs.
Arguments:
haste_buffs (list): List of strings denoting the active haste buffs.
At present, 'mcp', 'icw', 'libram_1', 'libram_2', and 'wcb' are
supported entries.
Returns:
swing_timer (float): Hasted swing timer in seconds.
"""
haste_multipliers = {
'mcp': 1.5, 'icw': 1.03, 'libram_1': 1.01, 'libram_2': 1.01,
'wcb': 1.15
}
total_multiplier = 1.0
for buff in haste_buffs:
if buff in haste_multipliers:
total_multiplier *= haste_multipliers[buff]
else:
raise ValueError(
'Unrecognized haste buff "%s". Supported buffs are: %s.' % (
buff, haste_multipliers.keys())
)
return 1.0 / total_multiplier
def gen_import_link(stat_weights, EP_name='Simmed Weights', multiplier=1.1):
"""Generate 60upgrades stat weight import link from calculated weights.
Arguments:
stat_weights (dict): Dictionary of weights generated by a Simulation
object. Required keys are: "1% hit", "1% crit", and "1% haste".
EP_name (str): Name for the EP set for auto-populating the 60upgrades
import interface. Defaults to "Simmed Weights".
multiplier (float): Scaling factor for raw primary stats. Defaults to
1.1 assuming Blessing of Kings.
Returns:
import_link (str): Full URL for stat weight import into 60upgrades.
"""
link = 'https://sixtyupgrades.com/ep/import?name='
# EP Name
link += urllib.parse.quote(EP_name)
# Attack Power and Strength
link += '&31=1&33=1&4=%.2f' % (2.4 * multiplier)
# Agility
agi_weight = multiplier * (1 + stat_weights['1% crit'] / 20)
link += '&0=%.2f' % agi_weight
# Hit Chance
link += '&34=%.2f' % stat_weights['1% hit']
# Critical Strike Chance
link += '&40=%.2f' % stat_weights['1% crit']
# Haste
link += '&42=%.2f' % stat_weights['1% haste']
return link
class Player():
"""Stores damage parameters, energy, combo points, and cooldowns for a
simulated player in a boss encounter. Executes events in the cat DPS
rotation."""
@property
def hit_chance(self):
return self._hit_chance
@hit_chance.setter
def hit_chance(self, value):
self._hit_chance = value
self.calc_miss_chance()
def __init__(
self, attack_power, hit_chance, crit_chance, swing_timer, mana,
intellect, spirit, mp5, jow=False, pot=True, rune=True,
bonus_damage=0, shred_bonus=0, bite_rank=4, multiplier=1.1,
omen=True, feral_aggression=0, blood_frenzy=2, savage_fury=2,
natural_shapeshifter=3, weapon_speed=2.0, proc_trinkets=[],
t0_bonus=False, log=False
):
"""Initialize player with key damage parameters.
Arguments:
attack_power (int): Fully raid buffed attack power.
hit_chance (float): Chance to hit as a fraction.
crit_chance (float): Fully raid buffed crit chance as a fraction.
swing_timer (float): Melee swing timer in seconds, including haste
effects such as MCP, Warchief's Blessing, and libram enchants.
mana (int): Fully raid buffed mana.
intellect (int): Fully raid buffed Intellect.
spirit (int): Fully raid buffed Spirit.
mp5 (int): Bonus mp5 from gear or buffs.
jow (bool): Whether the player is receiving Judgment of Wisdom
procs. Defaults False.
pot (bool): Whether mana potions are used. Defaults True.
rune (bool): Whether Dark/Demonic Runes are used. Defaults True.
bonus_damage (int): Bonus weapon damage from buffs such as Bogling
Root or Dense Weightstone. Defaults to 0.
shred_bonus (int): Bonus damage to Shred ability from Idols and set
bonuses. Defaults to 0.
bite_rank (int): Rank of Ferocious Bite to use. Defaults to Rank 4
for Classic Phase 1-5, but Rank 5 can be specified instead for
Phase 6.
multiplier (float): Overall damage multiplier from talents and
buffs. Defaults to 1.1 (from 5/5 Natural Weapons).
omen (bool): Whether Omen of Clarity is active. Defaults True.
feral_aggression (int): Points taken in Feral Aggression talent.
Defaults to 2.
blood_frenzy (int): Points taken in Blood Frenzy talent. Defaults
to 2.
savage_fury (int): Points taken in Savage Fury talent. Defaults
to 2.
natural_shapeshifter (int): Points taken in Natural Shapeshifter
talent. Defaults to 3.
weapon_speed (float): Equipped weapon speed, used for calculating
Omen of Clarity proc rate. Defaults to 2.0.
proc_trinkets (list of trinkets.ProcTrinket): If applicable, a list
of ProcTrinket objects modeling each on-hit or on-crit trinket
used by the player.
t0_bonus (bool): Whether the 6-piece Shadowcraft set bonus is used.
Defaults False.
log (bool): If True, maintain a log of the most recent event,
formatted as a list of strings [event, outcome, energy, combo
points]. Defaults False.
"""
self.attack_power = attack_power
# Set internal hit value, and derive total miss chance.
self.hit_chance = hit_chance
self.crit_chance = crit_chance - 0.048
self.armor_pen = 0
self.swing_timer = swing_timer
self.mana_pool = mana
self.intellect = intellect
self.spirit = spirit
self.mp5 = mp5
self.jow = jow
self.pot = pot
self.rune = rune
self.t0_bonus = t0_bonus
self.bonus_damage = bonus_damage
self.shred_bonus = shred_bonus
self.bite_rank = bite_rank
self.damage_multiplier = multiplier
self.omen = omen
self.feral_aggression = feral_aggression
self.blood_frenzy = blood_frenzy
self.savage_fury = savage_fury
self.natural_shapeshifter = natural_shapeshifter
self.weapon_speed = weapon_speed
self.omen_rates = {
'white': 2.0/60,
'yellow': 2.0/60 * self.weapon_speed
}
self.proc_trinkets = proc_trinkets
self.set_mana_regen()
self.log = log
self.reset()
def calc_miss_chance(self):
"""Update overall miss chance when a change to the player's hit percent
occurs."""
miss_reduction = min(self._hit_chance * 100, 9.)
dodge_reduction = 0.
self.miss_chance = 0.01 * (
(9. - miss_reduction) + (6.5 - dodge_reduction)
)
def set_mana_regen(self):
"""Calculate and store mana regeneration rates based on specified regen
stats.
"""
base_regen = 15 + self.spirit / 5
bonus_regen = self.mp5 / 5 * 2
self.regen_rates = {
'base': base_regen + bonus_regen,
'five_second_rule': bonus_regen,
'innervated': 5 * base_regen + bonus_regen
}
self.shift_cost = 684 * (1 - 0.1 * self.natural_shapeshifter)
self.pot_threshold = self.mana_pool - 2250
def calc_damage_params(
self, gift_of_arthas, boss_armor, sunder, imp_EA, CoR, faerie_fire,
annihilator, tigers_fury=False
):
"""Calculate high and low end damage of all abilities as a function of
specified boss debuffs."""
bonus_damage = (
self.attack_power/14 + self.bonus_damage + 40 * tigers_fury - 10.1
)
# Legacy compatibility with older Sunder code in case it is needed
if isinstance(sunder, bool):
sunder *= 5
residual_armor = max(0, (
boss_armor - max(sunder * 450, imp_EA * 2550) - 640 * CoR
- 505 * faerie_fire - 600 * annihilator - self.armor_pen
))
armor_multiplier = 1 - residual_armor / (residual_armor + 400 + 85*60)
self.multiplier = armor_multiplier * self.damage_multiplier
self.white_low = (60*0.85 + bonus_damage) * self.multiplier
self.white_high = (60*1.25 + bonus_damage) * self.multiplier
self.shred_low = (
self.white_low * 2.25 + (180 + self.shred_bonus) * self.multiplier
)
self.shred_high = (
self.white_high * 2.25 + (180 + self.shred_bonus) * self.multiplier
)
self.bite_multiplier = (
self.multiplier * (1 + 0.03 * self.feral_aggression)
)
# 11/13/21 - Added toggle for both Rank 4 and Rank 5 Bite
if self.bite_rank == 4:
self.bite_low = {
5: (685 + 0.15 * self.attack_power) * self.bite_multiplier,
4: (557 + 0.12 * self.attack_power) * self.bite_multiplier
}
self.bite_high = {
5: (735 + 0.15 * self.attack_power) * self.bite_multiplier,
4: (607 + 0.12 * self.attack_power) * self.bite_multiplier
}
else:
self.bite_low = {
5: (787 + 0.15 * self.attack_power) * self.bite_multiplier,
4: (640 + 0.12 * self.attack_power) * self.bite_multiplier
}
self.bite_high = {
5: (847 + 0.15 * self.attack_power) * self.bite_multiplier,
4: (700 + 0.12 * self.attack_power) * self.bite_multiplier
}
claw_fac = 1 + 0.1 * self.savage_fury
self.claw_low = claw_fac * (self.white_low + 115 * self.multiplier)
self.claw_high = claw_fac * (self.white_high + 115 * self.multiplier)
# Need to double check that both the scaling coefficients and base
# damage values are correct! In TBC, we had to change them, and the
# tooltips were incorrect...
self.rip_tick = {
5: (942 + 0.24*self.attack_power) / 6 * self.damage_multiplier,
4: (774 + 0.24*self.attack_power) / 6 * self.damage_multiplier
}
# Adjust damage values for Gift of Arthas
if not gift_of_arthas:
return
for bound in ['low', 'high']:
for ability in ['white', 'shred', 'claw']:
attr = '%s_%s' % (ability, bound)
setattr(self, attr, getattr(self, attr) + 8 * armor_multiplier)
bite_damage = getattr(self, 'bite_%s' % bound)
for cp in [4, 5]:
bite_damage[cp] += 8 * armor_multiplier
def reset(self):
"""Reset fight-specific parameters to their starting values at the
beginning of an encounter."""
self.gcd = 0.0
self.omen_proc = False
self.omen_icd = 0.0
self.energy = 100
self.combo_points = 0
self.mana = self.mana_pool
self.rune_cd = 0.0
self.pot_cd = 0.0
self.innervated = False
self.innervate_cd = 0.0
self.five_second_rule = False
self.cat_form = True
self.t0_proc = False
# Create dictionary to hold breakdown of total casts and damage
self.dmg_breakdown = collections.OrderedDict()
for cast_type in [
'Melee', 'Shred', 'Rip', 'Claw', 'Ferocious Bite', 'Shift'
]:
self.dmg_breakdown[cast_type] = {'casts': 0, 'damage': 0.0}
def check_omen_proc(self, yellow=False):
"""Check for Omen of Clarity proc on a successful swing.
Arguments:
yellow (bool): Check proc for a yellow ability rather than a melee
swing. Defaults False.
"""
if not self.omen:
return
if self.omen_icd > 1e-9:
return
if yellow:
proc_rate = self.omen_rates['yellow']
else:
proc_rate = self.omen_rates['white']
proc_roll = np.random.rand()
if proc_roll < proc_rate:
self.omen_proc = True
self.omen_icd = 10.0
def check_jow_proc(self):
"""Check for a Judgment Wisdom on a successful melee attack."""
if not self.jow:
return
proc_roll = np.random.rand()
if proc_roll < 0.5:
self.mana = min(self.mana + 59, self.mana_pool)
def check_t0_proc(self, yellow=False):
"""Check for a 6p-Shadowcraft energy proc on a successful melee
attack.
Arguments:
yellow (bool): Check proc for a yellow ability rather than a melee
swing. Defaults False.
"""
self.t0_proc = False
if yellow or (not self.t0_bonus):
return
proc_roll = np.random.rand()
if proc_roll < 1/60.:
self.energy = min(self.energy + 35, 100)
self.t0_proc = True
def check_procs(self, yellow=False, crit=False):
"""Check all relevant procs that trigger on a successful attack.
Arguments:
yellow (bool): Check proc for a yellow ability rather than a melee
swing. Defaults False.
crit (bool): Whether the attack was a critical strike. Defaults
False.
"""
self.check_omen_proc(yellow=yellow)
self.check_jow_proc()
self.check_t0_proc(yellow=yellow)
for trinket in self.proc_trinkets:
trinket.check_for_proc(crit, yellow)
def regen_mana(self):
"""Update player mana on a Spirit tick."""
if self.innervated:
regen = self.regen_rates['innervated']
elif self.five_second_rule:
regen = self.regen_rates['five_second_rule']
else:
regen = self.regen_rates['base']
self.mana = min(self.mana + regen, self.mana_pool)
def use_rune(self):
"""Pop a Dark/Demonic Rune to restore mana when appropriate.
Returns:
rune_used (bool): Whether the rune was used.
"""
if ((not self.rune) or (self.rune_cd > 1e-9)
or (self.mana > self.mana_pool - 1500)):
return False
self.mana += (900 + np.random.rand() * 600)
self.rune_cd = 120.0
return True
def use_pot(self):
"""Pop a Mana Potion to restore mana when appropriate.
Returns:
pot_used (bool): Wheter the potion was used.
"""
if ((not self.pot) or (self.pot_cd > 1e-9)
or (self.mana > self.pot_threshold)):
return False
self.pot_cd = 120.0
self.mana += (1350 + np.random.rand() * 900)
return True
def swing(self):
"""Execute a melee swing.
Returns:
damage_done (float): Damage done by the swing.
"""
damage_done, miss, crit = calc_white_damage(
self.white_low, self.white_high, self.miss_chance, self.crit_chance
)
# Check for Omen and JoW procs
if not miss:
self.check_procs(crit=crit)
# Log the swing
self.dmg_breakdown['Melee']['casts'] += 1
self.dmg_breakdown['Melee']['damage'] += damage_done
if self.log:
self.gen_log('melee', damage_done, miss, crit, False)
return damage_done
def gen_log(self, ability_name, dmg_done, miss, crit, clearcast):
"""Generate a combat log entry for an ability.
Arguments:
ability_name (str): Name of the ability.
dmg_done (float): Damage done by the ability.
miss (bool): Whether the ability missed.
crit (bool): Whether the ability crit.
clearcast (bool): Whether the ability was a Clearcast.
"""
if miss:
damage_str = 'miss' + ' (clearcast)' * clearcast
else:
try:
damage_str = '%d' % dmg_done
except TypeError:
damage_str = dmg_done
if crit and clearcast:
damage_str += ' (crit, clearcast)'
elif crit:
damage_str += ' (crit)'
elif clearcast:
damage_str += ' (clearcast)'
if self.t0_proc:
if ')' in damage_str:
damage_str = damage_str[:-1] + ', T0 proc)'
else:
damage_str += ' (T0 proc)'
self.combat_log = [
ability_name, damage_str, '%d' % self.energy,
'%d' % self.combo_points, '%d' % self.mana
]
def execute_builder(self, ability_name, min_dmg, max_dmg, energy_cost):
"""Execute a combo point builder (either Claw, Shred, or Mangle).
Arguments:
ability_name (str): Name of the ability for use in logging.
min_dmg (float): Low end damage of the ability.
max_dmg (float): High end damage of the ability.
energy_cost (int): Energy cost of the ability.
Returns:
damage_done (float): Damage done by the ability.
"""
# Perform Monte Carlo
damage_done, miss, crit = calc_yellow_damage(
min_dmg, max_dmg, self.miss_chance, self.crit_chance
)
# Set GCD
self.gcd = 1.0
# Update energy
clearcast = self.omen_proc
if clearcast:
self.omen_proc = False
else:
self.energy -= energy_cost * (1 - 0.8 * miss)
# Update combo points
points_added = 1 * (not miss)
if crit and (self.blood_frenzy > 0):
if self.blood_frenzy == 1:
bf_roll = np.random.rand()
points_added += (bf_roll < 0.5)
else:
points_added += 1
self.combo_points = min(5, self.combo_points + points_added)
# Check for Omen and JoW procs
if not miss:
self.check_procs(yellow=True, crit=crit)
# Log the cast
self.dmg_breakdown[ability_name]['casts'] += 1
self.dmg_breakdown[ability_name]['damage'] += damage_done
if self.log:
self.gen_log(ability_name, damage_done, miss, crit, clearcast)
return damage_done
def shred(self):
"""Execute a Shred.
Returns:
damage_done (float): Damage done by the Shred cast.
"""
return self.execute_builder(
'Shred', self.shred_low, self.shred_high, 48
)
def claw(self):
"""Execute a Claw.
Returns:
damage_done (float): Damage done by the Claw cast.
"""
return self.execute_builder('Claw', self.claw_low, self.claw_high, 40)
def bite(self):
"""Execute a Ferocious Bite.
Returns:
damage_done (float): Damage done by the Bite cast.
"""
# Bite always costs at least 35 combo points without Omen of Clarity
clearcast = self.omen_proc
if clearcast:
self.omen_proc = False
else:
self.energy -= 35
# Update Bite damage based on excess energy available
bonus_damage = self.energy * 2.7 * self.bite_multiplier
# Perform Monte Carlo
damage_done, miss, crit = calc_yellow_damage(
self.bite_low[self.combo_points] + bonus_damage,
self.bite_high[self.combo_points] + bonus_damage, self.miss_chance,
self.crit_chance
)
# Consume energy pool and combo points on successful Bite
self.energy *= miss
self.combo_points *= miss
# Set GCD
self.gcd = 1.0
# Check for Omen and JoW procs
if not miss:
self.check_procs(yellow=True, crit=crit)
# Log the cast
self.dmg_breakdown['Ferocious Bite']['casts'] += 1
self.dmg_breakdown['Ferocious Bite']['damage'] += damage_done
if self.log:
self.gen_log('Ferocious Bite', damage_done, miss, crit, clearcast)
return damage_done
def rip(self):
"""Cast Rip as a finishing move.
Returns:
damage_per_tick (float): Damage done per subsequent Rip tick.
success (bool): Whether the Rip debuff was successfully applied.
"""
# Perform Monte Carlo to see if it landed and record damage per tick
miss = (np.random.rand() < self.miss_chance)
damage_per_tick = self.rip_tick[self.combo_points] * (not miss)
# Set GCD
self.gcd = 1.0
# Update energy
clearcast = self.omen_proc
if clearcast:
self.omen_proc = False
else:
self.energy -= 30
# Consume combo points on successful cast
self.combo_points *= miss
# Check for Omen and JoW procs
if not miss:
self.check_procs(yellow=True)
# Log the cast and total damage that will be done
self.dmg_breakdown['Rip']['casts'] += 1
self.dmg_breakdown['Rip']['damage'] += damage_per_tick * 6
if self.log:
self.gen_log('Rip', 'applied', miss, False, clearcast)
return damage_per_tick, not miss
def shift(self, time):
"""Execute a powershift.
Arguments:
time (float): Time at which the shift is executed, in seconds. Used
for determining the five second rule.
"""
self.energy = 60
self.gcd = 1.5
self.dmg_breakdown['Shift']['casts'] += 1
self.mana -= self.shift_cost
self.five_second_rule = True
self.last_cast_time = time
self.cat_form = True
mana_str = ''
# Pop a Dark Rune if we can get full value from it
if self.use_rune():
mana_str = 'use Dark Rune'
# Pop a Mana Potion if we can get full value from it
if self.use_pot():
mana_str = 'use Mana Potion'
if self.log:
self.combat_log = [
'shift', mana_str, '%d' % self.energy,
'%d' % self.combo_points, '%d' % self.mana
]
def innervate(self, time):
"""Cast Innervate.
Arguments:
time (float): Time of Innervate cast, in seconds. Used for
determining when the Innervate buff falls off.
"""
self.mana -= 62 # Innervate mana cost
self.innervate_end = time + 20
self.innervated = True
self.cat_form = False
self.energy = 0
self.gcd = 1.5
self.innervate_cd = 360.0
if self.log:
self.combat_log = [
'Innervate', '', '%d' % self.energy,
'%d' % self.combo_points, '%d' % self.mana
]
class ArmorDebuffs():
"""Controls the delayed application of boss armor debuffs after an
encounter begins. At present, only Sunder Armor and Expose Armor are
modeled with delayed application, and all other boss debuffs are modeled
as applying instantly at the fight start."""
def __init__(self, sim):
"""Initialize controller by specifying whether Sunder, EA, or both will
be applied.
sim (Simulation): Simulation object controlling fight execution. The
params dictionary of the Simulation will be modified by the debuff
controller during the fight.
"""
self.params = sim.params
self.process_params()
def process_params(self):
"""Use the simulation's existing params dictionary to determine whether
Sunder, EA, or both should be applied."""
self.use_sunder = bool(self.params['sunder'])
self.use_ea = bool(self.params['imp_EA'])
self.reset()
def reset(self):
"""Remove all armor debuffs at the start of a fight."""
self.params['sunder'] = 0
self.params['imp_EA'] = False
def update(self, time, player, sim):
"""Add Sunder or EA applications at the appropriate times. Currently,
the debuff schedule is hard coded as 1 Sunder stack every GCD, and
EA applied at 15 seconds if used. This can be made more flexible if
desired in the future using class attributes.
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.
"""
# If we are Sundering and are at less than 5 stacks, then add a stack
# every GCD.
if (self.use_sunder and (self.params['sunder'] < 5)
and (time >= 1.5 * self.params['sunder'])):
self.params['sunder'] += 1
if sim.log:
sim.combat_log.append(
sim.gen_log(time, 'Sunder Armor', 'applied')
)
player.calc_damage_params(**self.params)
elif self.use_ea and (not self.params['imp_EA']) and (time >= 15.):
self.params['imp_EA'] = True
if sim.log:
if self.params['sunder'] > 0:
sim.combat_log.append(
sim.gen_log(time, 'Sunder Armor', 'falls off')
)
sim.combat_log.append(
sim.gen_log(time, 'Expose Armor', 'applied')
)
player.calc_damage_params(**self.params)
return 0.0
class Simulation():
"""Sets up and runs a simulated fight with the cat DPS rotation."""
# Default fight parameters, including boss armor and all relevant debuffs.
default_params = {
'gift_of_arthas': True,
'boss_armor': 3731,
'sunder': True,
'imp_EA': True,
'CoR': True,
'faerie_fire': True,
'annihilator': False,
}
# Default parameters specifying the player execution strategy
default_strategy = {
'prepop_TF': False,
'prepop_numticks': 2,
'min_combos_for_rip': 6,
'use_claw_trick': True,
'use_bite': True,
'bite_time': 0.0,
'min_combos_for_bite': 5,
'use_innervate': True,
'max_wait_time': 1.0,
}
def __init__(
self, player, fight_length, num_mcp=0, trinkets=[], **kwargs
):
"""Initialize simulation.
Arguments:
player (Player): An instantiated Player object which can execute
the DPS rotation.
fight_length (float): Fight length in seconds.
num_mcp (int): Maximum number of MCPs that can be used during the
fight. If nonzero, the Player object should be instantiated
with a hasted swing timer, and the simulation will slow it down
once the haste buff expires. Defaults to 0.
trinkets (list of trinkets.Trinket): List of ActivatedTrinket or
ProcTrinket objects that will be used on cooldown.
kwargs (dict): Key, value pairs for all other encounter parameters,
including boss armor, relevant debuffs, and player stregy
specification. An error will be thrown if the parameter is not
recognized. Any parameters not supplied will be set to default
values.
"""
self.player = player
self.fight_length = fight_length
self.max_mcp = int(round(num_mcp))
self.trinkets = trinkets
self.params = copy.deepcopy(self.default_params)
self.strategy = copy.deepcopy(self.default_strategy)
for key, value in kwargs.items():
if key in self.params:
self.params[key] = value
elif key in self.strategy:
self.strategy[key] = value
else:
raise KeyError(
('"%s" is not a supported parameter. Supported encounter '
'parameters are: %s. Supported strategy parameters are: '
'%s.') % (key, self.params.keys(), self.strategy.keys())
)
# Determine whether Ferocious Bite is to be used instead of Rip as the
# primary finishing move.
self.strategy['bite_over_rip'] = (
self.strategy['use_bite']
and (self.strategy['min_combos_for_rip'] > 5)
)
self.strategy['no_finisher'] = (
(not self.strategy['use_bite'])
and (self.strategy['min_combos_for_rip'] > 5)
)
# Set up controller for delayed armor debuffs. The controller can be
# treated identically to a Trinket object as far as the sim is
# concerned.
self.debuff_controller = ArmorDebuffs(self)
self.trinkets.append(self.debuff_controller)
# Calculate damage ranges for player abilities under the given
# encounter parameters.
self.player.calc_damage_params(**self.params)
def set_active_debuffs(self, debuff_list):
"""Set active debuffs according to a specified list.
Arguments:
debuff_list (list): List of strings containing supported debuff
names.
"""
active_debuffs = copy.copy(debuff_list)
all_debuffs = [key for key in self.params if key != 'boss_armor']
for key in all_debuffs:
if key in active_debuffs:
self.params[key] = True
active_debuffs.remove(key)
else:
self.params[key] = False
if active_debuffs:
raise ValueError(
'Unsupported debuffs found: %s. Supported debuffs are: %s.' % (
active_debuffs, self.params.keys()
)
)
self.debuff_controller.process_params()
def gen_log(self, time, event, outcome):
"""Generate a custom combat log entry.
Arguments:
time (float): Current simulation time in seconds.
event (str): First "event" field for the log entry.
outcome (str): Second "outcome" field for the log entry.
"""
return [
'%.3f' % time, event, outcome, '%d' % self.player.energy,
'%d' % self.player.combo_points, '%d' % self.player.mana
]
def innervate_or_shift(self, time):
"""Decide whether to cast Innervate or perform a normal powershift.
Arguments:
time (float): Current simulation time in seconds.
"""
# Only Innervate if (a) we don't have enough mana for two shifts, (b)
# the fight isn't ending, and (c) Innervate is not on cooldown.
if (self.strategy['use_innervate']
and (self.player.mana <= self.innervate_threshold)
and (time < self.fight_length - 1.6)
and (self.player.innervate_cd < 1e-9)):
# First execute the Innervate cast. Player object will track the
# time of cast.
self.player.innervate(time)
# Next we need to reset the melee swing timer since we're staying
# in caster form. We'll use the same logic as at the start of
# combat, setting the first swing just slightly after the shift
# back into cat.
self.update_swing_times(
time + 1.5 + 0.1 * np.random.rand(), self.swing_timer,
first_swing=True
)
else:
self.player.shift(time)
# If needed, squeeze in a weapon swap into the same GCD
if (not self.mcp_equipped) and (self.num_mcp >= 1):
self.mcp_equipped = True
self.mcp_cd = 30.0
self.num_mcp -= 1
def rip(self, time):
"""Instruct Player to apply Rip, and perform related bookkeeping.
Arguments:
time (float): Current simulation time in seconds.
"""
damage_per_tick, success = self.player.rip()
if success:
self.rip_debuff = True