Random Pyramid Encounter fixes (#4326)

This commit is contained in:
ghoulslash 2024-04-01 14:58:36 -04:00 committed by GitHub
commit e1f6480e32
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1401,27 +1401,32 @@ void GenerateBattlePyramidWildMon(void)
if (reqs->nMoves != 0) if (reqs->nMoves != 0)
moves = AllocZeroed(sizeof(u16) * reqs->nMoves); moves = AllocZeroed(sizeof(u16) * reqs->nMoves);
if (reqs->nAbilities != 0) if (reqs->nAbilities != 0)
abilities = AllocZeroed(sizeof(u16) * reqs->nAbilities); abilities = AllocZeroed(sizeof(u16) * reqs->nAbilities);
if (round >= TOTAL_PYRAMID_ROUNDS) if (round >= TOTAL_PYRAMID_ROUNDS)
round = TOTAL_PYRAMID_ROUNDS - 1; round = TOTAL_PYRAMID_ROUNDS - 1;
id = GetMonData(&gEnemyParty[0], MON_DATA_SPECIES, NULL) - 1; // index in table (0-11) -> higher index is lower probability 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 bstLim = 450 + (25*round) + (5*id); // higher BST limit for 'rarer' wild mon rolls
while (1) while (1)
{ {
species = Random() % FORMS_START; species = Random() % NUM_SPECIES;
// check if base species
if (GET_BASE_SPECIES_ID(species) != species)
continue;
// check type // check type
if (reqs->type != TYPE_MYSTERY && gSpeciesInfo[species].types[0] != reqs->type && gSpeciesInfo[species].types[1] != reqs->type) if (reqs->type != TYPE_MYSTERY && gSpeciesInfo[species].types[0] != reqs->type && gSpeciesInfo[species].types[1] != reqs->type)
continue; continue;
// check base stat total // check base stat total
if (GetTotalBaseStat(species) > bstLim) if (GetTotalBaseStat(species) > bstLim)
continue; continue;
// check moves // check moves
if (reqs->nMoves != 0) if (reqs->nMoves != 0)
{ {
@ -1438,7 +1443,7 @@ void GenerateBattlePyramidWildMon(void)
if (moveCount == 0) if (moveCount == 0)
continue; continue;
} }
// check abilities // check abilities
if (reqs->nAbilities != 0) if (reqs->nAbilities != 0)
{ {
@ -1460,9 +1465,9 @@ void GenerateBattlePyramidWildMon(void)
continue; continue;
} }
// check evos // check evos
if (reqs->evoItems[0] != 0 && !CheckBattlePyramidEvoRequirement(species, reqs->evoItems, reqs->nEvoItems)) if (reqs->evoItems != NULL && !CheckBattlePyramidEvoRequirement(species, reqs->evoItems, reqs->nEvoItems))
continue; continue;
// we found a species we can use! // we found a species we can use!
break; break;
} }
@ -1471,7 +1476,7 @@ void GenerateBattlePyramidWildMon(void)
SetMonData(&gEnemyParty[0], MON_DATA_SPECIES, &species); SetMonData(&gEnemyParty[0], MON_DATA_SPECIES, &species);
StringCopy(name, GetSpeciesName(species)); StringCopy(name, GetSpeciesName(species));
SetMonData(&gEnemyParty[0], MON_DATA_NICKNAME, &name); SetMonData(&gEnemyParty[0], MON_DATA_NICKNAME, &name);
// set level // set level
if (lvl != FRONTIER_LVL_50) if (lvl != FRONTIER_LVL_50)
{ {
@ -1507,7 +1512,7 @@ void GenerateBattlePyramidWildMon(void)
} }
Free(moves); Free(moves);
} }
// Initialize a random ability num // Initialize a random ability num
if (gSpeciesInfo[species].abilities[1]) if (gSpeciesInfo[species].abilities[1])
{ {
@ -1519,7 +1524,7 @@ void GenerateBattlePyramidWildMon(void)
i = 0; i = 0;
SetMonData(&gEnemyParty[0], MON_DATA_ABILITY_NUM, &i); SetMonData(&gEnemyParty[0], MON_DATA_ABILITY_NUM, &i);
} }
// Try to replace with desired ability // Try to replace with desired ability
if (abilities != NULL) if (abilities != NULL)
{ {
@ -1533,12 +1538,15 @@ void GenerateBattlePyramidWildMon(void)
{ {
// Set this ability num // Set this ability num
SetMonData(&gEnemyParty[0], MON_DATA_ABILITY_NUM, &id); SetMonData(&gEnemyParty[0], MON_DATA_ABILITY_NUM, &id);
break;
} }
} }
if (id >= NUM_ABILITY_SLOTS - 1)
break;
} }
Free(abilities); Free(abilities);
} }
if (gSaveBlock2Ptr->frontier.pyramidWinStreaks[gSaveBlock2Ptr->frontier.lvlMode] >= 140) if (gSaveBlock2Ptr->frontier.pyramidWinStreaks[gSaveBlock2Ptr->frontier.lvlMode] >= 140)
{ {
id = (Random() % 17) + 15; id = (Random() % 17) + 15;