# Plan 6 Task 4: a ball catches the LAST wild Pokémon whichever slot it is in: foe 3 is down (absent, 0 HP), foe 1 sleeps with 1 HP, and the PARTNER's
# ball (which the game aims at foe 3) catches foe 1: the master retargets it (link_entry_BALLTHROW). link_catch_partner's twin; same checks
# (a ZIGZAGOON this time). The partner's own game also lets the ball out of the bag: its rule reads which foes stand, not where.
#
# After the battle the partner's game gives it to ITSELF (pk_coop_give_mon through `coopgive`): it lands in the partner's real party with
# the partner's OT ID, OT name and gender, and the host's game gets nothing (its party count and slot 3 are as they were).
# Needs EMERALD_PARTNER_SAVE (`$PARTNER_SAVE`).
#
# want: PASS linkwait 2
# want: PASS linkwait 3
# want: PASS expectdelta b_ball -> b_ball2 = -1
# want: PASS expectdelta a_ball -> a_ball2 = 0
# want: link: caught by 2
# want: PASS expectnum a_out = 7
# want: PASS expectnum b_out = 7
# want: PASS expectnum b_count2 = 4
# want: PASS expectnum a_count2 = 3
# want: PASS expectnum a_slot3b = 0
# want: PASS expectmon 02024618
# want: PASS expectotname 02024618
pair $PARTNER_SAVE
on b
@boot
poke16 0x02024542 999
poke16 0x02024544 999
bagqty b_ball 4
on a
poke16 0x02024542 999
poke16 0x02024544 999
bagqty a_ball 4
coopbegin 1 2 333 318
on b
coopbegin 0 2 333 318
linkwait 2 1500
on a
waitmem32 0x03005D60 0x08057589 3000
poke32 0x02022FEC 0x800163
poke8 0x02024210 8
poke16 0x020241B4 0
poke16 0x020248C6 0
poke32 0x02024128 7
poke16 0x02024104 1
on b
waitmem32 0x03005D68 0x08057589 3000
poke16 0x020248C6 0
poke32 0x02022FEC 0x800163
hold RIGHT 4
linkrun 30
hold A 4
linkrun 120
hold RIGHT 4
linkrun 30
hold A 4
linkrun 30
hold A 4
linkrun 100
hold A 4
linkrun 100
bagqty b_ball2 4
on a
bagqty a_ball2 4
hold A 4
linkrun 40
hold A 4
linkrun 40
hold A 4
linkrun 40
linkwait 3 4000
peeknum a_out 0x0202433A 1
expectnum a_out 7
linkcaught /work/caught_partner_far.bin
peeknum a_count 0x020244E9 1

on b
peeknum b_out 0x0202433A 1
expectnum b_out 7
peeknum b_count 0x020244E9 1
linkreset
on a
linkreset
waitmem32 0x030022C4 0x08085E5D 4000
on b
waitmem32 0x030022C4 0x08085E5D 4000
linkrun 200
coopgive /work/caught_partner_far.bin
linkrun 5
peeknum b_count2 0x020244E9 1
expectnum b_count2 4
monexp b_slot3 0x02024618
expectmon 0x02024618 own 288 own
expectotname 0x02024618
on a
linkrun 5
peeknum a_count2 0x020244E9 1
expectnum a_count2 3
monexp a_slot3b 0x02024618
expectnum a_slot3b 0
expectdelta b_ball b_ball2 -1
expectdelta a_ball a_ball2 0
