Skip to content

Commit

Permalink
Merge pull request #24 from FredrIQ/master
Browse files Browse the repository at this point in the history
Fix Lucky Number Show
  • Loading branch information
SoupPotato authored Jan 20, 2024
2 parents 1a5fade + 9d65127 commit 59962c3
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 32 deletions.
10 changes: 6 additions & 4 deletions data/text/common_2.asm
Original file line number Diff line number Diff line change
Expand Up @@ -1073,7 +1073,7 @@ _KarpGuruRecordText::
text "CURRENT RECORD"

para "@"
text_ram wStringBuffer1
text_decimal wBufferMonID, 2, 5
text " caught by"
line "@"
text_ram wMagikarpRecordHoldersName
Expand All @@ -1089,7 +1089,7 @@ _LuckyNumberMatchPartyText::
line "with the ID number"

para "of @"
text_ram wStringBuffer1
text_ram wStringBuffer2
text " in"
line "your party."
prompt
Expand All @@ -1101,9 +1101,11 @@ _LuckyNumberMatchPCText::
line "with the ID number"

para "of @"
text_decimal wBufferMonID, 2, 5
text " in Box"
line "“@"
text_ram wStringBuffer1
text " in"
line "your PC BOX."
text "”."
prompt

_CaughtAskNicknameText::
Expand Down
39 changes: 15 additions & 24 deletions engine/events/lucky_number.asm
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ CheckForLuckyNumberWinners:
; Returns number of digits matching
xor a
ld [wScriptVar], a
ld [wTempByteValue], a

; Prepare lucky number buffer
ld hl, wStringBuffer1
Expand All @@ -11,6 +10,7 @@ CheckForLuckyNumberWinners:
call PrintNum

ld b, NUM_BOXES
push bc ; will be where box+position number is stored
.outer_loop
inc b
dec b
Expand All @@ -36,62 +36,53 @@ CheckForLuckyNumberWinners:
.compare_loop
ld a, [de]
cp [hl]
jr nz, .compare_failed
jr nz, .compare_end
inc b
dec de
dec hl
ld a, b
cp 5
jr nz, .compare_loop
; if we're here, all 5 digits match
.compare_failed
.compare_end
ld a, [wScriptVar]
and $f
cp b
ld a, b
pop bc
jr nc, .next
swap a
or b
swap a

; if matching digits were found...
ld [wScriptVar], a
ld hl, wTempByteValue
ld hl, sp+0 ; store box + position on the stack for mon with matching digits
ld [hl], c
inc hl
ld [hl], b
cp 5
jr z, .done
jr nz, .next
.next
dec c
jr nz, .loop
dec b
bit 7, b ; check for reaching -1
jr z, .outer_loop
.done
pop bc ; restores box + position, if applicable
call WaitSFX
ld a, [wScriptVar]
and a
ret z ; found nothing

; Get storage mon nickname
push af
swap a
and $f
ld b, a
ld a, [wTempByteValue]
ld c, a
; Prepare found storage mon ID
push bc
farcall GetStorageBoxMon
pop af
and $f
ld [wScriptVar], a
pop bc

; Get box name (if applicable)
inc b
dec b
ld hl, .MatchInParty
jr z, .got_text
farcall GetBoxName
ld hl, wStringBuffer1
ld de, wStringBuffer2
ld bc, BOX_NAME_LENGTH
call CopyBytes
farcall GetBoxName ; loads box name into wStringBuffer1
ld hl, .MatchInStorage
.got_text
jp PrintText
Expand Down
8 changes: 4 additions & 4 deletions maps/RadioTower1F.asm
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ RadioTower1FLuckyNumberManScript:
closetext
applymovement RADIOTOWER1F_LUCKYNUMBERMAN, RadioTower1FLuckyNumberManReturnToPlayerMovement
opentext
ifequal 1, .FirstPlace
ifequal 2, .SecondPlace
ifequal 3, .ThirdPlace
sjump .NoPrize
ifless 2, .NoPrize ; 0-1 digits match
ifless 3, .ThirdPlace ; 2 digits match
ifless 5, .SecondPlace ; 3-4 digits match
sjump .FirstPlace ; all digits match

.GameOver:
writetext RadioTower1FLuckyNumberManComeAgainText
Expand Down

0 comments on commit 59962c3

Please sign in to comment.