diff --git a/include/battle.h b/include/battle.h index 36ffdb6da0..82993b73e2 100644 --- a/include/battle.h +++ b/include/battle.h @@ -456,6 +456,7 @@ struct MegaEvolutionData bool8 playerSelect; u8 triggerSpriteId; bool8 isWishMegaEvo; + bool32 didMegaEvo[PARTY_SIZE][2]; // For each party member and side. }; struct Illusion diff --git a/include/battle_util.h b/include/battle_util.h index 5dbefd7e7e..9b8109c398 100644 --- a/include/battle_util.h +++ b/include/battle_util.h @@ -201,6 +201,6 @@ bool32 CanBeParalyzed(u8 battlerId); bool32 CanBeFrozen(u8 battlerId); bool32 CanBeConfused(u8 battlerId); bool32 IsBattlerTerrainAffected(u8 battlerId, u32 terrainFlag); -u32 GetMonFriendshipScore(struct Pokemon *pokemon); +u32 GetBattlerFriendshipScore(u8 battlerId); #endif // GUARD_BATTLE_UTIL_H diff --git a/include/pokemon.h b/include/pokemon.h index c05628a598..7a38508274 100644 --- a/include/pokemon.h +++ b/include/pokemon.h @@ -559,5 +559,6 @@ u16 GetFormChangeTargetSpecies(struct Pokemon *mon, u16 method, u32 arg); u16 GetFormChangeTargetSpeciesBoxMon(struct BoxPokemon *mon, u16 method, u32 arg); u16 MonTryLearningNewMoveEvolution(struct Pokemon *mon, bool8 firstMove); bool32 ShouldShowFemaleDifferences(u16 species, u32 personality); +u32 GetMonFriendshipScore(struct Pokemon *pokemon); #endif // GUARD_POKEMON_H diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c index a5a822546c..361abe2419 100644 --- a/src/battle_script_commands.c +++ b/src/battle_script_commands.c @@ -1734,7 +1734,7 @@ u32 GetTotalAccuracy(u32 battlerAtk, u32 battlerDef, u32 move, u32 atkAbility, u #if B_AFFECTION_MECHANICS == TRUE // With high affection/friendship there's a chance to evade a move by substracting 10% of its accuracy. // I can't find exact information about that chance, so I'm just gonna write it as a 20% chance for now. - if (GetMonFriendshipScore(&gPlayerParty[gBattlerPartyIndexes[battlerDef]]) >= FRIENDSHIP_150_TO_199 && (Random() % 100) <= 20) + if (GetMonFriendshipScore(battlerDef) >= FRIENDSHIP_150_TO_199 && (Random() % 100) <= 20) calc = (calc * 90) / 100; #endif @@ -1907,7 +1907,7 @@ s32 CalcCritChanceStage(u8 battlerAtk, u8 battlerDef, u32 move, bool32 recordAbi + 2 * (holdEffectAtk == HOLD_EFFECT_LUCKY_PUNCH && gBattleMons[gBattlerAttacker].species == SPECIES_CHANSEY) + 2 * BENEFITS_FROM_LEEK(battlerAtk, holdEffectAtk) #if B_AFFECTION_MECHANICS == TRUE - + 2 * (GetMonFriendshipScore(&gPlayerParty[gBattlerPartyIndexes[gBattlerAttacker]]) >= FRIENDSHIP_200_TO_254) + + 2 * (GetMonFriendshipScore(gBattlerAttacker) >= FRIENDSHIP_200_TO_254) #endif + (abilityAtk == ABILITY_SUPER_LUCK); @@ -1977,7 +1977,7 @@ static void Cmd_adjustdamage(void) { u8 holdEffect, param; u32 moveType; - u32 friendshipScore = GetMonFriendshipScore(&gPlayerParty[gBattlerPartyIndexes[gBattlerTarget]]); + u32 friendshipScore = GetBattlerFriendshipScore(gBattlerTarget); u32 rand = Random() % 100; GET_MOVE_TYPE(gCurrentMove, moveType); @@ -4063,7 +4063,7 @@ static void Cmd_getexp(void) } #endif #if B_AFFECTION_MECHANICS == TRUE - if (GetMonFriendshipScore(&gPlayerParty[gBattleStruct->expGetterMonId]) >= FRIENDSHIP_50_TO_99) + if (GetMonFriendshipScore(gBattleStruct->expGetterMonId) >= FRIENDSHIP_50_TO_99) gBattleMoveDamage = (gBattleMoveDamage * 120) / 100; #endif @@ -8652,6 +8652,7 @@ static void Cmd_various(void) gBattleMons[gActiveBattler].species = megaSpecies; PREPARE_SPECIES_BUFFER(gBattleTextBuff1, gBattleMons[gActiveBattler].species); + gBattleStruct->mega.didMegaEvo[gActiveBattler][GetBattlerSide(gActiveBattler)] = TRUE; BtlController_EmitSetMonData(BUFFER_A, REQUEST_SPECIES_BATTLE, gBitTable[gBattlerPartyIndexes[gActiveBattler]], sizeof(gBattleMons[gActiveBattler].species), &gBattleMons[gActiveBattler].species); MarkBattlerForControllerExec(gActiveBattler); diff --git a/src/battle_util.c b/src/battle_util.c index f38d80a69c..5cb2badb0e 100644 --- a/src/battle_util.c +++ b/src/battle_util.c @@ -2104,24 +2104,23 @@ void TryToRevertMimicry(void) } } -u32 GetMonFriendshipScore(struct Pokemon *pokemon) +u32 GetBattlerFriendshipScore(u8 battlerId) { - u32 friendshipScore = GetMonData(pokemon, MON_DATA_FRIENDSHIP); + struct MegaEvolutionData *mega = &(((struct ChooseMoveStruct *)(&gBattleResources->bufferA[battlerId][4]))->mega); + u8 side = GetBattlerSide(battlerId); + struct Pokemon *party = (side == B_SIDE_PLAYER) ? gPlayerParty : gEnemyParty; - if (friendshipScore == MAX_FRIENDSHIP) - return FRIENDSHIP_MAX; - if (friendshipScore >= 200) - return FRIENDSHIP_200_TO_254; - if (friendshipScore >= 150) - return FRIENDSHIP_150_TO_199; - if (friendshipScore >= 100) - return FRIENDSHIP_100_TO_149; - if (friendshipScore >= 50) - return FRIENDSHIP_50_TO_99; - if (friendshipScore >= 1) - return FRIENDSHIP_1_TO_49; + if (side != B_SIDE_PLAYER) + return FRIENDSHIP_NONE; + else if (gBattleStruct->mega.didMegaEvo[battlerId][side] + || (gBattleTypeFlags & (BATTLE_TYPE_EREADER_TRAINER + | BATTLE_TYPE_FRONTIER + | BATTLE_TYPE_LINK + | BATTLE_TYPE_RECORDED_LINK + | BATTLE_TYPE_SECRET_BASE))) + return FRIENDSHIP_NONE; - return FRIENDSHIP_NONE; + return GetMonFriendshipScore(&party[gBattlerPartyIndexes[battlerId]]); } enum @@ -2605,7 +2604,7 @@ u8 DoFieldEndTurnEffects(void) { #if B_AFFECTION_MECHANICS == TRUE if (GetBattlerSide(gBattlerAttacker) == B_SIDE_PLAYER - && GetMonFriendshipScore(&gPlayerParty[gBattlerPartyIndexes[gBattlerAttacker]]) >= FRIENDSHIP_150_TO_199 + && GetBattlerFriendshipScore(gBattlerAttacker) >= FRIENDSHIP_150_TO_199 && (Random() % 100 < 20)) { gBattleCommunication[MULTISTRING_CHOOSER] = 1; diff --git a/src/pokemon.c b/src/pokemon.c index 92bd923f08..61c72c363e 100644 --- a/src/pokemon.c +++ b/src/pokemon.c @@ -8384,3 +8384,23 @@ bool32 ShouldShowFemaleDifferences(u16 species, u32 personality) { return (gBaseStats[species].flags & FLAG_GENDER_DIFFERENCE) && GetGenderFromSpeciesAndPersonality(species, personality) == MON_FEMALE; } + +u32 GetMonFriendshipScore(struct Pokemon *pokemon) +{ + u32 friendshipScore = GetMonData(pokemon, MON_DATA_FRIENDSHIP, NULL); + + if (friendshipScore == MAX_FRIENDSHIP) + return FRIENDSHIP_MAX; + if (friendshipScore >= 200) + return FRIENDSHIP_200_TO_254; + if (friendshipScore >= 150) + return FRIENDSHIP_150_TO_199; + if (friendshipScore >= 100) + return FRIENDSHIP_100_TO_149; + if (friendshipScore >= 50) + return FRIENDSHIP_50_TO_99; + if (friendshipScore >= 1) + return FRIENDSHIP_1_TO_49; + + return FRIENDSHIP_NONE; +}