From 4ceb61b1dda908dcdb52c928d380be3036342128 Mon Sep 17 00:00:00 2001 From: AgustinGDLV Date: Mon, 20 Mar 2023 21:50:55 -0700 Subject: [PATCH] updated Gigantamax form changing + tests --- src/battle_dynamax.c | 8 +------- src/battle_util.c | 7 +++++++ test/dynamax.c | 40 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 48 insertions(+), 7 deletions(-) diff --git a/src/battle_dynamax.c b/src/battle_dynamax.c index 7d84872544..87f7c2291f 100644 --- a/src/battle_dynamax.c +++ b/src/battle_dynamax.c @@ -150,12 +150,7 @@ void PrepareBattlerForDynamax(u16 battlerId) gBattleStruct->choicedMove[battlerId] = MOVE_NONE; // Try Gigantamax form change. - newSpecies = GetBattleFormChangeTargetSpecies(battlerId, FORM_CHANGE_BATTLE_GIGANTAMAX); - if (newSpecies != SPECIES_NONE) - { - gBattleStruct->changedSpecies[gBitTable[gBattlerPartyIndexes[battlerId]]] = gBattleMons[battlerId].species; - TryBattleFormChange(battlerId, FORM_CHANGE_BATTLE_GIGANTAMAX); - } + TryBattleFormChange(battlerId, FORM_CHANGE_BATTLE_GIGANTAMAX); } // Sets flags needed for undoing Dynamax and undoes Gigantamax forms. @@ -164,7 +159,6 @@ void UndoDynamax(u16 battlerId) u8 side = GetBattlerSide(battlerId); gBattleStruct->dynamax.dynamaxed[battlerId] = FALSE; gBattleStruct->dynamax.dynamaxTurns[battlerId] = 0; // safety check for switch-in / faint - TryBattleFormChange(battlerId, FORM_CHANGE_BATTLE_SWITCH); // TODO: maybe nicer way to do this? } // Weight-based moves (and some other moves in Raids) are blocked by Dynamax. diff --git a/src/battle_util.c b/src/battle_util.c index 034e2b93a7..6f2f8b56fe 100644 --- a/src/battle_util.c +++ b/src/battle_util.c @@ -10232,6 +10232,9 @@ bool32 CanBattlerFormChange(u8 battlerId, u16 method) return TRUE; else if (IsBattlerPrimalReverted(battlerId) && (method == FORM_CHANGE_END_BATTLE)) return TRUE; + // Gigantamaxed Pokemon should revert upon fainting, switching, or ending the battle. + else if (IsDynamaxed(battlerId) && (method == FORM_CHANGE_FAINT || method == FORM_CHANGE_BATTLE_SWITCH || method == FORM_CHANGE_END_BATTLE)) + return TRUE; return DoesSpeciesHaveFormChangeMethod(gBattleMons[battlerId].species, method); } @@ -10272,6 +10275,10 @@ bool32 TryBattleFormChange(u8 battlerId, u16 method) else if (IsBattlerPrimalReverted(battlerId) && (method == FORM_CHANGE_END_BATTLE)) restoreSpecies = TRUE; + // Gigantamax Pokemon have their forms reverted after fainting, switching, or ending the battle. + else if (IsDynamaxed(battlerId) && (method == FORM_CHANGE_FAINT || method == FORM_CHANGE_BATTLE_SWITCH || method == FORM_CHANGE_END_BATTLE)) + restoreSpecies = TRUE; + if (restoreSpecies) { // Reverts the original species diff --git a/test/dynamax.c b/test/dynamax.c index 31434c50fc..114b5b51e7 100644 --- a/test/dynamax.c +++ b/test/dynamax.c @@ -436,6 +436,46 @@ DOUBLE_BATTLE_TEST("(DYNAMAX) Dynamaxed Pokemon are immune to Instruct") } } +// TODO: Gigantamax factor +SINGLE_BATTLE_TEST("(DYNAMAX) Pokemon with Gigantamax forms change upon Dynamaxing") +{ + GIVEN { + PLAYER(SPECIES_VENUSAUR); + OPPONENT(SPECIES_WOBBUFFET); + } WHEN { + TURN { MOVE(player, MOVE_TACKLE, dynamax: TRUE); } + } FINALLY { + EXPECT_EQ(gBattleMons[B_POSITION_PLAYER_LEFT].species, SPECIES_VENUSAUR_GMAX); + } +} + +SINGLE_BATTLE_TEST("(DYNAMAX) Pokemon with Gigantamax forms revert upon switching") +{ + GIVEN { + PLAYER(SPECIES_VENUSAUR); + PLAYER(SPECIES_WOBBUFFET); + OPPONENT(SPECIES_WOBBUFFET); + } WHEN { + TURN { MOVE(player, MOVE_TACKLE, dynamax: TRUE); } + TURN { SWITCH(player, 1); } + TURN { SWITCH(player, 0); } + } FINALLY { + EXPECT_EQ(gBattleMons[B_POSITION_PLAYER_LEFT].species, SPECIES_VENUSAUR); + } +} + +SINGLE_BATTLE_TEST("(DYNAMAX) Pokemon with Gigantamax forms revert upon fainting") +{ + GIVEN { + PLAYER(SPECIES_VENUSAUR) { HP(1); }; + OPPONENT(SPECIES_WOBBUFFET); + } WHEN { + TURN { MOVE(player, MOVE_TACKLE, dynamax: TRUE); MOVE(opponent, MOVE_TACKLE); } + } FINALLY { + EXPECT_EQ(gBattleMons[B_POSITION_PLAYER_LEFT].species, SPECIES_VENUSAUR); + } +} + // Move selection tests can't be simulated :( SINGLE_BATTLE_TEST("(DYNAMAX) Dynamaxed Pokemon are not affected by Choice items", s16 damage) {