2018-06-24 07:09:41 -07:00
|
|
|
CheckForLuckyNumberWinners:
|
2017-12-15 17:10:54 -08:00
|
|
|
xor a
|
2023-09-30 10:12:57 -07:00
|
|
|
ldh [hScriptVar], a
|
2018-07-28 16:27:34 -07:00
|
|
|
ld [wTempByteValue], a
|
2018-01-23 14:39:09 -08:00
|
|
|
ld a, [wPartyCount]
|
2017-12-15 17:10:54 -08:00
|
|
|
and a
|
|
|
|
ret z
|
|
|
|
ld d, a
|
2018-01-23 14:39:09 -08:00
|
|
|
ld hl, wPartyMon1ID
|
|
|
|
ld bc, wPartySpecies
|
2017-12-15 17:10:54 -08:00
|
|
|
.PartyLoop:
|
|
|
|
ld a, [bc]
|
|
|
|
inc bc
|
|
|
|
cp EGG
|
|
|
|
call nz, .CompareLuckyNumberToMonID
|
|
|
|
push bc
|
|
|
|
ld bc, PARTYMON_STRUCT_LENGTH
|
|
|
|
add hl, bc
|
|
|
|
pop bc
|
|
|
|
dec d
|
|
|
|
jr nz, .PartyLoop
|
|
|
|
ld a, BANK(sBox)
|
2020-06-17 14:03:38 -07:00
|
|
|
call OpenSRAM
|
2017-12-15 17:10:54 -08:00
|
|
|
ld a, [sBoxCount]
|
|
|
|
and a
|
|
|
|
jr z, .SkipOpenBox
|
|
|
|
ld d, a
|
|
|
|
ld hl, sBoxMon1ID
|
|
|
|
ld bc, sBoxSpecies
|
|
|
|
.OpenBoxLoop:
|
|
|
|
ld a, [bc]
|
|
|
|
inc bc
|
|
|
|
cp EGG
|
|
|
|
jr z, .SkipOpenBoxMon
|
|
|
|
call .CompareLuckyNumberToMonID
|
|
|
|
jr nc, .SkipOpenBoxMon
|
2018-07-28 16:27:34 -07:00
|
|
|
ld a, TRUE
|
|
|
|
ld [wTempByteValue], a
|
2017-12-15 17:10:54 -08:00
|
|
|
|
|
|
|
.SkipOpenBoxMon:
|
|
|
|
push bc
|
|
|
|
ld bc, BOXMON_STRUCT_LENGTH
|
|
|
|
add hl, bc
|
|
|
|
pop bc
|
|
|
|
dec d
|
|
|
|
jr nz, .OpenBoxLoop
|
|
|
|
|
|
|
|
.SkipOpenBox:
|
|
|
|
call CloseSRAM
|
|
|
|
ld c, $0
|
|
|
|
.BoxesLoop:
|
|
|
|
ld a, [wCurBox]
|
|
|
|
and $f
|
|
|
|
cp c
|
|
|
|
jr z, .SkipBox
|
|
|
|
ld hl, .BoxBankAddresses
|
|
|
|
ld b, 0
|
|
|
|
add hl, bc
|
|
|
|
add hl, bc
|
|
|
|
add hl, bc
|
|
|
|
ld a, [hli]
|
2020-06-17 14:03:38 -07:00
|
|
|
call OpenSRAM
|
2017-12-15 17:10:54 -08:00
|
|
|
ld a, [hli]
|
|
|
|
ld h, [hl]
|
|
|
|
ld l, a ; hl now contains the address of the loaded box in SRAM
|
|
|
|
ld a, [hl]
|
|
|
|
and a
|
|
|
|
jr z, .SkipBox ; no mons in this box
|
|
|
|
push bc
|
|
|
|
ld b, h
|
|
|
|
ld c, l
|
|
|
|
inc bc
|
|
|
|
ld de, sBoxMon1ID - sBox
|
|
|
|
add hl, de
|
|
|
|
ld d, a
|
|
|
|
.BoxNLoop:
|
|
|
|
ld a, [bc]
|
|
|
|
inc bc
|
|
|
|
cp EGG
|
|
|
|
jr z, .SkipBoxMon
|
|
|
|
|
2023-09-30 10:12:57 -07:00
|
|
|
call .CompareLuckyNumberToMonID ; sets hScriptVar and wCurPartySpecies appropriately
|
2017-12-15 17:10:54 -08:00
|
|
|
jr nc, .SkipBoxMon
|
2018-07-28 16:27:34 -07:00
|
|
|
ld a, TRUE
|
|
|
|
ld [wTempByteValue], a
|
2017-12-15 17:10:54 -08:00
|
|
|
|
|
|
|
.SkipBoxMon:
|
|
|
|
push bc
|
|
|
|
ld bc, BOXMON_STRUCT_LENGTH
|
|
|
|
add hl, bc
|
|
|
|
pop bc
|
|
|
|
dec d
|
|
|
|
jr nz, .BoxNLoop
|
|
|
|
pop bc
|
|
|
|
|
|
|
|
.SkipBox:
|
|
|
|
inc c
|
|
|
|
ld a, c
|
|
|
|
cp NUM_BOXES
|
|
|
|
jr c, .BoxesLoop
|
|
|
|
|
|
|
|
call CloseSRAM
|
2023-09-30 10:12:57 -07:00
|
|
|
ldh a, [hScriptVar]
|
2017-12-15 17:10:54 -08:00
|
|
|
and a
|
|
|
|
ret z ; found nothing
|
2020-06-16 16:32:36 -07:00
|
|
|
|
2018-07-28 16:27:34 -07:00
|
|
|
ld a, [wTempByteValue]
|
2017-12-15 17:10:54 -08:00
|
|
|
and a
|
|
|
|
push af
|
2018-01-23 14:39:09 -08:00
|
|
|
ld a, [wCurPartySpecies]
|
2020-12-23 13:29:30 -08:00
|
|
|
ld [wNamedObjectIndex], a
|
2017-12-15 17:10:54 -08:00
|
|
|
call GetPokemonName
|
2019-10-20 15:24:17 -07:00
|
|
|
ld hl, .LuckyNumberMatchPartyText
|
2017-12-15 17:10:54 -08:00
|
|
|
pop af
|
|
|
|
jr z, .print
|
2019-10-20 15:24:17 -07:00
|
|
|
ld hl, .LuckyNumberMatchPCText
|
2017-12-15 17:10:54 -08:00
|
|
|
|
|
|
|
.print
|
2023-08-11 03:28:14 -07:00
|
|
|
jp PrintText2bpp
|
2017-12-15 17:10:54 -08:00
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
.CompareLuckyNumberToMonID:
|
2017-12-15 17:10:54 -08:00
|
|
|
push bc
|
|
|
|
push de
|
|
|
|
push hl
|
|
|
|
ld d, h
|
|
|
|
ld e, l
|
2020-11-03 16:53:07 -08:00
|
|
|
ld hl, wMonIDDigitsBuffer
|
2017-12-15 17:10:54 -08:00
|
|
|
lb bc, PRINTNUM_LEADINGZEROS | 2, 5
|
|
|
|
call PrintNum
|
2018-07-28 22:13:25 -07:00
|
|
|
ld hl, wLuckyNumberDigitsBuffer
|
2017-12-15 17:10:54 -08:00
|
|
|
ld de, wLuckyIDNumber
|
|
|
|
lb bc, PRINTNUM_LEADINGZEROS | 2, 5
|
|
|
|
call PrintNum
|
|
|
|
ld b, 5
|
|
|
|
ld c, 0
|
2018-07-28 22:13:25 -07:00
|
|
|
ld hl, wLuckyNumberDigitsBuffer + 4
|
2020-11-03 16:53:07 -08:00
|
|
|
ld de, wMonIDDigitsBuffer + 4
|
2017-12-15 17:10:54 -08:00
|
|
|
.loop
|
|
|
|
ld a, [de]
|
|
|
|
cp [hl]
|
|
|
|
jr nz, .done
|
|
|
|
dec de
|
|
|
|
dec hl
|
|
|
|
inc c
|
|
|
|
dec b
|
|
|
|
jr nz, .loop
|
|
|
|
|
|
|
|
.done
|
|
|
|
pop hl
|
|
|
|
push hl
|
2019-11-23 17:56:22 -08:00
|
|
|
ld de, MON_SPECIES - MON_ID
|
2017-12-15 17:10:54 -08:00
|
|
|
add hl, de
|
|
|
|
ld a, [hl]
|
|
|
|
pop hl
|
|
|
|
pop de
|
|
|
|
push af
|
|
|
|
ld a, c
|
|
|
|
ld b, 1
|
|
|
|
cp 5
|
|
|
|
jr z, .okay
|
|
|
|
ld b, 2
|
|
|
|
cp 3
|
|
|
|
jr nc, .okay
|
|
|
|
ld b, 3
|
|
|
|
cp 2
|
|
|
|
jr nz, .nomatch
|
|
|
|
|
|
|
|
.okay
|
|
|
|
inc b
|
2023-09-30 10:12:57 -07:00
|
|
|
ldh a, [hScriptVar]
|
2017-12-15 17:10:54 -08:00
|
|
|
and a
|
|
|
|
jr z, .bettermatch
|
|
|
|
cp b
|
|
|
|
jr c, .nomatch
|
|
|
|
|
|
|
|
.bettermatch
|
|
|
|
dec b
|
|
|
|
ld a, b
|
2023-09-30 10:12:57 -07:00
|
|
|
ldh [hScriptVar], a
|
2017-12-15 17:10:54 -08:00
|
|
|
pop bc
|
|
|
|
ld a, b
|
2018-01-23 14:39:09 -08:00
|
|
|
ld [wCurPartySpecies], a
|
2017-12-15 17:10:54 -08:00
|
|
|
pop bc
|
|
|
|
scf
|
|
|
|
ret
|
|
|
|
|
|
|
|
.nomatch
|
|
|
|
pop bc
|
|
|
|
pop bc
|
|
|
|
and a
|
|
|
|
ret
|
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
.BoxBankAddresses:
|
2021-03-21 14:47:53 -07:00
|
|
|
table_width 3, CheckForLuckyNumberWinners.BoxBankAddresses
|
2022-08-31 15:03:49 -07:00
|
|
|
for n, 1, NUM_BOXES + 1
|
|
|
|
dba sBox{d:n}
|
|
|
|
endr
|
2021-03-21 14:47:53 -07:00
|
|
|
assert_table_length NUM_BOXES
|
2017-12-15 17:10:54 -08:00
|
|
|
|
2019-10-20 15:24:17 -07:00
|
|
|
.LuckyNumberMatchPartyText:
|
|
|
|
text_far _LuckyNumberMatchPartyText
|
2018-11-17 10:33:03 -08:00
|
|
|
text_end
|
2017-12-15 17:10:54 -08:00
|
|
|
|
2019-10-20 15:24:17 -07:00
|
|
|
.LuckyNumberMatchPCText:
|
|
|
|
text_far _LuckyNumberMatchPCText
|
2018-11-17 10:33:03 -08:00
|
|
|
text_end
|
2017-12-15 17:10:54 -08:00
|
|
|
|
2018-06-24 07:09:41 -07:00
|
|
|
PrintTodaysLuckyNumber:
|
2018-01-23 14:39:09 -08:00
|
|
|
ld hl, wStringBuffer3
|
2017-12-15 17:10:54 -08:00
|
|
|
ld de, wLuckyIDNumber
|
|
|
|
lb bc, PRINTNUM_LEADINGZEROS | 2, 5
|
|
|
|
call PrintNum
|
|
|
|
ld a, "@"
|
2018-01-23 14:39:09 -08:00
|
|
|
ld [wStringBuffer3 + 5], a
|
2017-12-15 17:10:54 -08:00
|
|
|
ret
|