Skip to content

Commit

Permalink
Sticky web / Court Change / Mirror Armor tests + small fixes (#3160)
Browse files Browse the repository at this point in the history
Co-authored-by: Eduardo Quezada D'Ottone <[email protected]>
Co-authored-by: Martin Griffin <[email protected]>
  • Loading branch information
3 people authored Aug 7, 2023
1 parent d74cbca commit 1fb42e4
Show file tree
Hide file tree
Showing 9 changed files with 620 additions and 18 deletions.
2 changes: 1 addition & 1 deletion include/battle.h
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ struct SideTimer
u8 toxicSpikesAmount;
u8 stealthRockAmount;
u8 stickyWebAmount;
u8 stickyWebBattlerId;
u8 stickyWebBattlerSide; // Used for Court Change
u8 auroraVeilTimer;
u8 auroraVeilBattlerId;
Expand Down Expand Up @@ -644,7 +645,6 @@ struct BattleStruct
u8 forcedSwitch:4; // For each battler
u8 switchInAbilityPostponed:4; // To not activate against an empty field, each bit for battler
u8 ballSpriteIds[2]; // item gfx, window gfx
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.
Expand Down
21 changes: 16 additions & 5 deletions src/battle_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -3170,7 +3170,10 @@ static void BattleStartClearSetData(void)

gBattleStruct->mega.triggerSpriteId = 0xFF;

gBattleStruct->stickyWebUser = 0xFF;
for (i = 0; i < ARRAY_COUNT(gSideTimers); i++)
{
gSideTimers[i].stickyWebBattlerId = 0xFF;
}
gBattleStruct->appearedInBattle = 0;
gBattleStruct->beatUpSlot = 0;

Expand Down Expand Up @@ -3276,8 +3279,12 @@ void SwitchInClearSetData(void)
gBattleStruct->lastMoveFailed &= ~(gBitTable[gActiveBattler]);
gBattleStruct->palaceFlags &= ~(gBitTable[gActiveBattler]);

if (gActiveBattler == gBattleStruct->stickyWebUser)
gBattleStruct->stickyWebUser = 0xFF; // Switched into sticky web user slot so reset it
for (i = 0; i < ARRAY_COUNT(gSideTimers); i++)
{
// Switched into sticky web user slot, so reset stored battler ID
if (gSideTimers[i].stickyWebBattlerId == gActiveBattler)
gSideTimers[i].stickyWebBattlerId = 0xFF;
}

for (i = 0; i < gBattlersCount; i++)
{
Expand Down Expand Up @@ -3390,8 +3397,12 @@ void FaintClearSetData(void)

gBattleStruct->palaceFlags &= ~(gBitTable[gActiveBattler]);

if (gActiveBattler == gBattleStruct->stickyWebUser)
gBattleStruct->stickyWebUser = 0xFF; // User of sticky web fainted, so reset the stored battler ID
for (i = 0; i < ARRAY_COUNT(gSideTimers); i++)
{
// User of sticky web fainted, so reset the stored battler ID
if (gSideTimers[i].stickyWebBattlerId == gActiveBattler)
gSideTimers[i].stickyWebBattlerId = 0xFF;
}

for (i = 0; i < gBattlersCount; i++)
{
Expand Down
4 changes: 2 additions & 2 deletions src/battle_message.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,8 @@ static const u8 sText_PkmnRaisedSpDefALittle[] = _("{B_ATK_PREFIX2}'s {B_CURRENT
static const u8 sText_PkmnRaisedDef[] = _("{B_ATK_PREFIX2}'s {B_CURRENT_MOVE}\nraised DEFENSE!");
static const u8 sText_PkmnRaisedDefALittle[] = _("{B_ATK_PREFIX2}'s {B_CURRENT_MOVE}\nraised DEFENSE a little!");
static const u8 sText_PkmnCoveredByVeil[] = _("{B_ATK_PREFIX2}'s party is covered\nby a veil!");
static const u8 sText_PkmnUsedSafeguard[] = _("{B_DEF_NAME_WITH_PREFIX}'s party is protected\nby SAFEGUARD!");
static const u8 sText_PkmnSafeguardExpired[] = _("{B_ATK_PREFIX3}'s party is no longer\nprotected by SAFEGUARD!");
static const u8 sText_PkmnUsedSafeguard[] = _("{B_DEF_NAME_WITH_PREFIX}'s party is protected\nby Safeguard!");
static const u8 sText_PkmnSafeguardExpired[] = _("{B_ATK_PREFIX3}'s party is no longer\nprotected by Safeguard!");
static const u8 sText_PkmnWentToSleep[] = _("{B_ATK_NAME_WITH_PREFIX} went\nto sleep!");
static const u8 sText_PkmnSleptHealthy[] = _("{B_ATK_NAME_WITH_PREFIX} slept and\nbecame healthy!");
static const u8 sText_PkmnWhippedWhirlwind[] = _("{B_ATK_NAME_WITH_PREFIX} whipped\nup a whirlwind!");
Expand Down
15 changes: 7 additions & 8 deletions src/battle_script_commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -8760,8 +8760,9 @@ static bool32 IsTeatimeAffected(u32 battlerId)

#define UPDATE_COURTCHANGED_BATTLER(structField)\
{ \
sideTimerPlayer->structField ^= BIT_SIDE; \
sideTimerOpp->structField ^= BIT_SIDE; \
temp = sideTimerPlayer->structField; \
sideTimerPlayer->structField = BATTLE_OPPOSITE(sideTimerOpp->structField); \
sideTimerOpp->structField = BATTLE_OPPOSITE(temp); \
} \

static bool32 CourtChangeSwapSideStatuses(void)
Expand Down Expand Up @@ -8796,9 +8797,7 @@ static bool32 CourtChangeSwapSideStatuses(void)
UPDATE_COURTCHANGED_BATTLER(auroraVeilBattlerId);
UPDATE_COURTCHANGED_BATTLER(tailwindBattlerId);
UPDATE_COURTCHANGED_BATTLER(luckyChantBattlerId);

// For Mirror Armor only
gBattleStruct->stickyWebUser = gBattlerAttacker;
UPDATE_COURTCHANGED_BATTLER(stickyWebBattlerId);

// Track which side originally set the Sticky Web
SWAP(sideTimerPlayer->stickyWebBattlerSide, sideTimerOpp->stickyWebBattlerSide, temp);
Expand Down Expand Up @@ -10830,8 +10829,8 @@ static void Cmd_various(void)
// If Pokémon which set up Sticky Web is not on the field, no Pokémon have their Speed lowered."
gBattlerAttacker = gBattlerTarget; // Initialize 'fail' condition
SET_STATCHANGER(STAT_SPEED, 1, TRUE);
if (gBattleStruct->stickyWebUser != 0xFF)
gBattlerAttacker = gBattleStruct->stickyWebUser;
if (gSideTimers[GetBattlerSide(gActiveBattler)].stickyWebBattlerId != 0xFF)
gBattlerAttacker = gSideTimers[GetBattlerSide(gActiveBattler)].stickyWebBattlerId;
break;
}
case VARIOUS_CUT_1_3_HP_RAISE_STATS:
Expand Down Expand Up @@ -14092,9 +14091,9 @@ static void Cmd_setstickyweb(void)
else
{
gSideStatuses[targetSide] |= SIDE_STATUS_STICKY_WEB;
gSideTimers[targetSide].stickyWebBattlerId = gBattlerAttacker; // For Mirror Armor
gSideTimers[targetSide].stickyWebBattlerSide = GetBattlerSide(gBattlerAttacker); // For Court Change/Defiant - set this to the user's side
gSideTimers[targetSide].stickyWebAmount = 1;
gBattleStruct->stickyWebUser = gBattlerAttacker; // For Mirror Armor
gBattlescriptCurrInstr = cmd->nextInstr;
}
}
Expand Down
202 changes: 202 additions & 0 deletions test/ability_mirror_armor.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,202 @@
#include "global.h"
#include "test_battle.h"

ASSUMPTIONS
{
ASSUME(P_GEN_8_POKEMON == TRUE);
}

SINGLE_BATTLE_TEST("Mirror Armor lowers a stat of the attacking pokemon")
{
u16 move, statId;

PARAMETRIZE { move = MOVE_LEER; statId = STAT_DEF; }
PARAMETRIZE { move = MOVE_GROWL; statId = STAT_ATK; }
PARAMETRIZE { move = MOVE_SWEET_SCENT; statId = STAT_EVASION; }
PARAMETRIZE { move = MOVE_SAND_ATTACK; statId = STAT_ACC; }
PARAMETRIZE { move = MOVE_CONFIDE; statId = STAT_SPATK; }
PARAMETRIZE { move = MOVE_FAKE_TEARS; statId = STAT_SPDEF; }

GIVEN {
PLAYER(SPECIES_CORVIKNIGHT) {Ability(ABILITY_MIRROR_ARMOR);}
OPPONENT(SPECIES_WYNAUT);
} WHEN {
TURN { MOVE(opponent, move); }
} SCENE {
ABILITY_POPUP(player, ABILITY_MIRROR_ARMOR);
ANIMATION(ANIM_TYPE_GENERAL, B_ANIM_STATS_CHANGE, opponent);
switch (statId)
{
case STAT_DEF:
MESSAGE("Foe Wynaut's Defense fell!");
break;
case STAT_ATK:
MESSAGE("Foe Wynaut's Attack fell!");
break;
case STAT_EVASION:
MESSAGE("Foe Wynaut's evasiveness harshly fell!");
break;
case STAT_ACC:
MESSAGE("Foe Wynaut's accuracy fell!");
break;
case STAT_SPATK:
MESSAGE("Foe Wynaut's Sp. Atk fell!");
break;
case STAT_SPDEF:
MESSAGE("Foe Wynaut's Sp. Def harshly fell!");
break;
}
} THEN {
EXPECT_EQ(player->statStages[statId], DEFAULT_STAT_STAGE);
EXPECT_EQ(opponent->statStages[statId], (statId == STAT_SPDEF || statId == STAT_EVASION) ? DEFAULT_STAT_STAGE - 2 : DEFAULT_STAT_STAGE - 1);
}
}

SINGLE_BATTLE_TEST("Mirror Armor triggers even if the attacking Pokemon also has Mirror Armor ability")
{
GIVEN {
PLAYER(SPECIES_CORVIKNIGHT) { Ability(ABILITY_MIRROR_ARMOR); }
OPPONENT(SPECIES_CORVIKNIGHT) { Ability(ABILITY_MIRROR_ARMOR); }
} WHEN {
TURN { MOVE(opponent, MOVE_LEER); }
} SCENE {
MESSAGE("Foe Corviknigh used Leer!");
ABILITY_POPUP(player, ABILITY_MIRROR_ARMOR);
NOT ANIMATION(ANIM_TYPE_GENERAL, B_ANIM_STATS_CHANGE, player);
ANIMATION(ANIM_TYPE_GENERAL, B_ANIM_STATS_CHANGE, opponent);
MESSAGE("Foe Corviknigh's Defense fell!");
} THEN {
EXPECT_EQ(player->statStages[STAT_DEF], DEFAULT_STAT_STAGE);
EXPECT_EQ(opponent->statStages[STAT_DEF], DEFAULT_STAT_STAGE - 1);
}
}

SINGLE_BATTLE_TEST("Mirror Armor doesn't lower the stats of an attacking Pokemon with the Clear Body ability")
{
GIVEN {
PLAYER(SPECIES_CORVIKNIGHT) { Ability(ABILITY_MIRROR_ARMOR); }
OPPONENT(SPECIES_WYNAUT) { Ability(ABILITY_CLEAR_BODY); }
} WHEN {
TURN { MOVE(opponent, MOVE_LEER); }
} SCENE {
MESSAGE("Foe Wynaut used Leer!");
ABILITY_POPUP(player, ABILITY_MIRROR_ARMOR);
ABILITY_POPUP(opponent, ABILITY_CLEAR_BODY);
MESSAGE("Foe Wynaut's Clear Body prevents stat loss!");
} THEN {
EXPECT_EQ(player->statStages[STAT_DEF], DEFAULT_STAT_STAGE);
EXPECT_EQ(opponent->statStages[STAT_DEF], DEFAULT_STAT_STAGE);
}
}

SINGLE_BATTLE_TEST("Mirror Armor lowers the Attack of Pokemon with Intimidate")
{
GIVEN {
PLAYER(SPECIES_CORVIKNIGHT) { Ability(ABILITY_MIRROR_ARMOR); }
OPPONENT(SPECIES_GYARADOS) { Ability(ABILITY_INTIMIDATE); }
} WHEN {
TURN {}
} SCENE {
ABILITY_POPUP(opponent, ABILITY_INTIMIDATE);
ABILITY_POPUP(player, ABILITY_MIRROR_ARMOR);
ANIMATION(ANIM_TYPE_GENERAL, B_ANIM_STATS_CHANGE, opponent);
MESSAGE("Foe Gyarados's Attack fell!");
} THEN {
EXPECT_EQ(player->statStages[STAT_ATK], DEFAULT_STAT_STAGE);
EXPECT_EQ(opponent->statStages[STAT_ATK], DEFAULT_STAT_STAGE - 1);
}
}

// Unsure whether this should or should not fail, as Showdown has conflicting information. Needs testing in gen8 games.
SINGLE_BATTLE_TEST("Mirror Armor doesn't lower the stats of an attacking Pokemon behind Substitute")
{
KNOWN_FAILING;
GIVEN {
PLAYER(SPECIES_CORVIKNIGHT) { Ability(ABILITY_MIRROR_ARMOR); }
OPPONENT(SPECIES_WYNAUT);
} WHEN {
TURN { MOVE(opponent, MOVE_SUBSTITUTE); }
TURN { MOVE(opponent, MOVE_LEER); }
} SCENE {
MESSAGE("Foe Wynaut used Substitute!");
ANIMATION(ANIM_TYPE_MOVE, MOVE_SUBSTITUTE, opponent);
MESSAGE("Foe Wynaut used Leer!");
ABILITY_POPUP(player, ABILITY_MIRROR_ARMOR);
NOT ANIMATION(ANIM_TYPE_GENERAL, B_ANIM_STATS_CHANGE, opponent);
} THEN {
EXPECT_EQ(player->statStages[STAT_DEF], DEFAULT_STAT_STAGE);
EXPECT_EQ(opponent->statStages[STAT_DEF], DEFAULT_STAT_STAGE);
}
}

SINGLE_BATTLE_TEST("Mirror Armor raises the stat of an attacking Pokemon with Contrary")
{
GIVEN {
PLAYER(SPECIES_CORVIKNIGHT) {Ability(ABILITY_MIRROR_ARMOR);}
OPPONENT(SPECIES_SHUCKLE) {Ability(ABILITY_CONTRARY);}
} WHEN {
TURN { MOVE(opponent, MOVE_LEER); }
} SCENE {
MESSAGE("Foe Shuckle used Leer!");
ABILITY_POPUP(player, ABILITY_MIRROR_ARMOR);
ANIMATION(ANIM_TYPE_GENERAL, B_ANIM_STATS_CHANGE, opponent);
MESSAGE("Foe Shuckle's Defense rose!");
} THEN {
EXPECT_EQ(player->statStages[STAT_DEF], DEFAULT_STAT_STAGE);
EXPECT_EQ(opponent->statStages[STAT_DEF], DEFAULT_STAT_STAGE + 1);
}
}

SINGLE_BATTLE_TEST("Mirror Armor doesn't lower the stat of the attacking Pokemon if it is already at -6")
{
GIVEN {
PLAYER(SPECIES_CORVIKNIGHT) {Ability(ABILITY_MIRROR_ARMOR);}
OPPONENT(SPECIES_WYNAUT);
} WHEN {
TURN { MOVE(player, MOVE_SCREECH); }
TURN { MOVE(player, MOVE_SCREECH); }
TURN { MOVE(player, MOVE_SCREECH); }
TURN { MOVE(opponent, MOVE_LEER); }
} SCENE {
MESSAGE("Corviknigh used Screech!");
MESSAGE("Corviknigh used Screech!");
MESSAGE("Corviknigh used Screech!");
MESSAGE("Foe Wynaut used Leer!");
ABILITY_POPUP(player, ABILITY_MIRROR_ARMOR);
NOT ANIMATION(ANIM_TYPE_GENERAL, B_ANIM_STATS_CHANGE, opponent);
MESSAGE("Foe Wynaut's Defense won't go lower!");
} THEN {
EXPECT_EQ(player->statStages[STAT_DEF], DEFAULT_STAT_STAGE);
EXPECT_EQ(opponent->statStages[STAT_DEF], MIN_STAT_STAGE);
}
}

// This behaviour needs to be verified in the actual games. Currently it's written to follow Showdown's logic.
DOUBLE_BATTLE_TEST("Mirror Armor lowers Speed of the partner Pokemon after Court Change was used by the opponent after it set up Sticky Web")
{
KNOWN_FAILING;
GIVEN {
ASSUME(gBattleMoves[MOVE_STICKY_WEB].effect == EFFECT_STICKY_WEB);
ASSUME(gBattleMoves[MOVE_COURT_CHANGE].effect == EFFECT_COURT_CHANGE);
PLAYER(SPECIES_WOBBUFFET);
PLAYER(SPECIES_WOBBUFFET);
PLAYER(SPECIES_CORVIKNIGHT) {Ability(ABILITY_MIRROR_ARMOR); Item(ITEM_IRON_BALL); }
OPPONENT(SPECIES_WYNAUT);
OPPONENT(SPECIES_WYNAUT);
OPPONENT(SPECIES_WYNAUT);
} WHEN {
TURN { MOVE(playerLeft, MOVE_STICKY_WEB); }
TURN { MOVE(opponentLeft, MOVE_COURT_CHANGE); }
TURN { SWITCH(playerRight, 2);}
TURN { }
} SCENE {
MESSAGE("Wobbuffet used Sticky Web!");
MESSAGE("Foe Wynaut used Court Change!");
MESSAGE("Foe Wynaut swapped the battle effects affecting each side!");
MESSAGE("Go! Corviknigh!");
MESSAGE("Corviknigh was caught in a Sticky Web!");
ABILITY_POPUP(playerRight, ABILITY_MIRROR_ARMOR);
ANIMATION(ANIM_TYPE_GENERAL, B_ANIM_STATS_CHANGE, playerLeft);
MESSAGE("Wobbuffet's Speed fell!");
}
}
2 changes: 1 addition & 1 deletion test/hold_effect_berserk_gene.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ SINGLE_BATTLE_TEST("Berserk Gene does not confuse when Safeguard is active")
} SCENE {
ANIMATION(ANIM_TYPE_GENERAL, B_ANIM_STATS_CHANGE, player);
MESSAGE("Using Berserk Gene, the Attack of Wobbuffet sharply rose!");
MESSAGE("Wobbuffet's party is protected by SAFEGUARD!");
MESSAGE("Wobbuffet's party is protected by Safeguard!");
NOT MESSAGE("Wobbuffet became confused!");
}
}
Expand Down
Loading

0 comments on commit 1fb42e4

Please sign in to comment.