From 3398d75fe873633da3f2d9d06121ea74d2478f28 Mon Sep 17 00:00:00 2001 From: Pawkkie <61265402+Pawkkie@users.noreply.github.com> Date: Tue, 4 Mar 2025 08:26:07 -0500 Subject: [PATCH] Improve AI's handling of player's Encore (#6305) Co-authored-by: Bassoonian --- src/battle_ai_util.c | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/src/battle_ai_util.c b/src/battle_ai_util.c index f7b5ab9c64..9a522fba09 100644 --- a/src/battle_ai_util.c +++ b/src/battle_ai_util.c @@ -3831,6 +3831,7 @@ static u32 IncreaseStatUpScoreInternal(u32 battlerAtk, u32 battlerDef, u32 statI u32 noOfHitsToFaint = NoOfHitsForTargetToFaintAI(battlerDef, battlerAtk); u32 aiIsFaster = AI_IsFaster(battlerAtk, battlerDef, TRUE); u32 shouldSetUp = ((noOfHitsToFaint >= 2 && aiIsFaster) || (noOfHitsToFaint >= 3 && !aiIsFaster) || noOfHitsToFaint == UNKNOWN_NO_OF_HITS); + u32 i; if (considerContrary && AI_DATA->abilities[battlerAtk] == ABILITY_CONTRARY) return NO_INCREASE; @@ -3851,9 +3852,30 @@ static u32 IncreaseStatUpScoreInternal(u32 battlerAtk, u32 battlerDef, u32 statI if (AI_DATA->abilities[battlerDef] == ABILITY_OPPORTUNIST) return NO_INCREASE; - // If predicting switch, stat increases are great momentum + // Don't increase stats if opposing battler has Encore + if (HasMoveEffect(battlerDef, EFFECT_ENCORE)) + return NO_INCREASE; + + if (IsDoubleBattle() && HasMoveEffect(GetPartnerBattler(battlerDef), EFFECT_ENCORE)) + return NO_INCREASE; + + // Predicting switch if (IsBattlerPredictedToSwitch(battlerDef)) + { + struct Pokemon *playerParty = GetBattlerParty(battlerDef); + // If expected switchin outspeeds and has Encore, don't increase + for (i = 0; i < MAX_MON_MOVES; i++) + { + if (GetMoveEffect(GetMonData(&playerParty[AI_DATA->mostSuitableMonId[battlerDef]], MON_DATA_MOVE1 + i, NULL)) == EFFECT_ENCORE + && GetMonData(&playerParty[AI_DATA->mostSuitableMonId[battlerDef]], MON_DATA_PP1 + i, NULL) > 0); + { + if (GetMonData(&playerParty[AI_DATA->mostSuitableMonId[battlerDef]], MON_DATA_SPEED, NULL) > gBattleMons[battlerAtk].speed) + return NO_INCREASE; + } + } + // Otherwise if predicting switch, stat increases are great momentum tempScore += WEAK_EFFECT; + } switch (statId) {