forked from NerdEgghead/WotLK_cat_sim
-
Notifications
You must be signed in to change notification settings - Fork 4
/
wotlk_cat_sim.py
2679 lines (2272 loc) · 110 KB
/
wotlk_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
import sim_utils
import player as player_class
import time
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.reset()
def reset(self):
"""Remove all armor debuffs at the start of a fight."""
self.params['sunder'] = 0
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 (player.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)
return 0.0
class UptimeTracker():
"""Provides an interface for tracking average uptime on buffs and debuffs,
analogous to Trinket objects."""
def __init__(self):
self.reset()
def reset(self):
self.uptime = 0.0
self.last_update = 15.0
self.active = False
self.num_procs = 0
def update(self, time, player, sim):
"""Update average aura uptime at a new timestep.
Arguments:
time (float): Simulation time, in seconds.
player (player.Player): Player object responsible for
ability casts.
sim (wotlk_cat_sim.Simulation): Simulation object controlling the
fight execution.
"""
if (time > self.last_update) and (time < sim.fight_length - 15):
dt = time - self.last_update
active_now = self.is_active(player, sim)
self.uptime = (
(self.uptime * (self.last_update - 15.) + dt * active_now)
/ (time - 15.)
)
self.last_update = time
if active_now and (not self.active):
self.num_procs += 1
self.active = active_now
return 0.0
def is_active(self, player, sim):
"""Determine whether or not the tracked aura is active at the current
time. This method must be implemented by UptimeTracker subclasses.
Arguments:
player (wotlk_cat_sim.Player): Player object responsible for
ability casts.
sim (wotlk_cat_sim.Simulation): Simulation object controlling the
fight execution.
Returns:
is_active (bool): Whether or not the aura is currently active.
"""
return NotImplementedError(
'Logic for aura active status must be implemented by UptimeTracker'
' subclasses.'
)
def deactivate(self, *args, **kwargs):
self.active = False
class RipTracker(UptimeTracker):
proc_name = 'Rip'
def is_active(self, player, sim):
return sim.rip_debuff
class RoarTracker(UptimeTracker):
proc_name = 'Savage Roar'
def is_active(self, player, sim):
return (player.savage_roar or (not player.cat_form))
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': False,
'faerie_fire': True,
'blood_frenzy': False,
'shattering_throw': False,
'curse_of_elements': True,
}
# Default parameters specifying the player execution strategy
default_strategy = {
'min_combos_for_rip': 5,
'use_rake': False,
'use_bite': True,
'bite_time': 8.0,
'min_combos_for_bite': 5,
'mangle_spam': False,
'bear_mangle': False,
'use_berserk': False,
'prepop_berserk': False,
'preproc_omen': False,
'bearweave': False,
'berserk_bite_thresh': 100,
'berserk_ff_thresh': 87,
'lacerate_prio': False,
'lacerate_time': 10.0,
'powerbear': False,
'min_roar_offset': 10.0,
'roar_clip_leeway': 0.0,
'snek': False,
'idol_swap': False,
'flowershift': False,
'daggerweave': False,
'dagger_ep_loss': 1461,
'mangle_idol_swap': False,
'max_ff_delay': 1.0,
'num_targets': 1,
'aoe': False,
}
def __init__(
self, player, fight_length, latency, trinkets=[], haste_multiplier=1.0,
hot_uptime=0.0, mangle_idol=None, rake_idol=None, mutilation_idol=None, **kwargs
):
"""Initialize simulation.
Arguments:
player (Player): An instantiated Player object which can execute
the DPS rotation.
fight_length (float): Fight length in seconds.
latency (float): Modeled player input delay in seconds. Used to
simulate realistic delays between energy gains and subsequent
special ability casts, as well as delays in powershift timing
relative to the GCD.
trinkets (list of trinkets.Trinket): List of ActivatedTrinket or
ProcTrinket objects that will be used on cooldown.
haste_multiplier (float): Total multiplier from external percentage
haste buffs such as Windfury Totem. Defaults to 1.
hot_uptime (float): Fractional uptime of Rejuvenation / Wild Growth
HoTs from a Restoration Druid. Used for simulating Revitalize
procs. Defaults to 0.
mangle_idol (trinkets.ProcTrinket): Optional Mangle proc Idol to
use. If supplied, then Mangle Idol swaps will be configured
automatically if appropriate.
rake_idol (trinkets.ProcTrinket): Optional Rake/Lacerate proc Idol
to use.
mutilation_idol (trinkets.RefreshingProcTrinket): Optional Mangle/
Shred proc idol to use.
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.latency = latency
self.trinkets = trinkets
self.mangle_idol = mangle_idol
self.rake_idol = rake_idol
self.mutilation_idol = mutilation_idol
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())
)
# 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)
# Set up trackers for Rip and Roar uptime
self.trinkets.append(RipTracker())
self.trinkets.append(RoarTracker())
# Enable AoE rotation for 3+ targets
self.strategy['aoe'] = (self.strategy['num_targets'] >= 3)
# Automatically detect an Idol swapping configuration
self.shred_bonus = self.player.shred_bonus
self.rip_bonus = self.player.rip_bonus
if (self.player.shred_bonus > 0) and (self.player.rip_bonus > 0):
self.strategy['idol_swap'] = True
if (self.mangle_idol and (self.shred_bonus or self.rip_bonus)
and (not self.strategy['aoe'])):
self.strategy['mangle_idol_swap'] = True
# Calculate damage ranges for player abilities under the given
# encounter parameters.
self.player.calc_damage_params(**self.params)
# Set multiplicative haste buffs. The multiplier can be increased
# during Bloodlust, etc.
self.haste_multiplier = haste_multiplier
# Calculate time interval between Revitalize dice rolls
self.revitalize_frequency = 15. / (8 * max(hot_uptime, 1e-9))
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, '%.1f' % self.player.energy,
'%d' % self.player.combo_points, '%d' % self.player.mana,
'%d' % self.player.rage
]
def mangle(self, time):
"""Instruct the Player to Mangle, and perform related bookkeeping.
Arguments:
time (float): Current simulation time in seconds.
Returns:
damage_done (float): Damage done by the Mangle cast.
"""
damage_done, success = self.player.mangle()
# If it landed, flag the debuff as active and start timer
if success:
self.mangle_debuff = True
self.mangle_end = (
np.inf if self.strategy['bear_mangle'] else (time + 60.0)
)
# If Idol swapping is configured, then swap to Shred or Rip Idol
# immmediately after Mangle is cast. This incurs a 0.5 second GCD
# extension as well as a swing timer reset, so it should only be done
# in Cat Form.
if (self.strategy['mangle_idol_swap'] and self.player.cat_form
and self.mangle_idol.equipped):
self.player.shred_bonus = (
0 if self.strategy['idol_swap'] else self.shred_bonus
)
self.player.rip_bonus = self.rip_bonus
self.player.calc_damage_params(**self.params)
self.player.gcd = 1.5
self.update_swing_times(
time + self.swing_timer, self.swing_timer, first_swing=True
)
self.mangle_idol.equipped = False
return damage_done
def rake(self, time):
"""Instruct the Player to Rake, and perform related bookkeeping.
Arguments:
time (float): Current simulation time in seconds.
Returns:
damage_done (float): Damage done by the Rake initial hit.
"""
damage_done, success = self.player.rake(self.mangle_debuff)
# If it landed, flag the debuff as active and start timer
if success:
self.rake_debuff = True
self.rake_end = time + self.player.rake_duration
self.rake_ticks = list(np.arange(time + 3, self.rake_end + 1e-9, 3))
self.rake_damage = self.player.rake_tick
self.rake_crit_chance = self.player.crit_chance
self.rake_sr_snapshot = self.player.savage_roar
return damage_done
def lacerate(self, time):
"""Instruct the Player to Lacerate, and perform related bookkeeping.
Arguments:
time (float): Current simulation time in seconds.
Returns:
damage_done (float): Damage done by the Lacerate initial hit.
"""
damage_done, success = self.player.lacerate(self.mangle_debuff)
if success:
self.lacerate_end = time + 15.0
if self.lacerate_debuff:
# Unlike our other bleeds, Lacerate maintains its tick rate
# when it is refreshed, so we simply append more ticks to
# extend the duration. Note that the current implementation
# allows for Lacerate to be refreshed *after* the final tick
# goes out as long as it happens before the duration expires.
if self.lacerate_ticks:
last_tick = self.lacerate_ticks[-1]
else:
last_tick = self.last_lacerate_tick
self.lacerate_ticks += list(np.arange(
last_tick + 3, self.lacerate_end + 1e-9, 3
))
self.lacerate_stacks = min(self.lacerate_stacks + 1, 5)
else:
self.lacerate_debuff = True
self.lacerate_ticks = list(np.arange(time + 3, time + 16, 3))
self.lacerate_stacks = 1
self.lacerate_damage = (
self.player.lacerate_tick * self.lacerate_stacks
* (1 + 0.15 * self.player.enrage) * self.player.lacerate_dot_multi
)
self.lacerate_crit_chance = self.player.crit_chance - 0.04
return damage_done
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
self.rip_start = time
self.rip_end = time + self.player.rip_duration
self.rip_ticks = list(np.arange(time + 2, self.rip_end + 1e-9, 2))
self.rip_damage = damage_per_tick
self.rip_crit_bonus_chance = self.player.crit_chance + self.player.rip_crit_bonus
self.rip_sr_snapshot = self.player.savage_roar
# If Idol swapping is configured, then swap to Shred Idol immmediately
# after Rip is cast. This incurs a 0.5 second GCD extension as well as
# a swing timer reset, so it should only be done during Berserk.
if (self.strategy['idol_swap'] and (self.player.rip_bonus > 0)
and self.player.berserk):
self.player.shred_bonus = self.shred_bonus
self.player.rip_bonus = 0
self.player.calc_damage_params(**self.params)
self.player.gcd = 1.5
self.update_swing_times(
time + self.swing_timer, self.swing_timer, first_swing=True
)
return 0.0
def shred(self):
"""Instruct Player to Shred, and perform related bookkeeping.
Returns:
damage_done (Float): Damage done by Shred cast.
"""
damage_done, success = self.player.shred(self.mangle_debuff)
# If it landed, apply Glyph of Shred
if success and self.rip_debuff and self.player.shred_glyph:
if (self.rip_end - self.rip_start) < self.player.rip_duration + 6:
self.rip_end += 2
self.rip_ticks.append(self.rip_end)
return damage_done
def berserk_expected_at(self, current_time, future_time):
"""Determine whether the Berserk buff is predicted to be active at
the requested future time.
Arguments:
current_time (float): Current simulation time in seconds.
future_time (float): Future time, in seconds, for querying Berserk
status.
Returns:
berserk_expected (bool): True if Berserk should be active at the
specified future time, False otherwise.
"""
if self.player.berserk:
return (
(future_time < self.berserk_end)
or (future_time > current_time + self.player.berserk_cd)
)
if self.player.berserk_cd > 1e-9:
return (future_time > current_time + self.player.berserk_cd)
if self.params['tigers_fury'] and self.strategy['use_berserk']:
return (future_time > self.tf_end)
return False
def tf_expected_before(self, current_time, future_time):
"""Determine whether Tiger's Fury is predicted to be used prior to the
requested future time.
Arguments:
current_time (float): Current simulation time in seconds.
future_time (float): Future time, in seconds, for querying Tiger's
Fury status.
Returns:
tf_expected (bool): True if Tiger's Fury should be activated prior
to the specified future time, False otherwise.
"""
if self.player.tf_cd > 1e-9:
return (current_time + self.player.tf_cd < future_time)
if self.player.berserk:
return (self.berserk_end < future_time)
return True
def can_bite(self, time):
"""Determine whether or not there is sufficient time left before Rip
falls off to fit in a Ferocious Bite. Uses either a fixed empirically
optimized time parameter or a first principles analytical calculation
depending on user options.
Arguments:
time (float): Current simulation time in seconds.
Returns:
can_bite (bool): True if Biting now is optimal.
"""
if self.strategy['bite_time'] is not None:
bt = self.strategy['bite_time']
# max_rip_dur = (
# self.player.rip_duration + 6 * self.player.shred_glyph
# )
# rip_end = self.rip_start + max_rip_dur
# if self.rip_end < self.roar_end:
# bt -= 6 * self.tf_expected_before(time, self.rip_end)
# else:
# bt -= 6 * self.tf_expected_before(time, self.roar_end)
return (
(self.rip_end - time >= bt) and (self.roar_end - time >= bt)
)
return self.can_bite_analytical(time)
def can_bite_analytical(self, time):
"""Analytical alternative to the empirical bite_time parameter used for
determining whether there is sufficient time left before Rip falls off
to fit in a Ferocious Bite.
Arguments:
time (float): Current simulation time in seconds.
Returns:
can_bite (bool): True if the analytical model indicates that Biting
now is optimal, False otherwise.
"""
# First calculate how much Energy we expect to accumulate before our
# next finisher expires.
maxripdur = self.player.rip_duration + 6 * self.player.shred_glyph
ripdur = self.rip_start + maxripdur - time
srdur = self.roar_end - time
mindur = min(ripdur, srdur)
maxdur = max(ripdur, srdur)
expected_energy_gain_min = 10 * mindur
expected_energy_gain_max = 10 * maxdur
if self.tf_expected_before(time, time + mindur):
expected_energy_gain_min += 60
if self.tf_expected_before(time, time + maxdur):
expected_energy_gain_max += 60
if self.player.omen:
expected_energy_gain_min += mindur / self.swing_timer * (
3.5 / 60. * (1 - self.player.miss_chance) * 42
)
expected_energy_gain_max += maxdur / self.swing_timer * (
3.5 / 60. * (1 - self.player.miss_chance) * 42
)
expected_energy_gain_min += mindur/self.revitalize_frequency*0.15*8
expected_energy_gain_max += maxdur/self.revitalize_frequency*0.15*8
total_energy_min = self.player.energy + expected_energy_gain_min
total_energy_max = self.player.energy + expected_energy_gain_max
# Now calculate the effective Energy cost for Biting now, which
# includes the cost of the Ferocious Bite itself, the cost of building
# CPs for Rip and Roar, and the cost of Rip/Roar.
ripcost, bitecost, srcost = self.get_finisher_costs(time)
cost_per_builder = (
(42. + 42. + 35.) / 3. * (1 + 0.2 * self.player.miss_chance)
)
# Aus did an analytical waterfall calculation of the expected number of
# builders required for building 5 CPs
cc = self.player.crit_chance
required_builders_min = cc**4 - 2 * cc**3 + 3 * cc**2 - 4 * cc + 5
if srdur < ripdur:
nextcost = srcost
required_builders_max = 2 * required_builders_min
else:
nextcost = ripcost
required_builders_max = required_builders_min + 1
total_energy_cost_min = (
bitecost + required_builders_min * cost_per_builder + nextcost
)
total_energy_cost_max = (
bitecost + required_builders_max * cost_per_builder + ripcost
+ srcost
)
# Actual Energy cost is a bit lower than this because it is okay to
# lose a few seconds of Rip or SR uptime to gain a Bite.
rip_downtime, sr_downtime = self.calc_allowed_rip_downtime(time)
# Adjust downtime estimate to account for end of fight losses
rip_downtime = maxripdur * (1 - 1. / (1. + rip_downtime / maxripdur))
sr_downtime = 34. * (1 - 1. / (1. + sr_downtime / 34.))
next_downtime = sr_downtime if srdur < ripdur else rip_downtime
total_energy_cost_min -= 10 * next_downtime
total_energy_cost_max -= 10 * min(rip_downtime, sr_downtime)
# Then we simply recommend Biting now if the available Energy to do so
# exceeds the effective cost.
return (
(total_energy_min > total_energy_cost_min)
and (total_energy_max > total_energy_cost_max)
)
def get_finisher_costs(self, time):
"""Determine the expected Energy cost for Rip when it needs to be
refreshed, and the expected Energy cost for Ferocious Bite if it is
cast right now.
Arguments:
time (float): Current simulation time, in seconds.
Returns:
ripcost (float): Energy cost of future Rip refresh.
bitecost (float): Energy cost of a current Ferocious Bite cast.
srcost (float): Energy cost of a Savage Roar refresh.
"""
rip_end = time if (not self.rip_debuff) else self.rip_end
ripcost = self.player._rip_cost / 2 if self.berserk_expected_at(time, rip_end) else self.player._rip_cost
if self.player.energy >= self.player.bite_cost:
bitecost = min(self.player.bite_cost + 30, self.player.energy)
else:
bitecost = self.player.bite_cost + 10 * self.latency
sr_end = time if (not self.player.savage_roar) else self.roar_end
srcost = 12.5 if self.berserk_expected_at(time, sr_end) else 25
return ripcost, bitecost, srcost
def calc_allowed_rip_downtime(self, time):
"""Determine how many seconds of Rip uptime can be lost in exchange for
a Ferocious Bite cast without losing damage. This calculation is used
in the analytical bite_time calculation above, as well as for
determining how close to the end of the fight we should be for
prioritizing Bite over Rip.
Arguments:
time (float): Current simulation time, in seconds.
Returns:
allowed_rip_downtime (float): Maximum acceptable Rip duration loss,
in seconds.
allowed_sr_downtime (float): Maximum acceptable Savage Roar
downtime, in seconds.
"""
rip_cp = self.strategy['min_combos_for_rip']
bite_cp = self.strategy['min_combos_for_bite']
rip_cost, bite_cost, roar_cost = self.get_finisher_costs(time)
crit_factor = self.player.calc_crit_multiplier() - 1
bite_base_dmg = 0.5 * (
self.player.bite_low[bite_cp] + self.player.bite_high[bite_cp]
)
bite_bonus_dmg = (
(bite_cost - self.player.bite_cost)
* (9.4 + self.player.attack_power / 410.)
* self.player.bite_multiplier
)
bite_dpc = (bite_base_dmg + bite_bonus_dmg) * (
1 + crit_factor * (self.player.crit_chance + 0.25)
)
crit_mod = crit_factor * self.player.crit_chance
avg_rip_tick = self.player.rip_tick[rip_cp] * 1.3 * (
1 + crit_mod * self.player.primal_gore
)
shred_dpc = (
0.5 * (self.player.shred_low + self.player.shred_high) * 1.3
* (1 + crit_mod)
)
allowed_rip_downtime = (
(bite_dpc - (bite_cost - rip_cost) * shred_dpc / 42.)
/ avg_rip_tick * 2
)
cpe = (42. * bite_dpc / shred_dpc - 35.) / 5.
srep = {1: (1 - 5) * (cpe - 125./34.), 2: (2 - 5) * (cpe - 125./34.)}
srep_avg = (
self.player.crit_chance * srep[2]
+ (1 - self.player.crit_chance) * srep[1]
)
rake_dpc = 1.3 * (
self.player.rake_hit * (1 + crit_mod)
+ 3*self.player.rake_tick*(1 + crit_mod*self.player.primal_gore)
)
allowed_sr_downtime = (
(bite_dpc - shred_dpc / 42. * min(srep_avg, srep[1], srep[2]))
/ (0.33/1.33 * rake_dpc)
)
return allowed_rip_downtime, allowed_sr_downtime
def calc_builder_dpe(self):
"""Calculate current damage-per-Energy of Rake vs. Shred. Used to
determine whether Rake is worth casting when player stats change upon a
dynamic proc occurring.
Returns:
rake_dpe (float): Average DPE of a Rake cast with current stats.
shred_dpe (float): Average DPE of a Shred cast with current stats.
"""
crit_factor = self.player.calc_crit_multiplier() - 1
crit_mod = crit_factor * self.player.crit_chance
shred_dpc = (1 + self.player.roar_fac) * (
0.5 * (self.player.shred_low + self.player.shred_high) * 1.3
* (1 + crit_mod)
)
rake_dpc = 1.3 * (1 + self.player.roar_fac) * (
self.player.rake_hit * (1 + crit_mod)
+ (self.player.rake_duration / 3) * self.player.rake_tick * (1 + crit_mod * self.player.t10_4p_bonus)
)
return rake_dpc/self.player.rake_cost, shred_dpc/self.player.shred_cost
def bite_over_rip(self, refresh_time, future_refresh=False):
"""Determine whether Rip will tick enough times between the specified
cast time and the end of the fight for it to be worth casting over
Ferocious Bite.
Arguments:
refresh_time (float): Time of potential Rip cast, in seconds.
future_refresh (bool): If True, then refresh_time is interpreted as
a future point in time rather than right now. In this case, a
minimum Energy Bite will be assumed, rather than using the
player's current Energy. Defaults False.
Returns:
should_bite (bool): True if Bite will provide higher DPE than Rip
given the expected number of ticks.
"""
rip_dpe, bite_dpe = self.calc_spender_dpe(
refresh_time, future_refresh=future_refresh
)
return (bite_dpe > rip_dpe)
def calc_spender_dpe(self, refresh_time, future_refresh=False):
"""Calculate damage-per-Energy of Rip vs. Ferocious Bite at the
specified Rip cast time.
Arguments:
refresh_time (float): Time of potential Rip cast, in seconds.
future_refresh (bool): If True, then refresh_time is interpreted as
a future point in time rather than right now. In this case, a
minimum Energy Bite will be assumed, rather than using the
player's current Energy. Defaults False.
Returns:
rip_dpe (float): Average DPE of a Rip cast at refresh_time.
bite_dpe (float): Average DPE of a Bite cast at refresh_time.
"""
if future_refresh:
bite_spend = 35
bite_cost = 35
bite_cp = self.strategy['min_combos_for_bite']
rip_cost = self.player._rip_cost
rip_cp = self.strategy['min_combos_for_rip']
else:
bite_cost = 0 if self.player.omen_proc else self.player.bite_cost
bite_spend = max(
min(self.player.energy, bite_cost + 30),
bite_cost + 10 * self.latency
)
bite_cp = self.player.combo_points
rip_cost = self.player.rip_cost
rip_cp = self.player.combo_points
# Rip DPE calculation
max_rip_dur = self.player.rip_duration + 6 * self.player.shred_glyph
rip_dur = min(max_rip_dur, self.fight_length - refresh_time)
num_rip_ticks = rip_dur // 2 # floored integer division here
crit_factor = self.player.calc_crit_multiplier() - 1
rip_crit_chance = self.player.crit_chance + self.player.rip_crit_bonus
avg_rip_tick = self.player.rip_tick[rip_cp] * 1.3 * (
1 + crit_factor * rip_crit_chance * self.player.primal_gore
)
rip_dpe = avg_rip_tick * num_rip_ticks / rip_cost
# Bite DPE calculation
bite_base_dmg = 0.5 * (
self.player.bite_low[bite_cp] + self.player.bite_high[bite_cp]
)
bite_bonus_dmg = (
(bite_spend - bite_cost) * (9.4 + self.player.attack_power / 410.)
* self.player.bite_multiplier
)
bite_crit_chance = min(
1.0, self.player.crit_chance + self.player.bite_crit_bonus
)
bite_dpe = (bite_base_dmg + bite_bonus_dmg) / bite_spend * (
1 + crit_factor * bite_crit_chance
)
return rip_dpe, bite_dpe
def clip_roar(self, time):
"""Determine whether to clip a currently active Savage Roar in order to
de-sync the Rip and Roar timers.
Arguments:
time (float): Current simulation time in seconds.
Returns:
can_roar (bool): Whether or not to clip Roar now.
"""
if (not self.rip_debuff) or self.block_rip_next:
return False
# Project Rip end time assuming full Glyph of Shred extensions.
max_rip_dur = self.player.rip_duration + 6 * self.player.shred_glyph
rip_end = self.rip_start + max_rip_dur
# If the existing Roar already falls off well after the existing Rip,
# then no need to clip.
if self.roar_end > rip_end + self.strategy['roar_clip_leeway']:
return False
# If the existing Roar already covers us to the end of the fight, then
# no need to clip.
if self.roar_end >= self.fight_length:
return False
# Calculate when Roar would end if we cast it now.
new_roar_dur = (
self.player.roar_durations[self.player.combo_points]
+ 8 * self.player.t8_4p_bonus
)
new_roar_end = time + new_roar_dur
# Clip as soon as we have enough CPs for the new Roar to expire well
# after the current Rip.
return (new_roar_end >= rip_end + self.strategy['min_roar_offset'])
def emergency_roar(self, time):
"""This function handles special logic to handle overriding the
standard Roar offsetting logic above in cases where the Rip and Roar
timers have become so closely synced relative to available Energy/CPs
that an inefficient low-CP Roar clip is required to save both timers.
Specifically, if Rip is currently not applied or is due to fall off
before the current Roar, then the standard logic forbids a Roar clip
and instead recommends building for Rip first. But in cases where there
is simply not enough time to build for Rip before Roar will *also*
expire, then clipping Roar first should be preferable.
Arguments:
time (float): Current simulation time in seconds.
Returns:
emergency_roar_now (bool): Whether or not to execute an emergency
SR cast.
"""
# The emergency logic does not apply if we are in "normal" offsetting
# territory where the current Roar will expire before the current Rip,
# or if we are close enough to end of fight.
if self.roar_end >= self.fight_length:
return False
if (self.rip_debuff and (self.roar_end < self.rip_end)):
return False
if self.block_rip_next:
return False
# Perform an estimate of the earliest we could reasonably cast Rip
# given current Energy/CP and FF/TF timers. Assume that all builders
# will Crit but no natural Omen procs.
min_builders_for_rip = np.ceil(
(self.strategy['min_combos_for_rip']-self.player.combo_points)/2
)
energy_for_rip = (
min_builders_for_rip * self.player.shred_cost
+ self.player.rip_cost
)
ff_available = self.player.faerie_fire_cd < (self.roar_end - time)
gcd_time_for_rip = min_builders_for_rip + 1.0 + ff_available
energy_time_for_rip = 0.1 * (
energy_for_rip - self.player.energy
- (ff_available + self.player.omen_proc) * self.player.shred_cost
- 60. * self.tf_expected_before(time, self.roar_end)
)
min_time_for_rip = max(gcd_time_for_rip, energy_time_for_rip)
# If min_time_for_rip takes us too close to fight end, then don't
# emergency Roar since we'll just be Biting anyway.
if self.bite_over_rip(time + min_time_for_rip, future_refresh=True):
return False
# Perform the emergency Roar if min_time_for_rip exceeds the remaining
# Roar duration in order to prevent the disaster scenario where both
# are down simultaneously.
return (time + min_time_for_rip >= self.roar_end)
def should_bearweave(self, time):
"""Determine whether the player should initiate a bearweave.
Arguments:
time (float): Current simulation time in seconds.
Returns:
can_bearweave (float): Whether or not a a bearweave should be
initiated at the specified time.
"""
rip_refresh_pending = self.rip_refresh_pending
ff_leeway = self.strategy['max_ff_delay']
# First check basic conditions for any type of bearweave, and return
# False if these are not met. All weave sequences involve 2 1.5 second
# shapeshift GCDs (both delayed by latency), 1 Mangle (Bear) cast,
# 1 Faerie Fire cast (either in cat or bear), and 1 Cat Form GCD to
# spend the Omen proc, and therefore take 6.5 seconds + 2 * latency to
# execute.
weave_end = time + 6.5 + 2 * self.latency
can_weave = (
self.strategy['bearweave'] and self.player.cat_form
and (not self.player.omen_proc) and (not self.player.berserk)
and ((not rip_refresh_pending) or (self.rip_end >= weave_end))
)
if can_weave and (not self.strategy['lacerate_prio']):
can_weave = not self.tf_expected_before(time, weave_end)
# Also add an end of fight condition to make sure we can spend down our
# Energy post-bearweave before the encounter ends. Time to spend is
# given by weave_end plus 1 second per 42 Energy that we have at
# weave_end.
if can_weave:
energy_to_dump = self.player.energy + (weave_end - time) * 10
can_weave = (
weave_end + energy_to_dump // 42 < self.fight_length
)
if not can_weave:
return False
# Now we check for conditions that allow for initiating one of two
# "flavors" of bearweaves: either a single-GCD Mangleweave or a two-GCD
# Mangle + Faerie Fire weave. These have different leeway constraints
# due to their differing lengths.
# Start with the simple Mangleweave. Here we FF in Cat Form after
# exiting the weave, so the maximum Energy cap is 65 when shifting back
# into cat (15 for Cat Form GCD, 10 for FF GCD, 10 to spend the Omen).
# The FF cast will happen 4.5 + 2 * latency seconds after initiation.
mangleweave_furor_cap = min(20 * self.player.furor, 65)
mangleweave_energy = mangleweave_furor_cap - 30 - 20 * self.latency
ff_cd = self.player.faerie_fire_cd
can_mangleweave = (
(self.player.energy <= mangleweave_energy)
and (ff_cd >= 4.5 + 2 * self.latency - ff_leeway)
)
# Now check the "Manglefire" sequence. Here we FF in Dire Bear Form
# *before* exiting the weave, so the maximum Energy cap is 75 when
# shifting back into cat (15 for Cat Form GCD and 10 to spend the Omen
# proc).The FF cast will nominally happen 3 + latency seconds after
# initiation, with possible additional small delays to wait for a Maul
# before casting FF.
manglefire_furor_cap = min(20 * self.player.furor, 75)
manglefire_energy = manglefire_furor_cap - 40 - 20 * self.latency
can_manglefire = (
(self.player.energy <= manglefire_energy)
and (ff_cd >= 3.0 + self.latency - ff_leeway)
)
return (can_mangleweave or can_manglefire)
def execute_rotation(self, time):
"""Execute the next player action in the DPS rotation according to the
specified player strategy in the simulation.
Arguments:
time (float): Current simulation time in seconds.
Returns:
damage_done (float): Damage done by the player action.
"""
# If we previously decided to cast GotW, then execute the cast now once
# the input delay is over.
if self.player.ready_to_gift:
self.player.flowershift(time)