Skip to content

Commit

Permalink
Fixes Called moves ignoring redirection (rh-hideout#6267)
Browse files Browse the repository at this point in the history
  • Loading branch information
PhallenTree authored Feb 14, 2025
1 parent 53727aa commit b1c5974
Show file tree
Hide file tree
Showing 8 changed files with 387 additions and 131 deletions.
14 changes: 0 additions & 14 deletions data/battle_scripts_1.s
Original file line number Diff line number Diff line change
Expand Up @@ -1744,8 +1744,6 @@ BattleScript_EffectCopycat::
trycopycat BattleScript_CopycatFail
attackanimation
waitanimation
setbyte sB_ANIM_TURN, 0
setbyte sB_ANIM_TARGETS_HIT, 0
jumptocalledmove TRUE
BattleScript_CopycatFail:
ppreduce
Expand All @@ -1763,8 +1761,6 @@ BattleScript_EffectInstruct::
copybyte gBattlerTarget, gEffectBattler
printstring STRINGID_USEDINSTRUCTEDMOVE
waitmessage B_WAIT_TIME_LONG
setbyte sB_ANIM_TURN, 0
setbyte sB_ANIM_TARGETS_HIT, 0
jumptocalledmove TRUE

BattleScript_EffectAutotomize::
Expand Down Expand Up @@ -2188,8 +2184,6 @@ BattleScript_EffectMeFirst::
trymefirst BattleScript_FailedFromPpReduce
attackanimation
waitanimation
setbyte sB_ANIM_TURN, 0
setbyte sB_ANIM_TARGETS_HIT, 0
jumptocalledmove TRUE

BattleScript_EffectAttackSpAttackUp::
Expand Down Expand Up @@ -3842,8 +3836,6 @@ BattleScript_EffectMetronome::
pause B_WAIT_TIME_SHORT
attackanimation
waitanimation
setbyte sB_ANIM_TURN, 0
setbyte sB_ANIM_TARGETS_HIT, 0
metronome

BattleScript_EffectLeechSeed::
Expand Down Expand Up @@ -4038,8 +4030,6 @@ BattleScript_SleepTalkIsAsleep::
BattleScript_SleepTalkUsingMove::
attackanimation
waitanimation
setbyte sB_ANIM_TURN, 0
setbyte sB_ANIM_TARGETS_HIT, 0
jumptocalledmove TRUE

BattleScript_EffectDestinyBond::
Expand Down Expand Up @@ -5055,8 +5045,6 @@ BattleScript_EffectAssist::
assistattackselect BattleScript_FailedFromPpReduce
attackanimation
waitanimation
setbyte sB_ANIM_TURN, 0
setbyte sB_ANIM_TARGETS_HIT, 0
jumptocalledmove TRUE

BattleScript_EffectIngrain::
Expand Down Expand Up @@ -8709,8 +8697,6 @@ BattleScript_BattleBondActivatesOnMoveEndAttacker::
BattleScript_DancerActivates::
call BattleScript_AbilityPopUp
waitmessage B_WAIT_TIME_SHORT
setbyte sB_ANIM_TURN, 0
setbyte sB_ANIM_TARGETS_HIT, 0
orword gHitMarker, HITMARKER_ALLOW_NO_PP
jumptocalledmove TRUE

Expand Down
1 change: 1 addition & 0 deletions include/battle_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ STATIC_ASSERT(sizeof(struct DamageCalculationData) <= 4, StructExceedsFourBytes)

void HandleAction_ThrowBall(void);
bool32 IsAffectedByFollowMe(u32 battlerAtk, u32 defSide, u32 move);
bool32 HandleMoveTargetRedirection(void);
void HandleAction_UseMove(void);
void HandleAction_Switch(void);
void HandleAction_UseItem(void);
Expand Down
29 changes: 19 additions & 10 deletions src/battle_script_commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,7 @@ static bool8 CanBurnHitThaw(u16 move);
static u32 GetNextTarget(u32 moveTarget, bool32 excludeCurrent);
static void TryUpdateEvolutionTracker(u32 evolutionMethod, u32 upAmount, u16 usedMove);
static void AccuracyCheck(bool32 recalcDragonDarts, const u8 *nextInstr, const u8 *failInstr, u16 move);
static void ResetValuesForCalledMove(void);

static void Cmd_attackcanceler(void);
static void Cmd_accuracycheck(void);
Expand Down Expand Up @@ -8133,6 +8134,18 @@ static void Cmd_hidepartystatussummary(void)
gBattlescriptCurrInstr = cmd->nextInstr;
}

