Skip to content

Commit

Permalink
fix and tweak level cap code (rh-hideout#4505)
Browse files Browse the repository at this point in the history
Co-authored-by: Baptiste-Lecoutre <[email protected]>
  • Loading branch information
Nopinou and Baptiste-Lecoutre authored May 7, 2024
1 parent 2d7c79e commit 82b626a
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 19 deletions.
16 changes: 10 additions & 6 deletions src/battle_script_commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -4431,15 +4431,19 @@ static void Cmd_getexp(void)
gBattleMoveDamage += GetSoftLevelCapExpValue(gPlayerParty[*expMonId].level, gBattleStruct->expShareExpValue);;
}

if (EXP_CAP_HARD && gBattleMoveDamage != 0)
ApplyExperienceMultipliers(&gBattleMoveDamage, *expMonId, gBattlerFainted);

if (B_EXP_CAP_TYPE == EXP_CAP_HARD && gBattleMoveDamage != 0)
{
u32 growthRate = gSpeciesInfo[GetMonData(&gPlayerParty[*expMonId], MON_DATA_SPECIES)].growthRate;
if (gExperienceTables[growthRate][GetCurrentLevelCap()] < gExperienceTables[growthRate][GetMonData(&gPlayerParty[*expMonId], MON_DATA_LEVEL)] + gBattleMoveDamage)
gBattleMoveDamage = gExperienceTables[growthRate][GetCurrentLevelCap()];
}
u32 currentExp = GetMonData(&gPlayerParty[*expMonId], MON_DATA_EXP);
u32 levelCap = GetCurrentLevelCap();

if (!EXP_CAP_HARD || gBattleMoveDamage != 0) // Edge case for hard level caps. Prevents mons from getting 1 exp
ApplyExperienceMultipliers(&gBattleMoveDamage, *expMonId, gBattlerFainted);
if (GetMonData(&gPlayerParty[*expMonId], MON_DATA_LEVEL) >= levelCap)
gBattleMoveDamage = 0;
else if (gExperienceTables[growthRate][levelCap] < currentExp + gBattleMoveDamage)
gBattleMoveDamage = gExperienceTables[growthRate][levelCap] - currentExp;
}

if (IsTradedMon(&gPlayerParty[*expMonId]))
{
Expand Down
30 changes: 18 additions & 12 deletions src/level_caps.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,29 +49,35 @@ u32 GetSoftLevelCapExpValue(u32 level, u32 expValue)
if (B_EXP_CAP_TYPE == EXP_CAP_NONE)
return expValue;

if (B_LEVEL_CAP_EXP_UP && level < currentLevelCap)
if (level < currentLevelCap)
{
levelDifference = currentLevelCap - level;
if (levelDifference > ARRAY_COUNT(sExpScalingDown))
return expValue + (expValue / sExpScalingUp[ARRAY_COUNT(sExpScalingDown) - 1]);
if (B_LEVEL_CAP_EXP_UP)
{
levelDifference = currentLevelCap - level;
if (levelDifference > ARRAY_COUNT(sExpScalingUp))
return expValue + (expValue / sExpScalingUp[ARRAY_COUNT(sExpScalingUp) - 1]);
else
return expValue + (expValue / sExpScalingUp[levelDifference]);
}
else
return expValue + (expValue / sExpScalingUp[levelDifference]);
{
return expValue;
}
}
else if (B_EXP_CAP_TYPE == EXP_CAP_HARD)
{
return 0;
}
else if (B_EXP_CAP_TYPE == EXP_CAP_SOFT && level >= currentLevelCap)
else if (B_EXP_CAP_TYPE == EXP_CAP_SOFT)
{
levelDifference = level - currentLevelCap;
if (levelDifference > ARRAY_COUNT(sExpScalingDown))
return expValue / sExpScalingDown[ARRAY_COUNT(sExpScalingDown) - 1];
else
return expValue / sExpScalingDown[levelDifference];
}
else if (level < currentLevelCap)
{
return expValue;
}
else
{
return 0;
return expValue;
}

}
2 changes: 1 addition & 1 deletion src/pokemon.c
Original file line number Diff line number Diff line change
Expand Up @@ -3531,7 +3531,7 @@ bool8 PokemonUseItemEffects(struct Pokemon *mon, u16 item, u8 partyIndex, u8 mov
u16 species = GetMonData(mon, MON_DATA_SPECIES, NULL);
dataUnsigned = sExpCandyExperienceTable[param - 1] + GetMonData(mon, MON_DATA_EXP, NULL);

if (B_RARE_CANDY_CAP && EXP_CAP_HARD)
if (B_RARE_CANDY_CAP && B_EXP_CAP_TYPE == EXP_CAP_HARD)
{
u32 currentLevelCap = GetCurrentLevelCap();
if (dataUnsigned > gExperienceTables[gSpeciesInfo[species].growthRate][currentLevelCap])
Expand Down

0 comments on commit 82b626a

Please sign in to comment.