diff --git a/include/battle_util.h b/include/battle_util.h index 28a488472d52..a456cc1e63e1 100644 --- a/include/battle_util.h +++ b/include/battle_util.h @@ -202,6 +202,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 2f2991139922..c4015d562187 100644 --- a/include/pokemon.h +++ b/include/pokemon.h @@ -565,5 +565,6 @@ u16 GetFormChangeTargetSpeciesBoxMon(struct BoxPokemon *mon, u16 method, u32 arg u16 MonTryLearningNewMoveEvolution(struct Pokemon *mon, bool8 firstMove); bool32 ShouldShowFemaleDifferences(u16 species, u32 personality); void TryToSetBattleFormChangeMoves(struct Pokemon *mon); +u32 GetMonFriendshipScore(struct Pokemon *pokemon); #endif // GUARD_POKEMON_H diff --git a/src/battle_anim_new.c b/src/battle_anim_new.c index e236e26bf5c0..0a65deb2829c 100644 --- a/src/battle_anim_new.c +++ b/src/battle_anim_new.c @@ -19,6 +19,7 @@ #include "constants/hold_effects.h" #include "constants/items.h" #include "constants/pokemon.h" +#include "battle_util.h" // function declarations static void SpriteCB_SpriteToCentreOfSide(struct Sprite *sprite); @@ -7899,6 +7900,6 @@ void AnimTask_AffectionHangedOn(u8 taskId) int side = GetBattlerSide(gBattleAnimTarget); struct Pokemon *party = (side == B_SIDE_PLAYER) ? gPlayerParty : gEnemyParty; - gBattleAnimArgs[0] = GetMonFriendshipScore(&party[gBattlerPartyIndexes[gBattleAnimTarget]]); + gBattleAnimArgs[0] = GetBattlerFriendshipScore(gBattleAnimTarget); DestroyAnimVisualTask(taskId); } diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c index 8057ea067f6c..eaa7bbde1a69 100644 --- a/src/battle_script_commands.c +++ b/src/battle_script_commands.c @@ -1760,7 +1760,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 (GetBattlerFriendshipScore(battlerDef) >= FRIENDSHIP_150_TO_199 && (Random() % 100) <= 20) calc = (calc * 90) / 100; #endif @@ -1933,7 +1933,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 * (GetBattlerFriendshipScore(gBattlerAttacker) >= FRIENDSHIP_200_TO_254) #endif + (abilityAtk == ABILITY_SUPER_LUCK); @@ -2003,7 +2003,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); @@ -4113,7 +4113,7 @@ static void Cmd_getexp(void) } #endif #if B_AFFECTION_MECHANICS == TRUE - if (GetMonFriendshipScore(&gPlayerParty[gBattleStruct->expGetterMonId]) >= FRIENDSHIP_50_TO_99) + if (GetBattlerFriendshipScore(gBattleStruct->expGetterMonId) >= FRIENDSHIP_50_TO_99) gBattleMoveDamage = (gBattleMoveDamage * 120) / 100; #endif diff --git a/src/battle_util.c b/src/battle_util.c index bed842911bc3..d83f8429e9da 100644 --- a/src/battle_util.c +++ b/src/battle_util.c @@ -2105,24 +2105,23 @@ void TryToRevertMimicry(void) } } -u32 GetMonFriendshipScore(struct Pokemon *pokemon) +u32 GetBattlerFriendshipScore(u8 battlerId) { - u32 friendshipScore = GetMonData(pokemon, MON_DATA_FRIENDSHIP); + u8 side = GetBattlerSide(battlerId); + struct Pokemon *party = (side == B_SIDE_PLAYER) ? gPlayerParty : gEnemyParty; + u16 species = GetMonData(&party[gBattlerPartyIndexes[battlerId]], MON_DATA_SPECIES); - 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 (gBaseStats[species].flags & SPECIES_FLAG_MEGA_EVOLUTION + || (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 @@ -2611,7 +2610,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 d6b6e2aed2a2..98ac99256007 100644 --- a/src/pokemon.c +++ b/src/pokemon.c @@ -8513,3 +8513,23 @@ void TryToSetBattleFormChangeMoves(struct Pokemon *mon) } } } + +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; +}