summaryrefslogtreecommitdiff
path: root/vba_autoplayer.py
blob: eafbff13463c16a810c32efb838f6cf7ea18ca73 (plain)
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
# -*- coding: utf-8 -*-
"""
Programmatic speedrun of Pokémon Crystal
"""
import os

# bring in the emulator and basic tools
import vba

def main():
    """
    Start the game.
    """
    vba.load_rom()

    # get past the opening sequence
    skip_intro()

    # walk to mom and handle her text
    handle_mom()

    # walk to elm and do whatever he wants
    handle_elm("totodile")

    new_bark_level_grind(10, skip=False)

def skippable(func):
    """
    Makes a function skippable by saving the state before and after the
    function runs. Pass "skip=True" to the function to load the previous save
    state from when the function finished.
    """
    def wrapped_function(*args, **kwargs):
        skip = True

        if "skip" in kwargs.keys():
            skip = kwargs["skip"]
            del kwargs["skip"]

        # override skip if there's no save
        if skip:
            full_name = func.__name__ + "-end.sav"
            if not os.path.exists(os.path.join(vba.save_state_path, full_name)):
                skip = False

        return_value = None

        if not skip:
            vba.save_state(func.__name__ + "-start", override=True)
            return_value = func(*args, **kwargs)
            vba.save_state(func.__name__ + "-end", override=True)
        elif skip:
            vba.set_state(vba.load_state(func.__name__ + "-end"))

        return return_value
    return wrapped_function

@skippable
def skip_intro():
    """
    Skip the game boot intro sequence.
    """
    # copyright sequence
    vba.nstep(400)

    # skip the ditto sequence
    vba.press("a")
    vba.nstep(100)

    # skip the start screen
    vba.press("start")
    vba.nstep(100)

    # click "new game"
    vba.press("a", holdsteps=50, aftersteps=1)

    # Are you a boy? Or are you a girl?
    vba.nstep(145)

    # pick "boy"
    vba.press("a", holdsteps=50, aftersteps=1)

    # ....
    vba.crystal.text_wait()

    vba.crystal.text_wait()

    # What time is it?
    vba.crystal.text_wait()

    # DAY 10 o'clock
    vba.press("a", holdsteps=50, aftersteps=1)

    # WHAT? DAY 10 o'clock? YES/NO.
    vba.press("a", holdsteps=50, aftersteps=1)

    # How many minutes? 0 min.
    vba.press("a", holdsteps=50, aftersteps=1)

    # Whoa! 0 min.? YES/NO.
    vba.press("a", holdsteps=50, aftersteps=1)

    vba.crystal.text_wait()
    vba.crystal.text_wait()

    # People call me
    vba.crystal.text_wait()
    vba.crystal.text_wait()

    # tures that we call
    vba.crystal.text_wait()

    vba.crystal.text_wait()
    vba.crystal.text_wait()

    vba.crystal.text_wait()
    vba.crystal.text_wait()

    vba.crystal.text_wait()

    # everything about pokemon yet.
    vba.crystal.text_wait()
    vba.crystal.text_wait()

    vba.crystal.text_wait()
    vba.crystal.text_wait()
    vba.crystal.text_wait()
    vba.crystal.text_wait()

    # Now, what did you say your name was?
    vba.crystal.text_wait()

    # move down to "CHRIS"
    vba.press("d")
    vba.nstep(50)

    vba.press("a", holdsteps=50, aftersteps=1)

    vba.crystal.text_wait()
    vba.crystal.text_wait()
    vba.crystal.text_wait()
    vba.crystal.text_wait()
    vba.crystal.text_wait()
    vba.crystal.text_wait()
    vba.crystal.text_wait()

    # wait until playable
    # could be 150, but it sometimes takes longer??
    vba.nstep(200)

    return

