-
Notifications
You must be signed in to change notification settings - Fork 9
/
resim.py
4095 lines (3574 loc) · 169 KB
/
resim.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
import math
import os
import re
import sys
import itertools
from data import (
Base,
Blood,
EventType,
GameData,
Mod,
ModType,
NullUpdate,
PlayerData,
TeamData,
Weather,
get_feed_between,
stat_indices,
)
from output import SaveCsv
from rng import Rng
from dataclasses import dataclass
from enum import Enum, unique
from typing import List, Optional
from formulas import (
get_contact_strike_threshold,
get_contact_ball_threshold,
get_hr_threshold,
get_strike_threshold,
get_foul_threshold,
StatRelevantData,
get_swing_ball_threshold,
get_swing_strike_threshold,
get_fly_or_ground_threshold,
get_out_threshold,
get_double_threshold,
get_triple_threshold,
)
from item_gen import ItemRollType, roll_item
@unique
class Csv(Enum):
"""
Tracks the .csv files we can log rolls for in Resim.
"""
STRIKES = "strikes"
FOULS = "fouls"
TRIPLES = "triples"
DOUBLES = "doubles"
QUADRUPLES = "quadruples"
SWING_ON_BALL = "swing-on-ball"
SWING_ON_STRIKE = "swing-on-strike"
CONTACT = "contact"
HR = "hr"
STEAL_ATTEMPT = "steal_attempt"
STEAL_SUCCESS = "steal_success"
OUT = "out"
FLY = "fly"
PARTY = "party"
BIRD_MESSAGE = "bird-message"
CONSUMERS = "consumers"
HITADVANCE = "hitadvance"
FLYOUT = "flyout"
GROUNDOUT = "groundout"
GROUNDOUT_FORMULAS = "groundout_formulas"
EXIT = "exit"
ENTER = "enter"
TRICK_ONE = "trick_one"
TRICK_TWO = "trick_two"
SWEET1 = "sweet1"
SWEET2 = "sweet2"
WEATHERPROC = "weatherproc"
MODPROC = "modproc"
BASE = "base"
INSTINCTS = "instincts"
PSYCHIC = "psychic"
BSYCHIC = "bsychic"
ITEM_CREATION = "item_creation"
class Resim:
def __init__(self, rng, out_file, run_name, raise_on_errors=True, csvs_to_log=[]):
object_cache = {}
self.rng = rng
self.out_file = out_file
self.data = GameData()
self.fetched_days = set()
self.raise_on_errors = raise_on_errors
self.update = NullUpdate()
self.next_update = NullUpdate()
self.is_strike = None
self.strike_roll = None
self.strike_threshold = None
self.strikes = 0
self.max_strikes = 3
self.balls = 0
self.max_balls = 4
self.outs = 0
self.max_outs = 3
self.game_id = None
self.play = None
self.weather = Weather.VOID
self.batter = self.data.get_player(None)
self.pitcher = self.data.get_player(None)
self.batting_team = self.data.get_team(None)
self.pitching_team = self.data.get_team(None)
self.home_team = self.data.get_team(None)
self.away_team = self.data.get_team(None)
self.stadium = self.data.get_stadium(None)
self.pending_attractor = None
self.event = None
self.prev_event = None
if run_name:
os.makedirs("roll_data", exist_ok=True)
run_name = run_name.replace(":", "_")
csvs_to_log = csvs_to_log or list(Csv)
self.csvs = {csv: SaveCsv(run_name, csv.value, object_cache) for csv in Csv if csv in csvs_to_log}
else:
self.csvs = {}
self.roll_log: List[LoggedRoll] = []
def print(self, *args, **kwargs):
if self.out_file is None:
return
print(*args, **kwargs, file=self.out_file)
def error(self, *args, **kwargs):
if not self.out_file:
return
if self.out_file != sys.stdout:
print("Error: ", *args, **kwargs, file=self.out_file)
print("Error: ", *args, **kwargs, file=sys.stderr)
if self.raise_on_errors:
error_string = " ".join(args)
raise RuntimeError(error_string)
def handle(self, event):
self.setup_data(event)
# hardcoding a fix for a data error - jands don't get the overperforming mod from earlbirds
# in chron until after the game ends, but we need it earlier
if self.game_id == "8577919c-4288-4404-bde2-694f5e7a38d1":
jands = self.data.get_team("a37f9158-7f82-46bc-908c-c9e2dda7c33b")
if not jands.has_mod(Mod.OVERPERFORMING):
jands.add_mod(Mod.OVERPERFORMING, ModType.PERMANENT)
jands.last_update_time = self.event["created"]
# another workaround for bad data
if self.game_id == "c608b5db-29ad-4216-a703-8f0627057523":
caleb_novak = self.data.get_player("0eddd056-9d72-4804-bd60-53144b785d5c")
if caleb_novak.has_mod(Mod.ELSEWHERE):
caleb_novak.remove_mod(Mod.ELSEWHERE, ModType.PERMANENT)
caleb_novak.last_update_time = self.event["created"]
# missed a "happy to be home" event 45 secs before the fragment starts
if self.game_id == "ee0066a5-8408-4270-a5d8-8e66abf55d03":
vela = self.data.get_player("4ca52626-58cd-449d-88bb-f6d631588640")
if not vela.has_mod(Mod.OVERPERFORMING):
vela.add_mod(Mod.OVERPERFORMING, ModType.PERMANENT)
vela.remove_mod(Mod.UNDERPERFORMING, ModType.PERMANENT)
# sometimes we start a fragment in the middle of a game and we wanna make sure we have the proper blood type
a_blood_type_overrides = {
"0aa57b7d-d78f-4090-8f0e-9273c285e698": Mod.PSYCHIC,
"d2e75d15-0348-4a2b-88ad-5a9205173494": Mod.PSYCHIC,
"bb5ad5c8-22b7-41a4-83f9-47b8ed8825b2": Mod.LOVE,
"61ac8e12-0c98-4d21-b827-eac77c0b407f": Mod.ACIDIC,
"d18f5735-17f2-40ed-949c-6ccfb69828be": Mod.FIERY,
"ff050ef3-c532-42bb-8c74-551a31784142": Mod.FIERY,
"55b8be59-93ac-4756-8f24-7a0ba0e0499f": Mod.AA,
"5007d0ef-2404-490f-97d7-69b98b08979a": Mod.PSYCHIC,
"2a7247fb-62cd-4f84-9f4e-77a1949bc1fb": Mod.BASE_INSTINCTS,
"bbd0c719-b6f9-45ae-946e-0d674d3811a9": Mod.H20,
"fe105cf7-ff56-42c7-b918-0ee3ab394f58": Mod.ELECTRIC,
"48ad61f1-a231-4061-bb84-331ce891626a": Mod.ZERO,
"b0a8c4c3-eeca-49a7-bf47-771a614bb3f3": Mod.LOVE,
"a0e2ba91-16d5-4f39-9bc8-7ee35042fae0": Mod.AAA,
}
if self.game_id in a_blood_type_overrides:
blood_type = a_blood_type_overrides[self.game_id]
shoe_thieves = self.data.get_team("bfd38797-8404-4b38-8b82-341da28b1f83")
if not shoe_thieves.has_mod(blood_type):
shoe_thieves.add_mod(blood_type, ModType.GAME)
shoe_thieves.last_update_time = self.event["created"]
self.print()
if not self.update and self.play and self.play > 1:
self.print("!!! missing update data")
self.print(
"===== {} {}/{} {}".format(
event["created"],
self.update["id"],
self.update["playCount"],
self.weather.name,
)
)
self.print(f"===== {self.ty.value} {self.desc}")
self.print(f"===== rng pos: {self.rng.get_state_str()}")
# I have no idea why there's an extra roll here, but it works.
if self.game_id == "e1fda957-f4ac-4188-835d-265a67b9585d" and self.play == 145:
self.roll("???")
event_adjustments = {
"2021-03-01T20:22:00.461Z": -1, # fix for missing data
"2021-03-01T21:00:16.006Z": -1, # fix for missing data
"2021-03-02T12:24:43.753Z": 1, # fix for missing data
"2021-03-02T13:25:06.682Z": -1, # fix for missing data
"2021-03-02T14:00:15.843Z": 1,
"2021-04-05T15:23:26.102Z": 1,
"2021-04-12T15:19:56.073Z": -2,
"2021-04-12T15:22:50.866Z": 1,
"2021-04-14T15:08:13.155Z": -1, # fix for missing data
"2021-04-14T17:06:28.047Z": -2, # i don't know
"2021-04-14T19:07:51.129Z": -2, # may be attractor-related?
"2021-04-20T12:00:00.931Z": -1, # item damage at end of game??
"2021-05-10T18:05:08.668Z": 1,
"2021-05-10T20:21:59.360Z": 1,
"2021-05-10T21:29:20.815Z": 1,
"2021-05-10T22:26:11.164Z": 1,
"2021-05-11T00:00:17.142Z": 1,
"2021-05-11T01:00:16.921Z": 1,
"2021-05-12T06:00:17.186Z": 1,
"2021-05-12T12:24:31.667Z": 1,
"2021-05-12T13:01:28.057Z": 1,
"2021-05-12T15:20:57.747Z": 1,
"2021-05-13T08:07:07.199Z": -1,
"2021-05-13T13:03:37.832Z": 1,
"2021-05-13T15:00:17.580Z": -1,
"2021-05-13T16:38:59.820Z": 387, # skipping latesiesta
"2021-05-14T11:21:37.843Z": 1, # instability?
"2021-05-14T13:07:02.411Z": 1,
"2021-05-14T15:17:08.833Z": 1,
"2021-05-17T17:20:09.894Z": 1,
"2021-05-17T23:10:48.902Z": 1, # dp item damage rolls...?
"2021-05-20T04:20:24.586Z": -1, # item damage
"2021-06-14T19:13:49.970Z": 1,
"2021-06-15T08:22:16.606Z": 1,
"2021-06-15Tz20:00:18.367Z": -1,
"2021-06-16T06:22:08.507Z": 1,
"2021-06-16T12:04:04.468Z": 1, # dp item damage?
"2021-06-16T20:00:20.027Z": -1,
"2021-06-17T02:00:04.148Z": -1,
"2021-06-17T19:09:41.707Z": 1,
"2021-06-17T19:09:42.498Z": 1,
"2021-06-17T19:09:45.885Z": 1,
"2021-06-18T07:01:54.628Z": -1,
"2021-06-18T17:01:00.415Z": -1,
"2021-06-18T19:18:22.631Z": -1,
}
to_step = event_adjustments.get(self.event["created"])
if to_step is not None:
self.rng.step(to_step)
time = self.event["created"]
self.print(f"!!! CORRECTION: stepping {to_step} @ {time}")
if self.handle_misc():
return
if self.handle_elsewhere_scattered():
return
if self.ty in [
EventType.RETURN_FROM_ELSEWHERE,
]:
# skipping elsewhere return
return
if self.batter:
self.print(
f"- batter mods: {self.batter.print_mods()} + "
f"{self.batting_team.print_mods()} ({self.batter.name}) "
)
if self.pitcher:
self.print(
f"- pitcher mods: {self.pitcher.print_mods()} + "
f"{self.pitching_team.print_mods()} ({self.pitcher.name})"
)
self.print(f"- stadium mods: {self.stadium.print_mods()} ({self.stadium.nickname})")
if self.handle_batter_up():
return
if self.handle_weather():
return
if self.handle_party():
return
# has to be rolled after party
if self.handle_flooding():
return
if self.handle_polarity():
return
if self.handle_consumers():
return
if self.handle_ballpark():
return
if self.ty == EventType.HIGH_PRESSURE_ON_OFF:
# s14 high pressure proc, not sure when this should interrupt
return
if self.handle_steal():
return
if self.handle_electric():
return
# todo: don't know where this actually is - seems to be before mild at least
if self.pitcher.has_mod(Mod.DEBT_THREE) and not self.batter.has_mod(Mod.COFFEE_PERIL):
debt_roll = self.roll("debt")
if self.ty == EventType.HIT_BY_PITCH:
self.log_roll(
Csv.MODPROC,
"Bonk",
debt_roll,
True,
)
# debt success
return True
else:
self.log_roll(
Csv.MODPROC,
"No Bonk",
debt_roll,
False,
)
if self.handle_bird_ambush():
return
if self.handle_mild():
return
if self.handle_charm():
return
self.is_strike = None
if self.ty in [
EventType.WALK,
EventType.BALL,
EventType.MILD_PITCH,
]:
self.handle_ball()
elif self.ty in [
EventType.FLY_OUT,
EventType.GROUND_OUT,
]:
self.handle_out()
elif self.ty in [
EventType.STRIKEOUT,
EventType.STRIKE,
]:
self.handle_strike()
elif self.ty in [EventType.HOME_RUN]:
self.handle_hr()
elif self.ty in [EventType.HIT]:
self.handle_base_hit()
elif self.ty in [EventType.FOUL_BALL]:
self.handle_foul()
else:
self.print(f"!!! unknown type: {self.ty.value}")
pass
self.handle_batter_reverb()
if self.pending_attractor:
if self.pending_attractor and self.pending_attractor.has_mod(Mod.REDACTED):
self.roll("attractor pitching stars")
self.roll("attractor batting stars")
self.roll("attractor baserunning stars")
self.roll("attractor defense stars")
self.pending_attractor = None
def handle_misc(self):
if (
self.season >= 17
and self.update["gameStartPhase"] < 0
and self.next_update["gameStartPhase"] >= 0
and self.ty
not in [
EventType.ADDED_MOD_FROM_OTHER_MOD,
EventType.REMOVED_MODIFICATION,
EventType.RUNS_SCORED,
]
):
min_roll, max_roll = (0, 0.02) if self.ty == EventType.PRIZE_MATCH else (0.02, 1)
self.roll("prize match", min_roll, max_roll)
PSYCHO_ACOUSTICS_PHASE_BY_SEASON = {
13: 10,
14: 11,
15: 11,
16: 11,
17: 13,
18: 13,
}
psycho_acoustics_phase = PSYCHO_ACOUSTICS_PHASE_BY_SEASON.get(self.season, 13)
if (
self.update["gameStartPhase"] < psycho_acoustics_phase
and self.next_update["gameStartPhase"] >= psycho_acoustics_phase
and self.ty != EventType.ADDED_MOD_FROM_OTHER_MOD
and self.weather
in [
Weather.FEEDBACK,
Weather.REVERB,
]
and self.stadium.has_mod(Mod.PSYCHOACOUSTICS)
):
self.print("away team mods:", self.away_team.print_mods(ModType.PERMANENT))
self.roll("echo team mod")
if self.ty in [
EventType.HOME_FIELD_ADVANTAGE,
EventType.BECOME_TRIPLE_THREAT,
EventType.SOLAR_PANELS_AWAIT,
EventType.SOLAR_PANELS_ACTIVATION,
EventType.EVENT_HORIZON_AWAITS,
EventType.EVENT_HORIZON_ACTIVATION,
EventType.HOMEBODY,
EventType.SUPERYUMMY,
EventType.PERK,
EventType.SHAME_DONOR,
EventType.PSYCHO_ACOUSTICS,
EventType.AMBITIOUS,
EventType.UNAMBITIOUS,
EventType.LATE_TO_THE_PARTY,
EventType.MIDDLING,
EventType.SHAMING_RUN,
EventType.EARLBIRD,
EventType.PRIZE_MATCH,
EventType.A_BLOOD_TYPE,
EventType.COASTING,
EventType.TEAM_RECEIVED_GIFT,
EventType.BLESSING_OR_GIFT_WON,
EventType.PLAYER_SOUL_INCREASED,
]:
if self.ty == EventType.PSYCHO_ACOUSTICS:
self.roll("which mod?")
if self.ty == EventType.A_BLOOD_TYPE:
self.roll("a blood type")
if self.ty == EventType.PRIZE_MATCH:
self.create_item(self.event, ItemRollType.PRIZE, self.prev_event)
# skipping pregame messages
return True
if self.ty in [
EventType.OVER_UNDER,
EventType.UNDER_OVER,
EventType.UNDERSEA,
EventType.ADDED_MOD_FROM_OTHER_MOD,
EventType.REMOVED_MODIFICATION,
EventType.CHANGED_MODIFIER,
EventType.REMOVED_MULTIPLE_MODIFICATIONS_ECHO,
EventType.ADDED_MULTIPLE_MODIFICATIONS_ECHO,
]:
# skipping mod added/removed
return True
if self.ty in [
EventType.BLACK_HOLE,
EventType.SUN2,
EventType.SUN_2_OUTCOME,
EventType.BLACK_HOLE_OUTCOME,
EventType.SUN_SUN_PRESSURE,
]:
if self.ty == EventType.SUN2 and "catches some rays" in self.desc:
self.roll("sun dialed target")
if self.ty == EventType.BLACK_HOLE:
if "is compressed by gamma" in self.desc:
self.roll("unholey target")
# skipping sun 2 / black hole proc
return True
if self.ty in [
EventType.PLAYER_STAT_INCREASE,
EventType.PLAYER_STAT_DECREASE,
EventType.PLAYER_STAT_DECREASE_FROM_SUPERALLERGIC,
]:
if "are Bottom Dwellers" in self.desc:
team = self.data.get_team(self.event["teamTags"][0])
# boost amounts are 0.04 * roll + 0.01, rolled in this order:
# Omniscience, Tenaciousness, Watchfulness, Anticapitalism, Chasiness,
# Shakespearianism, Suppression, Unthwackability, Coldness, Overpowerment, Ruthlessness,
# Base Thirst, Laserlikeness, Ground Friction, Continuation, Indulgence,
# Tragicness, Buoyancy, Thwackability, Moxie, Divinity, Musclitude, Patheticism, Martyrdom, Cinnamon
for player_id in team.lineup:
for _ in range(25):
self.roll("stat")
for player_id in team.rotation:
for _ in range(25):
self.roll("stat")
if "re-congealed differently" in self.desc:
for _ in range(25):
self.roll("stat")
if "is Partying" in self.desc:
# we want to roll this only if this is a *holiday inning* party,
# and we currently have no nice way of seeing that
# we can check the date, but after_party is also a thing.
# and there's at least one occasion where a player has both, and we can't disambiguate
team = self.data.get_team(self.event["teamTags"][0])
if (
not team.has_mod(Mod.PARTY_TIME) and not team.has_mod(Mod.AFTER_PARTY) and self.day < 27
) or self.event["created"] in [
"2021-05-17T21:21:21.303Z",
"2021-05-17T21:22:11.076Z",
]:
# this is a holiday inning party (why 26?)
for _ in range(26):
self.roll("stat")
if "entered the Shadows" in self.desc:
# fax machine dunk
# boost amounts are 0.04 * roll + 0.01, rolled in this order:
# Shakespearianism, Suppression, Unthwackability, Coldness, Overpowerment, Ruthlessness, Tragicness,
# Buoyancy, Thwackability, Moxie, Divinity, Musclitude, Patheticism, Martyrdom,
# Base Thirst, Laserlikeness, Ground Friction, Continuation, Indulgence,
# Omniscience, Tenaciousness, Watchfulness, Anticapitalism, Chasiness, Cinnamon
for _ in range(25):
self.roll("stat")
# skip party/consumer stat change
return True
if self.ty in [
EventType.PLAYER_BORN_FROM_INCINERATION,
EventType.ENTER_HALL_OF_FLAME,
EventType.EXIT_HALL_OF_FLAME,
EventType.PLAYER_HATCHED,
]:
# skipping incineration stuff
return True
if self.ty in [
EventType.PLAYER_REMOVED_FROM_TEAM,
EventType.MODIFICATION_CHANGE,
]:
# skipping echo/static
return True
if self.ty == EventType.INCINERATION and "parent" in self.event["metadata"]:
# incin has two events and one's a subevent so ignore one of them
return True
if self.ty == EventType.PITCHER_CHANGE:
# s skipping pitcher change?
return True
if self.ty in [
EventType.REMOVED_MOD,
EventType.PLAYER_MOVE,
EventType.INVESTIGATION_PROGRESS,
EventType.ENTERING_CRIMESCENE,
EventType.WEATHER_EVENT,
EventType.RUNS_SCORED,
EventType.TUNNEL_FLED_ELSEWHERE,
EventType.TUNNEL_FOUND_NOTHING,
]:
return True
if self.ty == EventType.EXISTING_PLAYER_ADDED_TO_ILB:
if "pulled through the Rift" in self.desc:
# The Second Wyatt Masoning
# The rolls normally assigned to "Let's Go" happen before the Second Wyatt Masoning
if self.desc == "Wyatt Mason was pulled through the Rift.":
for _ in range(12):
self.roll("game start")
self.generate_player()
return True
if self.ty in [
EventType.PLAYER_ADDED_TO_TEAM,
EventType.BIG_DEAL,
EventType.WON_INTERNET_SERIES,
EventType.UNDEFINED_TYPE,
]:
# skip postseason
return True
if self.ty == EventType.POSTSEASON_SPOT:
self.generate_player()
return True
if self.ty in [
EventType.REVERB_ROTATION_SHUFFLE,
EventType.REVERB_FULL_SHUFFLE,
EventType.REVERB_LINEUP_SHUFFLE,
]:
# skip reverb
self.data.fetch_teams(self.event["created"], 30)
return True
if self.ty == EventType.PLAYER_TRADED:
# skip feedback
return True
if self.ty in [EventType.INNING_END]:
# skipping inning outing
if self.update["inning"] == 2:
# so if this *is* a coffee 3s game the pitchers are definitely gonna have the mod
# even if we pulled too early to catch it getting added. so i'm cheating here who cares
# it's also specifically permanent mods, not seasonal mods that may or may not be echoed/received
self.print(
f"home pitcher mods: {self.home_pitcher.print_mods(ModType.PERMANENT)} "
f"({self.home_pitcher.name})"
)
self.print(
f"away pitcher mods: {self.away_pitcher.print_mods(ModType.PERMANENT)} "
f"({self.away_pitcher.name})"
)
if self.home_pitcher.has_mod(Mod.TRIPLE_THREAT, ModType.PERMANENT) or self.weather == Weather.COFFEE_3S:
self.roll("remove home pitcher triple threat")
if self.away_pitcher.has_mod(Mod.TRIPLE_THREAT, ModType.PERMANENT) or self.weather == Weather.COFFEE_3S:
self.roll("remove away pitcher triple threat")
# todo: salmon
return True
if self.ty in [EventType.HALF_INNING]:
# skipping top-of/bottom-of
is_holiday = self.next_update.get("state", {}).get("holidayInning")
# if this was a holiday inning then we already rolled in the block below
if is_holiday:
return True
if self.weather == Weather.SALMON:
self.try_roll_salmon()
if self.next_update["topOfInning"]:
# if this was a holiday inning then we already rolled in the block below
# hm was ratified in the season 18 election
has_hotel_motel = self.stadium.has_mod(Mod.HOTEL_MOTEL) or self.season >= 18
if has_hotel_motel and self.day < 27:
hotel_roll = self.roll("hotel motel")
self.log_roll(Csv.MODPROC, "Notel", hotel_roll, False)
return True
if self.ty == EventType.SALMON_SWIM:
salmon_roll = self.roll("salmon")
self.log_roll(Csv.WEATHERPROC, "Salmon", salmon_roll, True)
# special case for a weird starting point with missing data
last_inning = self.update["inning"]
last_inning_away_score, last_inning_home_score = self.find_start_of_inning_score(self.game_id, last_inning)
current_away_score, current_home_score = (
self.update["awayScore"],
self.update["homeScore"],
)
# todo: figure out order here
if current_away_score != last_inning_away_score:
self.roll("reset runs (away)")
if current_home_score != last_inning_home_score:
self.roll("reset runs (home)")
if self.season >= 15:
self.roll("reset items? idk?")
if self.event["created"] in [
# these two are probably not the same reason
"2021-04-13T01:06:52.165Z",
"2021-04-13T01:28:04.005Z",
]:
self.roll("extra for some reason")
if (
"was restored!" in self.desc
or "were restored!" in self.desc
or "were restored!" in self.desc
or "was repaired." in self.desc
or "were repaired." in self.desc
):
self.roll("restore item??")
self.roll("restore item??")
self.roll("restore item??")
if self.stadium.has_mod(Mod.SALMON_CANNONS):
self.roll("salmon cannons")
if "caught in the bind!" in self.desc:
self.roll("salmon cannons player")
has_undertaker = False
for player_id in self.away_team.lineup + self.away_team.rotation:
player = self.data.get_player(player_id)
if player.has_mod(Mod.UNDERTAKER) and not player.has_mod(Mod.ELSEWHERE):
has_undertaker = True
break
if has_undertaker:
self.roll("undertaker")
self.roll("undertaker")
return True
if self.ty == EventType.HOLIDAY_INNING:
if self.weather == Weather.SALMON:
self.try_roll_salmon(holiday_inning=True)
hotel_roll = self.roll("hotel motel") # success
self.log_roll(Csv.MODPROC, "Hotel", hotel_roll, True)
return True
if self.ty in [
EventType.GAME_END,
EventType.ADDED_MOD,
EventType.REMOVED_MOD,
EventType.MOD_EXPIRES,
EventType.FINAL_STANDINGS,
EventType.TEAM_WAS_SHAMED,
EventType.TEAM_DID_SHAME,
EventType.ELIMINATED_FROM_POSTSEASON,
EventType.POSTSEASON_ADVANCE,
EventType.HYPE_BUILT,
EventType.PRACTICING_MODERATION,
EventType.WIN_COLLECTED_REGULAR,
EventType.WIN_COLLECTED_POSTSEASON,
EventType.GAME_OVER,
EventType.BALLOONS_INFLATED,
]:
# skipping game end
if self.ty == EventType.GAME_END and self.weather.is_coffee():
# end of coffee game redaction
rosters = (
self.home_team.lineup + self.home_team.rotation + self.away_team.lineup + self.away_team.rotation
)
for player_id in rosters:
player = self.data.get_player(player_id)
if player.has_mod(Mod.COFFEE_PERIL) and not player.has_mod(Mod.FORCE):
self.roll(f"redaction ({player.name})")
return True
if self.ty in [EventType.LETS_GO]:
# game start - probably like, postseason weather gen
if self.event["day"] >= 99:
self.roll("game start")
if self.event["day"] != 98 and (
# These rolls happen before the Second Wyatt Masoning
self.event["season"] != 13
or self.event["day"] != 72
):
# *why*
self.roll("game start")
# todo: figure out the real logic here, i'm sure there's some
extra_start_rolls = {
"e07d8602-ec51-4ef6-be20-4a07da6b457e": 1,
"3c1b4d10-78af-4b8e-a9f5-e6ea2d50e5c4": 1,
"196f195c-f8b2-44e9-b117-a7a46de390cd": 1,
"502d6a06-1975-4c70-94d6-bdf9e31aaec6": 1,
"2dff1e11-c2b9-4423-9930-6bb96d1a72d7": 1,
"c09fbaf1-c068-45a5-b644-e481f18be0bd": 216, # ...earlsiesta reading???
"94785708-7b40-47b7-a258-9ce10a157395": 9, # earlsiesta reading
"e39803d0-add7-43cb-b472-04f04e4b0935": 1,
"3ff91111-7862-442e-aa59-c338871c63fe": 2,
"1514e79b-e14b-45e0-aada-dad2ba4d753d": 1,
"a327e425-aaf4-4199-8292-bba0ec4a226a": 2,
"d03ad239-25ee-41bf-a1d3-6e087f302171": 1,
"b2bb8e5c-358f-448b-bbf3-7c8c33148107": 1,
"bf35c2a3-61f3-49e2-b693-9e7ead9a2f8e": 1,
"5b9dcdb4-db02-400a-9d6d-55713939332f": 1,
"9ded2295-da80-4395-9f70-92f5bdae38a1": 1,
"893edab1-9100-4164-a72c-3d2ace026f8a": 1,
"adcbbf30-de0d-4df2-ad93-7d91d6daaa6a": 1,
"cb7dd13c-bf04-4bb1-a53a-cf478bc2e26c": 2,
"2fabc7aa-8c17-4b8b-aa10-bb1a7af90d82": 1,
"eb441ce0-6768-4463-a997-817381b176fe": 1,
"0633f858-d1cb-4ba2-a04b-6b035767bed5": 1,
"e2a7f575-b165-485f-b1c9-39a3c8edacbf": 1,
"883b56f8-d470-4a9f-b709-7647ffcac4cc": 1,
"f39fc061-5485-4140-9ec0-92d716c1fa67": 1,
"ca53fd25-ed06-4d6d-b0ae-80d0a1b58ed1": 2,
"a581bfd7-725f-49a3-83ff-dc98806ef262": 1,
"0cde3960-b7dd-4df2-b469-5274be158563": 1,
"8a90bd4b-9f51-4c2e-9c24-882dabdfe932": 1,
"0a79fdbb-73ca-4b8e-8696-10776d75cd0f": 1,
"42fb4a2e-c471-4f2c-96b4-e0319e3f9aa0": 1,
"a2d9e7c4-9a4e-4573-ac13-90f1fa64c13d": 0,
"662e2383-1b5e-4a46-9598-da4a574f58ae": 1,
"c27b5393-4910-4a8c-a6a5-93cce32fe30a": 1,
"bd9c9d74-39c8-4195-8777-06b49c2f912a": 1,
"0aa716c9-9745-4606-bbdc-34d4b1845f0c": 1,
"1ae97925-6db8-47ad-8216-fc872b12a7dc": 2,
"957acc90-52f2-4c07-bac2-a92696acea37": 220, # earlsiesta reading
"3e35defb-51c0-48ad-87bc-3a36c63b951c": 1,
"be04f619-f595-46c5-8b8c-87befc1418fa": 221, # earlsiesta reading
"9b46f551-1e5c-4482-8ac1-81d4e36df31a": 1,
"e7387f25-31f7-4047-83b7-7770f166a6ef": 1,
"f628e63b-dcc2-45bc-b16a-ff053d4ece0b": 1,
"72b41d5c-7e97-4ee1-b5a3-5a01aaf5f043": 2,
"54055971-2287-4f34-abb1-0a21aeb1a994": 1,
"de996e83-6584-4312-8e2b-613e4c8bb0ee": 1,
"78838e9a-16b2-4733-8194-c629eb57d803": 1,
"4ed7ce17-f47d-41ce-aad3-1089ab54bd2c": 2,
"9a5b1658-0924-43ef-a417-e7de8076a57c": 1,
"e1c383ab-efc0-49ad-91e2-3d29cca47a90": 1,
"b62e2bd0-333e-4462-a84d-5aecabd0c1bc": 1,
"45f65a7f-ed58-4482-8139-92d2e2ef7bfa": 1,
"9291e5ce-a49f-44dc-9bb4-747bc783c351": 1,
"33415dda-9822-4bfd-b943-b8f7c4fb3af4": 1,
"0b82745a-e797-4256-9ce7-9868253a9e4b": 1,
"4f8ce860-fb5e-4cff-8111-d687fa438876": 2,
"e0880bb0-60b2-4778-a209-977bd4b23ab6": 1,
"a12bbed2-68b4-4db0-b408-6727b28743c3": 1,
"fa320c4c-ceab-48a5-b3a1-8a064977d974": 217, # earlsiesta reading
"426196ac-8600-4929-af6f-d750517eec87": 1,
"0486ea3c-9a94-4fdc-82cd-78feca6e00d7": 1,
"9485f77d-3c78-40dc-a6ba-d56e231a5902": 1,
"3dfdcc5d-f3f5-49ae-a826-451843e1177b": 1,
"48c355e1-b656-4afb-b05b-17e0e9b13f07": 1,
"2a712340-9a47-430a-8645-5ab61a4fa6da": 2,
"2d4465c0-60e4-42e3-a630-712d9bcfb253": 1,
"9df98fb5-e015-497b-bc47-6a6701a5e69a": 1,
"3954b1cc-01bc-48a5-b2d1-936ae28997db": 1,
"30f866e2-af0d-4609-8973-19d1c9be96d2": 1,
"75961c1b-d2e1-4ed3-bd44-0a2d49ad9962": 1,
"2c64f251-fc1f-4c38-bd10-af37f39de0b6": 1,
"3445c14f-87ee-49a0-8fa0-53bcb940bc02": 2,
"178842c6-56f6-42c2-b4b1-a729c6e7ca9a": 2,
"41a1a650-e904-4680-931e-32668eacf05c": 1,
"87734e6d-ef2f-4fd8-b500-07a28be7460d": 1,
"df4179c0-2f9e-404d-b0bf-533d9dba8708": 1,
"b02f8c3e-af15-4b9c-ad9e-9d7b4e89f668": 1,
"d8804067-5e97-4021-8751-16522cf441d2": 1,
"ee4e79c5-0c7e-4b39-842a-b40aa789eb40": 1,
"431c5898-80ef-4ab3-9b39-a613cf19cb40": 1,
"965970f3-50c5-4505-a4ac-edd2d363ee46": 13,
"6413415b-5d99-4d0b-bf4a-78b78ec9a189": 13,
"381dece4-f588-4ce0-8888-10b18ba5569c": 1,
"c4e1ea58-db25-4718-97a0-579358db09f5": 1,
"357c47f2-ab96-4415-92b2-a9ef4dd2fe7d": 10,
"7521166b-c4fc-4304-a1d8-d43df64eb6e2": 1,
"45056362-eb46-4241-a42d-f2854bc99f2d": 230, # earlsiesta
"60fd2130-3119-4745-9161-6bd5327f4195": 11,
"f914bf59-da58-4446-a3c4-37b0ab5afb10": 1,
"ca709402-4d02-4cc4-ba3f-2fcc58a6bbc2": 10,
"7680cb25-e5ca-4f2d-b145-37fffdcc3fed": 2,
"9015bf17-2df6-4411-9acc-09fcfeb01b5f": 1,
"16c44f72-f840-46e3-820f-36047dc1634c": 1,
"42c2f144-11d6-4bb0-90a2-50f299eca0d2": 1,
"c6251d2b-7afe-459b-86cb-a7a19b5393af": 1,
"a12b9078-e542-4a8f-9945-f6277df5aa07": 1,
"4ef2e44d-eeb9-409b-9045-642fe7c0ee59": 1,
"4bf61772-c2df-4686-9faa-f2a63eab3315": 1,
"468165ed-e121-4b74-b3a0-1296c2be96df": 1,
"516c3340-397f-4286-b602-56ee1768718b": 1,
"57d6b2e4-16a3-4003-819c-3e9ccc782f1c": 1,
"00bb09d0-6ecc-4689-8d34-9b0b08d909d2": 1,
"ca97b3dc-37b3-4869-844d-c99bc39a2dbc": 1,
"668acb2d-5ae4-464e-b0c2-e4a9e23ab772": 1,
"a71c3990-83ad-47d3-a1e8-4356f033d69e": 3,
"2256478e-b398-4490-9094-7a26ece0a401": 1,
"f8d36399-62dd-4ace-b260-4eee3d35bf1c": 1,
"3277b36c-31a4-4149-9830-17cccbe9369c": 1,
"ad03ae0e-5ab1-48f2-8888-c10fbea85945": 1,
"f65e2d08-c9e8-42a5-8b85-0c92f5f3bd07": 2,
"c5d9a884-9cfa-450a-a091-cb467207de12": 10,
"d56e0ad0-77fe-43fa-853d-52cf46b2ef79": 1,
"721f52d0-742a-4fdd-9f02-4693062b8d81": 2,
"32b31491-a4ba-4808-8518-17e89938bc77": 1,
"c38db87d-bcc1-463f-b7dc-0a47b769ac22": 2,
"9e2570e5-2a82-4be6-96d8-a49240c12be6": 1,
"a95681ab-d4fd-4bf7-b94d-3b23622405ee": 10,
"f95f63ac-a16e-4530-8661-27a8a0a35e13": 2,
}
for _ in range(extra_start_rolls.get(self.game_id, 0)):
self.roll(f"align start {self.game_id} day {self.day}")
return True
if self.ty in [EventType.PLAY_BALL]:
# play ball (already handled above but we want to fetch a tiny tick later)
if self.event["day"] not in self.fetched_days:
self.fetched_days.add(self.event["day"])
timestamp = self.event["created"]
self.data.fetch_league_data(timestamp, 20)
for team_id in [self.next_update["homeTeam"], self.next_update["awayTeam"]]:
team = self.data.get_team(team_id)
prev_pitcher_id = team.rotation[(team.rotation_slot - 2) % len(team.rotation)]
prev_pitcher = self.data.get_player(prev_pitcher_id)
if prev_pitcher.has_mod(Mod.SHELLED):
# don't roll immediately after sixpack receives shelled, for some reason that doesn't trigger it
# and not in postseason either
if self.game_id != "31ae7c75-b30a-49b1-bddd-b40e3ebd518e" and self.day < 99:
self.roll("extra roll for shelled pitcher")
return True
if self.ty in [EventType.FLAG_PLANTED]:
for _ in range(11):
self.roll("flag planted")
return True
if self.ty in [EventType.RENOVATION_BUILT]:
if "% more " in self.desc or "% less " in self.desc:
self.roll("stat change")
return True
if self.ty == EventType.TAROT_READING:
return True
if self.ty == EventType.LOVERS_LINEUP_OPTIMIZED:
return True
if self.ty in [EventType.EMERGENCY_ALERT, EventType.BIG_DEAL]:
if "NEW CHALLENGERS SURFACE" in self.desc:
# might be placing teams into divisions? divine favor? idk
self.roll("breach team stuff")
self.roll("breach team stuff")
self.roll("breach team stuff")
self.roll("breach team stuff")
self.roll("breach team stuff")
self.roll("breach team stuff")
self.roll("breach team stuff")
self.roll("breach team stuff")
self.roll("breach team stuff")
self.roll("breach team stuff")
for i in range(3): # worms-mechs-georgias
for j in range(9 + 5 + 11): # lineup+rotation+shadows
for k in range(2 + 26 + 6): # name+stats+interview
# todo: label this nicer, but these *do* line up as expected
self.roll(f"breach team player gen (team {i} player {j})")
# i have no clue what this is but it makes day 73 line up.
for _ in range(339):
self.roll("something else")
return True
if self.ty == EventType.TEAM_JOINED_LEAGUE:
return True
if self.ty in [
EventType.ITEM_BREAKS,
EventType.ITEM_DAMAGE,
EventType.PLAYER_GAINED_ITEM,
EventType.PLAYER_LOST_ITEM,
EventType.BROKEN_ITEM_REPAIRED,
EventType.DAMAGED_ITEM_REPAIRED,
EventType.TUNNEL_STOLE_ITEM,
]:
if self.ty == EventType.PLAYER_GAINED_ITEM and "gained the Prized" in self.desc:
# prize match reward
self.roll("prize target")
if self.ty == EventType.PLAYER_GAINED_ITEM and "The Community Chest Opens" in self.desc:
self.create_item(self.event, ItemRollType.CHEST, self.prev_event)
return True
if self.ty == EventType.PLAYER_SWAP:
return True
if self.ty in [EventType.PLAYER_HIDDEN_STAT_INCREASE, EventType.PLAYER_HIDDEN_STAT_DECREASE]:
return True
if self.ty == EventType.WEATHER_CHANGE:
return True
if self.ty == EventType.COMMUNITY_CHEST_GAME_EVENT:
# It looks like before season 18 there are 12 rolls after all of the items are created
# regardless of the number of COMMUNITY_CHEST_GAME_EVENTs,
# except the one at 2021-04-20T21:43:13.835Z, which has 0.
# After that, it's apparently 1 per event.
chests = {
"2021-04-22T06:15:48.986Z": 12,
"2021-04-23T14:06:46.795Z": 12,
}
time = self.event["created"]
to_step = chests.get(time)
if to_step:
self.print(f"!!! stepping {to_step} @ {time} for Community Chest")
self.rng.step(to_step)
elif self.season >= 17:
self.roll("?????")
# todo: properly handle the item changes
if self.event["created"] == "2021-05-11T16:05:03.662Z":
steph_weeks = self.data.get_player("18f45a1b-76eb-4b59-a275-c64cf62afce0")
steph_weeks.add_mod(Mod.CAREFUL, ModType.ITEM)
steph_weeks.last_update_time = self.event["created"]
if self.event["created"] == "2021-05-18T13:07:33.068Z":
aldon_cashmoney_ii = self.data.get_player("194a78fd-3aa7-4356-8ba0-b9fdcbc0ea85")
aldon_cashmoney_ii.add_mod(Mod.CAREFUL, ModType.ITEM)
aldon_cashmoney_ii.last_update_time = self.event["created"]
return True
if self.ty == EventType.BALLPARK_MOD_RATIFIED:
return True
def handle_polarity(self):
if self.weather.is_polarity():
# polarity +/-
polarity_roll = self.roll("polarity")
if self.ty == EventType.POLARITY_SHIFT:
self.log_roll(Csv.WEATHERPROC, "Switch", polarity_roll, True)
return True
else:
self.log_roll(Csv.WEATHERPROC, "NoSwitch", polarity_roll, False)
def handle_bird_ambush(self):
if self.weather == Weather.BIRDS: