HauntedMansion_MapScriptHeader;trigger count
	db 0
 ;callback count
	db 0

HauntedMansion_Item_1:
	db SUPER_REPEL, 2

HauntedMansion_Item_2:
	db SPELL_TAG, 1

HauntedMansion_Item_3:
	db RARE_CANDY, 1

HauntedMansionNPC1:
	jumptextfaceplayer .text

.text
	db TX_COMPRESSED, $15, $05, $39, $5e, $93, $2f, $86, $d2, $6b
	db $79, $a4, $1e, $65, $86, $06, $a2, $4b, $48
	db $d0, $a8, $18, $d6, $0a, $3f, $a4, $40, $c2, $4f

	db $00, $50, $93, $9b, $da, $b4, $12, $25, $87, $b9
	db $79, $f3, $96, $9d, $b9, $69
	db $30, $0c, $87, $a1, $5a, $20, $70, $96, $93
	db $79, $7a, $32, $2b, $0d, $50, $64, $81, $5e, $4d
	db $60, $2a, $35, $9c, $72, $1e, $7f, $18, $4b, $30, $5f
	db $78, $4b, $ad, $1f, $e3, $94, $fb, $d0, $d5
	db $f5, $42, $4b, $0d, $44, $9a, $4c, $c2, $8f, $7b

	db $e0, $0e, $8b, $21, $03, $71, $0d, $2c, $e5, $49
	db $04, $f2, $12, $73, $7b, $56, $82, $44, $b0, $f7
	db $2a, $9f, $39, $69, $db, $96, $90, $b5, $ca, $69, $e0
	db $a6, $80

HauntedMansionNPC2:
	jumptextfaceplayer .text

.text
	db TX_COMPRESSED, $72, $85, $a2, $e3, $84, $0d, $c5, $9e, $e4, $14, $b0
	db $bc, $c8, $5f, $39, $90, $d4, $48, $93, $59

	db $f8, $01, $49, $38, $0e, $57, $c2, $49, $90, $d4
	db $47, $91, $7a, $35, $a2, $6a, $ce, $58

	db $42, $01, $16, $b0, $93, $99, $80, $57, $01, $05
	db $a7, $96, $3e, $53, $70, $81, $ab

	db $c0, $1b, $42, $f9, $c5, $7a, $ca, $94, $ee, $d9, $af
	db $d4, $d0

HauntedMansion_Trainer_1:
	trainer EVENT_HAUNTED_MANSION_TRAINER_1, MEDIUM, 2, .before_battle_text, .battle_won_text, $0000, .Script

.Script
	end_if_just_battled
	jumptextfaceplayer .after_battle_text

.before_battle_text
	db TX_COMPRESSED, $13, $2d, $22, $e2, $43, $54, $c8, $f3, $01, $05
	db $a7, $b0, $1f, $2d, $2c, $e0, $5a, $b8, $90, $d5, $2c
	db $2a, $b9, $3b, $96, $93, $88, $11, $ab, $38, $a4, $60, $a9
	db $69, $a0

.battle_won_text
	db TX_COMPRESSED, $76, $9f, $c7, $c1, $45, $7d, $d5, $6a, $cd
	db $6f, $3e, $16, $ad, $30, $38, $4d
	db $55, $ca, $f4, $99, $ce, $b5, $ca, $6c, $d7, $4f
	db $05, $34

.after_battle_text
	db TX_COMPRESSED, $6e, $65, $c7, $08, $1b, $9d, $3d, $06, $19, $39
	db $fb, $c6, $0c, $64, $83, $c2, $5a, $4e, $72, $90, $a2
	db $d0, $01, $90, $92, $c6, $46, $8e, $08, $5e, $91, $48, $64
	db $e5, $e6, $91, $0c, $18, $d6, $0a, $67, $41
	db $7a, $9a

HauntedMansion_Trainer_2:
	trainer EVENT_HAUNTED_MANSION_TRAINER_2, MEDIUM, 3, .text, .text, $0000, .Script

.Script
	end_if_just_battled
	jumptextfaceplayer .text

.text
	text "<...>"
	done

HauntedMansion_Trainer_3:
	trainer EVENT_HAUNTED_MANSION_TRAINER_3, SAGE, 3, .before_battle_text, .battle_won_text, $0000, .Script

.Script
	end_if_just_battled
	jumptextfaceplayer .after_battle_text

.before_battle_text
	db TX_COMPRESSED, $29, $27, $39, $48, $51, $68, $9a, $b3
	db $79, $66, $cf, $74, $6f, $8c, $9c, $cb, $49, $8d
	db $6a, $96, $3e, $53, $78, $35, $d9, $dd, $26, $69, $e0
	db $a6, $80

