BallMakingScript::
	pushhalfword PokeballTable
	writehalfword PokeballMenu
	jump BallMakingMain
	
BallMakingBasementScript::
	pushhalfword PokeballBasementTable
	writehalfword PokeballBasementMenu

BallMakingMain:
	opentext
	callasm _LoadFontsBattleExtra
	writetext ChoosePokeballText
	loadscrollingmenudata -1
.ballMakingLoop
	scrollingmenu %10
	sif false, then
		pophalfwordvar
		closewindow
		closetextend
	sendif
	
	pullhalfwordvar
	addvar -1
	loadarray -1, PokeballTableEntrySizeEnd - PokeballTable

	readarray 1
	comparevartobyte wBallMakingLevel
	sif false, then
		readarray 1
		writetext LowBallLevelText
	selse
		readarray 2
		itemtotext 0, 0
		copyvartobyte wCurItem
		takeitem ITEM_FROM_MEM
		sif false, then
			readarray 0
			writetext NotEnoughApricornsText
		selse
			readarray 1
			sif >, 49, then
				copybytetovar wBallMakingLevel
				addvar -49
				copyvartobyte wScriptBuffer
				random
				comparevartobyte wScriptBuffer
				iftrue .madeSpecialBall ; basically a goto
				writetext BallFailText
			selse
.madeSpecialBall
				readarray 0
				sif =, MASTER_BALL
					setevent EVENT_CRAFTED_MASTER_BALL
				verbosegiveitem ITEM_FROM_MEM, 1
				sif false, then
					readarray 2
					giveitem ITEM_FROM_MEM
				selse
					readarray 1
					divideop 0, 10
					addvar 1
					givecraftingEXP CRAFT_BALLMAKING
					waitbutton
				sendif
			sendif
		sendif
	sendif
	jump .ballMakingLoop

BallFailText:
	db TX_COMPRESSED, $e0, $d5, $93, $8c, $29, $27, $34, $42, $c6, $c8, $56
	db $47, $95, $ac, $2a, $47
	
	db $c4, $02, $9e, $8f, $a7, $99, $61, $8f, $ea, $91
	db $bd, $b1, $5e, $f7, $be
	db $07, $30

NotEnoughApricornsText:
	db TX_COMPRESSED, $72, $85, $a8, $43, $3c, $cd
	db $7a, $9e, $52
	db $c2, $a9, $fd, $52, $39, $69, $1a
	db $15, $03, $95, $5e, $f7, $be
	db $07, $30

LowBallLevelText:
	db TX_COMPRESSED, $72, $85, $a8, $fb, $48, $b8, $ac, $e7, $4c, $18
	db $fa, $f3, $98, $00
	deciram hScriptVar, 1, 0
	db TX_COMPRESSED, $96, $18, $fe, $a9, $1c, $b4, $8d
	db $0a, $81, $ca, $af, $7b, $df
	db $03, $98

ChoosePokeballText:
	db TX_COMPRESSED, $6d, $48, $42, $83, $96, $93, $8a, $f7, $bd
	db $78, $10, $5a, $95, $69, $2e, $58, $63, $fa, $a4, $7e
	db $a7, $88

PokeballMenu:
	db %1000010
	db 02, 01
	db 10, 15
	dw .PokeballMenuOptions
	db 1

.PokeballMenuOptions
	db %100000
	db 4, SCREEN_WIDTH + 7
	db PokeballTableEntrySizeEnd - PokeballTable
	dba PokeballTable_WithListQuantity
	dba PlaceMenuItemName
	dba PlaceBallMakingLevelRequirement
	dba UpdateItemDescription

PokeballBasementMenu:
	db %1000010
	db 02, 01
	db 10, 15
	dw .PokeballBasementMenuOptions
	db 1

.PokeballBasementMenuOptions:
	db %100000
	db 4, SCREEN_WIDTH + 6
	db PokeballTableEntrySizeEnd - PokeballTable
	dba PokeballBasementTable_WithListQuantity
	dba PlaceMenuItemName
	dba PlaceBallMakingLevelRequirement
	dba UpdateItemDescription

PlaceBallMakingLevelRequirement:
	push de
	callba ScrollingMenu_GetAddressOfMenu_UseScrollingMenuCursorPosition
	inc hl
	inc hl
	ld a, [hl]
	ld [wd265], a
	call GetItemName
	ld b, 4
	ld h, d
	ld l, e
.findSpaceLoop
	ld a, [hli]
	cp " "
	jr z, .foundSpace
	dec b
	jr nz, .findSpaceLoop
	inc hl
.foundSpace
	dec hl
	ld [hl], "@"
	pop hl
	ld de, .ApricornColourAndLevelString
	jp PlaceText

.ApricornColourAndLevelString:
	text "<STRBF1>/", $6e, "@"
	deciram wMenuSelectionQuantity, 1, 2
	done

PokeballTable_WithListQuantity:
	db 10
PokeballTable:
	db POKE_BALL, 0, ORNGAPRICORN
PokeballTableEntrySizeEnd:
	db GREAT_BALL, 4, CYANAPRICORN
	db ULTRA_BALL, 7, GREYAPRICORN
	db QUICK_BALL, 10, YLW_APRICORN
	db DUSK_BALL, 14, BLK_APRICORN
	db FAST_BALL, 18, RED_APRICORN
	db DIVE_BALL, 22, BLU_APRICORN
	db REPEAT_BALL, 26, PNK_APRICORN
	db TIMER_BALL, 30, WHT_APRICORN
	db FRIEND_BALL, 35, GRN_APRICORN
	db $ff

PokeballBasementTable_WithListQuantity:
	db 2
PokeballBasementTable:
	db MASTER_BALL, 50, PRPLAPRICORN
	db SHINY_BALL, 50, SHNYAPRICORN
	db $ff