@skippable
def handle_mom():
    """
    Walk to mom. Handle her speech and questions.
    """
    vba.press("r"); vba.nstep(50)
    vba.press("r"); vba.nstep(50)
    vba.press("r"); vba.nstep(50)
    vba.press("r"); vba.nstep(50)
    vba.press("r"); vba.nstep(50)
    vba.press("u"); vba.nstep(50)
    vba.press("u"); vba.nstep(50)
    vba.press("u"); vba.nstep(50)
    vba.press("u"); vba.nstep(50)

    # wait for next map to load
    vba.nstep(50)

    vba.press("d"); vba.nstep(50)
    vba.press("d"); vba.nstep(50)
    vba.press("d"); vba.nstep(50)

    # walk into mom's line of sight
    vba.press("d"); vba.nstep(50)

    vba.nstep(50)
    vba.crystal.text_wait()
    vba.crystal.text_wait()
    vba.crystal.text_wait()
    vba.crystal.text_wait()
    vba.crystal.text_wait()
    vba.crystal.text_wait()
    vba.crystal.text_wait()
    vba.crystal.text_wait()
    vba.crystal.text_wait()
    vba.crystal.text_wait()
    vba.crystal.text_wait()
    vba.crystal.text_wait()

    # What day is it? SUNDAY.
    vba.press("a", holdsteps=50, aftersteps=1)

    # SUNDAY, is it? YES/NO
    vba.press("a", holdsteps=50, aftersteps=1)

    vba.nstep(200)

    # is it DST now? YES/NO.
    vba.press("a", holdsteps=50, aftersteps=1)

    # 10:06 AM DST, is that OK? YES/NO.
    vba.press("a", holdsteps=50, aftersteps=1)

    vba.crystal.text_wait()
    vba.crystal.text_wait()
    vba.crystal.text_wait()

    # know how to use the PHONE? YES/NO.
    vba.press("a", holdsteps=50, aftersteps=1)

    vba.crystal.text_wait()
    vba.crystal.text_wait()
    vba.crystal.text_wait()
    vba.crystal.text_wait()

    vba.press("a", holdsteps=50, aftersteps=1)

    # have to wait for her to move back :(
    vba.nstep(50)

    # face down
    vba.press("d"); vba.nstep(50)

    return

