-
Notifications
You must be signed in to change notification settings - Fork 5
/
main.py
1139 lines (979 loc) · 43.8 KB
/
main.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
# Libraries and Core Files
import logging
import random
import sys
import argparse
# This needs to be before the other imports in case they log things when imported
import log_init
import area.baaj
import area.besaid
import area.boats
import area.chocobos
import area.djose
import area.dream_zan
import area.gagazet
import area.guadosalam
import area.home
import area.kilika
import area.luca
import area.mac_temple
import area.mac_woods
import area.miihen
import area.moonflow
import area.mrr
from area.mrr_skip import skip_prep, attempt_skip, advance_to_aftermath
import area.ne_armor
import area.rescue_yuna
import area.sin
import area.thunder_plains
import area.zanarkand
import battle.boss
import battle.main
import blitz
import config
import load_game
import logs
import memory.main
import nemesis.advanced_farm
import nemesis.arena_battles
import nemesis.arena_prep
import nemesis.changes
import pathing
import reset
import rng_track
import save_sphere
import screen
import vars
import xbox
from gamestate import game
from image_to_text import maybe_show_image
import manip_planning.rng
import manip_planning.ammes
import manip_planning.baaj_to_tros
# This sets up console and file logging (should only be called once)
log_init.initialize_logging()
logger = logging.getLogger(__name__)
FFXC = xbox.controller_handle()
truerng = False
def configuration_setup():
game_vars = vars.vars_handle()
# Open the config file and parse game configuration
# This may overwrite configuration above
config_data = config.open_config()
# Argument parsing
parser = argparse.ArgumentParser()
parser.add_argument("-seed")
parser.add_argument("-state")
parser.add_argument("-step")
parser.add_argument("-train_blitz")
parser.add_argument("-godrng")
args = parser.parse_args()
global truerng
# gamestate
try:
# logger.warning(args)
logger.info(f"Twitch states passed forward: {args.state}, {args.step}")
if args.state is not None or args.step is not None:
logger.warning(
f"Loading in variables from Twitch, {args.state}, {args.step}"
)
game.state = args.state
game.step = int(args.step)
else:
game.state = config_data.get("gamestate", "none")
game.step = config_data.get("step_counter", 1)
except Exception:
logger.warning("Failure, could not load variables from Twitch")
game.state = "VAR_ERROR"
game.step = 999
if args.train_blitz is not None:
game_vars.set_loop_blitz(True)
logger.warning("Training Blitzball, may reset after Blitzball wins.")
if args.seed is not None:
logger.debug(f"Seed passed from Twitch: {args.seed}")
twitch_seed = int(args.seed)
game_vars.rng_seed_num_set(twitch_seed)
game_length = "Seed set via Twitch chat"
if args.godrng is not None:
game_vars.activate_god_rng()
elif game.state != "none": # Loading a save file, no RNG manip here
game_vars.rng_seed_num_set(255)
game_length = "Loading mid point for testing."
elif game_vars.rng_mode() == "set":
game_length = f"Full Run, set seed: [{game_vars.rng_seed_num()}]"
elif game_vars.rng_mode() == "preferred":
game_vars.rng_seed_num_set(random.choice(game_vars.rng_preferred_array()))
game_length = f"Full Run, favored seed: {game_vars.rng_seed_num()}"
elif game_vars.rng_mode()=="truerng":
truerng = True
# Full run starting from New Game, random seed
else:
game_vars.rng_seed_num_set(random.choice(range(256)))
# Current WR is on seed 160 for both any% and CSR%
game_length = f"Full Run, random seed: {game_vars.rng_seed_num()}"
logger.info(f"Game type will be: {game_length}")
if game_vars.get_battle_speedup():
logger.warning(
"THIS RUN IS USING AUTOMATIC 4X BATTLE SPEEDUP. ONLY USE FOR TESTING."
)
def memory_setup():
# Initiate memory reading, after we know the game is open.
while not memory.main.start():
pass
# Main
if memory.main.get_map not in [23, 348, 349]:
reset.reset_to_main_menu()
logger.info("Game start screen")
def rng_seed_setup():
game_vars = vars.vars_handle()
# Using Rossy's FFX.exe fix,
# this allows us to choose the RNG seed we want. From 0-255
if game_vars.game_is_patched():
memory.main.set_rng_seed(game_vars.rng_seed_num())
rng_seed = memory.main.rng_seed()
logger.info(f"RNG Seed: {rng_seed}")
if game.state == "none":
# record the RNG seed on full runs.
logs.next_stats(rng_seed)
logs.write_stats("RNG seed:")
logs.write_stats(rng_seed)
def load_game_state():
from json_ai_files.write_seed import write_state_step
# loading from a save file
write_state_step(state=game.state, step=game.step)
load_game.load_into_game(gamestate=game.state, step_counter=game.step)
game.start_time = logs.time_stamp()
def maybe_create_save(save_num: int):
memory.main.await_control()
memory.main.wait_frames(6)
game_vars = vars.vars_handle()
if game_vars.create_saves():
save_sphere.touch_and_save(
save_num=save_num, game_state=game.state, step_count=game.step
)
def perform_TAS():
# Force looping on Blitzball only.
if game.state == "Luca" and game.step == 3:
only_play_blitz = True
logger.warning("Who's ready to play some Blitzball?")
else:
only_play_blitz = False
game_vars = vars.vars_handle()
# Original seed for when looping
rng_seed_orig = game_vars.rng_seed_num()
blitz_loops = 0
max_loops = 12 # TODO: Move into config.yaml?
seed_found = False
while game.state != "End":
try:
if game_vars.rng_seed_num() >= 256:
game.state = "End"
# Start of the game, start of Dream Zanarkand section
if game.state == "none" and game.step == 1:
from json_ai_files.write_seed import write_new_game
write_new_game()
logger.info("New Game 1 function initiated.")
area.dream_zan.new_game(game.state)
logger.info("New Game 1 function complete.")
game_vars.set_csr(True)
logger.info("Variables initialized.")
game.state = "DreamZan"
game.step = 1
if game.state == "DreamZan":
if game.step == 1:
memory.main.wait_frames(30 * 0.5)
logger.info("New Game 2 function initiated.")
maybe_show_image(filename="images/laugh.jpg")
area.dream_zan.new_game_2()
game.start_time = logs.time_stamp()
logs.write_stats("Start time:")
logs.write_stats(str(game.start_time))
# reset reference timestamp so that log output is synced to run time
log_init.reset_logging_time_reference()
logger.info("Timer starts now.")
area.dream_zan.listen_story()
# Find rng seed from memory
rng_seed = manip_planning.rng.get_seed()
if rng_seed != "Err_seed_not_found":
game_vars.set_confirmed_seed(rng_seed)
else:
logging.error(f"Unable to derive seed")
seed_found = True
# Calculate manips for Sinscales and Ammes
tidus_sinspawn_attacks, tidus_potion, tidus_spiral_cut_turn = manip_planning.ammes.plan_ammes()
logger.debug(f"Tidus Sinspawn Attacks: {tidus_sinspawn_attacks}")
logger.debug(f"Tidus Potion: {tidus_potion}")
logger.debug(f"Spiral Cut Turn: {tidus_spiral_cut_turn}")
# game.state, game.step = reset.mid_run_reset()
# Start of the game, up through the start of Sinspawn Ammes fight
if truerng:
area.dream_zan.ammes_battle_truerng()
else:
area.dream_zan.ammes_battle(tidus_total_attacks=tidus_sinspawn_attacks, tidus_potion=tidus_potion)
game.step = 2
if game.step == 2:
if truerng:
battle.boss.ammes_truerng()
else:
battle.boss.ammes(spiral_cut_turn=tidus_spiral_cut_turn)
game.step = 3
if game.step == 3:
klikk_steals, tanker_sinscale_kill = manip_planning.baaj_to_tros.plan_klikk_steals()
logger.debug(f"Steals: {klikk_steals}")
logger.debug(f"Tanker Sinscale Kill: {tanker_sinscale_kill}")
if truerng:
area.dream_zan.after_ammes_truerng()
else:
strats = area.dream_zan.after_ammes(tanker_sinscale_kill=tanker_sinscale_kill,
klikk_steals=klikk_steals)
# Sin drops us near Baaj temple.
game.state = "Baaj"
game.step = 1
maybe_create_save(save_num=20)
if game.state == "Baaj":
if game.step == 1:
logger.info("Starting Baaj temple section")
# klikk_steals = 4
# strats = manip_planning.baaj_to_tros.plan_manips(klikk_steals=klikk_steals)
if truerng:
area.baaj.entrance_truerng()
else:
area.baaj.entrance(sahagin_b_first=strats["sahagin_b_first"], geos_potion=strats["geos_potion"],
geos_attacks=strats["geos_attacks"])
game.step = 2
if game.step == 2:
area.baaj.baaj_puzzle()
game.step = 3
if game.step == 3:
if truerng:
area.baaj.klikk_fight_truerng()
else:
area.baaj.klikk_fight(tidus_potion_klikk=strats["tidus_potion_klikk"],
tidus_potion_turn=strats["tidus_potion_turn"],
rikku_potion_klikk=strats["rikku_potion_klikk"],
klikk_steals=klikk_steals)
game.step = 4
maybe_create_save(save_num=21)
if game.step == 4:
# Klikk fight done. Now to wait for the Al Bhed ship.
logger.info("Al Bhed boat part 1")
area.baaj.ab_boat_1()
game.step = 5
if game.step == 5:
if truerng:
area.baaj.ab_swimming_1_truerng()
else:
rikku_attacks_left = area.baaj.ab_swimming_1(chain_encounter_strat=strats["chain_encounter_strat"])
game.step = 6
if game.step == 6:
logger.info("Underwater Airship section")
if truerng:
area.baaj.ab_swimming_2_truerng()
else:
area.baaj.ab_swimming_2(ruins_encounter_strat=strats["ruins_encounter_strat"])
game.state = "Besaid"
game.step = 1
if game.state == "Besaid":
if game.step == 1:
area.besaid.beach(lagoon_strats=strats["lagoon_strats"])
game.step = 2
# maybe_create_save(save_num=22)
if game.step == 2:
area.besaid.trials()
game.step = 3
maybe_create_save(save_num=79)
if game.step == 3:
kim_success = area.besaid.leaving()
if kim_success:
game.state = "Boat1"
game.step = 1
else:
game.state, game.step = reset.mid_run_reset()
if game.state == "Boat1":
area.boats.ss_liki()
area.kilika.arrival()
game.state = "Kilika"
maybe_create_save(save_num=23)
if game.state == "Kilika":
if game.step == 1:
area.kilika.forest_1()
game.step = 3
if game.step == 3:
area.kilika.trials()
area.kilika.trials_end()
game.step = 4
if game.step == 4:
area.kilika.forest_3()
game.step = 5
if game.step == 5:
game.step = 1
game.state = "Boat2"
if game.state == "Boat2":
area.boats.ss_winno()
game.state = "Boat3"
if game.state == "Boat3":
area.boats.ss_winno_2()
game.state = "Luca"
maybe_create_save(save_num=81)
if game.state == "Luca":
if game.step == 1:
area.luca.arrival()
game.step = 2
if game.step == 2:
end_time = logs.time_stamp()
total_time = end_time - game.start_time
logger.info(f"Pre-Blitz time: {total_time}")
logs.write_stats("Pre Blitz time:")
logs.write_stats(total_time)
game.step = 3
maybe_create_save(save_num=24)
if game.step == 3:
area.luca.blitz_start()
game.step = 4
if game.step == 4:
blitz_threshold = 410
logger.info("----- Blitz Start")
force_blitz_win = game_vars.get_force_blitz_win()
blitz_duration = blitz.blitz_main(force_blitz_win)
logger.info("----- Blitz End")
if not game_vars.csr():
xbox.await_save()
if only_play_blitz:
logger.info("------------------------")
logger.info("- Need more Blitzball! -")
logger.info("------------------------")
game.state, game.step = reset.mid_run_reset()
load_game.load_into_game(gamestate="Luca", step_counter=3)
game.step = 3
game.state = "Luca"
elif game_vars.loop_blitz() and blitz_duration < blitz_threshold:
logger.manip("--------------")
logger.manip(
"Good Blitz, worth completing. Duration in seconds:"
)
logger.manip(blitz_duration)
logger.manip("--------------")
game.step = 5
elif game_vars.loop_blitz() and blitz_loops < max_loops:
FFXC.set_neutral()
logger.info("-------------")
logger.info(
"- Resetting: Blitz time: {blitz_duration} seconds."
)
logger.info("-------------")
screen.await_turn()
game.state, game.step = reset.mid_run_reset()
blitz_loops += 1
elif game_vars.blitz_loss_reset() and not game_vars.get_blitz_win():
FFXC.set_neutral()
logger.info("------------------------------")
logger.info("- Resetting - Lost Blitzball -")
logger.info("------------------------------")
screen.await_turn()
game.state, game.step = reset.mid_run_reset()
else:
logger.info("--------------")
logger.info("- Post-Blitz -")
logger.info("--------------")
game.step = 5
if game.step == 5:
area.luca.after_blitz()
game.step = 1
game.state = "Miihen"
maybe_create_save(save_num=25)
# Just to make sure we set this variable somewhere.
if game.state == "Miihen":
return_array = [False, 0, False, False]
if game.step == 1:
return_array = area.miihen.arrival()
if return_array[2] is False:
game.state, game.step = reset.mid_run_reset()
return_array = area.miihen.arrival_2(
return_array[0], return_array[1]
)
if return_array[2] is False:
game.state, game.step = reset.mid_run_reset()
area.miihen.mid_point()
logger.info("End of Mi'ihen mid point section.")
game.step = 2
maybe_create_save(save_num=26)
if game.step == 2:
return_val = area.miihen.low_road(return_array[0], return_array[1])
if return_val is False:
reset.reset_to_main_menu()
area.dream_zan.new_game(gamestate="reload_autosave")
load_game.load_save_num(0)
else:
# Report duration at the end of Mi'ihen section for all runs.
end_time = logs.time_stamp()
total_time = end_time - game.start_time
logger.info(f"Mi'ihen End timer is: {total_time}")
logs.write_stats("Miihen End time:")
logs.write_stats(total_time)
game.state = "MRR"
game.step = 1
if game.state == "MRR":
if game.step == 1:
if area.mrr.arrival() == 1: # Perform section before Terra skip attempt.
game_vars.mrr_skip_set(True)
if not game_vars.csr():
#skip_prep()
if attempt_skip(): # i.e. if this step is successful
if advance_to_aftermath(): # i.e. if this step is successful
game.step = 4 # There is no 3 since Terra Skip found.
else:
game.step = 2
else:
reset.reset_to_main_menu()
area.dream_zan.new_game(gamestate="reload_autosave")
load_game.load_save_num(0)
# Do not change game.state or game.step. Will restart this section.
if game.step == 2:
# These three steps are all performed on the same map.
# i.e. they reload to the same autosave.
skip_prep()
if attempt_skip(): # i.e. if this step is successful
if advance_to_aftermath(): # i.e. if this step is successful
game.step = 4 # There is no 3 since Terra Skip found.
# Cathall for all the Else statements
if game.step == 2:
reset.reset_to_main_menu()
area.dream_zan.new_game(gamestate="reload_autosave")
load_game.load_save_num(0)
# Do not change game.state or game.step. Will restart this section.
'''
if result == 1:
game.step = 4
elif result == 2:
game.state, game.step = reset.mid_run_reset()
else:
game.step = 2
maybe_create_save(save_num=27)
'''
if game.step == 12:
# Formerly step 2, this was the section leading up to battle site.
area.mrr.main_path()
if memory.main.game_over():
game.state = "game_over_error"
game.step = 3
maybe_create_save(save_num=88)
if game.step == 13:
# Formerly step 3, this was the entire battle site logic.
area.mrr.battle_site()
game.step = 4
if game.step == 4:
area.mrr.aftermath()
end_time = logs.time_stamp()
total_time = end_time - game.start_time
logger.info(f"End of Battle Site timer is: {total_time}")
logs.write_stats("Djose-Start time:")
logs.write_stats(total_time)
game.state = "Djose"
game.step = 1
maybe_create_save(save_num=28)
if game.state == "Djose":
if game.step == 1:
area.djose.path()
game.step = 2
if game.step == 2:
area.djose.temple()
area.djose.trials()
game.step = 3
if game_vars.create_saves():
while not pathing.set_movement([66, -227]):
pass
maybe_create_save(save_num=29)
if game.step == 3:
area.djose.leaving_djose()
game.step = 1
game.state = "Moonflow"
if game.state == "Moonflow":
if game.step == 1:
area.moonflow.arrival()
area.moonflow.south_bank()
game.step = 2
maybe_create_save(save_num=30)
if game.step == 2:
area.moonflow.north_bank()
game.step = 1
game.state = "Guadosalam"
if game_vars.create_saves():
while memory.main.get_map() != 243:
FFXC.set_movement(1, 1)
FFXC.set_neutral()
memory.main.await_control()
maybe_create_save(save_num=31)
while memory.main.get_map() != 135:
FFXC.set_movement(1, -1)
FFXC.set_neutral()
memory.main.wait_frames(1)
memory.main.await_control()
if game.state == "Guadosalam":
if game.step == 1:
area.guadosalam.arrival()
area.guadosalam.after_speech()
game.step = 2
# maybe_create_save(save_num=32)
if game.step == 2:
area.guadosalam.guado_skip()
game.step = 1
game.state = "ThunderPlains"
if game.state == "ThunderPlains":
if game.step == 1:
plains_battles = area.thunder_plains.south_pathing()
if plains_battles == 999:
#game.state, game.step = reset.mid_run_reset()
reset.reset_to_main_menu()
area.dream_zan.new_game(gamestate="reload_autosave")
load_game.load_save_num(0)
# Do not change game.state or game.step. Will restart this section.
else:
game.step = 2
# maybe_create_save(save_num=33)
if game.step == 2:
area.thunder_plains.agency()
game.step = 3
if game.step == 3:
result = area.thunder_plains.north_pathing(plains_battles)
if result:
game.state = "Macalania"
game.step = 1
maybe_create_save(save_num=34)
else:
#game.state, game.step = reset.mid_run_reset()
reset.reset_to_main_menu()
area.dream_zan.new_game(gamestate="reload_autosave")
load_game.load_save_num(0)
# Do not change game.state or game.step. Will restart this section.
if game.state == "Macalania":
if game.step == 1:
if area.mac_woods.arrival(False):
# Successful completion of this area.
game.step = 2
else:
reset.reset_to_main_menu()
area.dream_zan.new_game(gamestate="reload_autosave")
load_game.load_save_num(0)
# Do not change game.state or game.step. Will restart this section.
maybe_create_save(save_num=35)
if game.step == 2:
area.mac_woods.lake_road()
area.mac_woods.lake_road_2()
game.step = 3
if game.step == 3:
area.mac_woods.lake()
area.mac_temple.approach()
game.step = 4
maybe_create_save(save_num=36)
if game.step == 4:
if memory.main.get_map() != 80:
area.mac_temple.arrival()
area.mac_temple.start_seymour_fight()
area.mac_temple.seymour_fight()
if memory.main.game_over():
reset.reset_to_main_menu()
area.dream_zan.new_game(gamestate="reload_autosave")
load_game.load_save_num(0)
# Do not change game.state or game.step. Will restart this section.
else:
game.step = 5
if game.step == 5:
area.mac_temple.trials()
game.step = 6
maybe_create_save(save_num=37)
if game.step == 6:
area.mac_temple.escape()
game.step = 7
maybe_create_save(save_num=38)
if game.step == 7:
area.mac_temple.under_lake()
game.step = 1
game.state = "Home"
if game_vars.create_saves():
memory.main.click_to_control()
maybe_create_save(save_num=39)
# Home section
if game.state == "Home":
if game.step == 1:
if area.home.desert():
game.step = 2
maybe_create_save(save_num=40)
else:
reset.reset_to_main_menu()
area.dream_zan.new_game(gamestate="reload_autosave")
load_game.load_save_num(0)
# Do not change game.state or game.step. Will restart this section.
if game.step == 2:
area.home.find_summoners()
game.step = 1
game.state = "rescue_yuna"
maybe_create_save(save_num=41)
# Rescuing Yuna
if game.state == "rescue_yuna":
if game.step == 1:
area.rescue_yuna.pre_evrae()
if battle.boss.evrae():
area.rescue_yuna.guards()
game.step = 2
else:
reset.reset_to_main_menu()
area.dream_zan.new_game(gamestate="reload_autosave")
load_game.load_save_num(0)
# Do not change game.state or game.step. Will restart this section.
if game.step == 2:
area.rescue_yuna.trials()
area.rescue_yuna.trials_end()
game.step = 3
if game.step == 3:
if area.rescue_yuna.via_purifico():
game.step = 4
maybe_create_save(save_num=42)
else:
reset.reset_to_main_menu()
area.dream_zan.new_game(gamestate="reload_autosave")
load_game.load_save_num(0)
# Do not change game.state or game.step. Will restart this section.
if game.step == 4:
area.rescue_yuna.evrae_altana()
game.step = 5
maybe_create_save(save_num=43)
if game.step == 5:
area.rescue_yuna.seymour_natus()
game.state = "Gagazet"
if game_vars.nemesis():
game.step = 10
else:
game.step = 1
if game_vars.create_saves():
FFXC.set_movement(0, -1)
memory.main.await_event()
FFXC.set_neutral()
memory.main.await_control()
maybe_create_save(save_num=44)
FFXC.set_movement(1, 1)
memory.main.await_event()
FFXC.set_neutral()
# Gagazet section
if game.state == "Gagazet":
if game.step == 1:
area.gagazet.calm_lands()
area.gagazet.defender_x()
logger.debug("Determining next decision")
if game_vars.get_nea_after_bny():
game.step = 3
else:
game.step = 2
if game.step == 2:
if game_vars.try_for_ne():
manip_time_1 = logs.time_stamp()
logger.debug("Mark 1")
area.ne_armor.to_hidden_cave()
logger.debug("Mark 2")
area.ne_armor.drop_hunt()
logger.debug("Mark 3")
area.ne_armor.return_to_gagazet()
manip_time_2 = logs.time_stamp()
try:
manip_time = manip_time_2 - manip_time_1
logger.info(f"NEA Manip duration: {str(manip_time)}")
logs.write_stats("NEA Manip duration:")
logs.write_stats(manip_time)
except Exception as e:
logger.warning(e)
game.step = 3
if game.step == 3:
area.gagazet.to_the_ronso()
nea_will_drop,_,_ = rng_track.rng_alignment_before_nea(enemies=["ghost"])
if nea_will_drop and game_vars.ne_armor() == 255:
area.ne_armor.loop_back_from_ronso()
game.step = 2
else:
area.gagazet.to_the_ronso(checkpoint=6)
game.step = 4
# maybe_create_save(save_num=45) # Placeholder.
# This save is used for immediately before climbing Gagazet.
# However, it does not properly save automatically.
# Must be created manually.
if game.step == 4:
area.gagazet.gagazet_gates()
area.gagazet.flux()
game.step = 5
maybe_create_save(save_num=46)
if game.step == 5:
area.gagazet.dream()
game.step = 6
if game.step == 6:
area.gagazet.cave()
area.gagazet.wrap_up()
game.step = 1
game.state = "Zanarkand"
maybe_create_save(save_num=47)
# Zanarkand section
if game.state == "Zanarkand":
if game.step == 1:
area.zanarkand.arrival()
game.step = 2
if game.step == 2:
area.zanarkand.trials()
game.step = 3
if game.step == 3:
area.zanarkand.sanctuary_keeper()
game.step = 4
maybe_create_save(save_num=48)
if game.step == 4:
if area.zanarkand.yunalesca():
game.step = 5
else:
game.state, game.step = reset.mid_run_reset()
if game.step == 5:
area.zanarkand.post_yunalesca()
game.step = 1
game.state = "Sin"
maybe_create_save(save_num=49)
# Sin section
if game.state == "Sin":
if game.step == 1:
area.sin.making_plans()
game.step = 2
if game.step == 2:
logger.debug("Test 1")
area.sin.shedinja()
logger.debug("Test 2")
area.sin.facing_sin()
logger.debug("Test 3")
if game_vars.nemesis():
game.state = "Nem_Farm"
game.step = 1
else:
game.step = 3
maybe_create_save(save_num=50)
if game.step == 3:
# Up to and including Seymour Omnis
if area.sin.inside_sin(checkpoint=0):
game.step = 4
else:
# Seymour fail/death
reset.reset_to_main_menu()
area.dream_zan.new_game(gamestate="reload_autosave")
load_game.load_save_num(0)
if game.step == 4:
# After Seymour Omnis
area.sin.inside_sin(checkpoint=41)
game.step = 5
if game.step == 5:
area.sin.execute_egg_hunt()
final_battle = True
if game_vars.nemesis():
final_battle = battle.main.bfa_nem()
else:
final_battle = battle.boss.bfa()
if final_battle:
battle.boss.yu_yevon()
if final_battle:
game.state = "End"
else:
game.state, game.step = reset.mid_run_reset()
logger.debug(f"State: {game.state}")
logger.debug(f"Step: {game.step}")
# Nemesis logic only:
if game.state == "Gagazet":
if game.step == 10:
nemesis.changes.calm_lands_1()
game.step = 12
if game.step == 11:
nemesis.changes.remiem_races()
game.step += 1
if game.step == 12:
memory.main.await_control()
nemesis.changes.arena_purchase()
area.gagazet.defender_x()
logger.debug("Determining next decision")
extra_drops, _ = rng_track.nea_track()
if extra_drops in [0, 1]:
logger.info(f"Straight to NEA area: {extra_drops}")
game.step = 2
else:
logger.info(f"B&Y battle before NEA: {extra_drops}")
game.step = 3
# Nemesis farming section
if game.state == "Nem_Farm":
if game.step == 1:
nemesis.arena_prep.transition()
nemesis.arena_prep.unlock_omega()
while not nemesis.arena_prep.t_plains(cap_num=1):
pass
while not nemesis.arena_prep.calm(cap_num=1, airship_return=False):
pass
# maybe_create_save(save_num=51)
game.step = 2
if game.step == 2:
nemesis.arena_prep.kilika_shop()
logger.debug("===Kilika shop to farm")
nemesis.arena_prep.kilika_farm(cap_num=1, checkpoint=3)
nemesis.arena_prep.besaid_farm(cap_num=1)
game.step = 3
maybe_create_save(save_num=52)
if game.step == 3:
nemesis.arena_prep.mac_woods(cap_num=1)
nemesis.arena_prep.stolen_fayth_cave(cap_num=1)
game.step = 4
maybe_create_save(save_num=53)
if game.step == 4:
nemesis.arena_prep.od_to_ap()
game.step = 5
maybe_create_save(save_num=54)
if game.step == 5:
nemesis.arena_prep.besaid_farm(cap_num=10)
nemesis.arena_prep.kilika_farm(cap_num=10)
game.step = 6
maybe_create_save(save_num=55)
if game.step == 6:
nemesis.advanced_farm.full_farm(phase=3)
game.step = 7
maybe_create_save(save_num=56)
if game.step == 7:
nemesis.arena_prep.auto_phoenix()
logger.debug("Auto_phoenix done.")
game.step = 8
maybe_create_save(save_num=57)
if game.step == 8:
nemesis.advanced_farm.full_farm(phase=4)
# nemesis.advanced_farm.full_farm(phase=7)
game.step = 9
maybe_create_save(save_num=58)
if game.step == 9:
nemesis.arena_prep.kilika_money()
nemesis.arena_prep.arena_return()
nemesis.arena_prep.quick_levels(force_levels=27, mon="don_tonberry")
nemesis.arena_prep.one_mp_weapon()
# Phase 5 farm
game.step = 10
maybe_create_save(save_num=59)
if game.step == 10:
nemesis.advanced_farm.full_farm(phase=5)
# Back to arena for auto-life and auto-haste
game.step = 11
maybe_create_save(save_num=60)
if game.step == 11:
nemesis.arena_prep.gagazet()
game.step = 12
maybe_create_save(save_num=61)
if game.step == 12:
nemesis.advanced_farm.full_farm(phase=6)
game.step = 13
maybe_create_save(save_num=62)
if game.step == 13: