MersonGoldTokenExchange_MapScriptHeader;trigger count
	db 0
 ;callback count
	db 0

MersonGoldTokenExchangeNPC:
	faceplayer
	opentext
	checkevent EVENT_GOLDTOKENMAN_INTRO
	sif false, then
		writetext MersonGoldTokenExchange_Text_Intro
		setevent EVENT_GOLDTOKENMAN_INTRO
	sendif
	scriptstartasm
	ld hl, MersonGoldTokenExchange_EventFlags
	call CountEventFlagsFromList
	ld a, e
	cp 8
	ld hl, MersonGoldTokenExchange_CheckFinishedDex
	ret z
	ld hl, MersonGoldTokenExchange_AfterFillingDex
	ret nc
	ld [hScriptVar], a
	ld hl, wPokedexCaught
	ld b, wEndPokedexCaught - wPokedexCaught
	call CountSetBits
	push af
	ld a, [hScriptVar]
	inc a
	ld b, a
	swap a
	sub b
	add a, a
	ld b, a
	pop af
	cp b
	ld hl, MersonGoldTokenExchange_RequirementsForMilestone
	ret c
	scriptstopasm
	writetext MersonGoldTokenExchange_Text_PassedMilestone
	waitbutton
	verbosegiveitem GOLD_TOKEN, 4
	sif false
		jumptext MersonGoldTokenExchange_Text_NeedMoreSpace
	closetext
	scriptstartasm
	ld hl, MersonGoldTokenExchange_EventFlags
.loop
	ld a, [hli]
	ld d, [hl]
	ld e, a
	inc hl
	push hl
	push de
	ld b, CHECK_FLAG
	predef EventFlagAction
	pop de
	pop hl
	jr nz, .loop
	ld b, 1
	predef EventFlagAction
	ld hl, 0
	ret

MersonGoldTokenExchange_EventFlags:
	dw EVENT_GOLDTOKENMAN_MILESTONE_1
	dw EVENT_GOLDTOKENMAN_MILESTONE_2
	dw EVENT_GOLDTOKENMAN_MILESTONE_3
	dw EVENT_GOLDTOKENMAN_MILESTONE_4
	dw EVENT_GOLDTOKENMAN_MILESTONE_5
	dw EVENT_GOLDTOKENMAN_MILESTONE_6
	dw EVENT_GOLDTOKENMAN_MILESTONE_7
	dw EVENT_GOLDTOKENMAN_MILESTONE_8
	dw EVENT_GOLDTOKENMAN_MILESTONE_9
	dw -1

MersonGoldTokenExchange_RequirementsForMilestone:
	jumptext MersonGoldTokenExchange_Text_RequirementsForMilestone

MersonGoldTokenExchange_CheckFinishedDex:
	checkcode VAR_DEXCAUGHT
	sif <, 253
		jumptext MersonGoldTokenExchange_Text_RequirementsForSpecialGift
	writetext MersonGoldTokenExchange_Text_FinishedDex
	waitbutton
	verbosegiveitem SHOP_TICKET, 1
	sif false
		jumptext MersonGoldTokenExchange_Text_NeedMoreSpace
	setevent EVENT_GOLDTOKENMAN_MILESTONE_9
	jumptext MersonGoldTokenExchange_Text_TicketGrantsAccessToShop

MersonGoldTokenExchange_AfterFillingDex:
	checkevent EVENT_SILPH_WAREHOUSE_GUARD_MOVED
	sif false
		jumptext MersonGoldTokenExchange_Text_AllICanRememberAboutSecretShop
	checkevent EVENT_TOLD_GOLDTOKENMAN_SECRET_SHOP_LOCATION
	setevent EVENT_TOLD_GOLDTOKENMAN_SECRET_SHOP_LOCATION
	sif false
		jumptext MersonGoldTokenExchange_Text_WhatSecretShopInSilphWarehouse
	jumptext MersonGoldTokenExchange_Text_AfterFillingDex

MersonGoldTokenExchange_Text_Intro:
	db TX_COMPRESSED, $62, $7d, $e8, $7f, $1d, $4d, $7e, $6c, $4b, $5c
	db $9b, $d8, $69, $20, $70, $80, $e5, $7c, $24

	db $e2, $01, $4c, $2b, $86, $0c, $6b, $05, $05, $90
	db $b0, $f0, $39, $5f, $09, $20, $20, $b5, $03, $51, $3f, $1d
	db $00, $a8, $7d, $ec, $e4, $60, $c7, $01, $05, $a9, $4f
	db $de, $61, $07, $b9, $85, $05, $48, $c8, $8f

	db $00, $61, $2c, $f6, $e6, $4f, $7b, $f8, $96, $93
	db $4b, $4f, $10

