From f58bec2397f4eeef3fa6a5384f2e439f4020d1c8 Mon Sep 17 00:00:00 2001 From: Alex Date: Mon, 1 Apr 2024 20:31:01 +0200 Subject: [PATCH 1/2] Random Pyramid Encounter fixes --- src/battle_pyramid.c | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/src/battle_pyramid.c b/src/battle_pyramid.c index a21034d75a52..eac03ca65962 100644 --- a/src/battle_pyramid.c +++ b/src/battle_pyramid.c @@ -1401,27 +1401,32 @@ void GenerateBattlePyramidWildMon(void) if (reqs->nMoves != 0) moves = AllocZeroed(sizeof(u16) * reqs->nMoves); - + if (reqs->nAbilities != 0) abilities = AllocZeroed(sizeof(u16) * reqs->nAbilities); if (round >= TOTAL_PYRAMID_ROUNDS) round = TOTAL_PYRAMID_ROUNDS - 1; - + id = GetMonData(&gEnemyParty[0], MON_DATA_SPECIES, NULL) - 1; // index in table (0-11) -> higher index is lower probability bstLim = 450 + (25*round) + (5*id); // higher BST limit for 'rarer' wild mon rolls while (1) { - species = Random() % FORMS_START; + species = Random() % NUM_SPECIES; + + // check if base species + if (!GET_BASE_SPECIES_ID(species)) + continue; + // check type if (reqs->type != TYPE_MYSTERY && gSpeciesInfo[species].types[0] != reqs->type && gSpeciesInfo[species].types[1] != reqs->type) continue; - + // check base stat total if (GetTotalBaseStat(species) > bstLim) continue; - + // check moves if (reqs->nMoves != 0) { @@ -1438,7 +1443,7 @@ void GenerateBattlePyramidWildMon(void) if (moveCount == 0) continue; } - + // check abilities if (reqs->nAbilities != 0) { @@ -1460,9 +1465,9 @@ void GenerateBattlePyramidWildMon(void) continue; } // check evos - if (reqs->evoItems[0] != 0 && !CheckBattlePyramidEvoRequirement(species, reqs->evoItems, reqs->nEvoItems)) + if (reqs->evoItems != NULL && !CheckBattlePyramidEvoRequirement(species, reqs->evoItems, reqs->nEvoItems)) continue; - + // we found a species we can use! break; } @@ -1471,7 +1476,7 @@ void GenerateBattlePyramidWildMon(void) SetMonData(&gEnemyParty[0], MON_DATA_SPECIES, &species); StringCopy(name, GetSpeciesName(species)); SetMonData(&gEnemyParty[0], MON_DATA_NICKNAME, &name); - + // set level if (lvl != FRONTIER_LVL_50) { @@ -1507,7 +1512,7 @@ void GenerateBattlePyramidWildMon(void) } Free(moves); } - + // Initialize a random ability num if (gSpeciesInfo[species].abilities[1]) { @@ -1519,7 +1524,7 @@ void GenerateBattlePyramidWildMon(void) i = 0; SetMonData(&gEnemyParty[0], MON_DATA_ABILITY_NUM, &i); } - + // Try to replace with desired ability if (abilities != NULL) { @@ -1533,12 +1538,15 @@ void GenerateBattlePyramidWildMon(void) { // Set this ability num SetMonData(&gEnemyParty[0], MON_DATA_ABILITY_NUM, &id); + break; } } + if (id >= NUM_ABILITY_SLOTS - 1) + break; } Free(abilities); } - + if (gSaveBlock2Ptr->frontier.pyramidWinStreaks[gSaveBlock2Ptr->frontier.lvlMode] >= 140) { id = (Random() % 17) + 15; From a54d6419436bfd9c0861517a76f0c0494f4b6505 Mon Sep 17 00:00:00 2001 From: Alex Date: Mon, 1 Apr 2024 20:38:58 +0200 Subject: [PATCH 2/2] fix get base species id --- src/battle_pyramid.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/battle_pyramid.c b/src/battle_pyramid.c index eac03ca65962..ce7a0526f225 100644 --- a/src/battle_pyramid.c +++ b/src/battle_pyramid.c @@ -1416,7 +1416,7 @@ void GenerateBattlePyramidWildMon(void) species = Random() % NUM_SPECIES; // check if base species - if (!GET_BASE_SPECIES_ID(species)) + if (GET_BASE_SPECIES_ID(species) != species) continue; // check type