From 0aab4fb5e804c5372339d1f4ff4b02f5a7b7d806 Mon Sep 17 00:00:00 2001 From: Llinos Evans <36418502+PlagueVonKarma@users.noreply.github.com> Date: Mon, 3 Jul 2023 15:41:31 +0100 Subject: [PATCH] Mystery Box bugfixes and improvements - Meltan is now loaded in engine/battle/wild_encounters.asm, allowing its level to be fixed at 5 and avoiding various glitches. This also fixed the "running from Meltan ends the Mystery Box game" bug. - Candy Jar now gives a message when it's full, more transparent to the player. - Fixed a bug where the increment text wouldn't load properly, it was very silly. --- data/text/text_3.asm | 5 ++++ engine/battle/core.asm | 49 ++++++++++++------------------- engine/battle/wild_encounters.asm | 32 ++++++++++++++++++-- 3 files changed, 52 insertions(+), 34 deletions(-) diff --git a/data/text/text_3.asm b/data/text/text_3.asm index 5530c997..9a6dcd63 100644 --- a/data/text/text_3.asm +++ b/data/text/text_3.asm @@ -328,3 +328,8 @@ _TradeCenterText1:: _ColosseumText1:: text "!" done + +_MeltanFullJar:: + text "The CANDY JAR" + line "is full!" + prompt diff --git a/engine/battle/core.asm b/engine/battle/core.asm index e516e1cc..e7c3a19f 100644 --- a/engine/battle/core.asm +++ b/engine/battle/core.asm @@ -854,16 +854,16 @@ FaintEnemyPokemon: ; Increment the Candy Jar count. ld a, [wCandyJarCount] ; Grab the jar. cp 40 ; Do we have 40? - jr z, .skip ; If yes, no more candies. + jr z, .skipFilling1 ; If yes, no more candies. inc a ; Increment candy count. ld [wCandyJarCount], a ; Store candy count. - ; For engine\overworld\clear_variables.asm - ; Needed so the Mystery Box effect isn't cleared upon leaving battle. - ld a, $01 - ld [wDontSwitchOffMysteryBoxYet], a - - ld hl, _MeltanIncrement ; Load text to show it's going up. +.skipFilling1 + ld hl, MeltanFullJar ; Special message for when the jar is full + cp 40 + jr z, .skipFilling2 + ld hl, MeltanIncrement ; Load text to show it's going up. +.skipFilling2 call PrintText ; Yep text. call PrintEmptyString ; vs text likes this. .skip @@ -6262,29 +6262,8 @@ LoadEnemyMonData: cp LINK_STATE_BATTLING jp z, LoadEnemyMonFromParty - ; Mystery Box functionality. - ; First, we need to check if it's a trainer battle, or everyone will use Meltan. - ld a, [wIsInBattle] - cp $2 ; is it a trainer battle? - jr z, .skip ; If so, skip. - - ; Upon initiating a battle, if not a trainer 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, .skip ; 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! - ld [wcf91], a - -.skip ; Standard loading. + ; New Meltan encounter code in engine/battle/wild_encounters.asm + ; It's way less buggy and just works better ld a, [wEnemyMonSpecies2] ld [wEnemyMonSpecies], a ld [wd0b5], a @@ -7268,4 +7247,12 @@ VermilionBeautyCheck: inc a ; Increment it... ld [wBeautyCounter], a ; and get the FUCK out of my office!!! .skipCounting - ret \ No newline at end of file + ret + +MeltanIncrement: + text_far _MeltanIncrement + text_end + +MeltanFullJar: + text_far _MeltanFullJar + text_end diff --git a/engine/battle/wild_encounters.asm b/engine/battle/wild_encounters.asm index 913a0ff8..5514ac97 100644 --- a/engine/battle/wild_encounters.asm +++ b/engine/battle/wild_encounters.asm @@ -20,7 +20,7 @@ TryDoWildEncounter: and a jr z, .next dec a - jr z, .lastRepelStep + jp z, .lastRepelStep ld [wRepelRemainingSteps], a .next ; determine if wild pokemon can appear in the half-block we're standing in @@ -53,10 +53,10 @@ TryDoWildEncounter: ; ...as long as it's not Viridian Forest or Safari Zone. ld a, [wCurMap] cp FIRST_INDOOR_MAP ; is this an indoor map? - jr c, .CantEncounter2 + jp c, .CantEncounter2 ld a, [wCurMapTileset] cp FOREST ; Viridian Forest/Safari Zone - jr z, .CantEncounter2 + jp z, .CantEncounter2 ld a, [wGrassRate] .CanEncounter ; compare encounter chance with a random number to determine if there will be an encounter @@ -84,6 +84,13 @@ TryDoWildEncounter: ; since the bottom right tile of a "left shore" half-block is $14 but the bottom left tile is not, ; "left shore" half-blocks (such as the one in the east coast of Cinnabar) load grass encounters. .gotWildEncounterType + ; Meltan functionality. + ; This used to be in engine/battle/core.asm. + ; However, it was a bit buggy as the implementation was forced. + ; So instead, we do this: + ld a, [wMysteryBoxActive] ; Load the box. + cp $01 ; Check if it's active. + jr z, .meltanEncounter ; If so, skip this. ld b, 0 add hl, bc ld a, [hli] @@ -99,6 +106,25 @@ TryDoWildEncounter: ld a, [wCurEnemyLVL] cp b jr c, .CantEncounter2 ; repel prevents encounters if the leading party mon's level is higher than the wild mon + jp .willEncounter +.meltanEncounter ; needed this function as otherwise we really mess up regular processing for no reason + ld a, $01 + ld [wDontSwitchOffMysteryBoxYet], a ; Using this variable here accounts for running from Meltan. + ld b, 0 + add hl, bc + ld a, 5 + ld [wCurEnemyLVL], a + ld a, MELTAN + ld [wcf91], a + ld [wEnemyMonSpecies2], a + ld a, [wRepelRemainingSteps] + and a + jr z, .willEncounter + ld a, [wPartyMon1Level] + ld b, a + ld a, [wCurEnemyLVL] + cp b + jr c, .CantEncounter2 jr .willEncounter .lastRepelStep ld [wRepelRemainingSteps], a