From 934f8adcac1ac1ecb5a1820d297e7eec43fc7c72 Mon Sep 17 00:00:00 2001 From: Llinos Evans <36418502+PlagueVonKarma@users.noreply.github.com> Date: Wed, 31 May 2023 05:03:22 +0100 Subject: [PATCH] Mystery Box functionality It was a long shot, but I did it! I added the Mystery Box from Pokemon GO! Very happy with the results here. So here's how it works: When used, the game will replace Pokemon encountered with Meltan until the player leaves the map. This is sort of how it works in GO, with the player unable to close it and naturally petering out as they play. Now multiple Meltan can be obtained, and in abundance, just like GO. Technically, someone could use this as a pseudo-Repel to replace hard encounters with easy ones. Oh, and I'm pretty sure this happens vs static encounters as well, but it's awkward to account for I think that's hilarious, so... --- README.md | 4 +- constants/item_constants.asm | 1 + data/items/key_items.asm | 1 + data/items/names.asm | 1 + data/items/prices.asm | 1 + data/text/item_descriptions.asm | 5 ++ data/text/text_2.asm | 10 +++ engine/battle/core.asm | 17 ++++ engine/debug/debug_party.asm | 1 + engine/items/item_effects.asm | 118 +++++++++++++++------------ engine/menus/item_descriptions.asm | 2 + engine/overworld/clear_variables.asm | 2 +- ram/wram.asm | 8 +- scripts/SafariZoneEastRestHouse.asm | 51 ++++++------ text/SafariZoneEastRestHouse.asm | 56 ++++++++++--- 15 files changed, 189 insertions(+), 89 deletions(-) diff --git a/README.md b/README.md index 73eaba7b..19efd57e 100644 --- a/README.md +++ b/README.md @@ -59,8 +59,10 @@ Naturally, these types get appropriate moves. They are currently distributed to New Items: ==== There are some new items here, with the aim of accomodating new Pokemon, adding features, and acting as methods of getting to new locations. +- To accomodate Meltan, the Mystery Box from Pokemon GO is featured. When used, wild encounters are replaced with Meltan until one leaves the location. + - Melmetal is obtained by using a Candy Jar on Meltan, which is obtained as a special reward later! - The Ice, Poison and Heart Stones have been added, the latter two being from the SpaceWorld '97 demo. - - Additional evolution items include the Protector, Black Augurite, Up-Grade, Dubious Disc, Metal Coat, and Candy Jar (for Melmetal). + - Additional evolution items include the Protector, Black Augurite, Up-Grade, Dubious Disc, and the Metal Coat. - The Bottle Cap has been added alongside a Hyper Training feature, acting as effectively a Gold Bottle Cap. - The Old Sea Map has been added, giving access to Faraway Island and Mew. - The Citrine Pass has been added, allowing access to a new post-game area based on the unused "C" map. diff --git a/constants/item_constants.asm b/constants/item_constants.asm index 7acdd5e0..05b2603d 100644 --- a/constants/item_constants.asm +++ b/constants/item_constants.asm @@ -101,6 +101,7 @@ DEF SAFARI_ROCK EQU $16 ; overload const OLD_SEA_MAP ; $5A const UP_GRADE ; $5B const METAL_COAT ; $5C + const MYSTERY_BOX ; $5D DEF NUM_ITEMS EQU const_value - 1 ; elevator floors use item IDs diff --git a/data/items/key_items.asm b/data/items/key_items.asm index 90215c7e..528374c1 100644 --- a/data/items/key_items.asm +++ b/data/items/key_items.asm @@ -92,6 +92,7 @@ KeyItemFlags: dbit TRUE ; OLD_SEA_MAP dbit FALSE ; UP_GRADE dbit FALSE ; METAL_COAT + dbit TRUE ; MYSTERY_BOX dbit TRUE ; FLOOR_B2F dbit TRUE ; FLOOR_B1F dbit TRUE ; FLOOR_1F diff --git a/data/items/names.asm b/data/items/names.asm index 12805d4d..f757bed2 100644 --- a/data/items/names.asm +++ b/data/items/names.asm @@ -92,6 +92,7 @@ ItemNames:: li "OLD SEA MAP" li "UP-GRADE" li "METAL COAT" + li "MYSTERY BOX" assert_list_length NUM_ITEMS li "B2F" li "B1F" diff --git a/data/items/prices.asm b/data/items/prices.asm index 79a06bca..4d3bc649 100644 --- a/data/items/prices.asm +++ b/data/items/prices.asm @@ -92,6 +92,7 @@ ItemPrices:: bcd3 0 ; OLD_SEA_MAP bcd3 3000 ; UP_GRADE bcd3 3000 ; METAL_COAT + bcd3 0 ; MYSTERY_BOX assert_table_length NUM_ITEMS bcd3 0 ; FLOOR_B2F bcd3 0 ; FLOOR_B1F diff --git a/data/text/item_descriptions.asm b/data/text/item_descriptions.asm index dbcd7bf7..f33c2f5f 100644 --- a/data/text/item_descriptions.asm +++ b/data/text/item_descriptions.asm @@ -348,6 +348,11 @@ _OldSeaMapDescription:: next "certain island." prompt +_MysteryBoxDescription:: ; GO Description: A mysterious old box. Opening it causes a certain Pokémon to appear for a limited time. + text "A mysterious old" + next "box." + prompt + _HM01Description:: text "Cuts using claws," next "scythes, etc." diff --git a/data/text/text_2.asm b/data/text/text_2.asm index ecc5fc4a..4dc2139c 100644 --- a/data/text/text_2.asm +++ b/data/text/text_2.asm @@ -1824,3 +1824,13 @@ _BoyGirlText:: text "Firstly, are you a" line "boy or a girl?" done + +_MysteryBoxText:: + text "A mysterious mist" + line "billowed out!" + prompt + +_MysteryBoxCloseText:: + text " closed" + line "the BOX!" + prompt diff --git a/engine/battle/core.asm b/engine/battle/core.asm index 98d50408..ad534594 100644 --- a/engine/battle/core.asm +++ b/engine/battle/core.asm @@ -6191,6 +6191,23 @@ LoadEnemyMonData: ld a, [wLinkState] cp LINK_STATE_BATTLING jp z, LoadEnemyMonFromParty + + ; Upon initiating a battle, check if the Mystery Box has been activated. + ; ~50% of the time, Meltan will replace what you encounter. + ld a, [wMysteryBoxActive] ; Load the box. + cp $01 ; Check if it's active. + jr nz, .cont ; If not, load a normal Pokemon. I know this looks sort of weird, it's just how it panned out. + + ; This didn't work for some reason. It seems unnecessary, anyway... + ;call Random + ;and a + ;cp 128 ; Compare Random (a) with 128 (b). + ;jr z, .cont ; If not within range, normal Pokemon appears. 50% chance. + + ld a, MELTAN ; Meltan is loaded... + ld [wEnemyMonSpecies2], a ; Here! + +.cont ; Standard loading. ld a, [wEnemyMonSpecies2] ld [wEnemyMonSpecies], a ld [wd0b5], a diff --git a/engine/debug/debug_party.asm b/engine/debug/debug_party.asm index d8237fae..fd0c6ad1 100644 --- a/engine/debug/debug_party.asm +++ b/engine/debug/debug_party.asm @@ -161,6 +161,7 @@ DebugSetPokedexEntries: ret DebugItemsList: + db MYSTERY_BOX, 1 db BICYCLE, 1 db FULL_RESTORE, 99 db MAX_REPEL, 99 diff --git a/engine/items/item_effects.asm b/engine/items/item_effects.asm index c71b80df..d44cce12 100644 --- a/engine/items/item_effects.asm +++ b/engine/items/item_effects.asm @@ -64,7 +64,7 @@ ItemUsePtrTable: dw UnusableItem ; BIKE_VOUCHER dw ItemUseXAccuracy ; X_ACCURACY dw ItemUseEvoStone ; LEAF_STONE - dw ItemUseCardKey ; CARD_KEY + dw UnusableItem ; CARD_KEY dw UnusableItem ; NUGGET dw UnusableItem ; WING_FOSSIL dw ItemUsePokedoll ; POKE_DOLL @@ -109,6 +109,7 @@ ItemUsePtrTable: dw UnusableItem ; OLD_SEA_MAP dw ItemUseEvoStone ; UP_GRADE dw ItemUseEvoStone ; METAL_COAT + dw ItemUseMysteryBox ; MYSTERY_BOX dw UnusableItem ; FLOOR_B2F dw UnusableItem ; FLOOR_B1F dw UnusableItem ; FLOOR_1F @@ -124,6 +125,19 @@ ItemUsePtrTable: dw UnusableItem ; FLOOR_11F dw UnusableItem ; FLOOR_14F +ItemUseMysteryBox: + ; Mystery Box can't be used in battle. + ld a, [wIsInBattle] + and a + jp nz, ItemUseNotTime + ; Sets a variable in WRAM that'll trigger a Meltan wild encounter. + ; Handled in engine\core.asm + ld a, $1 + ld [wMysteryBoxActive], a + ld hl, MysteryBoxText ; Simple text is shown. Ambiguous to the user, identical to GO. + call PrintText + jp TextScriptEnd + ItemUseBall: ; Balls can't be used out of battle. @@ -1585,55 +1599,55 @@ ItemUseXAccuracy: ; This function is bugged and never works. It always jumps to ItemUseNotTime. ; The Card Key is handled in a different way. -ItemUseCardKey: - xor a - ld [wUnusedD71F], a - call GetTileAndCoordsInFrontOfPlayer - ld a, [GetTileAndCoordsInFrontOfPlayer] - cp $18 - jr nz, .next0 - ld hl, CardKeyTable1 - jr .next1 -.next0 - cp $24 - jr nz, .next2 - ld hl, CardKeyTable2 - jr .next1 -.next2 - cp $5e - jp nz, ItemUseNotTime - ld hl, CardKeyTable3 -.next1 - ld a, [wCurMap] - ld b, a -.loop - ld a, [hli] - cp -1 - jp z, ItemUseNotTime - cp b - jr nz, .nextEntry1 - ld a, [hli] - cp d - jr nz, .nextEntry2 - ld a, [hli] - cp e - jr nz, .nextEntry3 - ld a, [hl] - ld [wUnusedD71F], a - jr .done -.nextEntry1 - inc hl -.nextEntry2 - inc hl -.nextEntry3 - inc hl - jr .loop -.done - ld hl, ItemUseText00 - call PrintText - ld hl, wd728 - set 7, [hl] - ret +;ItemUseCardKey: +; xor a +; ld [wUnusedD71F], a +; call GetTileAndCoordsInFrontOfPlayer +; ld a, [GetTileAndCoordsInFrontOfPlayer] +; cp $18 +; jr nz, .next0 +; ld hl, CardKeyTable1 +; jr .next1 +;.next0 +; cp $24 +; jr nz, .next2 +; ld hl, CardKeyTable2 +; jr .next1 +;.next2 +; cp $5e +; jp nz, ItemUseNotTime +; ld hl, CardKeyTable3 +;.next1 +; ld a, [wCurMap] +; ld b, a +;.loop +; ld a, [hli] +; cp -1 +; jp z, ItemUseNotTime +; cp b +; jr nz, .nextEntry1 +; ld a, [hli] +; cp d +; jr nz, .nextEntry2 +; ld a, [hli] +; cp e +; jr nz, .nextEntry3 +; ld a, [hl] +; ld [wUnusedD71F], a +; jr .done +;.nextEntry1 +; inc hl +;.nextEntry2 +; inc hl +;.nextEntry3 +; inc hl +; jr .loop +;.done +; ld hl, ItemUseText00 +; call PrintText +; ld hl, wd728 +; set 7, [hl] +; ret INCLUDE "data/events/card_key_coords.asm" @@ -2980,3 +2994,7 @@ CheckMapForMon: jr nz, .loop dec hl ret + +MysteryBoxText: + text_far _MysteryBoxText + text_end diff --git a/engine/menus/item_descriptions.asm b/engine/menus/item_descriptions.asm index dc52b809..71d8cf13 100644 --- a/engine/menus/item_descriptions.asm +++ b/engine/menus/item_descriptions.asm @@ -198,6 +198,8 @@ ItemDescriptionPointers: text_end text_far _MetalCoatDescription text_end + text_far _MysteryBoxDescription + text_end text_far _HM01Description text_end text_far _HM02Description diff --git a/engine/overworld/clear_variables.asm b/engine/overworld/clear_variables.asm index bbb7c986..185c64bd 100644 --- a/engine/overworld/clear_variables.asm +++ b/engine/overworld/clear_variables.asm @@ -10,7 +10,7 @@ ClearVariablesOnEnterMap:: ldh [hJoyReleased], a ldh [hJoyHeld], a ld [wActionResultOrTookBattleTurn], a - ld [wUnusedD5A3], a + ld [wMysteryBoxActive], a ld hl, wCardKeyDoorY ld [hli], a ld [hl], a diff --git a/ram/wram.asm b/ram/wram.asm index 0f559053..f76ba126 100644 --- a/ram/wram.asm +++ b/ram/wram.asm @@ -1953,7 +1953,7 @@ wCurrentBoxNum:: db ; number of HOF teams wNumHoFTeams:: db -wUnusedD5A3:: db +ds 1 ; was wUnusedD5A3, removed when putting the Mystery Box in. wPlayerCoins:: ds 2 ; BCD @@ -2177,7 +2177,11 @@ wDungeonWarpDestinationMap:: db ; which dungeon warp within the source map was used wWhichDungeonWarp:: db -wUnusedD71F:: db +; Used for Meltan implementation. Replaced unused Card Key function. +; When byte is $01, Meltan has a chance to replace a Pokemon that appears. + ; $00 - Not Active + ; $01 - Active +wMysteryBoxActive:: db ds 8 diff --git a/scripts/SafariZoneEastRestHouse.asm b/scripts/SafariZoneEastRestHouse.asm index 63dae453..ea30f6cb 100644 --- a/scripts/SafariZoneEastRestHouse.asm +++ b/scripts/SafariZoneEastRestHouse.asm @@ -21,42 +21,43 @@ SafariZoneRestHouse3Text3: text_end SafariZoneRestHouse3Meltan: -; meltan guy +; Meltan Guy +; Originally, he was just going to give Meltan. +; But later on, we added the Mystery Box from GO for something more accurate, and for a possible Living Dex. text_asm - ld a, [wd72e] - bit 0, a ; got meltan? - jr z, .giveMeltan CheckEvent EVENT_GOT_MELTAN - jr nz, .MeltanInfo - ld hl, .MeltanGuyText + jr nz, .got_item + ld hl, MeltanGuyText call PrintText - jr .done -.giveMeltan - ld hl, .MeltanGuyText + lb bc, MYSTERY_BOX, 1 + call GiveItem + jr nc, .bag_full + ld hl, ReceivedBoxText call PrintText - lb bc, MELTAN, 5 SetEvent EVENT_GOT_MELTAN - call GivePokemon - jr nc, .done - ld a, [wSimulatedJoypadStatesEnd] - and a - call z, WaitForTextScrollButtonPress - call EnableAutoTextBoxDrawing - ld hl, .MeltanInfoWithBlackjackAndHookers - call PrintText - ld hl, wd72e - set 0, [hl] jr .done -.MeltanInfo - ld hl, .MeltanInfoWithBlackjackAndHookers +.bag_full + ld hl, BoxNoRoom + call PrintText + jr .done +.got_item + ld hl, MeltanInfo call PrintText .done jp TextScriptEnd -.MeltanInfoWithBlackjackAndHookers +MeltanGuyText: + text_far _MeltanGuyText + text_end + +MeltanInfo: text_far _MeltanInfo text_end -.MeltanGuyText - text_far _MeltanGuyText +ReceivedBoxText: + text_far _ReceivedBoxText text_end + +BoxNoRoom: + text_far _BoxNoRoom + text_end \ No newline at end of file diff --git a/text/SafariZoneEastRestHouse.asm b/text/SafariZoneEastRestHouse.asm index d3441f1c..d1da1184 100644 --- a/text/SafariZoneEastRestHouse.asm +++ b/text/SafariZoneEastRestHouse.asm @@ -18,21 +18,57 @@ _SafariZoneRestHouse3Text3:: done _MeltanGuyText:: - text "I found a lost" - line "#MON. It seems" - cont "to be looking" - cont "for its friends." + text "Sheesh! This old" + line "BOX I found is" + cont "heavy." - para "Could you take" - line "care of it, kid?" + para "Mind taking it" + line "off my hands," + cont "kid?" prompt _MeltanInfo:: - text "My sources say it's" - line "called MELTAN." + text "I saw a strange" + line "#MON coming" + cont "out of that" + cont "thing." - para "It's never seen in" - line "KANTO..." + para "It's so creepy!" done + +_BoxNoRoom:: + text "No room? Ugh," + line "kids these" + cont "days..." + + done + +_ReceivedBoxText:: + text " received" + line "@" + text_ram wStringBuffer + text "!@" + text_end + +; Old Meltan Guy text. +;_MeltanGuyText:: +; text "I found a lost" +; line "#MON. It seems" +; cont "to be looking" +; cont "for its friends." +; +; para "Could you take" +; line "care of it, kid?" + +; prompt + +;_MeltanInfo:: +; text "My sources say it's" +; line "called MELTAN." + +; para "It's never seen in" +; line "KANTO..." + +; done