MersonGoldTokenExchange_Text_NeedMoreSpace:
	db TX_COMPRESSED, $72, $85, $a8, $43, $3c, $c7, $c2, $b3
	db $79, $02, $35, $93, $98, $05, $70, $10, $5a
	db $5a, $ae, $47, $85, $f1
	db $a6, $80

MersonGoldTokenExchange_Text_PassedMilestone:
	start_asm
	call MersonGoldTextExchange_GetMilestoneNumber
	ld hl, .text
	ret
.text
	db TX_COMPRESSED, $72, $85, $a8, $23, $50, $83, $cc, $b4
	db $9b, $c0, $e4, $47, $c7, $d3, $45, $84, $87
	db $c6, $9a

MersonGoldTokenExchange_Text_RequirementsForMilestone:
	start_asm
	call MersonGoldTextExchange_GetMilestoneNumber
	ld a, [hScriptVar]
	inc a
	ld l, a
	swap a
	sub l
	add a, a
	ld [hTemp], a
	ld hl, .text
	ret
.text
	db TX_COMPRESSED, $72, $85, $a8, $43, $3c, $cb, $0c, $0d, $44
	db $79, $cc, $00
	deciram hTemp, 1, 3
	db TX_COMPRESSED, $80, $e5, $7c, $24, $83
	db $20, $00, $af, $26, $b9, $61, $82, $35, $08
	db $7a, $d2, $70, $1c
	db $85, $4f, $8f, $a6, $8b, $09, $0f
	db $8d, $34

MersonGoldTextExchange_GetMilestoneNumber:
	push bc
	ld a, [hScriptVar]
	ld hl, MersonGoldTokenExchange_Text_OrdinalNumbers
	call GetNthString
	ld d, h
	ld e, l
	ld hl, wStringBuffer1
	ld bc, 8
	ld a, "@"
	push hl
	call ByteFill
	pop hl
	call PlaceString
	pop bc
	ret

MersonGoldTokenExchange_Text_OrdinalNumbers:
	db "first@"
	db "second@"
	db "third@"
	db "fourth@"
	db "fifth@"
	db "sixth@"
	db "seventh@"
	db "eighth@"

MersonGoldTokenExchange_Text_FinishedDex:
	db TX_COMPRESSED, $74, $f8, $85, $9a, $10, $30, $63

	db $e2, $01, $ca, $16, $a6, $03, $20, $d0, $93, $cc, $b4
	db $9b, $c0, $fd, $ed, $38, $18, $0e, $5c, $9d, $3b

	db $c4, $05, $68, $82, $16, $17, $c6, $83, $cf, $e2, $4d
	db $66, $f0, $d1, $1f, $05, $01, $8d, $60, $a2, $04, $1b, $23, $de
	db $aa, $e4, $78, $5f
	db $a9, $e2

MersonGoldTokenExchange_Text_TicketGrantsAccessToShop:
	db TX_COMPRESSED, $29, $23, $44, $b1, $b2, $a4, $77, $39, $5e, $92
	db $d0, $f0, $20, $b5, $35, $96, $4d, $08, $96, $19
	db $a0, $10, $20, $d9, $1e, $f6, $21, $21, $11, $10, $17, $cc
	db $0b, $d5, $24, $d6, $70, $64, $8e, $41, $d3, $81, $27
	
	db $80, $3b, $4f, $e3, $a8, $b3, $7c, $df, $56, $6b
	db $7a, $a4, $99, $23, $a8, $d2, $0f, $32, $c3, $1a, $41
	db $80, $1d, $cb, $0c, $56, $d0, $29, $69, $38, $bd, $59
	db $bc, $3b, $37, $d1, $2d, $26, $0a, $27
	db $72, $ab, $00, $ae, $23, $7a, $7e

	db $00, $24, $d5, $c7, $51, $3a, $0c, $70, $81, $8d, $20
	db $de, $c0, $2b, $83, $b9, $a4, $04, $f8, $56, $7e

	db $00, $ed, $3f, $83, $c2, $04, $9d, $05, $1d
	db $3c, $c8, $5a, $ee, $62, $cd, $f3, $7d, $59
	db $ac, $05, $49, $35, $9c, $1d, $ca, $b5, $1f, $96, $93
	db $23, $ce, $b1, $a5, $9f, $7b, $01, $05, $af
	
	db $00, $af, $bd, $8e, $a3, $3a, $48, $b3, $7c, $df, $56, $6b
	db $78, $68, $97, $aa, $43, $27, $32, $d2
	db $60, $05, $77, $92, $1d, $c2, $97, $a3, $24, $c1, $61
	db $7d, $e0, $7e, $f6, $9c, $0c, $b0, $cd, $5a, $c6, $0c
	db $6a, $ad, $26, $b3
	db $f5, $34