static void ResetValuesForCalledMove(void)
{
if (gBattlerByTurnOrder[gCurrentTurnActionNumber] != gBattlerAttacker)
gBattleStruct->atkCancellerTracker = 0;
else
SetAtkCancellerForCalledMove();
gBattleScripting.animTurn = 0;
gBattleScripting.animTargetsHit = 0;
SetTypeBeforeUsingMove(gCurrentMove, gBattlerAttacker);
HandleMoveTargetRedirection();
}

static void Cmd_jumptocalledmove(void)
{
CMD_ARGS(bool8 notChosenMove);
Expand All @@ -8142,6 +8155,8 @@ static void Cmd_jumptocalledmove(void)
else
gChosenMove = gCurrentMove = gCalledMove;

ResetValuesForCalledMove();

gBattlescriptCurrInstr = GET_MOVE_BATTLESCRIPT(gCurrentMove);
}

Expand Down Expand Up @@ -10193,10 +10208,8 @@ static void Cmd_various(void)
gBattlescriptCurrInstr = cmd->failInstr;
else
{
SetTypeBeforeUsingMove(gCalledMove, gBattlerTarget);
gEffectBattler = gBattleStruct->lastMoveTarget[gBattlerTarget];
gHitMarker &= ~HITMARKER_ATTACKSTRING_PRINTED;
gBattleStruct->atkCancellerTracker = 0;
PREPARE_MON_NICK_WITH_PREFIX_BUFFER(gBattleTextBuff1, battler, gBattlerPartyIndexes[battler]);
gBattlescriptCurrInstr = cmd->nextInstr;
}
Expand Down Expand Up @@ -11212,8 +11225,8 @@ static void SetMoveForMirrorMove(u32 move)
gCurrentMove = move;
}

SetAtkCancellerForCalledMove();
gBattlerTarget = GetMoveTarget(gCurrentMove, NO_TARGET_OVERRIDE);
ResetValuesForCalledMove();
gBattlescriptCurrInstr = GET_MOVE_BATTLESCRIPT(gCurrentMove);
}

Expand Down Expand Up @@ -12765,10 +12778,10 @@ static void Cmd_metronome(void)
#endif

gCurrentMove = RandomUniformExcept(RNG_METRONOME, 1, moveCount - 1, InvalidMetronomeMove);
SetAtkCancellerForCalledMove();
PrepareStringBattle(STRINGID_WAGGLINGAFINGER, gBattlerAttacker);
gBattlescriptCurrInstr = GET_MOVE_BATTLESCRIPT(gCurrentMove);
gBattlerTarget = GetMoveTarget(gCurrentMove, NO_TARGET_OVERRIDE);
ResetValuesForCalledMove();
}

static void Cmd_dmgtolevel(void)
Expand Down Expand Up @@ -17342,14 +17355,10 @@ void BS_JumpIfBlockedBySoundproof(void)
void BS_SetMagicCoatTarget(void)
{
NATIVE_ARGS();
u32 side;
gBattleStruct->attackerBeforeBounce = gBattleScripting.battler = gBattlerAttacker;
gBattlerAttacker = gBattlerTarget;
side = BATTLE_OPPOSITE(GetBattlerSide(gBattlerAttacker));
if (IsAffectedByFollowMe(gBattlerAttacker, side, gCurrentMove))
gBattlerTarget = gSideTimers[side].followmeTarget;
else
gBattlerTarget = gBattleStruct->attackerBeforeBounce;
gBattlerTarget = gBattleStruct->attackerBeforeBounce;
HandleMoveTargetRedirection();

gBattlescriptCurrInstr = cmd->nextInstr;
}
Expand Down
Loading

0 comments on commit b1c5974

Please sign in to comment.