Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shell Bell Clean up / Simplification and Tests #5924

Merged
merged 6 commits into from
Jan 7, 2025
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 3 additions & 9 deletions include/battle.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,6 @@

#define BATTLE_BUFFER_LINK_SIZE 0x1000

// Special indicator value for shellBellDmg in SpecialStatus
#define IGNORE_SHELL_BELL 0xFFFF

// For defining EFFECT_HIT etc. with battle TV scores and flags etc.
struct __attribute__((packed, aligned(2))) BattleMoveEffect
{
Expand Down Expand Up @@ -212,7 +209,6 @@ struct ProtectStruct

struct SpecialStatus
{
s32 shellBellDmg;
s32 physicalDmg;
s32 specialDmg;
u8 physicalBattlerId;
Expand All @@ -224,7 +220,8 @@ struct SpecialStatus
u8 faintedHasReplacement:1;
u8 focusBanded:1;
u8 focusSashed:1;
u8 unused:2;
u8 emergencyExited:1;
u8 afterYou:1;
// End of byte
u8 sturdied:1;
u8 stormDrainRedirected:1;
Expand All @@ -243,16 +240,13 @@ struct SpecialStatus
u8 neutralizingGasRemoved:1; // See VARIOUS_TRY_END_NEUTRALIZING_GAS
u8 affectionEndured:1;
// End of byte
u8 damagedMons:4; // Mons that have been damaged directly by using a move, includes substitute.
u8 dancerUsedMove:1;
u8 dancerOriginalTarget:3;
// End of byte
u8 emergencyExited:1;
u8 afterYou:1;
u8 preventLifeOrbDamage:1; // So that Life Orb doesn't activate various effects.
u8 distortedTypeMatchups:1;
u8 teraShellAbilityDone:1;
u8 criticalHit:1;
// End of byte
};

struct SideTimer
Expand Down
38 changes: 9 additions & 29 deletions src/battle_script_commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -2116,12 +2116,12 @@ static void Cmd_adjustdamage(void)
continue;

if (DoesSubstituteBlockMove(gBattlerAttacker, battlerDef, gCurrentMove))
goto END;
continue;

if (DoesDisguiseBlockMove(battlerDef, gCurrentMove))
{
gBattleStruct->enduredDamage |= 1u << battlerDef;
goto END;
continue;
}
if (GetBattlerAbility(battlerDef) == ABILITY_ICE_FACE && IS_MOVE_PHYSICAL(gCurrentMove) && gBattleMons[battlerDef].species == SPECIES_EISCUE)
{
Expand All @@ -2131,10 +2131,10 @@ static void Cmd_adjustdamage(void)
RecordAbilityBattle(gBattlerTarget, ABILITY_ICE_FACE);
gBattleResources->flags->flags[battlerDef] |= RESOURCE_FLAG_ICE_FACE;
// Form change will be done after attack animation in Cmd_resultmessage.
goto END;
continue;
}
if (gBattleMons[gBattlerTarget].hp > gBattleStruct->moveDamage[battlerDef])
goto END;
continue;

holdEffect = GetBattlerHoldEffect(battlerDef, TRUE);
param = GetBattlerHoldEffectParam(battlerDef);
Expand Down Expand Up @@ -2170,7 +2170,7 @@ static void Cmd_adjustdamage(void)
&& !gSpecialStatuses[battlerDef].focusSashed
&& (B_AFFECTION_MECHANICS == FALSE || !gSpecialStatuses[battlerDef].affectionEndured)
&& !gSpecialStatuses[battlerDef].sturdied)
goto END;
continue;

// Handle reducing the dmg to 1 hp.
gBattleStruct->moveDamage[battlerDef] = gBattleMons[battlerDef].hp - 1;
Expand All @@ -2196,10 +2196,6 @@ static void Cmd_adjustdamage(void)
{
gBattleStruct->moveResultFlags[battlerDef] |= MOVE_RESULT_FOE_ENDURED_AFFECTION;
}

