Fix Teleport ending trainer battles (#3166)

This commit is contained in:
Alex 2023-08-07 17:23:12 +02:00 committed by GitHub
parent 1fb42e4497
commit 42992ca5ce
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 74 additions and 72 deletions

View File

@ -1318,7 +1318,7 @@
.2byte \holdEffect .2byte \holdEffect
.4byte \jumpInstr .4byte \jumpInstr
.endm .endm
.macro dostockpilestatchangeswearoff, battler:req, statChangeInstr:req .macro dostockpilestatchangeswearoff, battler:req, statChangeInstr:req
callnative BS_DoStockpileStatChangesWearOff callnative BS_DoStockpileStatChangesWearOff
.byte \battler .byte \battler
@ -1354,7 +1354,7 @@
.macro setsnow .macro setsnow
callnative BS_SetSnow callnative BS_SetSnow
.endm .endm
.macro setzeffect .macro setzeffect
callnative BS_SetZEffect callnative BS_SetZEffect
.endm .endm
@ -1364,12 +1364,6 @@
callnative BS_TrySymbiosis callnative BS_TrySymbiosis
.endm .endm
@ returns TRUE or FALSE to gBattleCommunication[0]
.macro canteleport battler:req
callnative BS_CanTeleport
.byte \battler
.endm
@ returns B_SIDE_x to gBattleCommunication[0] @ returns B_SIDE_x to gBattleCommunication[0]
.macro getbattlerside battler:req .macro getbattlerside battler:req
callnative BS_GetBattlerSide callnative BS_GetBattlerSide
@ -2077,7 +2071,7 @@
.macro swapsidestatuses .macro swapsidestatuses
various BS_ATTACKER, VARIOUS_SWAP_SIDE_STATUSES various BS_ATTACKER, VARIOUS_SWAP_SIDE_STATUSES
.endm .endm
.macro swapstats stat:req .macro swapstats stat:req
various BS_ATTACKER, VARIOUS_SWAP_STATS various BS_ATTACKER, VARIOUS_SWAP_STATS
.byte \stat .byte \stat
@ -2178,6 +2172,11 @@
jumpifbyte CMP_COMMON_BITS, gMoveResultFlags, MOVE_RESULT_NO_EFFECT, \jumpInstr jumpifbyte CMP_COMMON_BITS, gMoveResultFlags, MOVE_RESULT_NO_EFFECT, \jumpInstr
.endm .endm
.macro jumpifside battler:req, side:req, equalJumpInstr:req
getbattlerside \battler
jumpifbyte CMP_EQUAL, gBattleCommunication, \side, \equalJumpInstr
.endm
.macro jumpifbattletype flags:req, jumpInstr:req .macro jumpifbattletype flags:req, jumpInstr:req
jumpifword CMP_COMMON_BITS, gBattleTypeFlags, \flags, \jumpInstr jumpifword CMP_COMMON_BITS, gBattleTypeFlags, \flags, \jumpInstr
.endm .endm

View File

@ -5401,15 +5401,14 @@ BattleScript_EffectHurricane:
BattleScript_EffectTeleport: BattleScript_EffectTeleport:
attackcanceler attackcanceler
attackstring attackstring
ppreduce
.if B_TELEPORT_BEHAVIOR >= GEN_7 .if B_TELEPORT_BEHAVIOR >= GEN_7
canteleport BS_ATTACKER jumpifbattletype BATTLE_TYPE_TRAINER, BattleScript_EffectBatonPass
jumpifbyte CMP_EQUAL, gBattleCommunication, TRUE, BattleScript_EffectTeleportNew jumpifside BS_ATTACKER, B_SIDE_PLAYER, BattleScript_EffectBatonPass
goto BattleScript_ButItFailed
.else .else
jumpifbattletype BATTLE_TYPE_TRAINER, BattleScript_ButItFailed jumpifbattletype BATTLE_TYPE_TRAINER, BattleScript_ButItFailed
.endif .endif
BattleScript_EffectTeleportTryToRunAway: BattleScript_EffectTeleportTryToRunAway:
ppreduce
getifcantrunfrombattle BS_ATTACKER getifcantrunfrombattle BS_ATTACKER
jumpifbyte CMP_EQUAL, gBattleCommunication, BATTLE_RUN_FORBIDDEN, BattleScript_ButItFailed jumpifbyte CMP_EQUAL, gBattleCommunication, BATTLE_RUN_FORBIDDEN, BattleScript_ButItFailed
jumpifbyte CMP_EQUAL, gBattleCommunication, BATTLE_RUN_FAILURE, BattleScript_PrintAbilityMadeIneffective jumpifbyte CMP_EQUAL, gBattleCommunication, BATTLE_RUN_FAILURE, BattleScript_PrintAbilityMadeIneffective
@ -5420,29 +5419,6 @@ BattleScript_EffectTeleportTryToRunAway:
setoutcomeonteleport BS_ATTACKER setoutcomeonteleport BS_ATTACKER
goto BattleScript_MoveEnd goto BattleScript_MoveEnd
BattleScript_EffectTeleportNew:
getbattlerside BS_ATTACKER
jumpifbyte CMP_EQUAL, gBattleCommunication, B_SIDE_OPPONENT, BattleScript_EffectTeleportTryToRunAway
attackanimation
waitanimation
openpartyscreen BS_ATTACKER, BattleScript_EffectTeleportNewEnd
switchoutabilities BS_ATTACKER
waitstate
switchhandleorder BS_ATTACKER, 2
returntoball BS_ATTACKER
getswitchedmondata BS_ATTACKER
switchindataupdate BS_ATTACKER
hpthresholds BS_ATTACKER
trytoclearprimalweather
printstring STRINGID_EMPTYSTRING3
waitmessage 1
printstring STRINGID_SWITCHINMON
switchinanim BS_ATTACKER, TRUE
waitstate
switchineffects BS_ATTACKER
BattleScript_EffectTeleportNewEnd:
goto BattleScript_MoveEnd
BattleScript_EffectBeatUp:: BattleScript_EffectBeatUp::
attackcanceler attackcanceler
accuracycheck BattleScript_PrintMoveMissed, ACC_CURR_MOVE accuracycheck BattleScript_PrintMoveMissed, ACC_CURR_MOVE
@ -7897,7 +7873,7 @@ BattleScript_WishMegaEvolution::
BattleScript_PrimalReversion:: BattleScript_PrimalReversion::
call BattleScript_PrimalReversionRet call BattleScript_PrimalReversionRet
end2 end2
BattleScript_PrimalReversionRestoreAttacker:: BattleScript_PrimalReversionRestoreAttacker::
call BattleScript_PrimalReversionRet call BattleScript_PrimalReversionRet
copybyte gBattlerAttacker, sSAVED_BATTLER copybyte gBattlerAttacker, sSAVED_BATTLER
@ -8944,7 +8920,7 @@ BattleScript_BadDreams_ShowPopUp:
goto BattleScript_BadDreams_DmgAfterPopUp goto BattleScript_BadDreams_DmgAfterPopUp
BattleScript_BadDreams_HidePopUp: BattleScript_BadDreams_HidePopUp:
destroyabilitypopup destroyabilitypopup
tryfaintmon BS_TARGET tryfaintmon BS_TARGET
goto BattleScript_BadDreamsIncrement goto BattleScript_BadDreamsIncrement
BattleScript_TookAttack:: BattleScript_TookAttack::

View File

@ -8837,33 +8837,6 @@ static void HandleScriptMegaPrimal(u32 caseId, u32 battlerId, bool32 isMega)
} }
} }
static bool32 CanTeleport(u8 battlerId)
{
struct Pokemon *party = GetBattlerParty(battlerId);
u32 species, count, i;
for (i = 0; i < PARTY_SIZE; i++)
{
species = GetMonData(&party[i], MON_DATA_SPECIES_OR_EGG);
if (species != SPECIES_NONE && species != SPECIES_EGG && GetMonData(&party[i], MON_DATA_HP) != 0)
count++;
}
switch (GetBattlerSide(battlerId))
{
case B_SIDE_OPPONENT:
if (count == 1 || gBattleTypeFlags & BATTLE_TYPE_DOUBLE)
return FALSE;
break;
case B_SIDE_PLAYER:
if (count == 1 || (gBattleTypeFlags & BATTLE_TYPE_DOUBLE && count <= 2))
return FALSE;
break;
}
return TRUE;
}
// Return True if the order was changed, and false if the order was not changed(for example because the target would move after the attacker anyway). // Return True if the order was changed, and false if the order was not changed(for example because the target would move after the attacker anyway).
static bool32 ChangeOrderTargetAfterAttacker(void) static bool32 ChangeOrderTargetAfterAttacker(void)
{ {
@ -16327,13 +16300,6 @@ void BS_GetBattlerSide(void)
gBattlescriptCurrInstr = cmd->nextInstr; gBattlescriptCurrInstr = cmd->nextInstr;
} }
void BS_CanTeleport(void)
{
NATIVE_ARGS(u8 battler);
gBattleCommunication[0] = CanTeleport(cmd->battler);
gBattlescriptCurrInstr = cmd->nextInstr;
}
void BS_TrySymbiosis(void) void BS_TrySymbiosis(void)
{ {
NATIVE_ARGS(); NATIVE_ARGS();

View File

@ -0,0 +1,61 @@
#include "global.h"
#include "test_battle.h"
ASSUMPTIONS
{
ASSUME(gBattleMoves[MOVE_TELEPORT].effect == EFFECT_TELEPORT);
}
SINGLE_BATTLE_TEST("Teleport fails when there is no pokemon to switch in")
{
GIVEN {
PLAYER(SPECIES_WOBBUFFET);
OPPONENT(SPECIES_WOBBUFFET);
} WHEN {
TURN { MOVE(opponent, MOVE_TELEPORT); }
} SCENE {
MESSAGE("But it failed!");
}
}
SINGLE_BATTLE_TEST("Teleport fails when there no alive pokemon left")
{
GIVEN {
PLAYER(SPECIES_WOBBUFFET);
OPPONENT(SPECIES_WOBBUFFET);
OPPONENT(SPECIES_WYNAUT) { HP(0); }
} WHEN {
TURN { MOVE(opponent, MOVE_TELEPORT); }
} SCENE {
MESSAGE("But it failed!");
}
}
SINGLE_BATTLE_TEST("Teleport forces the pokemon to switch out")
{
GIVEN {
PLAYER(SPECIES_WOBBUFFET);
OPPONENT(SPECIES_WOBBUFFET);
OPPONENT(SPECIES_WYNAUT);
} WHEN {
TURN { MOVE(opponent, MOVE_TELEPORT); SEND_OUT(opponent, 1); }
} SCENE {
ANIMATION(ANIM_TYPE_MOVE, MOVE_TELEPORT, opponent);
MESSAGE("2 sent out Wynaut!");
}
}
SINGLE_BATTLE_TEST("Teleport does not fail if the user is trapped")
{
GIVEN {
PLAYER(SPECIES_WOBBUFFET);
OPPONENT(SPECIES_WOBBUFFET);
OPPONENT(SPECIES_WYNAUT);
} WHEN {
TURN { MOVE(player, MOVE_FIRE_SPIN); MOVE(opponent, MOVE_TELEPORT); SEND_OUT(opponent, 1); }
} SCENE {
ANIMATION(ANIM_TYPE_MOVE, MOVE_FIRE_SPIN, player);
ANIMATION(ANIM_TYPE_MOVE, MOVE_TELEPORT, opponent);
MESSAGE("2 sent out Wynaut!");
}
}