pokecrystal-board/engine/events/lucky_number.asm
Rangi 32ed487a47 Merge branch 'master' of https://github.com/pret/pokecrystal
# Conflicts:
#	audio/engine.asm
#	constants/gfx_constants.asm
#	constants/map_data_constants.asm
#	constants/pokemon_data_constants.asm
#	constants/sprite_constants.asm
#	constants/wram_constants.asm
#	data/maps/data.asm
#	engine/battle/ai/scoring.asm
#	engine/battle/core.asm
#	engine/battle/effect_commands.asm
#	engine/battle/misc.asm
#	engine/battle_anims/getpokeballwobble.asm
#	engine/breeding.asm
#	engine/buy_sell_toss.asm
#	engine/decorations.asm
#	engine/events/battle_tower/battle_tower.asm
#	engine/events/battle_tower/rules.asm
#	engine/events/buena.asm
#	engine/events/bug_contest/contest_2.asm
#	engine/events/daycare.asm
#	engine/events/dratini.asm
#	engine/events/halloffame.asm
#	engine/events/happiness_egg.asm
#	engine/events/kurt.asm
#	engine/events/lucky_number.asm
#	engine/events/magnet_train.asm
#	engine/events/overworld.asm
#	engine/events/pokerus/pokerus.asm
#	engine/events/print_unown.asm
#	engine/events/print_unown_2.asm
#	engine/events/unown_walls.asm
#	engine/item_effects.asm
#	engine/link.asm
#	engine/mon_menu.asm
#	engine/player_object.asm
#	engine/routines/playslowcry.asm
#	engine/scripting.asm
#	engine/search.asm
#	engine/search2.asm
#	engine/specials.asm
#	engine/start_menu.asm
#	engine/timeset.asm
#	home/battle_vars.asm
#	home/map.asm
#	maps/GoldenrodUndergroundSwitchRoomEntrances.asm
#	maps/IlexForest.asm
#	maps/KrissHouse2F.asm
#	maps/Route39Barn.asm
#	mobile/mobile_12_2.asm
#	mobile/mobile_40.asm
#	mobile/mobile_5f.asm
#	wram.asm
2018-02-03 19:42:56 -05:00

227 lines
3.3 KiB
NASM

CheckForLuckyNumberWinners: ; 4d87a
xor a
ld [wScriptVar], a
ld [wFoundMatchingIDInParty], a
ld a, [wPartyCount]
and a
ret z
ld d, a
ld hl, wPartyMon1ID
ld bc, wPartySpecies
.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)
call GetSRAMBank
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
ld a, 1
ld [wFoundMatchingIDInParty], a
.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]
call GetSRAMBank
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
call .CompareLuckyNumberToMonID ; sets wScriptVar and wCurPartySpecies appropriately
jr nc, .SkipBoxMon
ld a, 1
ld [wFoundMatchingIDInParty], a
.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
ld a, [wScriptVar]
and a
ret z ; found nothing
farcall StubbedTrainerRankings_LuckyNumberShow
ld a, [wFoundMatchingIDInParty]
and a
push af
ld a, [wCurPartySpecies]
ld [wNamedObjectIndexBuffer], a
call GetPokemonName
ld hl, .FoundPartymonText
pop af
jr z, .print
ld hl, .FoundBoxmonText
.print
jp PrintText
.CompareLuckyNumberToMonID: ; 4d939
push bc
push de
push hl
ld d, h
ld e, l
ld hl, wBuffer1
lb bc, PRINTNUM_LEADINGZEROS | 2, 5
call PrintNum
ld hl, wLuckyNumberDigit1Buffer
ld de, wLuckyIDNumber
lb bc, PRINTNUM_LEADINGZEROS | 2, 5
call PrintNum
ld b, 5
ld c, 0
ld hl, wLuckyNumberDigit5Buffer
ld de, wBuffer5
.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
ld de, -6
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
ld a, [wScriptVar]
and a
jr z, .bettermatch
cp b
jr c, .nomatch
.bettermatch
dec b
ld a, b
ld [wScriptVar], a
pop bc
ld a, b
ld [wCurPartySpecies], a
pop bc
scf
ret
.nomatch
pop bc
pop bc
and a
ret
.BoxBankAddresses: ; 4d99f
dba sBox1
dba sBox2
dba sBox3
dba sBox4
dba sBox5
dba sBox6
dba sBox7
dba sBox8
dba sBox9
dba sBox10
dba sBox11
dba sBox12
dba sBox13
dba sBox14
.FoundPartymonText: ; 0x4d9c9
; Congratulations! We have a match with the ID number of @ in your party.
text_jump UnknownText_0x1c1261
db "@"
.FoundBoxmonText: ; 0x4d9ce
; Congratulations! We have a match with the ID number of @ in your PC BOX.
text_jump UnknownText_0x1c12ae
db "@"
PrintTodaysLuckyNumber: ; 4d9d3
ld hl, wStringBuffer3
ld de, wLuckyIDNumber
lb bc, PRINTNUM_LEADINGZEROS | 2, 5
call PrintNum
ld a, "@"
ld [wStringBuffer3 + 5], a
ret