Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed Mega Evolved Pokémon being able to get Friendship effects in battle #2262

Merged
merged 5 commits into from
Oct 7, 2022
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/battle_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
1 change: 1 addition & 0 deletions include/pokemon.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 2 additions & 1 deletion src/battle_anim_new.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
}
8 changes: 4 additions & 4 deletions src/battle_script_commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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);

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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

Expand Down
32 changes: 16 additions & 16 deletions src/battle_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -2105,24 +2105,24 @@ 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);
LOuroboros marked this conversation as resolved.
Show resolved Hide resolved
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
Expand Down Expand Up @@ -2611,7 +2611,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;
Expand Down
20 changes: 20 additions & 0 deletions src/pokemon.c
Original file line number Diff line number Diff line change
Expand Up @@ -8487,3 +8487,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;
}