-
Notifications
You must be signed in to change notification settings - Fork 2
/
prepatch_cat_sim.py
2736 lines (2273 loc) · 103 KB
/
prepatch_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, meta=False,
predatory_instincts=True
):
"""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.
meta (bool): Whether the Relentless Earthstorm Diamond meta-gem is
used. Defaults False.
predatory_instincts (bool): Whether to apply the critical damage
modifier from the Predatory Instincts talent. Defaults True.
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.24:
glance_reduction = 0.15 + np.random.rand() * 0.2
return (1.0 - glance_reduction) * base_dmg, False, False
if outcome_roll < miss_chance + 0.24 + crit_chance:
crit_multi = 2.2 if predatory_instincts else 2.0
return crit_multi * (1 + meta * 0.03) * base_dmg, False, True
return base_dmg, False, False
def calc_yellow_damage(
low_end, high_end, miss_chance, crit_chance, meta=False,
predatory_instincts=True
):
"""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.
meta (bool): Whether the Relentless Earthstorm Diamond meta-gem is
used. Defaults False.
predatory_instincts (bool): Whether to apply the critical damage
modifier from the Predatory Instincts talent. Defaults True.
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:
crit_multi = 2.2 if predatory_instincts else 2.0
return crit_multi * (1 + meta * 0.03) * 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_rating, multiplier=1.0, cat_form=True):
"""Calculate swing timer given a total haste rating stat.
Arguments:
haste_rating (int): Player haste rating stat.
multiplier (float): Overall haste multiplier from multiplicative haste
buffs such as Bloodlust. Defaults to 1.
cat_form (bool): If True, calculate Cat Form swing timer. If False,
calculate Dire Bear Form swing timer. Defaults True.
Returns:
swing_timer (float): Hasted swing timer in seconds.
"""
base_timer = 1.0 if cat_form else 2.5
return base_timer / (multiplier * (1 + haste_rating / 1577))
def calc_haste_rating(swing_timer, multiplier=1.0, cat_form=True):
"""Calculate the haste rating that is consistent with a given swing timer.
Arguments:
swing_timer (float): Hasted swing timer in seconds.
multiplier (float): Overall haste multiplier from multiplicative haste
buffs such as Bloodlust. Defaults to 1.
cat_form (bool): If True, assume swing timer is for Cat Form. If False,
assume swing timer is for Dire Bear Form. Defaults True.
Returns:
haste_rating (float): Unrounded haste rating.
"""
base_timer = 1.0 if cat_form else 2.5
return 1577 * (base_timer / (swing_timer * multiplier) - 1)
def gen_import_link(
stat_weights, EP_name='Simmed Weights', multiplier=1.133, epic_gems=False
):
"""Generate 80upgrades 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", "1% haste",
and "1 Armor Pen".
EP_name (str): Name for the EP set for auto-populating the 70upgrades
import interface. Defaults to "Simmed Weights".
multiplier (float): Scaling factor for raw primary stats. Defaults to
1.133 assuming Blessing of Kings and Predatory Instincts.
epic_gems (bool): Whether Epic quality gems (10 Agility) should be
assumed for socket weight calculations. Defaults to False (Rare
quality 8 Agi gems).
Returns:
import_link (str): Full URL for stat weight import into 80upgrades.
"""
link = 'https://eightyupgrades.com/ep/import?name='
# EP Name
link += urllib.parse.quote(EP_name)
# Attack Power and Strength
link += '&31=1&33=1.2&4=%.3f' % (2 * multiplier)
# Agility
# agi_weight = multiplier * (1 + stat_weights['1% crit'] / 40)
agi_weight = stat_weights['1 Agility']
link += '&0=%.2f' % agi_weight
# Hit Rating and Expertise Rating
hit_weight = stat_weights['1% hit'] / 15.77
link += '&35=%.2f&46=%.2f' % (hit_weight, hit_weight)
# Critical Strike Rating
link += '&41=%.2f' % (stat_weights['1% crit'] / 22.1)
# Haste Rating
link += '&43=%.2f' % (stat_weights['1% haste'] / 15.77)
# Armor Penetration
link += '&87=%.2f' % stat_weights['1 Armor Pen Rating']
# Weapon Damage
link += '&51=%.2f' % stat_weights['1 Weapon Damage']
# Gems
gem_agi = 10 if epic_gems else 8
gem_weight = agi_weight * gem_agi
link += '&74=%.2f&75=%.2f&76=%.2f' % (gem_weight, gem_weight, gem_weight)
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()
@property
def expertise_rating(self):
return self._expertise_rating
@expertise_rating.setter
def expertise_rating(self, value):
self._expertise_rating = value
self.calc_miss_chance()
# Implement all ability costs as read-only properties here.
def __init__(
self, attack_power, ap_mod, agility, hit_chance, expertise_rating,
crit_chance, armor_pen_rating, swing_timer, mana, intellect,
spirit, mp5, jow=False, pot=True, cheap_pot=False, rune=True,
t4_bonus=False, t6_2p=False, t6_4p=False, wolfshead=True,
meta=False, bonus_damage=0, shred_bonus=0, rip_bonus=0,
debuff_ap=0, multiplier=1.1, omen=True, primal_gore=True,
feral_aggression=0, savage_fury=2, furor=3, natural_shapeshifter=3,
intensity=3, potp=2, improved_mangle=0, weapon_speed=3.0,
proc_trinkets=[], log=False
):
"""Initialize player with key damage parameters.
Arguments:
attack_power (int): Fully raid buffed attack power in Cat Form.
ap_mod (float): Total multiplier for Attack Power in Cat Form.
agility (int): Fully raid buffed Agility attribute.
hit_chance (float): Chance to hit as a fraction.
expertise_rating (int): Player's Expertise Rating stat.
crit_chance (float): Fully raid buffed crit chance as a fraction.
armor_pen_rating (int): Armor penetration rating from gear. Boss
armor debuffs are handled by Simulation objects as they are not
properties of the player character.
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.
cheap_pot (bool): Whether the budget Super Mana Potion is used
instead of the optimal Fel Mana Potion. Defaults False.
rune (bool): Whether Dark/Demonic Runes are used. Defaults True.
t4_bonus (bool): Whether the 2-piece T4 set bonus is used. Defaults
False.
t6_2p (bool): Whether the 2-piece T6 set bonus is used. Defaults
False.
t6_4p (bool): Whether the 4-piece T6 set bonus is used. Defaults
False.
wolfshead (bool): Whether Wolfshead is worn. Defaults to True.
meta (bool): Whether a Relentless Earthstorm Diamond meta gem is
socketed. Defaults to False.
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.
rip_bonus (int): Bonus periodic damage to Rip (per CP) from Idols
and set bonuses. Defaults to 0.
debuff_ap (int): Bonus Attack Power from boss debuffs such as
Improved Hunter's Mark or Expose Weakness. Treated differently
from "normal" AP because it does not boost abilities with
explicit AP scaling. Defaults to 0.
multiplier (float): Overall damage multiplier from talents and
buffs. Defaults to 1.1 (from 5/5 Naturalist).
omen (bool): Whether Omen of Clarity is active. Defaults True.
primal_gore (bool): Whether Primal Gore is talented. Defaults True.
feral_aggression (int): Points taken in Feral Aggression talent.
Defaults to 2.
savage_fury (int): Points taken in Savage Fury talent. Defaults
to 0.
furor (int): Points taken in Furor talent. Default to 3.
natural_shapeshifter (int): Points taken in Natural Shapeshifter
talent. Defaults to 3.
intensity (int): Points taken in Intensity talent. Defaults to 3.
potp (int): Points taken in Protector of the Pack talent. Defaults
to 2.
improved_mangle (int): Points taken in Improved Mangle talent.
Defaults to 0.
weapon_speed (float): Equipped weapon speed, used for calculating
Omen of Clarity proc rate. Defaults to 3.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.
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
self.debuff_ap = debuff_ap
self.agility = agility
self.ap_mod = ap_mod
self.bear_ap_mod = ap_mod / 1.1 * (1 + 0.02 * potp)
# Set internal hit and expertise values, and derive total miss chance.
self._hit_chance = hit_chance
self.expertise_rating = expertise_rating
self.crit_chance = crit_chance - 0.048
self.armor_pen_rating = armor_pen_rating
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.cheap_pot = cheap_pot
self.mana_pot_multi = 1.0
self.rune = rune
self.t4_bonus = t4_bonus
self.bonus_damage = bonus_damage
self.shred_bonus = shred_bonus
self.rip_bonus = rip_bonus
self._mangle_cost = 40 - 5 * t6_2p - 2 * improved_mangle
self.t6_bonus = t6_4p
self.wolfshead = wolfshead
self.meta = meta
self.damage_multiplier = multiplier
self.omen = omen
self.primal_gore = primal_gore
self.feral_aggression = feral_aggression
self.savage_fury = savage_fury
self.furor = furor
self.natural_shapeshifter = natural_shapeshifter
self.intensity = intensity
self.weapon_speed = weapon_speed
self.omen_rates = {
'white': 3.5/60,
'yellow': 0.0,
'bear': 3.5/60*2.5,
}
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
or Expertise Rating occurs."""
miss_reduction = min(self._hit_chance * 100, 8.)
dodge_reduction = min(
6.5, (10 + np.floor(self._expertise_rating / 3.9425)) * 0.25
)
self.miss_chance = 0.01 * (
(8. - miss_reduction) + (6.5 - dodge_reduction)
)
self.dodge_chance = 0.01 * (6.5 - dodge_reduction)
def set_mana_regen(self):
"""Calculate and store mana regeneration rates based on specified regen
stats.
"""
# Mana regen is still linear in Spirit for TBC, but the scaling
# coefficient is now Int-dependent.
# 10/11/21 - Edited base_regen parameter from 0.009327 to 0.0085 while
# shapeshifted, based on the average of three measurements by Rokpaus.
# Neither number fits the caster/cat data exactly, so the formula is
# likely not exact.
self.regen_factor = 0.0085 * np.sqrt(self.intellect)
base_regen = self.spirit * self.regen_factor
bonus_regen = self.mp5 / 5
# In TBC, the Intensity talent allows a portion of the base regen to
# apply while within the five second rule
self.regen_rates = {
'base': base_regen + bonus_regen,
'five_second_rule': 0.5/3*self.intensity*base_regen + bonus_regen,
}
self.shift_cost = 1224 * 0.4 * (1 - 0.1 * self.natural_shapeshifter)
# Since Fel Mana pots regen over time rather than instantaneously, we
# need to use a more sophisticated heuristic for when to pop it.
# We pop the potion when our mana has decreased by 1.5x the value at
# which we would be exactly topped off on average after the 24 second
# pot duration, factoring in other regen sources and mana spent on
# shifting. This provides buffer against rng with respect to JoW procs
# or the number of shift cycles completed in that time.
if self.cheap_pot:
self.pot_threshold = self.mana_pool - 3000*self.mana_pot_multi
return
self.pot_threshold = self.mana_pool - 36 * (
400./3 * self.mana_pot_multi
+ self.regen_rates['five_second_rule'] / 2
+ 35. * (1./self.swing_timer + 1./4.2)
)
def calc_damage_params(
self, gift_of_arthas, boss_armor, sunder, faerie_fire,
blood_frenzy, tigers_fury=False
):
"""Calculate high and low end damage of all abilities as a function of
specified boss debuffs."""
bonus_damage = (
(self.attack_power + self.debuff_ap) / 14 + self.bonus_damage
+ 40 * tigers_fury
)
# Legacy compatibility with older Sunder code in case it is needed
if isinstance(sunder, bool):
sunder *= 5
debuffed_armor = (
boss_armor * (1 - 0.04 * sunder) * (1 - 0.05 * faerie_fire)
)
armor_constant = 467.5 * 70 - 22167.5
arp_cap = (debuffed_armor + armor_constant) / 3.
armor_pen = (
self.armor_pen_rating / 6.73 / 100 * min(arp_cap, debuffed_armor)
)
residual_armor = debuffed_armor - armor_pen
armor_multiplier = (
1 - residual_armor / (residual_armor + armor_constant)
)
damage_multiplier = self.damage_multiplier * (1 + 0.04 * blood_frenzy)
self.multiplier = armor_multiplier * damage_multiplier
self.white_low = (43.0 + bonus_damage) * self.multiplier
self.white_high = (66.0 + bonus_damage) * self.multiplier
self.shred_low = 1.2 * (
self.white_low * 2.25 + (405 + self.shred_bonus) * self.multiplier
)
self.shred_high = 1.2 * (
self.white_high * 2.25 + (405 + self.shred_bonus) * self.multiplier
)
self.bite_multiplier = (
self.multiplier * (1 + 0.03 * self.feral_aggression)
* (1 + 0.15 * self.t6_bonus)
)
# Tooltip low range base values for Bite are 935 and 766, but that's
# incorrect according to the DB.
ap, bm = self.attack_power, self.bite_multiplier
self.bite_low = {
i: (169*i + 57 + 0.07 * i * ap) * bm for i in range(1, 6)
}
self.bite_high = {
i: (169*i + 123 + 0.07 * i * ap) * bm for i in range(1, 6)
}
mangle_fac = 1 + 0.1 * self.savage_fury
self.mangle_low = mangle_fac * (
self.white_low * 2 + 330 * self.multiplier
)
self.mangle_high = mangle_fac * (
self.white_high * 2 + 330 * self.multiplier
)
rake_multi = mangle_fac * damage_multiplier
self.rake_hit = rake_multi * (90 + 0.01 * self.attack_power)
self.rake_tick = rake_multi * (138 + 0.06 * self.attack_power)
rip_multiplier = damage_multiplier * (1 + 0.15 * self.t6_bonus)
self.rip_tick = {
i: (24 + 47*i + 0.01*i*ap + self.rip_bonus*i) * rip_multiplier
for i in range(1,6)
}
# Bearweave damage calculations
bear_ap = self.bear_ap_mod * (
self.attack_power / self.ap_mod - self.agility + 70
)
bear_bonus_damage = (
(bear_ap + self.debuff_ap) / 14 * 2.5 + self.bonus_damage
)
self.white_bear_low = (109.0 + bear_bonus_damage) * self.multiplier
self.white_bear_high = (165.0 + bear_bonus_damage) * self.multiplier
self.maul_low = (self.white_bear_low + 290 * self.multiplier) * 1.872
self.maul_high = (self.white_bear_high + 290 * self.multiplier) * 1.872
self.mangle_bear_low = 1.2 * (
self.white_bear_low * 1.15 + 155 * self.multiplier
)
self.mangle_bear_high = 1.2 * (
self.white_bear_high * 1.15 + 155 * self.multiplier
)
self.lacerate_hit = (31 + 0.01 * bear_ap) * self.multiplier
self.lacerate_tick = self.lacerate_hit / armor_multiplier # for 1 stack
# Adjust damage values for Gift of Arthas
if not gift_of_arthas:
return
for bound in ['low', 'high']:
for ability in [
'white', 'shred', 'mangle', 'white_bear', 'maul', 'mangle_bear'
]:
attr = '%s_%s' % (ability, bound)
setattr(self, attr, getattr(self, attr) + 8 * armor_multiplier)
bite_damage = getattr(self, 'bite_%s' % bound)
for cp in range(1, 6):
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.tf_cd = 0.0
self.energy = 100
self.combo_points = 0
self.mana = self.mana_pool
self.rage = 0
self.rune_cd = 0.0
self.pot_cd = 0.0
self.pot_active = False
self.innervated = False
self.innervate_cd = 0.0
self.five_second_rule = False
self.cat_form = True
self.t4_proc = False
self.ready_to_shift = False
self.berserk = False
self.berserk_cd = 0.0
self.enrage = False
self.enrage_cd = 0.0
self.mangle_cd = 0.0
self.set_ability_costs()
# Create dictionary to hold breakdown of total casts and damage
self.dmg_breakdown = collections.OrderedDict()
for cast_type in [
'Melee', 'Mangle (Cat)', 'Shred', 'Rip', 'Rake', 'Ferocious Bite',
'Shift (Bear)', 'Maul', 'Mangle (Bear)', 'Lacerate', 'Shift (Cat)'
]:
self.dmg_breakdown[cast_type] = {'casts': 0, 'damage': 0.0}
def set_ability_costs(self):
"""Store Energy costs for all specials in the rotation based on whether
or not Berserk is active."""
self.shred_cost = 42. / (1 + self.berserk)
self.rake_cost = 35. / (1 + self.berserk)
self.mangle_cost = self._mangle_cost / (1 + self.berserk)
self.bite_cost = 35. / (1 + self.berserk)
self.rip_cost = 30. / (1 + self.berserk)
def check_omen_proc(self, yellow=False, spell=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.
spell (bool): Check proc for a spell cast rather than a melee
swing or ability. Defaults False.
"""
if (not self.omen) or yellow:
return
if spell and (self.omen_icd > 1e-9):
return
if spell:
proc_rate = self.omen_rates['spell']
elif self.cat_form:
proc_rate = self.omen_rates['white']
else:
proc_rate = self.omen_rates['bear']
proc_roll = np.random.rand()
if proc_roll < proc_rate:
self.omen_proc = True
if spell:
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.25:
self.mana = min(self.mana + 70, self.mana_pool)
def check_t4_proc(self):
"""Check for a 2p-T4 energy proc on a successful melee attack."""
self.t4_proc = False
if not self.t4_bonus:
return
proc_roll = np.random.rand()
if proc_roll < 0.04:
if self.cat_form:
self.energy = min(self.energy + 20, 100)
else:
self.rage = min(self.rage + 10, 100)
self.t4_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_t4_proc()
# Now check for all trinket procs that may occur. Only trinkets that
# can trigger on all possible abilities will be checked here. The
# handful of proc effects that trigger only on Mangle must be
# separately checked within the mangle() function.
for trinket in self.proc_trinkets:
if not trinket.mangle_only:
trinket.check_for_proc(crit, yellow)
def regen(self, delta_t):
"""Update player Energy and Mana.
Arguments:
delta_t (float): Elapsed time, in seconds, since last resource
update.
"""
self.energy = min(100, self.energy + 10 * delta_t)
if self.five_second_rule:
mana_regen = self.regen_rates['five_second_rule']
else:
mana_regen = self.regen_rates['base']
self.mana = min(self.mana + mana_regen * delta_t, self.mana_pool)
if self.enrage:
self.rage = min(100, self.rage + delta_t)
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, time):
"""Pop a Mana Potion to restore mana when appropriate.
Arguments:
time (float): Time at which the potion is consumed. Used to
generate a list of tick times for Fel Mana regen.
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
# If we're using cheap potions, we ignore the Fel Mana tick logic
if self.cheap_pot:
self.mana += (1800 + np.random.rand() * 1200)*self.mana_pot_multi
else:
self.pot_active = True
self.pot_ticks = list(np.arange(time + 3, time + 24.01, 3))
self.pot_end = time + 24
return True
def swing(self):
"""Execute a melee swing.
Returns:
damage_done (float): Damage done by the swing.
"""
low = self.white_low if self.cat_form else self.white_bear_low
high = self.white_high if self.cat_form else self.white_bear_high
damage_done, miss, crit = calc_white_damage(
low, high, self.miss_chance, self.crit_chance, meta=self.meta,
predatory_instincts=self.cat_form
)
# Apply King of the Jungle for bear form swings
if self.enrage:
damage_done *= 1.15
if not miss:
# Check for Omen and JoW procs
self.check_procs(crit=crit)
# If in Dire Bear Form, generate Rage from the swing
if not self.cat_form:
# If the swing missed, then re-roll to see whether it was an actual
# miss or a dodge, since dodges still generate Rage.
dodge = False
if miss:
dodge = (np.random.rand() < self.dodge_chance/self.miss_chance)
if dodge:
# Determine how much damage a successful non-crit / non-glance
# auto would have done.
proxy_damage = 0.5 * (low + high) * (1 + 0.15 * self.enrage)
else:
proxy_damage = damage_done
if (not miss) or dodge:
rage_gen = (
15./4./274.7 * proxy_damage + 2.5/2*3.5 * (1 + crit)
+ 5 * crit
)
self.rage = min(self.rage + rage_gen, 100)
# 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 execute_bear_special(
self, ability_name, min_dmg, max_dmg, rage_cost, yellow=True
):
"""Execute a special ability cast in Dire Bear form.
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.
rage_cost (int): Rage cost of the ability.
yellow (bool): Whether the ability should be treated as "yellow
damage" for the purposes of proc calculations. Defaults True.
Returns:
damage_done (float): Damage done by the ability.
success (bool): Whether the ability successfully landed.
"""
# Perform Monte Carlo
damage_done, miss, crit = calc_yellow_damage(
min_dmg, max_dmg, self.miss_chance, self.crit_chance,
meta=self.meta, predatory_instincts=False
)
# Apply King of the Jungle
if self.enrage:
damage_done *= 1.15
# Set GCD
if yellow:
self.gcd = 1.5
# Update Rage
clearcast = self.omen_proc
if clearcast:
self.omen_proc = False
else:
self.rage -= rage_cost * (1 - 0.8 * miss)
self.rage += 5 * crit
# Check for procs
if not miss:
self.check_procs(crit=crit, yellow=yellow)
# 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, not miss
def maul(self):
"""Execute a Maul when in Dire Bear Form.
Returns:
damage_done (float): Damage done by the Maul cast.
"""
damage_done, success = self.execute_bear_special(
'Maul', self.maul_low, self.maul_high, 10, yellow=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.t4_proc:
if ')' in damage_str:
damage_str = damage_str[:-1] + ', T4 proc)'
else:
damage_str += ' (T4 proc)'
self.combat_log = [
ability_name, damage_str, '%.1f' % self.energy,
'%d' % self.combo_points, '%d' % self.mana, '%d' % self.rage
]
def execute_builder(
self, ability_name, min_dmg, max_dmg, energy_cost, mangle_mod=False
):
"""Execute a combo point builder (either Rake, 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.
mangle_mod (bool): Whether to apply the Mangle damage modifier to
the ability. Defaults False.
Returns:
damage_done (float): Damage done by the ability.
success (bool): Whether the ability successfully landed.
"""
# Perform Monte Carlo
damage_done, miss, crit = calc_yellow_damage(
min_dmg, max_dmg, self.miss_chance, self.crit_chance, self.meta
)
if mangle_mod:
damage_done *= 1.3
# 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) + crit
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, not miss
def shred(self):
"""Execute a Shred.
Returns:
damage_done (float): Damage done by the Shred cast.
success (bool): Whether the Shred landed successfully.
"""
damage_done, success = self.execute_builder(
'Shred', self.shred_low, self.shred_high, self.shred_cost,
mangle_mod=True
)
return damage_done, success
def rake(self):
"""Execute a Rake.
Returns:
damage_done (float): Damage done by the Rake cast.
success (bool): Whether the Rake landed successfully.
"""
damage_done, success = self.execute_builder(
'Rake', self.rake_hit, self.rake_hit, self.rake_cost,
mangle_mod=True
)
return damage_done, success
def lacerate(self):
"""Execute a Lacerate.
Returns:
damage_done (float): Damage done just by the Lacerate cast itself.
success (bool): Whether the Lacerate debuff was successfully
applied or refreshed.
"""
return self.execute_bear_special(
'Lacerate', self.lacerate_hit, self.lacerate_hit, 13
)
def mangle(self):
"""Execute a Mangle.
Returns:
damage_done (float): Damage done by the Mangle cast.
success (bool): Whether the Mangle debuff was successfully applied.
"""
if self.cat_form:
dmg, success = self.execute_builder(
'Mangle (Cat)', self.mangle_low, self.mangle_high,
self.mangle_cost
)
else:
dmg, success = self.execute_bear_special(
'Mangle (Bear)', self.mangle_bear_low, self.mangle_bear_high,
15
)
self.mangle_cd = 6.0
# Since a handful of proc effects trigger only on Mangle, we separately
# check for those procs here if the Mangle landed successfully.
if success:
for trinket in self.proc_trinkets:
if trinket.mangle_only:
trinket.check_for_proc(False, True)
return dmg, success
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 -= self.bite_cost
# Update Bite damage based on excess energy available
bonus_damage = (
min(self.energy, 30) * (3.4 + self.attack_power / 410.)
* 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 + 0.25, self.meta
)
# Consume energy pool and combo points on successful Bite
if miss:
self.energy += 0.8 * self.bite_cost * (not clearcast)
else:
self.energy -= min(self.energy, 30)
self.combo_points = 0
# 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