Fixes Ally Switch in multi battles (#7109)

This commit is contained in:
Alex 2025-06-13 15:18:27 +02:00 committed by GitHub
parent a000a743df
commit c120fa71dc
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 16 additions and 8 deletions

View File

@ -1398,8 +1398,8 @@
callnative BS_AllySwitchSwapBattler
.endm
.macro allyswitchfailchance jumpInstr:req
callnative BS_AllySwitchFailChance
.macro tryallyswitch jumpInstr:req
callnative BS_TryAllySwitch
.4byte \jumpInstr
.endm

View File

@ -1105,8 +1105,7 @@ BattleScript_EffectAllySwitch::
accuracycheck BattleScript_PrintMoveMissed, ACC_CURR_MOVE
attackstring
ppreduce
jumpifnoally BS_ATTACKER, BattleScript_ButItFailed
allyswitchfailchance BattleScript_ButItFailed
tryallyswitch BattleScript_ButItFailed
attackanimation
waitanimation
@ The actual data/gfx swap happens in the move animation. Here it's just the gBattlerAttacker / scripting battler change

View File

@ -17699,26 +17699,35 @@ void BS_AllySwitchSwapBattler(void)
gBattlescriptCurrInstr = cmd->nextInstr;
}
void BS_AllySwitchFailChance(void)
void BS_TryAllySwitch(void)
{
NATIVE_ARGS(const u8 *failInstr);
if (B_ALLY_SWITCH_FAIL_CHANCE >= GEN_9)
if (!IsBattlerAlive(BATTLE_PARTNER(gBattlerAttacker))
|| (GetBattlerSide(gBattlerAttacker) == B_SIDE_PLAYER && gBattleTypeFlags & BATTLE_TYPE_INGAME_PARTNER)
|| (GetBattlerSide(gBattlerAttacker) == B_SIDE_OPPONENT && gBattleTypeFlags & BATTLE_TYPE_TWO_OPPONENTS))
{
gBattlescriptCurrInstr = cmd->failInstr;
}
else if (B_ALLY_SWITCH_FAIL_CHANCE >= GEN_9)
{
TryResetProtectUseCounter(gBattlerAttacker);
if (sProtectSuccessRates[gDisableStructs[gBattlerAttacker].protectUses] < Random())
{
gDisableStructs[gBattlerAttacker].protectUses = 0;
gBattlescriptCurrInstr = cmd->failInstr;
return;
}
else
{
gDisableStructs[gBattlerAttacker].protectUses++;
}
}
gBattlescriptCurrInstr = cmd->nextInstr;
}
}
else
{
gBattlescriptCurrInstr = cmd->nextInstr;
}
}
void BS_RunStatChangeItems(void)
{