END:
if (!(gBattleStruct->moveResultFlags[battlerDef] & MOVE_RESULT_NO_EFFECT) && gBattleStruct->moveDamage[battlerDef] >= 1)
gSpecialStatuses[gBattlerAttacker].damagedMons |= 1u << battlerDef;
}

if (calcSpreadMoveDamage)
Expand Down Expand Up @@ -2572,16 +2568,12 @@ static void Cmd_datahpupdate(void)
{
if (gDisableStructs[battler].substituteHP >= gBattleStruct->moveDamage[battler])
{
if (gSpecialStatuses[battler].shellBellDmg == 0)
gSpecialStatuses[battler].shellBellDmg = gBattleStruct->moveDamage[battler];
gDisableStructs[battler].substituteHP -= gBattleStruct->moveDamage[battler];
gHpDealt = gBattleStruct->moveDamage[battler];
}
else
{
if (gSpecialStatuses[battler].shellBellDmg == 0)
gSpecialStatuses[battler].shellBellDmg = gDisableStructs[battler].substituteHP;
gHpDealt = gDisableStructs[battler].substituteHP;
gHpDealt = gBattleStruct->moveDamage[battler] = gDisableStructs[battler].substituteHP;
gDisableStructs[battler].substituteHP = 0;
}
// check substitute fading
Expand Down Expand Up @@ -2643,14 +2635,10 @@ static void Cmd_datahpupdate(void)
}
else
{
gHpDealt = gBattleMons[battler].hp;
gHpDealt = gBattleStruct->moveDamage[battler] = gBattleMons[battler].hp;
gBattleMons[battler].hp = 0;
}

// Record damage for Shell Bell
if (gSpecialStatuses[battler].shellBellDmg == 0 && !(gHitMarker & HITMARKER_PASSIVE_DAMAGE))
gSpecialStatuses[battler].shellBellDmg = gHpDealt;

// Note: While physicalDmg/specialDmg below are only distinguished between for Counter/Mirror Coat, they are
// used in combination as general damage trackers for other purposes. specialDmg is additionally used
// to help determine if a fire move should defrost the target.
Expand Down Expand Up @@ -2692,13 +2680,7 @@ static void Cmd_datahpupdate(void)
MarkBattlerForControllerExec(battler);
}
}
else
{
// MOVE_RESULT_NO_EFFECT was set
battler = GetBattlerForBattleScript(cmd->battler);
if (gSpecialStatuses[battler].shellBellDmg == 0)
gSpecialStatuses[battler].shellBellDmg = IGNORE_SHELL_BELL;
}

gBattlescriptCurrInstr = cmd->nextInstr;
}

Expand Down Expand Up @@ -5931,7 +5913,7 @@ static void Cmd_moveend(void)
switch (gBattleScripting.moveendState)
{
case MOVEEND_SUM_DAMAGE: // Sum and store damage dealt for multi strike recoil
gBattleScripting.savedDmg += gHpDealt;
gBattleScripting.savedDmg += gBattleStruct->moveDamage[gBattlerTarget];;
gBattleScripting.moveendState++;
break;
case MOVEEND_PROTECT_LIKE_EFFECT:
Expand Down Expand Up @@ -6979,7 +6961,6 @@ static void Cmd_moveend(void)
gBattleStruct->ateBoost[gBattlerAttacker] = FALSE;
gStatuses3[gBattlerAttacker] &= ~STATUS3_ME_FIRST;
gSpecialStatuses[gBattlerAttacker].gemBoost = FALSE;
gSpecialStatuses[gBattlerAttacker].damagedMons = 0;
gSpecialStatuses[gBattlerAttacker].preventLifeOrbDamage = 0;
gSpecialStatuses[gBattlerTarget].berryReduced = FALSE;
gSpecialStatuses[gBattlerTarget].distortedTypeMatchups = FALSE;
Expand Down Expand Up @@ -13260,7 +13241,6 @@ static void Cmd_painsplitdmgcalc(void)
gBattleStruct->moveDamage[gBattlerTarget] = GetNonDynamaxHP(gBattlerTarget) - hpDiff;
gBattleStruct->moveDamage[gBattlerAttacker] = gBattleMons[gBattlerAttacker].hp - hpDiff;

gSpecialStatuses[gBattlerTarget].shellBellDmg = IGNORE_SHELL_BELL;
gBattlescriptCurrInstr = cmd->nextInstr;
}
else
Expand Down
19 changes: 10 additions & 9 deletions src/battle_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -2940,7 +2940,6 @@ bool32 HandleWishPerishSongOnTurnEnd(void)

