; NAME: Landing Bank Game Guy final
; GAMES: MP3_USA
; EXECUTION: Direct

; This code is designed to mimic the "Visit Koopa" event from MP1.
; Koopa gives 10 coins upon passing/landing, or 20 coins during the
; Last 5 Turns. Use in conjunction with the "Model View Koopa" event
; to actively load the Koopa model on the board!

ADDIU SP SP -40
SW RA 36(SP)
SW S0 32(SP)
SW S1 28(SP)

; S0 = Current Player Index
; S1 = Coins in Bank

;===Store Current Player Index in S0===
JAL GetCurrentPlayerIndex
NOP
MOVE S0 V0

;===Hooray Message===
JAL PlayMusic
LI A0 0x43 ; Koopa sound effect
; Visit the following link to get SFX Indexes:
; https://pastebin.com/H1jxNFqr

SW R0 16(SP) ; A4
SW R0 20(SP) ; A5
SW R0 24(SP) ; A6
LI A0 0xA ; Character image (-1 for none, 0x2 for Koopa)
; Visit the following link to get the full list of Character Images:
; https://github.com/PartyPlanner64/PartyPlanner64/wiki/Displaying-Messages
; If you use a character image, check the bottom of the code
LUI A1 hi(HoorayMessage)
ADDIU A1 A1 lo(HoorayMessage) ; This loads "Message" into the textbox
LI A2 0
JAL ShowMessage
LI A3 0

; The rest here perform the "wait for confirmation"
; and probably messagebox teardown.
JAL 0x800EC9DC
NOP
JAL CloseMessage
NOP
JAL 0x800EC6EC
NOP

;===Check Coins in Bank===
LUI T0 hi(bank_coin_total)
ADDIU T0 T0 lo(bank_coin_total)
LHU S1 0(T0)
BEQZ S1 nocoins
NOP
SH R0 0(T0)

LUI A0 hi(coin_string_loc)
ADDIU A0 A0 lo(coin_string_loc)
LUI A1 hi(percent_d)
ADDIU A1 A1 lo(percent_d)
JAL sprintf
MOVE A2 S1

;===Give Coins Message===
JAL PlayMusic
LI A0 0x46 ; Koopa sound effect
; Visit the following link to get SFX Indexes:
; https://pastebin.com/H1jxNFqr

SW R0 16(SP) ; A4
SW R0 20(SP) ; A5
SW R0 24(SP) ; A6
LI A0 0xA ; Character image (-1 for none, 0x2 for Koopa)
; Visit the following link to get the full list of Character Images:
; https://github.com/PartyPlanner64/PartyPlanner64/wiki/Displaying-Messages
; If you use a character image, check the bottom of the code
LUI A1 hi(GiveCoinsMessage)
ADDIU A1 A1 lo(GiveCoinsMessage) ; This loads "Message" into the textbox
LUI A2 hi(coin_string_loc)
ADDIU A2 A2 lo(coin_string_loc)
JAL ShowMessage
LI A3 0
; The rest here perform the "wait for confirmation"
; and probably messagebox teardown.
JAL 0x800EC9DC
NOP
JAL CloseMessage
NOP
JAL 0x800EC6EC
NOP

;===Give Coins===
MOVE A0 S0
JAL AdjustPlayerCoinsGradual ; Give 10 coins to current player
MOVE A1 S1

MOVE A0 S0
JAL ShowPlayerCoinChange ; Show "+10" next to player HUD
MOVE A1 S1

JAL GetPlayerStruct
LI A0 -1 ; Get current player struct

LBU T0 3(V0) ; Load character value into T0
JAL PlaySound
ADDIU A0 T0 0x2BE ; Mario's Happy Voice
; Character voices are their "character value" distance away from
; Mario's, e.g. Luigi's character value = 1, so Luigi's happy voice
; is 1 away from Mario's

LI A0 -1 ; Load Current Player Index
LI A1 5 ; Animation Index (Joy)
JAL SetBoardPlayerAnimation
LI A2 0 ; Do not loop animation

JAL SleepProcess ; Wait 40 frames for animation
LI A0 40

J exit ; Finish the event
NOP

nocoins:
JAL PlayMusic
LI A0 0x47 ; Koopa sound effect
; Visit the following link to get SFX Indexes:
; https://pastebin.com/H1jxNFqr

SW R0 16(SP) ; A4
SW R0 20(SP) ; A5
SW R0 24(SP) ; A6
LI A0 0xA ; Character image (-1 for none, 0x2 for Koopa)
; Visit the following link to get the full list of Character Images:
; https://github.com/PartyPlanner64/PartyPlanner64/wiki/Displaying-Messages
; If you use a character image, check the bottom of the code
LUI A1 hi(BonusMessage)
ADDIU A1 A1 lo(BonusMessage) ; This loads "LastMessage" into the textbox
LI A2 0
JAL ShowMessage
LI A3 0

; The rest here perform the "wait for confirmation"
; and probably messagebox teardown.
JAL 0x800EC9DC
NOP
JAL CloseMessage
NOP
JAL 0x800EC6EC
NOP

