-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathreset.py
179 lines (162 loc) · 5.5 KB
/
reset.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
import datetime
import logging
import logs
import memory.main
from memory.main import user_control, turn_ready, battle_wrap_up_active
import vars
import xbox
logger = logging.getLogger(__name__)
game_vars = vars.vars_handle()
FFXC = xbox.controller_handle()
def mid_run_reset(land_run: bool = False, start_time=datetime.datetime.now()):
if land_run:
end_time = logs.time_stamp()
total_time = end_time - start_time
logs.write_stats("Total time:")
logs.write_stats(str(total_time))
logger.info(f"The game duration was: {total_time}")
logger.info(
"This duration is intended for comparison reference only, "
+ "not as a true timer."
)
logger.info("Please do not use this as your submitted time.")
memory.main.wait_frames(30)
logger.info("--------")
logger.info("In order to conform with speedrun standards,")
memory.main.wait_frames(60)
logger.info("we now wait until the end of the credits and stuff")
memory.main.wait_frames(60)
logger.info("and then will open up the list of saves.")
memory.main.wait_frames(60)
logger.info(
"This will show the autosave values, which conforms to the speedrun rules."
)
# Bring up auto-save
while memory.main.get_map() != 23:
if memory.main.get_map() in [348, 349]:
xbox.tap_start()
elif memory.main.cutscene_skip_possible():
xbox.skip_scene()
memory.main.wait_frames(180)
while not memory.main.save_menu_open():
xbox.tap_b()
memory.main.wait_frames(180)
xbox.menu_a()
xbox.menu_a()
xbox.menu_a()
else:
memory.main.wait_frames(60)
reset_to_main_menu()
# Now to re-start
game_vars.set_start_vars()
rng_seed = memory.main.rng_seed()
if land_run:
rng_seed += 0
if rng_seed == 256:
rng_seed = 0
logs.reset_stats_log()
logs.next_stats(rng_seed) # Start next stats file
if game_vars.rng_mode() in ["set", "preferred"]:
memory.main.set_rng_seed(rng_seed)
logger.info(f"This run will be using RNG seed: {rng_seed}")
logs.next_stats(rng_seed)
logs.write_stats("RNG seed:")
logs.write_stats(rng_seed)
gamestate = "none"
step_counter = 1
return gamestate, step_counter
def _attempt_reset():
memory.main.wait_frames(30 * 0.07)
if memory.main.s_grid_active():
logger.debug("Reset: S-grid open")
from menu_grid import (
ready_use_sphere,
first_position,
quit_grid_ready,
move_use_menu,
move_ready,
move_active,
move_complete,
use_ready,
ready_select_sphere,
)
while memory.main.s_grid_active():
if ready_use_sphere():
logger.debug("Using the current item.")
xbox.menu_b()
elif first_position():
logger.debug("Opening the Quit menu")
xbox.menu_a()
elif quit_grid_ready():
logger.debug("quitting sphere grid")
xbox.menu_b()
elif (
move_use_menu()
or move_ready()
or move_active()
or move_complete()
or use_ready()
or ready_select_sphere()
):
xbox.menu_a()
while memory.main.menu_number() != 5:
pass
if memory.main.game_over():
logger.debug("Reset: game over")
while memory.main.get_map() not in [23, 62, 348, 349]:
xbox.tap_b()
return
if battle_wrap_up_active():
logger.debug("Reset: end of battle")
while battle_wrap_up_active():
xbox.menu_b()
if memory.main.menu_open():
logger.debug("Reset: menu open")
memory.main.close_menu()
while not (user_control() or turn_ready()) and memory.main.get_map() not in [
23,
62,
348,
349,
]:
xbox.tap_a()
while memory.main.get_map() not in [23, 348, 349]:
logger.info("Attempting reset")
logger.info(f"FFX map: {memory.main.get_map()}")
memory.main.set_map_reset()
memory.main.wait_frames(30 * 0.1)
memory.main.force_map_load()
memory.main.wait_frames(30 * 1)
def reset_to_main_menu():
FFXC.set_neutral()
if memory.main.get_story_progress() <= 8:
_attempt_reset()
elif memory.main.game_over():
while not memory.main.get_map() in [21,23]:
xbox.menu_b()
elif memory.main.battle_active():
logger.info("Battle is active. Forcing battle to end so we can soft reset.")
while not memory.main.turn_ready():
xbox.menu_a()
memory.main.reset_battle_end()
while memory.main.get_map() not in [23, 348, 349]:
xbox.menu_b()
else:
_attempt_reset()
logger.info("Resetting")
def reset_no_battles():
memory.main.wait_frames(90)
while not (user_control() or turn_ready()) and memory.main.get_map() not in [
23,
62,
348,
349,
]:
xbox.tap_a()
while memory.main.get_map() not in [23, 348, 349]:
logger.info("Attempting reset")
logger.info(f"FFX map: {memory.main.get_map()}")
memory.main.set_map_reset()
memory.main.wait_frames(30 * 0.1)
memory.main.force_map_load()
memory.main.wait_frames(30 * 1)