@skippable
def handle_elm(starter_choice):
    """
    Walk to Elm's Lab and get a starter.
    """

    # walk down
    vba.press("d"); vba.nstep(50)
    vba.press("d"); vba.nstep(50)

    # face left
    vba.press("l"); vba.nstep(50)

    # walk left
    vba.press("l"); vba.nstep(50)
    vba.press("l"); vba.nstep(50)

    # face down
    vba.press("d"); vba.nstep(50)

    # walk down
    vba.press("d"); vba.nstep(50)

    # walk down to warp to outside
    vba.press("d"); vba.nstep(50)
    vba.nstep(10)

    vba.press("l", holdsteps=10, aftersteps=50)
    vba.press("l", holdsteps=10, aftersteps=50)
    vba.press("l", holdsteps=10, aftersteps=50)

    vba.press("l", holdsteps=10, aftersteps=50)
    vba.press("l", holdsteps=10, aftersteps=50)
    vba.press("l", holdsteps=10, aftersteps=50)
    vba.press("l", holdsteps=10, aftersteps=50)

    vba.press("u", holdsteps=10, aftersteps=50)
    vba.press("u", holdsteps=10, aftersteps=50)

    # warp into elm's lab (bottom left warp)
    vba.press("u", holdsteps=5, aftersteps=50)

    # let the script play
    vba.nstep(200)

    vba.crystal.text_wait()
    # I needed to ask you a fa

    vba.crystal.text_wait()
    vba.crystal.text_wait()
    vba.crystal.text_wait()
    vba.crystal.text_wait()
    vba.crystal.text_wait()
    vba.crystal.text_wait()
    vba.crystal.text_wait()
    vba.crystal.text_wait()
    vba.crystal.text_wait()
    vba.crystal.text_wait()
    vba.crystal.text_wait()

    vba.nstep(50)

    # YES/NO.
    vba.press("a")

    vba.crystal.text_wait()
    vba.crystal.text_wait()
    vba.crystal.text_wait()
    vba.crystal.text_wait()
    vba.crystal.text_wait()

    vba.press("a")

    vba.crystal.text_wait()
    vba.crystal.text_wait()
    vba.press("a")
    vba.crystal.text_wait()
    vba.crystal.text_wait()

    vba.crystal.text_wait()

    for x in range(0, 8): # was 15
        vba.crystal.text_wait()

    vba.nstep(50)
    vba.press("a")
    vba.nstep(100)

    vba.crystal.text_wait()
    vba.crystal.text_wait()
    vba.crystal.text_wait()
    vba.crystal.text_wait()

    # Go on! Pick one.
    vba.nstep(100)
    vba.press("a"); vba.nstep(50)

    vba.press("r"); vba.nstep(50)
    vba.press("r"); vba.nstep(50)

    right = 0
    if starter_choice in [1, "cyndaquil"]:
        right = 0
    elif starter_choice in [2, "totodile"]:
        right = 1
    elif starter_choice in [3, "chikorita"]:
        right = 2
    else:
        raise Exception("bad starter")

    for each in range(0, right):
        vba.press("r"); vba.nstep(50)

    # look up
    vba.press("u", holdsteps=5, aftersteps=50)

    # get menu
    vba.press("a", holdsteps=5, aftersteps=50)

    # let the image show
    vba.nstep(100)

    vba.crystal.text_wait()
    vba.crystal.text_wait()

    # YES/NO.
    vba.press("a")

    vba.crystal.text_wait()
    vba.crystal.text_wait()

    # received.. music is playing.
    vba.press("a")
    vba.crystal.text_wait()

    # YES/NO (nickname)
    vba.crystal.text_wait()

    vba.press("b")

    # get back to elm
    vba.nstep(100)
    vba.nstep(100)

    vba.crystal.text_wait()
    vba.crystal.text_wait()
    vba.crystal.text_wait()
    vba.crystal.text_wait()
    vba.crystal.text_wait()

    # phone number..
    vba.press("a")
    vba.crystal.text_wait()
    vba.nstep(100)
    vba.press("a")
    vba.nstep(300)
    vba.press("a")
    vba.nstep(100)

    vba.crystal.text_wait()
    vba.crystal.text_wait()
    vba.crystal.text_wait()

    # I'm counting on you!
    vba.nstep(200)
    vba.press("a")
    vba.nstep(50)

    # look down
    vba.press("d", holdsteps=5, aftersteps=50)

    # walk down
    vba.press("d", holdsteps=10, aftersteps=50)

    vba.press("d", holdsteps=10, aftersteps=50)
    vba.press("d", holdsteps=10, aftersteps=50)
    vba.press("d", holdsteps=10, aftersteps=50)
    vba.press("d", holdsteps=10, aftersteps=50)

    vba.crystal.text_wait()
    vba.crystal.text_wait()

    vba.press("a")
    vba.nstep(50)
    vba.press("a")

    vba.crystal.text_wait()
    vba.crystal.text_wait()

    vba.press("a")
    vba.nstep(50)

    vba.crystal.text_wait()
    vba.press("a")

    vba.nstep(100)

    vba.press("d", holdsteps=10, aftersteps=50)
    vba.press("d", holdsteps=10, aftersteps=50)
    vba.press("d", holdsteps=10, aftersteps=50)
    vba.press("d", holdsteps=10, aftersteps=50)

    # step outside
    vba.nstep(40)

@skippable
def new_bark_level_grind(level):
    """
    Starting just outside of Elm's Lab, do some level grinding until the first
    partymon level is equal to the given value..
    """

    # walk to the grass area
    new_bark_level_grind_walk_to_grass(skip=False)

    # TODO: walk around in grass, handle battles
    # TODO: heal at the lab, then repeat entire function

@skippable
def new_bark_level_grind_travel_to_grass():
    """
    Move to just above the grass.
    """
    vba.press("d", holdsteps=10, aftersteps=50)
    vba.press("d", holdsteps=10, aftersteps=50)
    vba.press("d", holdsteps=10, aftersteps=50)

    vba.press("l", holdsteps=10, aftersteps=50)
    vba.press("l", holdsteps=10, aftersteps=50)
    vba.press("l", holdsteps=10, aftersteps=50)
    vba.press("l", holdsteps=10, aftersteps=50)

    vba.press("d", holdsteps=10, aftersteps=50)
    vba.press("d", holdsteps=10, aftersteps=50)

if __name__ == "__main__":
    main()