BattleArcadeLobby_MapScriptHeader:

;trigger count
	db 0
;callback count
	db 0

BattleArcadeLobbyInstructionsNPC:
	jumptextfaceplayer BattleArcadeLobbyInstructionsNPC_Text

BattleArcadeLobbyBattleNPC:
	opentext
	special PlaceMoneyTopRight
	writetext BattleArcadeLobbyBattleNPC_Text_Enter
	menuanonjumptable BattleArcadeLobby_EnterMenu
	dw .come_back_later
	dw .enter
	dw .instructions
	dw .come_back_later
.instructions
	writetext BattleArcadeLobbyBattleNPC_Text_Instructions
	waitbutton
	writetext BattleArcadeLobbyBattleNPC_Text_EnterInsist
	yesorno
	sif false
.come_back_later
		jumptext BattleArcadeLobby_Text_ComeBackLater
.enter
	checkcode VAR_PARTYCOUNT
	sif <, 3
		jumptext BattleArcadeLobby_Text_RequireThreePokemon
	callasm BattleArcadeLobby_LegalityCheck
	sif <, 3
		jumptext BattleArcadeLobby_Text_NotLevelForty
	checkmoney 0, 500
	sif =, 2
		jumptext BattleArcadeLobby_Text_NeedMoreMoney
	takemoney 0, 500
	waitsfx ;wait for the text's "click" sound to end
	special PlaceMoneyTopRight
	playwaitsfx SFX_TRANSACTION
.selection_loop
	writetext BattleArcadeLobby_Text_SelectParty
	waitbutton
	callasm BattleArcadeLobby_LegalityCheck
	callasm ChooseThreePartyMonsForBattle
	sif false, then
		writetext BattleArcadeLobby_Text_CancelChallenge
		yesorno
		iffalse .selection_loop
		givemoney 0, 500
		jumptext BattleArcadeLobby_Text_Refund
	sendif
	writetext BattleArcadeLobby_Text_EnterToBegin
	waitbutton
	closetext
	applymovement PLAYER, .entrance_movement
	special ClearBGPalettes
	warpsound
	waitsfx
	warp BATTLE_ARCADE_BATTLEROOM, 4, 7
	applymovement PLAYER, .approach_machine
	farscall MainArcadeScript
	applymovement PLAYER, .leave_machine
	warpsound
	waitsfx
	warp BATTLE_ARCADE_LOBBY, 5, 0
	applymovement PLAYER, .exit_movement
	spriteface PLAYER, UP
	jumptext BattleArcadeLobby_Text_ThanksForPlaying
.entrance_movement
	step_right
	step_right
	step_right
	step_up
	step_up
	step_up
	remove_person
	step_end
.exit_movement
	step_down
	step_down
	step_down
	step_left
	step_left
	step_left
	step_end
.approach_machine
	step_left
	step_left
	step_up
	step_up
	step_up
	step_left
	step_end
.leave_machine
	step_right
	step_down
	step_down
	step_down
	step_right
	step_right
	turn_head_down
	remove_person
	step_end

BattleArcadeLobby_EnterMenu:
	db $40 ;flags (?)
	db 4, 4 ;start coordinates (y, x)
	db 11, 19 ;end coordinates (y, x) -- final y - initial y = 2 * items + 1, final x - initial x = longest item + 3
	dw .options
	db 1 ;default option
.options
	db $a0 ;flags 2.0 (??)
	db 3 ;option count
	db "Enter arcade@"
	db "Instructions@"
	db "Cancel@"

BattleArcadeLobbyRedeemNPC:
	opentext
	pokemart 6, 0
	closetext
	end

BattleArcadeLobby_Door:
	jumptext BattleArcadeLobby_Text_Door

BattleArcadeLobby_HighScoreDisplay:
	jumptext BattleArcadeLobby_Text_HighScores

BattleArcadeLobbyInstructionsNPC_Text:
	ctxt "The battles you"
	line "encounter are"

	para "completely"
	line "randomized!"

	para "The more fights"
	line "you win in a"

	para "row, the more"
	line "Arcade Tickets"
	cont "you get."

	para "You can exchange"
	line "them for some"
	cont "cool stuff!"
	done

BattleArcadeLobbyRedeemNPC_Text_Redeem:
	ctxt "Welcome!"

	para "We can redeem your"
	line "Arcade Tickets"
	cont "for prizes here!"
	done

BattleArcadeLobbyBattleNPC_Text_Enter:
	ctxt "Welcome to the"
	line "Battle Arcade!"

	para "It costs ¥500"
	line "per try."

	para "Would you like"
	line "to enter?"
	done

BattleArcadeLobbyBattleNPC_Text_Instructions:
	ctxt "You will face a"
	line "series of random"

	para "battles until"
	line "your party is"
	cont "defeated."

	para "Your PP will be"
	line "restored between"

	para "battles, but your"
	line "party will not be"
	cont "otherwise healed."

	para "The battles will"
	line "slowly rise in"

	para "difficulty as"
	line "you progress."

	para "At the end of"
	line "every round, you"

	para "will receive a"
	line "number of points"

	para "based on your"
	line "performance."

	para "The amount of"
	line "points you"

	para "receive will be"
	line "multiplied by the"

	para "round number, so"
	line "try to get a long"
	cont "win streak!"

	para "At the end, your"
	line "total score will"

	para "be shown and you"
	line "will receive an"

	para "Arcade Ticket for"
	line "every 300 points."

	para "You can exchange"
	line "those tickets on"

	para "the counter on"
	line "the right for"
	cont "various prizes."
	done

