diff --git a/data/battle_scripts_1.s b/data/battle_scripts_1.s index dacae63c3..e3d4c8943 100644 --- a/data/battle_scripts_1.s +++ b/data/battle_scripts_1.s @@ -7455,6 +7455,7 @@ BattleScript_MagicCoatBounce:: printfromtable gMagicCoatBounceStringIds waitmessage B_WAIT_TIME_LONG orword gHitMarker, HITMARKER_ATTACKSTRING_PRINTED | HITMARKER_NO_PPDEDUCT | HITMARKER_ALLOW_NO_PP + bicword gHitMarker, HITMARKER_NO_ATTACKSTRING setmagiccoattarget BS_ATTACKER return diff --git a/include/battle.h b/include/battle.h index fa8d4f7c7..a51e9c631 100644 --- a/include/battle.h +++ b/include/battle.h @@ -621,6 +621,9 @@ struct BattleStruct u8 stickyWebUser; u8 appearedInBattle; // Bitfield to track which Pokemon appeared in battle. Used for Burmy's form change u8 skyDropTargets[MAX_BATTLERS_COUNT]; // For Sky Drop, to account for if multiple Pokemon use Sky Drop in a double battle. + // When using a move which hits multiple opponents which is then bounced by a target, we need to make sure, the move hits both opponents, the one with bounce, and the one without. + u8 attackerBeforeBounce:2; + u8 targetsDone[MAX_BATTLERS_COUNT]; // Each battler as a bit. }; #define F_DYNAMIC_TYPE_1 (1 << 6) diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c index c0e7dd2e5..18fa5bbdf 100644 --- a/src/battle_script_commands.c +++ b/src/battle_script_commands.c @@ -1467,7 +1467,6 @@ static void Cmd_attackcanceler(void) && !gProtectStructs[gBattlerAttacker].usesBouncedMove) { PressurePPLose(gBattlerAttacker, gBattlerTarget, MOVE_MAGIC_COAT); - gProtectStructs[gBattlerTarget].bounceMove = FALSE; gProtectStructs[gBattlerTarget].usesBouncedMove = TRUE; gBattleCommunication[MULTISTRING_CHOOSER] = 0; if (BlocksPrankster(gCurrentMove, gBattlerTarget, gBattlerAttacker, TRUE)) @@ -5035,6 +5034,20 @@ static bool32 TryKnockOffBattleScript(u32 battlerDef) return FALSE; } +static u32 GetNextTarget(u32 moveTarget) +{ + u32 i; + for (i = 0; i < MAX_BATTLERS_COUNT; i++) + { + if (i != gBattlerAttacker + && IsBattlerAlive(i) + && !(gBattleStruct->targetsDone[gBattlerAttacker] & gBitTable[i]) + && (GetBattlerSide(i) != GetBattlerSide(gBattlerAttacker) || moveTarget == MOVE_TARGET_FOES_AND_ALLY)) + break; + } + return i; +} + static void Cmd_moveend(void) { s32 i; @@ -5427,6 +5440,7 @@ static void Cmd_moveend(void) && !(gMoveResultFlags & MOVE_RESULT_NO_EFFECT)) gProtectStructs[gBattlerAttacker].targetAffected = TRUE; + gBattleStruct->targetsDone[gBattlerAttacker] |= gBitTable[gBattlerTarget]; if (!(gHitMarker & HITMARKER_UNABLE_TO_USE_MOVE) && gBattleTypeFlags & BATTLE_TYPE_DOUBLE && !gProtectStructs[gBattlerAttacker].chargingTurn @@ -5434,28 +5448,12 @@ static void Cmd_moveend(void) || moveTarget == MOVE_TARGET_FOES_AND_ALLY) && !(gHitMarker & HITMARKER_NO_ATTACKSTRING)) { - u8 battlerId; + u32 nextTarget = GetNextTarget(moveTarget); + gHitMarker |= HITMARKER_NO_PPDEDUCT; - if (moveTarget == MOVE_TARGET_FOES_AND_ALLY) + if (nextTarget != MAX_BATTLERS_COUNT) { - gHitMarker |= HITMARKER_NO_PPDEDUCT; - for (battlerId = gBattlerTarget + 1; battlerId < gBattlersCount; battlerId++) - { - if (battlerId == gBattlerAttacker) - continue; - if (IsBattlerAlive(battlerId)) - break; - } - } - else - { - battlerId = GetBattlerAtPosition(BATTLE_PARTNER(GetBattlerPosition(gBattlerTarget))); - gHitMarker |= HITMARKER_NO_ATTACKSTRING; - } - - if (IsBattlerAlive(battlerId)) - { - gBattleStruct->moveTarget[gBattlerAttacker] = gBattlerTarget = battlerId; // Fix for moxie spread moves + gBattleStruct->moveTarget[gBattlerAttacker] = gBattlerTarget = nextTarget; // Fix for moxie spread moves gBattleScripting.moveendState = 0; MoveValuesCleanUp(); gBattleScripting.moveEffect = gBattleScripting.savedMoveEffect; @@ -5463,11 +5461,31 @@ static void Cmd_moveend(void) gBattlescriptCurrInstr = BattleScript_FlushMessageBox; return; } - else + // Check if the move used was actually a bounced move. If so, we need to go back to the original attacker and make sure, its move hits all 2 or 3 pokemon. + else if (gProtectStructs[gBattlerAttacker].usesBouncedMove) { - gHitMarker |= HITMARKER_NO_ATTACKSTRING; - gHitMarker &= ~HITMARKER_NO_PPDEDUCT; + u8 originalBounceTarget = gBattlerAttacker; + gBattlerAttacker = gBattleStruct->attackerBeforeBounce; + gBattleStruct->targetsDone[gBattlerAttacker] |= gBitTable[originalBounceTarget]; + gBattleStruct->targetsDone[originalBounceTarget] = 0; + + nextTarget = GetNextTarget(moveTarget); + if (nextTarget != MAX_BATTLERS_COUNT) + { + // We found another target for the original move user. + gBattleStruct->moveTarget[gBattlerAttacker] = gBattlerTarget = nextTarget; + gBattleScripting.moveendState = 0; + gBattleScripting.animTurn = 0; + gBattleScripting.animTargetsHit = 0; + MoveValuesCleanUp(); + BattleScriptPush(gBattleScriptsForMoveEffects[gBattleMoves[gCurrentMove].effect]); + gBattlescriptCurrInstr = BattleScript_FlushMessageBox; + return; + } } + + gHitMarker |= HITMARKER_NO_ATTACKSTRING; + gHitMarker &= ~HITMARKER_NO_PPDEDUCT; } RecordLastUsedMoveBy(gBattlerAttacker, gCurrentMove); gBattleScripting.moveendState++; @@ -5681,6 +5699,7 @@ static void Cmd_moveend(void) CancelMultiTurnMoves(gBattlerAttacker); // Cancel it #endif + gBattleStruct->targetsDone[gBattlerAttacker] = 0; gProtectStructs[gBattlerAttacker].usesBouncedMove = FALSE; gProtectStructs[gBattlerAttacker].targetAffected = FALSE; gBattleStruct->ateBoost[gBattlerAttacker] = 0; @@ -8083,6 +8102,7 @@ static void Cmd_various(void) CancelMultiTurnMoves(gActiveBattler); break; case VARIOUS_SET_MAGIC_COAT_TARGET: + gBattleStruct->attackerBeforeBounce = gActiveBattler; gBattlerAttacker = gBattlerTarget; side = GetBattlerSide(gBattlerAttacker) ^ BIT_SIDE; if (IsAffectedByFollowMe(gBattlerAttacker, side, gCurrentMove))