.battle_won_text
	db TX_COMPRESSED, $29, $26, $83, $9c, $a4, $28, $b4, $44, $34, $b3
	db $79, $9d, $21, $03, $73, $01, $f2, $9b
	db $e3, $4d

.after_battle_text
	db TX_COMPRESSED, $29, $27, $39, $48, $51, $68, $96, $9d
	db $b7, $b3, $51, $f7, $b1, $26, $b3, $9a, $b3
	db $01, $a4, $20, $41, $0c, $9c, $fe, $02, $3b, $96, $93
	db $04, $f6, $ac, $e6, $f7, $b1, $3a, $b7, $fa, $68, $47
	db $a9, $a0

HauntedMansionChestKey1:
	writehalfword EVENT_GOT_BEDROOM_KEY_1
	selse

HauntedMansionChestKey2:
	writehalfword EVENT_GOT_BEDROOM_KEY_2
	sendif

;fallthrough
	opentext
	writetext .opened_text
	checkevent -1
	sif true
		jumptext .empty_text
	verbosegiveitem BEDROOM_KEY, 1
	setevent -1
	endtext

.opened_text
	db TX_COMPRESSED, $a7, $8e, $04, $41, $90
	db $f2, $f5, $a4, $e3, $29, $34, $5d, $3c
	db $14, $f1, $00

.empty_text
	db TX_COMPRESSED, $29, $27, $19, $49, $a2, $e0
	db $d0, $f1, $be, $22, $c1, $71
	db $a6, $80

HauntedMansionGengar:
	faceplayer
	opentext
	writetext .text
	closetext
	playsound SFX_PERISH_SONG
	special Special_BattleTowerFade
	waitsfx
	warp DREAMSEQUENCE, 34, 2
	end

.text
	db TX_COMPRESSED, $62, $69, $34, $9f, $e5, $a4, $e6, $56, $7a, $fa
	db $1e, $64, $2f, $9c, $b0, $c7, $ce, $10, $35, $71

	db $00, $ea, $55, $a8, $88, $bd, $58, $30, $c9, $cf

	db $10, $0e, $43, $dc, $82, $98, $05, $71, $59, $e6, $c6, $f9, $d2

	db $80, $62, $69, $34, $9f
	db $1a, $78, $80

HauntedMansionMansionDoor:
	checkitem MANSION_KEY
	sif false
		jumptext .locked_text
	opentext
	writetext .opened_text
	playsound SFX_ENTER_DOOR
	special Special_BattleTowerFade
	waitsfx
	warpfacing UP, HAUNTED_MANSION, 42, 15
	closetext
	end

.locked_text
	db TX_COMPRESSED, $29, $27, $32, $10, $ae, $0d
	db $0f, $74, $2c, $a9, $1e
	db $7d, $4d

.opened_text
	db TX_COMPRESSED, $a7, $8e, $04, $41, $90
	db $f2, $f5, $a4, $e6, $42, $15, $ca, $87, $69, $96, $93
	db $54, $2b, $a4, $40, $c2, $48, $26, $0c, $17
	db $a9, $e2

HauntedMansionBedroomDoor:
	checkevent EVENT_GOT_BEDROOM_KEY_1
	iffalse .locked
	checkevent EVENT_GOT_BEDROOM_KEY_2
	sif false
.locked
		jumptext .locked_text
	opentext
	writetext .opened_text
	playsound SFX_ENTER_DOOR
	special Special_BattleTowerFade
	waitsfx
	warpfacing UP, HAUNTED_MANSION, 52, 31
	closetext
	end

.locked_text
	db TX_COMPRESSED, $29, $23, $44, $c8, $42, $b8, $34
	db $3d, $d0, $b2, $a4, $79, $8a, $c1, $4b, $a8
	db $2a, $ba, $16, $54, $91
	db $ea, $68

.opened_text
	db TX_COMPRESSED, $a7, $8e, $34, $4e, $85, $95, $23
	db $cb, $d6, $93, $99, $08, $57, $2a, $1d, $a6, $5a
	db $4d, $50, $8d, $1a, $e0, $70, $8a, $46, $09, $1e
	db $a7, $88

HauntedMansion_MapEventHeader ;filler
	db 0, 0

