From 07579bd42bbf5087274af3504af9da3d92df558d Mon Sep 17 00:00:00 2001 From: ghoulslash Date: Sat, 7 May 2022 09:56:32 -0400 Subject: [PATCH 1/2] prevent ally pollen puff selection under heal block. add some ai checks for heal block --- include/battle_util.h | 1 + src/battle_ai_main.c | 8 ++++++++ src/battle_controller_opponent.c | 11 ++++++++--- src/battle_controller_player.c | 6 ++++-- src/battle_util.c | 9 +++++++++ 5 files changed, 30 insertions(+), 5 deletions(-) diff --git a/include/battle_util.h b/include/battle_util.h index d2d7ac29f..dee85ef7f 100644 --- a/include/battle_util.h +++ b/include/battle_util.h @@ -171,6 +171,7 @@ void TryToApplyMimicry(u8 battlerId, bool8 various); void TryToRevertMimicry(void); void RestoreBattlerOriginalTypes(u8 battlerId); u32 GetBattlerMoveTargetType(u8 battlerId, u16 move); +bool32 CanTargetBattler(u8 battlerAtk, u8 battlerDef, u16 move); // Ability checks bool32 IsRolePlayBannedAbilityAtk(u16 ability); bool32 IsRolePlayBannedAbility(u16 ability); diff --git a/src/battle_ai_main.c b/src/battle_ai_main.c index 192b75d74..5c7d577c0 100644 --- a/src/battle_ai_main.c +++ b/src/battle_ai_main.c @@ -438,6 +438,9 @@ static u8 ChooseMoveOrAction_Doubles(void) { if (gBattleMons[sBattler_AI].moves[j] != 0) { + if (!CanTargetBattler(sBattler_AI, i, gBattleMons[sBattler_AI].moves[j])) + continue; + if (mostViableMovesScores[0] == AI_THINKING_STRUCT->score[j]) { mostViableMovesScores[mostViableMovesNo] = AI_THINKING_STRUCT->score[j]; @@ -2296,6 +2299,8 @@ static s16 AI_CheckBadMove(u8 battlerAtk, u8 battlerDef, u16 move, s16 score) case EFFECT_HIT_ENEMY_HEAL_ALLY: // pollen puff if (IsTargetingPartner(battlerAtk, battlerDef)) { + if (gStatuses3[battlerDef] & STATUS3_HEAL_BLOCK) + return 0; if (AtMaxHp(battlerDef)) score -= 10; else if (gBattleMons[battlerDef].hp > gBattleMons[battlerDef].maxHP / 2) @@ -4902,6 +4907,9 @@ static s16 AI_HPAware(u8 battlerAtk, u8 battlerDef, u16 move, s16 score) || (moveType == TYPE_ELECTRIC && AI_DATA->atkPartnerAbility == ABILITY_VOLT_ABSORB) || (moveType == TYPE_WATER && (AI_DATA->atkPartnerAbility == ABILITY_DRY_SKIN || AI_DATA->atkPartnerAbility == ABILITY_WATER_ABSORB))) { + if (gStatuses3[battlerDef] & STATUS3_HEAL_BLOCK) + return 0; + if (CanTargetFaintAi(FOE(battlerAtk), AI_DATA->battlerAtkPartner) || (CanTargetFaintAi(BATTLE_PARTNER(FOE(battlerAtk)), AI_DATA->battlerAtkPartner))) score--; diff --git a/src/battle_controller_opponent.c b/src/battle_controller_opponent.c index 69e0de5af..35e774341 100644 --- a/src/battle_controller_opponent.c +++ b/src/battle_controller_opponent.c @@ -1605,6 +1605,7 @@ static void OpponentHandleChooseMove(void) else // Wild pokemon - use random move { u16 move; + u8 target; do { chosenMoveId = Random() & 3; @@ -1615,6 +1616,10 @@ static void OpponentHandleChooseMove(void) BtlController_EmitTwoReturnValues(BUFFER_B, 10, (chosenMoveId) | (gActiveBattler << 8)); else if (gBattleTypeFlags & BATTLE_TYPE_DOUBLE) { + do { + target = GetBattlerAtPosition(Random() & 2); + } while (!CanTargetBattler(gActiveBattler, target, move)); + #if B_WILD_NATURAL_ENEMIES == TRUE // Don't bother to loop through table if the move can't attack ally if (!(gBattleMoves[move].target & MOVE_TARGET_BOTH)) @@ -1641,14 +1646,14 @@ static void OpponentHandleChooseMove(void) break; } } - if (isPartnerEnemy) + if (isPartnerEnemy && CanTargetBattler(gActiveBattler, target, move)) BtlController_EmitTwoReturnValues(BUFFER_B, 10, (chosenMoveId) | (GetBattlerAtPosition(BATTLE_PARTNER(gActiveBattler)) << 8)); else - BtlController_EmitTwoReturnValues(BUFFER_B, 10, (chosenMoveId) | (GetBattlerAtPosition(Random() & 2) << 8)); + BtlController_EmitTwoReturnValues(BUFFER_B, 10, (chosenMoveId) | (target << 8)); } else #endif - BtlController_EmitTwoReturnValues(BUFFER_B, 10, (chosenMoveId) | (GetBattlerAtPosition(Random() & 2) << 8)); + BtlController_EmitTwoReturnValues(BUFFER_B, 10, (chosenMoveId) | (target << 8)); } else BtlController_EmitTwoReturnValues(BUFFER_B, 10, (chosenMoveId) | (GetBattlerAtPosition(B_POSITION_PLAYER_LEFT) << 8)); diff --git a/src/battle_controller_player.c b/src/battle_controller_player.c index bd6b3a023..0e01eb549 100644 --- a/src/battle_controller_player.c +++ b/src/battle_controller_player.c @@ -436,7 +436,8 @@ static void HandleInputChooseTarget(void) break; } - if (gAbsentBattlerFlags & gBitTable[gMultiUsePlayerCursor]) + if (gAbsentBattlerFlags & gBitTable[gMultiUsePlayerCursor] + || !CanTargetBattler(gActiveBattler, gMultiUsePlayerCursor, move)) i = 0; } while (i == 0); } @@ -485,7 +486,8 @@ static void HandleInputChooseTarget(void) break; } - if (gAbsentBattlerFlags & gBitTable[gMultiUsePlayerCursor]) + if (gAbsentBattlerFlags & gBitTable[gMultiUsePlayerCursor] + || !CanTargetBattler(gActiveBattler, gMultiUsePlayerCursor, move)) i = 0; } while (i == 0); } diff --git a/src/battle_util.c b/src/battle_util.c index 68c675c54..d17c9ce99 100644 --- a/src/battle_util.c +++ b/src/battle_util.c @@ -10099,3 +10099,12 @@ u32 GetBattlerMoveTargetType(u8 battlerId, u16 move) else return gBattleMoves[move].target; } + +bool32 CanTargetBattler(u8 battlerAtk, u8 battlerDef, u16 move) +{ + if (gBattleMoves[move].effect == EFFECT_HIT_ENEMY_HEAL_ALLY + && GetBattlerSide(battlerAtk) == GetBattlerSide(battlerDef) + && gStatuses3[battlerDef] & STATUS3_HEAL_BLOCK) + return FALSE; + return TRUE; +} From 5456a87b83a7a86655c7a757a8bd6f1a8535da75 Mon Sep 17 00:00:00 2001 From: ghoulslash Date: Sat, 7 May 2022 11:27:32 -0400 Subject: [PATCH 2/2] fix pollen puff heal blocked battler in CanTargetBattler --- src/battle_util.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/battle_util.c b/src/battle_util.c index d17c9ce99..f1a5bd883 100644 --- a/src/battle_util.c +++ b/src/battle_util.c @@ -10104,7 +10104,7 @@ bool32 CanTargetBattler(u8 battlerAtk, u8 battlerDef, u16 move) { if (gBattleMoves[move].effect == EFFECT_HIT_ENEMY_HEAL_ALLY && GetBattlerSide(battlerAtk) == GetBattlerSide(battlerDef) - && gStatuses3[battlerDef] & STATUS3_HEAL_BLOCK) - return FALSE; + && gStatuses3[battlerAtk] & STATUS3_HEAL_BLOCK) + return FALSE; // Pokémon affected by Heal Block cannot target allies with Pollen Puff return TRUE; }