SW R0 16(SP) ; A4
SW R0 20(SP) ; A5
SW R0 24(SP) ; A6
LI A0 0xA ; Character image (-1 for none, 0x2 for Koopa)
; Visit the following link to get the full list of Character Images:
; https://github.com/PartyPlanner64/PartyPlanner64/wiki/Displaying-Messages
; If you use a character image, check the bottom of the code
LUI A1 hi(NoCoinsMessage)
ADDIU A1 A1 lo(NoCoinsMessage) ; This loads "LastMessage" into the textbox
LI A2 0
JAL ShowMessage
LI A3 0

; The rest here perform the "wait for confirmation"
; and probably messagebox teardown.
JAL 0x800EC9DC
NOP
JAL CloseMessage
NOP
JAL 0x800EC6EC
NOP

exit:

JAL GetBoardAudioIndex
NOP

JAL PlayMusic
MOVE A0 V0

LW S0 32(SP)
LW S1 28(SP)
LW RA 36(SP)
JR RA
ADDIU SP SP 40

percent_d:
.asciiz "%d" ; 0x25640000

coin_string_loc:
.fill 8

Greeting_Message:
.byte 0x1A,0x1A,0x1A,0x1A ; Standard padding for picture
.ascii "Welcome to the Game Guy Bank"
.byte 0x85 ; Period (.)
.byte 0x0A ; New Line (Writes Below)
.byte 0x1A,0x1A,0x1A,0x1A ; Standard padding for picture
.ascii "We will take up to "
.byte 0x0A ; New Line (Writes Below)
.byte 0x1A,0x1A,0x1A,0x1A ; Standard padding for picture
.ascii "a"
.byte 0x06 ; Blue font
.ascii " 30"
.byte 0x3D ; - (minus)
.ascii "Coin"
.byte 0x08 ; White Font
.ascii " deposit"
.byte 0x85 ; Period (.)
.byte 0xFF,0 ; FF=Pause

.align 16
HoorayMessage:
.byte 0x1A,0x1A,0x1A,0x1A
.ascii "Ooo"
.byte 0xC2
.byte 0x0A,0x1A,0x1A,0x1A,0x1A
.ascii "Congratulations"
.byte 0xC2
.byte 0xFF,0

.align 16
GiveCoinsMessage:
.byte 0x1A,0x1A,0x1A,0x1A
.ascii "As a"
.byte 0x07
.ascii " special bonus"
.byte 0x08,0x82
.ascii " you get"
.byte 0x0A,0x1A,0x1A,0x1A,0x1A
.ascii "all the coins we"
.byte 0x5C
.ascii "ve collected"
.byte 0xC2
.byte 0x0A,0x1A,0x1A,0x1A,0x1A
.ascii "The number of"
.byte 0x06
.ascii " coins"
.byte 0x08
.ascii " is "
.byte 0x06
.byte 0x11
.byte 0x08,0xC2
.byte 0xFF,0

.align 16
BonusMessage:
.byte 0x1A,0x1A,0x1A,0x1A
.ascii "You"
.byte 0x5C
.ascii "ve won a"
.byte 0x07
.ascii " special bonus"
.byte 0x08,0xC2
.byte 0x0A,0x1A,0x1A,0x1A,0x1A
.ascii "You get all the coins the"
.byte 0x0A,0x1A,0x1A,0x1A,0x1A
.ascii "bank has collected so far"
.byte 0xC2
.byte 0xFF,0

.align 16
NoCoinsMessage:
.byte 0x0A,0x1A,0x1A,0x1A,0x1A
.byte 0x85,0x85,0x85
.ascii "Oh wait"
.byte 0xFF,0
.ascii "That"
.byte 0x5C
.ascii "s right"
.byte 0x0A,0x1A,0x1A,0x1A,0x1A
.ascii "We don"
.byte 0x5C
.ascii "t" 
.ascii " have coins"
.byte 0x08,0x85
.byte 0x0A,0x1A,0x1A,0x1A,0x1A
.ascii "Heh"
.byte 0x85
.byte 0xFF,0

.align 16
GoodbyeMessage:
.byte 0x0A,0x1A,0x1A,0x1A,0x1A
.byte 0x85,0x85,0x85
.ascii "It"
.byte 0xC2
.ascii " ain"
.byte 0x5C
.ascii "t"
.byte 0x0A,0x1A,0x1A,0x1A,0x1A
.ascii "My fault"
.ascii " you walked in"
.ascii " front of me"
.byte 0x08,0x85
.byte 0x0A,0x1A,0x1A,0x1A,0x1A
.ascii "See ya"
.byte 0x85
.byte 0xFF,0

; Here's a list of the most common bytes you'll need
; .byte 0x01 ; Black Font
; .byte 0x03 ; Red Font
; .byte 0x04 ; Purple Font
; .byte 0x05 ; Green Font
; .byte 0x06 ; Blue font
; .byte 0x07 ; Yellow Font
; .byte 0x08 ; White Font
; .byte 0x85 ; Period (.)
; .byte 0xC2 ; Exclamation Mark (!)
; .byte 0xC3 ; Question Mark (?)
; .byte 0x82 ; Comma (,)
; .byte 0x0A ; New Line (Writes Below)
; .byte 0x5C ; Apostrophe (')
; .byte 0x29 ; Coin icon
; .byte 0x3D ; - (minus)
; .byte 0x3E ; x (multiply)
; .byte 0xFF,0 ; FF=Pause

; If your message has an image, use this at the start of each line
; .byte 0x1A,0x1A,0x1A,0x1A ; Padding for picture