From 271ca56bdb7b9f2cc3da298715bcbcc9a76137fe Mon Sep 17 00:00:00 2001 From: grintoul <166724814+grintoul1@users.noreply.github.com> Date: Sat, 25 Oct 2025 13:42:28 +0100 Subject: [PATCH] Fixes CanUseLastResort and resolves 3 KNOWN_FAILING Last Resort tests (#8032) Co-authored-by: Alex <93446519+AlexOn1ine@users.noreply.github.com> --- src/battle_script_commands.c | 6 ++---- test/battle/move_effect/last_resort.c | 10 +++++----- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c index 949e0d4df0..2be580e1ee 100644 --- a/src/battle_script_commands.c +++ b/src/battle_script_commands.c @@ -9118,17 +9118,15 @@ static void Cmd_useitemonopponent(void) bool32 CanUseLastResort(u8 battler) { - u32 i; u32 knownMovesCount = 0, usedMovesCount = 0; - for (i = 0; i < 4; i++) + for (u32 i = 0; i < MAX_MON_MOVES; i++) { if (gBattleMons[battler].moves[i] != MOVE_NONE) knownMovesCount++; - if (i != gCurrMovePos && gDisableStructs[battler].usedMoves & (1u << i)) // Increment used move count for all moves except current Last Resort. + if (GetMoveEffect(gBattleMons[battler].moves[i]) != EFFECT_LAST_RESORT && gDisableStructs[battler].usedMoves & (1u << i)) // Increment used move count for all moves except current Last Resort. usedMovesCount++; } - return (knownMovesCount >= 2 && usedMovesCount >= knownMovesCount - 1); } diff --git a/test/battle/move_effect/last_resort.c b/test/battle/move_effect/last_resort.c index 602f4ad2a3..089a723304 100644 --- a/test/battle/move_effect/last_resort.c +++ b/test/battle/move_effect/last_resort.c @@ -117,7 +117,7 @@ SINGLE_BATTLE_TEST("Last Resort works with Sleep Talk") AI_SINGLE_BATTLE_TEST("AI uses Last Resort - 2 moves") { - KNOWN_FAILING; + AI_FLAGS(AI_FLAG_CHECK_BAD_MOVE | AI_FLAG_CHECK_VIABILITY | AI_FLAG_TRY_TO_FAINT); GIVEN { PLAYER(SPECIES_WOBBUFFET); OPPONENT(SPECIES_WOBBUFFET) { Moves(MOVE_LAST_RESORT, MOVE_SCRATCH); } @@ -129,10 +129,10 @@ AI_SINGLE_BATTLE_TEST("AI uses Last Resort - 2 moves") AI_SINGLE_BATTLE_TEST("AI uses Last Resort - 3 moves") { - KNOWN_FAILING; + AI_FLAGS(AI_FLAG_CHECK_BAD_MOVE | AI_FLAG_CHECK_VIABILITY | AI_FLAG_TRY_TO_FAINT); GIVEN { PLAYER(SPECIES_WOBBUFFET); - OPPONENT(SPECIES_WOBBUFFET) { Moves(MOVE_LAST_RESORT, MOVE_QUICK_ATTACK, MOVE_SCRATCH); } + OPPONENT(SPECIES_WOBBUFFET) { MovesWithPP({MOVE_LAST_RESORT, 5}, {MOVE_QUICK_ATTACK, 1}, {MOVE_SCRATCH, 35}); } } WHEN { TURN { NOT_EXPECT_MOVE(opponent, MOVE_LAST_RESORT); } TURN { NOT_EXPECT_MOVE(opponent, MOVE_LAST_RESORT); } @@ -142,10 +142,10 @@ AI_SINGLE_BATTLE_TEST("AI uses Last Resort - 3 moves") AI_SINGLE_BATTLE_TEST("AI uses Last Resort - 4 moves") { - KNOWN_FAILING; + AI_FLAGS(AI_FLAG_CHECK_BAD_MOVE | AI_FLAG_CHECK_VIABILITY | AI_FLAG_TRY_TO_FAINT); GIVEN { PLAYER(SPECIES_WOBBUFFET); - OPPONENT(SPECIES_WOBBUFFET) { Moves(MOVE_LAST_RESORT, MOVE_QUICK_ATTACK, MOVE_SCRATCH, MOVE_GUST); } + OPPONENT(SPECIES_WOBBUFFET) { MovesWithPP({MOVE_LAST_RESORT, 5}, {MOVE_QUICK_ATTACK, 1}, {MOVE_SCRATCH, 1}, {MOVE_GUST, 35}); } } WHEN { TURN { NOT_EXPECT_MOVE(opponent, MOVE_LAST_RESORT); } TURN { NOT_EXPECT_MOVE(opponent, MOVE_LAST_RESORT); }