gBattlerTarget = battler;
gBattlerAttacker = gWishFutureKnock.futureSightBattlerIndex[battler];
gSpecialStatuses[gBattlerTarget].shellBellDmg = IGNORE_SHELL_BELL;
gCurrentMove = gWishFutureKnock.futureSightMove[battler];

party = GetSideParty(GetBattlerSide(gBattlerAttacker));
Expand Down Expand Up @@ -5877,7 +5876,7 @@ u32 AbilityBattleEffects(u32 caseID, u32 battler, u32 ability, u32 special, u32
&& !IsBattlerAlive(gBattlerTarget)
&& IsBattlerAlive(gBattlerAttacker))
{
gBattleStruct->moveDamage[gBattlerAttacker] = gSpecialStatuses[gBattlerTarget].shellBellDmg;
gBattleStruct->moveDamage[gBattlerAttacker] = gBattleStruct->moveDamage[gBattlerTarget];
BattleScriptPushCursor();
gBattlescriptCurrInstr = BattleScript_AftermathDmg;
effect++;
Expand Down Expand Up @@ -8159,39 +8158,41 @@ u32 ItemBattleEffects(enum ItemEffect caseID, u32 battler, bool32 moveTurn)
switch (atkHoldEffect)
{
case HOLD_EFFECT_SHELL_BELL:
if (gSpecialStatuses[gBattlerAttacker].damagedMons // Need to have done damage
if (gBattleScripting.savedDmg > 0
&& MoveResultHasEffect(battler)
&& gBattlerAttacker != gBattlerTarget
&& gBattleMons[gBattlerAttacker].hp != gBattleMons[gBattlerAttacker].maxHP
&& !IsBattlerAtMaxHp(gBattlerAttacker)
&& IsBattlerAlive(gBattlerAttacker)
&& gMovesInfo[gCurrentMove].effect != EFFECT_FUTURE_SIGHT
&& gMovesInfo[gCurrentMove].effect != EFFECT_PAIN_SPLIT
&& (B_HEAL_BLOCKING < GEN_5 || !(gStatuses3[battler] & STATUS3_HEAL_BLOCK)))
{
gLastUsedItem = atkItem;
gPotentialItemEffectBattler = gBattlerAttacker;
gBattleScripting.battler = gBattlerAttacker;
gBattleStruct->moveDamage[gBattlerAttacker] = (gSpecialStatuses[gBattlerTarget].shellBellDmg / atkHoldEffectParam) * -1;
gBattleStruct->moveDamage[gBattlerAttacker] = (gBattleScripting.savedDmg / atkHoldEffectParam) * -1;
if (gBattleStruct->moveDamage[gBattlerAttacker] == 0)
gBattleStruct->moveDamage[gBattlerAttacker] = -1;
gSpecialStatuses[gBattlerTarget].shellBellDmg = 0;
BattleScriptPushCursor();
gBattlescriptCurrInstr = BattleScript_ItemHealHP_Ret;
effect = ITEM_HP_CHANGE;
}
break;
case HOLD_EFFECT_LIFE_ORB:
if (IsBattlerAlive(gBattlerAttacker)
&& (IsBattlerTurnDamaged(gBattlerTarget) || gBattleStruct->moveDamage[gBattlerTarget]) // Needs the second check in case of Substitute
&& !(TestIfSheerForceAffected(gBattlerAttacker, gCurrentMove))
&& GetBattlerAbility(gBattlerAttacker) != ABILITY_MAGIC_GUARD
&& !gProtectStructs[gBattlerAttacker].confusionSelfDmg
&& !gSpecialStatuses[gBattlerAttacker].preventLifeOrbDamage
&& gSpecialStatuses[gBattlerAttacker].damagedMons)
&& !gSpecialStatuses[gBattlerAttacker].preventLifeOrbDamage)
{
gBattleStruct->moveDamage[gBattlerAttacker] = GetNonDynamaxMaxHP(gBattlerAttacker) / 10;
if (gBattleStruct->moveDamage[gBattlerAttacker] == 0)
gBattleStruct->moveDamage[gBattlerAttacker] = 1;
effect = ITEM_HP_CHANGE;
BattleScriptPushCursor();
gBattlescriptCurrInstr = BattleScript_ItemHurtRet;
gLastUsedItem = gBattleMons[gBattlerAttacker].item;
gLastUsedItem = atkItem;
}
break;
case HOLD_EFFECT_THROAT_SPRAY: // Does NOT need to be a damaging move
Expand Down
Empty file.
144 changes: 144 additions & 0 deletions test/battle/hold_effect/shell_bell.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
#include "global.h"
#include "test/battle.h"

ASSUMPTIONS
{
ASSUME(gItemsInfo[ITEM_SHELL_BELL].holdEffect == HOLD_EFFECT_SHELL_BELL);
}

#define HITS 5
SINGLE_BATTLE_TEST("Shell Bell recovers 1/8 of HP from after the last hit from all hits of a multi hit move")
{
s16 multiHitDamage[HITS];
s16 totalDamage = 0;
s16 shellBellRecovery = 0;

GIVEN {
PLAYER(SPECIES_WOBBUFFET) { HP(1); Item(ITEM_SHELL_BELL); }
OPPONENT(SPECIES_WOBBUFFET);
} WHEN {
TURN { MOVE(player, MOVE_BULLET_SEED); }
} SCENE {
for (u32 i = 0; i < HITS; i++) {
ANIMATION(ANIM_TYPE_MOVE, MOVE_BULLET_SEED, player);
HP_BAR(opponent, captureDamage: &multiHitDamage[i]);
totalDamage += multiHitDamage[i];
}
HP_BAR(player, captureDamage: &shellBellRecovery);
} THEN {
EXPECT_EQ(totalDamage / 8, -1 * shellBellRecovery);
}
}
#undef HITS

SINGLE_BATTLE_TEST("Shell Bell recovers no HP if the move did no damage")
{
GIVEN {
PLAYER(SPECIES_WOBBUFFET) { HP(1); Item(ITEM_SHELL_BELL); }
OPPONENT(SPECIES_WOBBUFFET) { HP(1); };
} WHEN {
TURN { MOVE(player, MOVE_FALSE_SWIPE); }
} SCENE {
ANIMATION(ANIM_TYPE_MOVE, MOVE_FALSE_SWIPE, player);
HP_BAR(opponent);
NONE_OF {
ANIMATION(ANIM_TYPE_GENERAL, B_ANIM_HELD_ITEM_EFFECT, player);
HP_BAR(player);
}

AlexOn1ine marked this conversation as resolved.
Show resolved Hide resolved
}
}

SINGLE_BATTLE_TEST("Shell Bell activates if it hits a Substitute")
{
GIVEN {
PLAYER(SPECIES_WOBBUFFET) { HP(1); Item(ITEM_SHELL_BELL); }
OPPONENT(SPECIES_WOBBUFFET);
} WHEN {
TURN { MOVE(opponent, MOVE_SUBSTITUTE); MOVE(player, MOVE_TACKLE); }
} SCENE {
ANIMATION(ANIM_TYPE_MOVE, MOVE_SUBSTITUTE, opponent);
ANIMATION(ANIM_TYPE_MOVE, MOVE_TACKLE, player);
// HP_BAR(opponent); // When you hit a sub the hp bar check doesn't work. Not sure if this is a bug
AlexOn1ine marked this conversation as resolved.
Show resolved Hide resolved
ANIMATION(ANIM_TYPE_GENERAL, B_ANIM_HELD_ITEM_EFFECT, player);
HP_BAR(player);
}
}

SINGLE_BATTLE_TEST("Shell Bell activates after Absorb")
{
GIVEN {
PLAYER(SPECIES_WOBBUFFET) { HP(1); Item(ITEM_SHELL_BELL); }
OPPONENT(SPECIES_WOBBUFFET);
} WHEN {
TURN { MOVE(player, MOVE_ABSORB); }
} SCENE {
ANIMATION(ANIM_TYPE_MOVE, MOVE_ABSORB, player);
HP_BAR(opponent);
HP_BAR(player);
ANIMATION(ANIM_TYPE_GENERAL, B_ANIM_HELD_ITEM_EFFECT, player);
HP_BAR(player);
}
}

SINGLE_BATTLE_TEST("Shell Bell activates after Rough Skin")
{
GIVEN {
PLAYER(SPECIES_WOBBUFFET) { Item(ITEM_SHELL_BELL); }
OPPONENT(SPECIES_GIBLE) { Ability(ABILITY_ROUGH_SKIN); }
} WHEN {
TURN { MOVE(player, MOVE_TACKLE); }
} SCENE {
ANIMATION(ANIM_TYPE_MOVE, MOVE_TACKLE, player);
HP_BAR(opponent);
HP_BAR(player);
ANIMATION(ANIM_TYPE_GENERAL, B_ANIM_HELD_ITEM_EFFECT, player);
HP_BAR(player);
}
}

SINGLE_BATTLE_TEST("Shell Bell does not activate on Future Sight if the original user is on the field")
{
GIVEN {
PLAYER(SPECIES_WOBBUFFET) { HP(1); Item(ITEM_SHELL_BELL); }
OPPONENT(SPECIES_WYNAUT);
} WHEN {
TURN { MOVE(player, MOVE_FUTURE_SIGHT); }
TURN {}
TURN {}
} SCENE {
ANIMATION(ANIM_TYPE_MOVE, MOVE_FUTURE_SIGHT, player);
MESSAGE("The opposing Wynaut took the Future Sight attack!");
HP_BAR(opponent);
NONE_OF {
ANIMATION(ANIM_TYPE_GENERAL, B_ANIM_HELD_ITEM_EFFECT, player);
HP_BAR(player);
}
}
}

SINGLE_BATTLE_TEST("Shell Bell does not activate on Future Sight if the original user is not on the field")
{
GIVEN {
PLAYER(SPECIES_WYNAUT);
PLAYER(SPECIES_WOBBUFFET) { HP(1); Item(ITEM_SHELL_BELL); }
OPPONENT(SPECIES_WYNAUT);
} WHEN {
TURN { MOVE(player, MOVE_FUTURE_SIGHT); }
TURN { SWITCH(player, 1); }
TURN {}
} SCENE {
ANIMATION(ANIM_TYPE_MOVE, MOVE_FUTURE_SIGHT, player);
MESSAGE("The opposing Wynaut took the Future Sight attack!");
HP_BAR(opponent);
NONE_OF {
ANIMATION(ANIM_TYPE_GENERAL, B_ANIM_HELD_ITEM_EFFECT, player);
HP_BAR(player);
}
}
}

// HOLD_EFFECT_LIFE_ORB
// !gSpecialStatuses[gBattlerAttacker].preventLifeOrbDamage
TO_DO_BATTLE_TEST("If a Pokémon steals a Shell Bell with Thief or Covet, it will recover HP for the use of that move that stole the Shell Bell")
TO_DO_BATTLE_TEST("If a Pokémon steals a Shell Bell with Magician, it will recover HP for the use of that move that stole the Shell Bell")
AlexOn1ine marked this conversation as resolved.
Show resolved Hide resolved
Loading