;warps
	db 24
	warp_def $29, $6, 3, HAUNTED_FOREST
	warp_def $29, $7, 3, HAUNTED_FOREST
	warp_def $3, $5, 8, HAUNTED_MANSION
	warp_def $4, $d, 1, HAUNTED_MANSION
	warp_def $3, $15, 10, HAUNTED_MANSION
	warp_def $7, $2, 12, HAUNTED_MANSION
	warp_def $7, $16, 15, HAUNTED_MANSION
	warp_def $17, $4, 3, HAUNTED_MANSION
	warp_def $17, $5, 3, HAUNTED_MANSION
	warp_def $17, $12, 5, HAUNTED_MANSION
	warp_def $17, $13, 5, HAUNTED_MANSION
	warp_def $5, $20, 6, HAUNTED_MANSION
	warp_def $3, $27, 20, HAUNTED_MANSION
	warp_def $3, $2f, 21, HAUNTED_MANSION
	warp_def $5, $36, 7, HAUNTED_MANSION
	warp_def $f, $2a, 23, HAUNTED_MANSION
	warp_def $f, $2b, 23, HAUNTED_MANSION
	warp_def $1f, $34, 4, HAUNTED_MANSION
	warp_def $1f, $35, 4, HAUNTED_MANSION
	warp_def $2b, $31, 13, HAUNTED_MANSION
	warp_def $3b, $1c, 14, HAUNTED_MANSION
	warp_def $3b, $1d, 14, HAUNTED_MANSION
	dummy_warp $24, $7
	warp_def $37, $2c, 1, HAUNTED_MANSION_BASEMENT

	;xy triggers
	db 0

	;signposts
	db 4
	signpost 16, 21, SIGNPOST_READ, HauntedMansionChestKey1
	signpost 54, 53, SIGNPOST_READ, HauntedMansionChestKey2
	signpost 35, 7, SIGNPOST_READ, HauntedMansionMansionDoor
	signpost 3, 13, SIGNPOST_READ, HauntedMansionBedroomDoor

	;people-events
	db 10
	person_event SPRITE_TEACHER, 37, 4, SPRITEMOVEDATA_SPINRANDOM_SLOW, 0, 0, -1, -1, PAL_OW_RED, PERSONTYPE_SCRIPT, 0, HauntedMansionNPC1, -1
	person_event SPRITE_POKE_BALL, 7, 11, SPRITEMOVEDATA_ITEM_TREE, 0, 0, -1, -1, PAL_OW_RED, PERSONTYPE_ITEMBALL, 0, HauntedMansion_Item_1, EVENT_HAUNTED_MANSION_ITEM_1
	person_event SPRITE_POKE_BALL, 16, 7, SPRITEMOVEDATA_ITEM_TREE, 0, 0, -1, -1, PAL_OW_YELLOW, PERSONTYPE_TMHMBALL, TM_DREAM_EATER, 0, EVENT_HAUNTED_MANSION_TM
	person_event SPRITE_POKE_BALL, 50, 26, SPRITEMOVEDATA_ITEM_TREE, 0, 0, -1, -1, PAL_OW_RED, PERSONTYPE_ITEMBALL, 0, HauntedMansion_Item_2, EVENT_HAUNTED_MANSION_ITEM_2
	person_event SPRITE_POKE_BALL, 7, 50, SPRITEMOVEDATA_ITEM_TREE, 0, 0, -1, -1, PAL_OW_RED, PERSONTYPE_ITEMBALL, 0, HauntedMansion_Item_3, EVENT_HAUNTED_MANSION_ITEM_3
	person_event SPRITE_GENGAR, 24, 52, SPRITEMOVEDATA_POKEMON, 0, 0, -1, -1, PAL_OW_RED, PERSONTYPE_SCRIPT, 0, HauntedMansionGengar, EVENT_HAUNTED_FOREST_GENGAR
	person_event SPRITE_GRANNY, 12, 42, SPRITEMOVEDATA_STANDING_RIGHT, 0, 0, -1, -1, PAL_OW_BROWN, PERSONTYPE_TRAINER, 1, HauntedMansion_Trainer_1, -1
	person_event SPRITE_GRANNY, 20, 18, SPRITEMOVEDATA_STANDING_RIGHT, 0, 0, -1, -1, PAL_OW_BROWN, PERSONTYPE_TRAINER, 1, HauntedMansion_Trainer_2, -1
	person_event SPRITE_SAGE, 44, 50, SPRITEMOVEDATA_STANDING_LEFT, 0, 0, -1, -1, PAL_OW_BLUE, PERSONTYPE_TRAINER, 1, HauntedMansion_Trainer_3, -1
	person_event SPRITE_GRANNY, 55, 44, SPRITEMOVEDATA_STANDING_RIGHT, 0, 0, -1, -1, PAL_OW_BROWN, PERSONTYPE_SCRIPT, 1, HauntedMansionNPC2, EVENT_RIJON_LEAGUE_WON

