From 4a3ee0db7f4aa77084d3cf50a8f9e1bfae1f71ee Mon Sep 17 00:00:00 2001 From: kittenchilly Date: Thu, 14 Sep 2023 13:37:57 -0500 Subject: [PATCH] Implement Exp Charm and unevolved Exp multipliers + Exp formula fixes (#3301) Co-authored-by: Eduardo Quezada D'Ottone --- include/config/battle.h | 1 + include/pokemon.h | 1 + src/battle_script_commands.c | 18 +++++++++--------- src/pokemon.c | 20 ++++++++++++++++++++ 4 files changed, 31 insertions(+), 9 deletions(-) diff --git a/include/config/battle.h b/include/config/battle.h index dd7e11f02..aee79daee 100644 --- a/include/config/battle.h +++ b/include/config/battle.h @@ -14,6 +14,7 @@ #define B_TRAINER_EXP_MULTIPLIER GEN_LATEST // In Gen7+, trainer battles no longer give a 1.5 multiplier to EXP gain. #define B_SPLIT_EXP GEN_LATEST // In Gen6+, all participating mon get full experience. #define B_SCALED_EXP GEN_LATEST // In Gen5 and Gen7+, experience is weighted by level difference. +#define B_UNEVOLVED_EXP_MULTIPLIER GEN_LATEST // In Gen6+, if the Pokémon is at or past the level where it would be able to evolve, but it has not, it gets a ~1.2 multiplier to EXP gain. Only applies to Pokémon with EVO_LEVEL method. // Stat settings #define B_BADGE_BOOST GEN_LATEST // In Gen4+, Gym Badges no longer boost a Pokémon's stats. diff --git a/include/pokemon.h b/include/pokemon.h index a37d5f010..7f70d8a52 100644 --- a/include/pokemon.h +++ b/include/pokemon.h @@ -543,6 +543,7 @@ u8 *UseStatIncreaseItem(u16 itemId); u8 GetNature(struct Pokemon *mon); u8 GetNatureFromPersonality(u32 personality); u16 GetEvolutionTargetSpecies(struct Pokemon *mon, u8 type, u16 evolutionItem, struct Pokemon *tradePartner); +bool8 IsMonPastEvolutionLevel(struct Pokemon *mon); u16 HoennPokedexNumToSpecies(u16 hoennNum); u16 NationalPokedexNumToSpecies(u16 nationalNum); u16 NationalToHoennOrder(u16 nationalNum); diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c index b89b7d844..5c779c3d1 100644 --- a/src/battle_script_commands.c +++ b/src/battle_script_commands.c @@ -4087,6 +4087,9 @@ static void Cmd_getexp(void) calculatedExp = gSpeciesInfo[gBattleMons[gBattlerFainted].species].expYield * gBattleMons[gBattlerFainted].level / 7; #endif + if (B_TRAINER_EXP_MULTIPLIER <= GEN_7 && gBattleTypeFlags & BATTLE_TYPE_TRAINER) + calculatedExp = (calculatedExp * 150) / 100; + #if B_SPLIT_EXP < GEN_6 if (viaExpShare) // at least one mon is getting exp via exp share { @@ -4179,14 +4182,9 @@ static void Cmd_getexp(void) { // check if the pokemon doesn't belong to the player if (gBattleTypeFlags & BATTLE_TYPE_INGAME_PARTNER && gBattleStruct->expGetterMonId >= 3) - { i = STRINGID_EMPTYSTRING4; - } else - { - gBattleMoveDamage = (gBattleMoveDamage * 150) / 100; i = STRINGID_ABOOSTED; - } } else { @@ -16029,13 +16027,15 @@ void ApplyExperienceMultipliers(s32 *expAmount, u8 expGetterMonId, u8 faintedBat else holdEffect = ItemId_GetHoldEffect(item); + if (IsTradedMon(&gPlayerParty[expGetterMonId])) + *expAmount = (*expAmount * 150) / 100; if (holdEffect == HOLD_EFFECT_LUCKY_EGG) *expAmount = (*expAmount * 150) / 100; - if (B_TRAINER_EXP_MULTIPLIER <= GEN_7 && gBattleTypeFlags & BATTLE_TYPE_TRAINER) - *expAmount = (*expAmount * 150) / 100; + if (B_UNEVOLVED_EXP_MULTIPLIER >= GEN_6 && IsMonPastEvolutionLevel(&gPlayerParty[expGetterMonId])) + *expAmount = (*expAmount * 4915) / 4096; if (B_AFFECTION_MECHANICS == TRUE && GetBattlerFriendshipScore(expGetterMonId) >= FRIENDSHIP_50_TO_99) - *expAmount = (*expAmount * 120) / 100; - if (IsTradedMon(&gPlayerParty[expGetterMonId])) + *expAmount = (*expAmount * 4915) / 4096; + if (CheckBagHasItem(ITEM_EXP_CHARM, 1)) //is also for other exp boosting Powers if/when implemented *expAmount = (*expAmount * 150) / 100; if (B_SCALED_EXP >= GEN_5 && B_SCALED_EXP != GEN_6) diff --git a/src/pokemon.c b/src/pokemon.c index 838d0068c..dc7054c04 100644 --- a/src/pokemon.c +++ b/src/pokemon.c @@ -6770,6 +6770,26 @@ u16 GetEvolutionTargetSpecies(struct Pokemon *mon, u8 mode, u16 evolutionItem, s return targetSpecies; } +bool8 IsMonPastEvolutionLevel(struct Pokemon *mon) +{ + int i; + u16 species = GetMonData(mon, MON_DATA_SPECIES, 0); + u8 level = GetMonData(mon, MON_DATA_LEVEL, 0); + + for (i = 0; i < EVOS_PER_MON; i++) + { + switch (gEvolutionTable[species][i].method) + { + case EVO_LEVEL: + if (gEvolutionTable[species][i].param <= level) + return TRUE; + break; + } + } + + return FALSE; +} + u16 HoennPokedexNumToSpecies(u16 hoennNum) { u16 species;