BattleArcadeLobbyBattleNPC_Text_EnterInsist:
	ctxt "So, do you want to"
	line "enter? It costs"
	cont "¥500 per try."
	done

BattleArcadeLobby_Text_ComeBackLater:
	ctxt "OK then, come"
	line "back some other"
	cont "time!"
	done

BattleArcadeLobby_Text_RequireThreePokemon:
	ctxt "You must have"
	line "at least three"
	para "#mon in your"
	line "team to enter."

	para "You can use the"
	line "computer nearby"
	para "to organize your"
	line "team."
	done

BattleArcadeLobby_Text_NeedMorePoints:
	ctxt "You don't have"
	line "enough tickets."
	done

BattleArcadeLobby_Text_NotLevelForty:
	ctxt "Sorry, your"
	line "#mon must be"

	para "at least level 40"
	line "to participate."

	para "You can use the"
	line "computer nearby"

	para "to organize your"
	line "team."
	done

BattleArcadeLobby_Text_SelectParty:
	ctxt "Please select the"
	line "#mon you want"
	cont "to battle with."
	done

BattleArcadeLobby_Text_EnterToBegin:
	ctxt "Wonderful!"

	para "Please enter the"
	line "arcade room to"
	
	para "begin your"
	line "battles!"
	done

BattleArcadeLobby_Text_AlreadyHaveItem:
	ctxt "You already have"
	line "this item."
	done

BattleArcadeLobby_Text_NeedMoreMoney:
	ctxt "Sorry, you don't"
	line "have enough money"
	cont "to enter."
	done

BattleArcadeLobby_Text_ThanksForPlaying:
	ctxt "Thanks for"
	line "playing, come"
	cont "again!"
	done

BattleArcadeLobby_Text_CancelChallenge:
	ctxt "Are you sure you"
	line "want to leave?"
	done

BattleArcadeLobby_Text_Refund:
	ctxt "Your ¥500 will now"
	line "be refunded."

	para "We hope you enter"
	line "the challenge next"
	cont "time. Come again!"
	done

BattleArcadeLobby_Text_Door:
	ctxt "It is locked!"
	line "A sign on it says,"

	para "BATTLE ARCADE"
	line "PLAYERS ONLY"
	done

BattleArcadeLobby_Text_HighScores:
	start_asm
	push bc
	ld hl, wBattleArcadeMaxScore
	ld a, [hli]
	ld b, a
	ld a, [hli]
	ld c, a
	ld a, [hli]
	ld d, a
	ld a, [hli]
	ld e, a
	push hl
	ld hl, wStringBuffer1
	ld a, $8a
	ld [hDigitsFlags], a
	predef PrintBigNumber
	ld bc, 0
	pop hl
	ld a, [hli]
	ld d, a
	ld e, [hl]
	ld a, 3
	ld [hDigitsFlags], a
	ld hl, wStringBuffer3
	predef PrintBigNumber
	ld a, "@"
	ld [wStringBuffer1 + 10], a
	ld [wStringBuffer3 + 3], a
	pop bc
	ld hl, .text
	ret
.text
	ctxt "Current Arcade"
	line "high scores:"

	para "Score: <STRBF1>"
	line "Rounds won:   <STRBF3>"
	done

BattleArcadeLobby_LegalityCheck:
	ld hl, wPartyCount
	ld a, [hli]
	ld c, a
	ld d, a
	ld b, 0
.loop_species
	sla b
	ld a, [hli]
	and a
	jr z, .checked_species
	inc a
	jr z, .checked_species
	cp EGG + 1 ; a has been incremented
	jr z, .checked_species
	set 0, b
.checked_species
	dec c
	jr nz, .loop_species
	ld c, d
	push bc
	ld b, 0
	ld de, wPartyMon2 - wPartyMon1
	ld hl, PartyMon1Level
.loop_level
	sla b
	ld a, [hl]
	add hl, de
	cp 40
	jr c, .checked_level
	set 0, b
.checked_level
	dec c
	jr nz, .loop_level
	ld a, b
	pop bc
	and b
	ld b, 0
	ld d, b
.loop_bits
	rrca
	jr nc, .no_increment
	inc d
.no_increment
	rl b
	dec c
	jr nz, .loop_bits
	ld a, d
	ld [hScriptVar], a
	ld a, b
	ld [wBattleTowerLegalPokemonFlags], a
	ret

BattleArcadeLobby_MapEventHeader:: db 0, 0

.Warps: db 2
	warp_def 9, 5, 1, ROUTE_86
	warp_def 9, 6, 1, ROUTE_86

.CoordEvents: db 0

.BGEvents: db 2
	signpost 0, 5, SIGNPOST_READ, BattleArcadeLobby_Door
	signpost 2, 4, SIGNPOST_READ, BattleArcadeLobby_HighScoreDisplay

.ObjectEvents: db 3
	person_event SPRITE_LASS, 5, 6, SPRITEMOVEDATA_WANDER, 0, 0, -1, -1, PAL_OW_RED, PERSONTYPE_SCRIPT, 0, BattleArcadeLobbyInstructionsNPC, -1
	person_event SPRITE_RECEPTIONIST, 1, 9, SPRITEMOVEDATA_00, 0, 0, -1, -1, PAL_OW_PURPLE, PERSONTYPE_SCRIPT, 0, BattleArcadeLobbyRedeemNPC, -1
	person_event SPRITE_RECEPTIONIST, 1, 2, SPRITEMOVEDATA_00, 0, 0, -1, -1, PAL_OW_YELLOW, PERSONTYPE_SCRIPT, 0, BattleArcadeLobbyBattleNPC, -1