MersonGoldTokenExchange_Text_RequirementsForSpecialGift:
	db TX_COMPRESSED, $75, $13, $a0, $c7, $36, $03, $1a, $c1
	db $3c, $81, $06, $c8, $f7, $b3, $91, $e1, $73, $00
	db $ac, $05, $a4, $28, $39, $52
	db $42, $f3, $21, $7c, $47, $4e, $ce, $5a, $4c, $6b
	db $54, $0f, $de, $d3, $81, $80, $e5, $c9, $d3, $bc

	db $40, $36, $85, $f3, $8a, $f5, $95, $29, $52, $4c
	db $8f, $02, $0b, $51, $90, $be, $23, $a7, $67, $07
	db $60, $2c, $33, $93, $b9, $b0, $18, $d6
	db $09, $e4, $08, $36, $47, $bd, $9c, $8f, $0b
	db $f5, $34

MersonGoldTokenExchange_Text_AllICanRememberAboutSecretShop:
	db TX_COMPRESSED, $62, $fb, $fe, $f7, $a2, $02, $f9, $d4, $93, $59
	db $bc, $43, $d5, $cb, $49, $c1, $5d, $e4, $87
	db $6a, $8a, $5e, $8c, $9e, $f7

	db $80, $56, $40, $55, $68, $2f, $c6, $42, $4e, $57, $b6, $d7, $40
	db $bd, $b6, $30, $91, $10, $24, $80, $82, $d2
	db $d5, $6b, $2c, $85, $f1, $1d, $1a, $12, $f9, $92

	db $fc, $01, $ca, $16, $98, $0e, $3f, $b9, $39
	db $af, $03, $95, $f0, $92, $61, $a4, $80, $c6, $b0
	db $4a, $93, $a2, $04, $02
	db $f5, $34

MersonGoldTokenExchange_Text_WhatSecretShopInSilphWarehouse:
	db TX_COMPRESSED, $6e, $9d, $ba, $58, $52, $4e, $21, $21, $11, $06
	db $87, $86, $49, $69, $38, $a0, $7d, $10
	db $95, $4d, $f5, $66, $90, $b4, $83, $a5

	db $00, $ed, $3f, $8e, $a2, $cd, $f3, $7d, $59, $ae, $0e
	db $de, $20, $6a

	db $e2, $01, $b9, $f7, $bf, $86, $4a, $70, $20, $a5, $49, $db
	db $78, $77, $13, $a8, $96, $18, $1c, $30, $35, $f1
	db $a6, $80

MersonGoldTokenExchange_Text_AfterFillingDex:
	db TX_COMPRESSED, $74, $59, $11, $63, $ef, $60, $c9, $10, $90, $b2
	db $a4, $f6, $93, $33, $6a, $38, $10, $63, $5c, $04, $16
	db $96, $ab, $59, $64, $2f, $88, $e8, $d0, $97, $cc, $97

	db $e0, $0e, $50, $b4, $c0, $71, $fd, $c9, $cd
	db $78, $1c, $af, $84, $93, $0d, $24, $06, $35, $82
	db $54, $9d, $10, $20, $17
	db $a9, $a0

MersonGoldTokenExchange_MapEventHeader:: db 0, 0

.Warps
	db 2
	warp_def $5, $4, 2, MERSON_CITY
	warp_def $5, $5, 2, MERSON_CITY

.CoordEvents
	db 0

.BGEvents
	db 0

.ObjectEvents
	db 1
	person_event SPRITE_GENTLEMAN, 3, 2, SPRITEMOVEDATA_00, 0, 0, -1, -1, 8 + PAL_OW_YELLOW, PERSONTYPE_SCRIPT, 0, MersonGoldTokenExchangeNPC, -1

