forked from coderwilson/FFX_TAS_Python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmenu_grid.py
645 lines (578 loc) · 16.5 KB
/
menu_grid.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
import logging
import memory.main
import vars
import xbox
logger = logging.getLogger(__name__)
game_vars = vars.vars_handle()
FFXC = xbox.controller_handle()
def grid_up():
FFXC.set_value("d_pad", 1)
memory.main.wait_frames(2)
FFXC.set_value("d_pad", 0)
memory.main.wait_frames(3)
def grid_down():
FFXC.set_value("d_pad", 2)
memory.main.wait_frames(2)
FFXC.set_value("d_pad", 0)
memory.main.wait_frames(3)
def grid_left():
FFXC.set_value("d_pad", 4)
memory.main.wait_frames(2)
FFXC.set_value("d_pad", 0)
memory.main.wait_frames(3)
def grid_right():
FFXC.set_value("d_pad", 8)
memory.main.wait_frames(2)
FFXC.set_value("d_pad", 0)
memory.main.wait_frames(3)
def grid_tidus():
if memory.main.s_grid_char() == 0:
return True
else:
return False
def grid_kimahri():
if memory.main.s_grid_char() == 3:
return True
else:
return False
def grid_auron():
if memory.main.s_grid_char() == 2:
return True
else:
return False
def grid_lulu():
if memory.main.s_grid_char() == 5:
return True
else:
return False
def grid_wakka():
if memory.main.s_grid_char() == 4:
return True
else:
return False
def grid_yuna():
if memory.main.s_grid_char() == 1:
return True
else:
return False
def grid_rikku():
if memory.main.s_grid_char() == 6:
return True
else:
return False
def first_position():
if memory.main.s_grid_menu() == 255:
if memory.main.get_grid_move_active():
return False
else:
return True
else:
return False
def move_use_menu():
if memory.main.s_grid_menu() == 7:
return True
else:
return False
def move_ready():
if move_use_menu():
if memory.main.get_grid_move_use_pos() == 0:
return True
else:
return False
elif ready_use_sphere() or move_active():
xbox.menu_a()
else:
return False
def move_active():
if memory.main.get_grid_move_active() and memory.main.s_grid_menu() == 255:
return True
else:
return False
def move_complete():
if memory.main.get_grid_move_active() and memory.main.s_grid_menu() == 11:
return True
else:
return False
def use_ready():
if move_use_menu():
if memory.main.get_grid_move_use_pos() == 1:
return True
else:
return False
elif ready_use_sphere() or move_active():
xbox.menu_a()
else:
return False
def ready_select_sphere():
if memory.main.s_grid_menu() == 8:
return True
else:
return False
def ready_use_sphere():
if memory.main.get_grid_use_active():
return True
else:
return False
def quit_grid_ready():
if memory.main.s_grid_menu() == 11:
if use_ready():
return False
elif move_complete():
return False
else:
return True
else:
return False
def use_first():
logger.debug("use first")
while not ready_select_sphere():
if first_position():
xbox.menu_b()
elif move_ready():
xbox.menu_down()
elif use_ready():
xbox.menu_b()
return True
def move_first():
logger.debug("move first")
while not move_active():
if first_position():
xbox.menu_b()
elif move_ready():
xbox.menu_b()
memory.main.wait_frames(3)
elif use_ready():
xbox.menu_up()
return True
def move_and_use():
logger.debug("move and use")
memory.main.wait_frames(1)
xbox.menu_b()
memory.main.wait_frames(1)
while not ready_select_sphere():
if move_complete() or first_position():
xbox.menu_b()
elif move_ready():
xbox.menu_down()
elif use_ready():
xbox.menu_b()
return True
def use_and_move():
logger.debug("use and move")
memory.main.wait_frames(1)
xbox.menu_b()
memory.main.wait_frames(1)
while not move_active():
if ready_use_sphere() or first_position():
xbox.menu_b()
elif move_ready():
xbox.menu_b()
elif use_ready():
xbox.menu_up()
else:
xbox.menu_b()
return True
def use_and_use_again():
logger.debug("use and use again")
memory.main.wait_frames(1)
xbox.menu_b()
memory.main.wait_frames(1)
while not ready_select_sphere():
if ready_use_sphere() or first_position():
xbox.menu_b()
elif move_ready():
xbox.menu_down()
elif use_ready():
xbox.menu_b()
if game_vars.use_pause():
memory.main.wait_frames(6)
return True
def use_shift_left(toon):
logger.debug("use and shift")
memory.main.wait_frames(1)
xbox.menu_b()
toon = toon.lower()
if toon == "yuna":
while not grid_yuna():
if ready_use_sphere():
xbox.menu_b()
elif move_use_menu():
xbox.menu_back()
elif first_position():
xbox.shoulder_left()
if toon == "lulu":
while not grid_lulu():
if ready_use_sphere():
xbox.menu_b()
elif move_use_menu():
xbox.menu_back()
elif first_position():
xbox.shoulder_left()
if toon == "auron":
while not grid_auron():
if ready_use_sphere():
xbox.menu_b()
elif move_use_menu():
xbox.menu_back()
elif first_position():
xbox.shoulder_left()
if toon == "wakka":
while not grid_wakka():
if ready_use_sphere():
xbox.menu_b()
elif move_use_menu():
xbox.menu_back()
elif first_position():
xbox.shoulder_left()
if toon == "tidus":
while not grid_tidus():
if ready_use_sphere():
xbox.menu_b()
elif move_use_menu():
xbox.menu_back()
elif first_position():
xbox.shoulder_left()
if toon == "kimahri":
while not grid_kimahri():
if ready_use_sphere():
xbox.menu_b()
elif move_use_menu():
xbox.menu_back()
elif first_position():
xbox.shoulder_left()
if toon == "rikku":
while not grid_rikku():
if ready_use_sphere():
xbox.menu_b()
elif move_use_menu():
xbox.menu_back()
elif first_position():
xbox.shoulder_left()
logger.debug(f"Ready for grid: {toon}")
def use_shift_right(toon):
logger.debug("use and shift")
xbox.menu_b()
toon = toon.lower()
if toon == "yuna":
while not grid_yuna():
if ready_use_sphere():
xbox.menu_b()
elif move_use_menu():
xbox.menu_back()
elif first_position():
xbox.shoulder_right()
if toon == "lulu":
while not grid_lulu():
if ready_use_sphere():
xbox.menu_b()
elif move_use_menu():
xbox.menu_back()
elif first_position():
xbox.shoulder_right()
memory.main.wait_frames(30 * 0.3)
if toon == "auron":
while not grid_auron():
if ready_use_sphere():
xbox.menu_b()
elif move_use_menu():
xbox.menu_back()
elif first_position():
xbox.shoulder_right()
if toon == "wakka":
while not grid_wakka():
if ready_use_sphere():
xbox.menu_b()
elif move_use_menu():
xbox.menu_back()
elif first_position():
xbox.shoulder_right()
if toon == "tidus":
while not grid_tidus():
if ready_use_sphere():
xbox.menu_b()
elif move_use_menu():
xbox.menu_back()
elif first_position():
xbox.shoulder_right()
if toon == "kimahri":
while not grid_kimahri():
if ready_use_sphere():
xbox.menu_b()
elif move_use_menu():
xbox.menu_back()
elif first_position():
xbox.shoulder_right()
if toon == "rikku":
while not grid_rikku():
if ready_use_sphere():
xbox.menu_b()
elif move_use_menu():
xbox.menu_back()
elif first_position():
xbox.shoulder_right()
logger.debug(f"Ready for grid: {toon}")
def move_shift_left(toon):
logger.debug("Move and shift, left")
memory.main.wait_frames(2)
xbox.menu_b()
memory.main.wait_frames(2)
toon = toon.lower()
if toon == "yuna":
while not grid_yuna():
if move_ready() or move_active() or move_complete():
xbox.menu_b()
elif move_use_menu():
xbox.menu_back()
elif first_position():
xbox.shoulder_left()
if toon == "lulu":
while not grid_lulu():
if move_ready() or move_active() or move_complete():
xbox.menu_b()
elif move_use_menu():
xbox.menu_back()
elif first_position():
xbox.shoulder_left()
if toon == "tidus":
while not grid_tidus():
if move_ready() or move_active() or move_complete():
xbox.menu_b()
elif move_use_menu():
xbox.menu_back()
elif first_position():
xbox.shoulder_left()
if toon == "rikku":
while not grid_rikku():
if move_ready() or move_active() or move_complete():
xbox.menu_b()
elif move_use_menu():
xbox.menu_back()
elif first_position():
xbox.shoulder_left()
logger.debug(f"Ready for grid: {toon}")
def move_shift_right(toon):
logger.debug("Move and shift, right")
memory.main.wait_frames(2)
xbox.menu_b()
memory.main.wait_frames(2)
toon = toon.lower()
if toon == "yuna":
while not grid_yuna():
if move_ready() or move_active() or move_complete():
xbox.menu_b()
elif move_use_menu():
xbox.menu_back()
elif first_position():
xbox.shoulder_right()
elif toon == "lulu":
while not grid_lulu():
if move_ready() or move_active() or move_complete():
xbox.menu_b()
elif move_use_menu():
xbox.menu_back()
elif first_position():
xbox.shoulder_right()
if toon == "tidus":
while not grid_tidus():
if move_ready() or move_active() or move_complete():
xbox.menu_b()
elif move_use_menu():
xbox.menu_back()
elif first_position():
xbox.shoulder_right()
if toon == "rikku":
while not grid_rikku():
if move_ready() or move_active() or move_complete():
xbox.menu_b()
elif move_use_menu():
xbox.menu_back()
elif first_position():
xbox.shoulder_right()
logger.debug(f"Ready for grid: {toon}")
def use_and_quit():
memory.main.wait_frames(30 * 0.1)
xbox.menu_b()
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()
while memory.main.menu_number() != 5:
pass
return True
def sphere_num(s_type) -> int:
s_type = s_type.lower()
if s_type == "power":
return 70
elif s_type == "mana":
return 71
elif s_type == "speed":
return 72
elif s_type == "ability":
return 73
elif s_type == "fortune":
return 74
elif s_type == "attribute":
return 75
elif s_type == "special":
return 76
elif s_type == "skill":
return 77
elif s_type == "wmag":
return 78
elif s_type == "bmag":
return 79
elif s_type == "master":
return 80
elif s_type == "lv1":
return 81
elif s_type == "lv2":
return 82
elif s_type == "lv3":
return 83
elif s_type == "lv4":
return 84
elif s_type == "hp":
return 85
elif s_type == "mp":
return 86
elif s_type == "strength":
return 87
elif s_type == "defense":
return 88
elif s_type == "magic":
return 89
elif s_type == "mdef":
return 90
elif s_type == "agility":
return 91
elif s_type == "evasion":
return 92
elif s_type == "accuracy":
return 93
elif s_type == "luck":
return 94
elif s_type == "clear":
return 95
elif s_type == "ret":
return 96
elif s_type == "friend":
return 97
elif s_type == "tele":
return 98
elif s_type == "warp":
return 99
return 255
def sel_sphere(s_type, shift):
s_num = 255
menu_pos = 0
logger.debug(s_type)
s_num = sphere_num(s_type)
logger.debug(s_num)
menu_pos = memory.main.get_grid_items_slot(s_num)
logger.debug(menu_pos)
if menu_pos == 255:
logger.debug(f"Sphere {s_type} is not in inventory.")
return
while menu_pos != memory.main.get_grid_cursor_pos():
if menu_pos > memory.main.get_grid_cursor_pos():
if game_vars.use_pause():
xbox.tap_down()
else:
if (
menu_pos - memory.main.get_grid_cursor_pos() >= 3
and len(memory.main.get_grid_items_order()) > 4
):
if (
menu_pos - memory.main.get_grid_cursor_pos() == 3
and menu_pos == len(memory.main.get_grid_items_order()) - 1
):
xbox.tap_down()
else:
xbox.trigger_r()
else:
xbox.tap_down()
elif menu_pos < memory.main.get_grid_cursor_pos():
if game_vars.use_pause():
xbox.tap_up()
else:
if memory.main.get_grid_cursor_pos() - menu_pos >= 3:
if (
menu_pos == 0
and memory.main.get_grid_cursor_pos() - menu_pos == 3
) or len(memory.main.get_grid_items_order()) <= 4:
xbox.tap_up()
else:
xbox.trigger_l()
else:
xbox.tap_up()
while not memory.main.sphere_grid_placement_open():
xbox.menu_b()
if shift == "up":
grid_up()
if shift == "left":
grid_left()
if shift == "l2":
grid_left()
grid_left()
if shift == "l5":
grid_left()
grid_left()
grid_left()
grid_left()
grid_left()
if shift == "right":
grid_right()
if shift == "r2":
grid_right()
grid_right()
if shift == "down":
grid_down()
if shift == "d2":
grid_down()
grid_down()
if shift == "up2":
grid_up()
grid_up()
if shift == "d5":
grid_down()
grid_down()
grid_down()
grid_down()
grid_down()
if shift == "aftersk":
grid_up()
grid_right()
grid_down()
memory.main.wait_frames(4)
if memory.main.s_grid_node_selected() == [248, 195]:
grid_down()
if shift == "aftersk2":
grid_right()
grid_right()
memory.main.wait_frames(30 * 0.1)
grid_left()
if shift == "after_by_spec":
grid_right()
grid_right()
grid_up()
if shift == "torikku":
memory.main.wait_frames(30 * 0.2)
grid_down()
grid_down()
grid_left()
grid_left()
if shift == "yunaspec":
# Yuna Special
grid_down()
grid_right()
grid_right()
grid_down()
grid_down()
while memory.main.sphere_grid_placement_open():
xbox.menu_b()