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

Fling fixes and tests #3191

Merged
merged 13 commits into from
Sep 5, 2023
11 changes: 6 additions & 5 deletions asm/macros/battle_script.inc
Original file line number Diff line number Diff line change
Expand Up @@ -1311,6 +1311,12 @@
callnative BS_CalcMetalBurstDmg
.4byte \failInstr
.endm

.macro jumpifcantfling battler:req, jumpInstr:req
callnative BS_JumpIfCantFling
.byte \battler
.4byte \jumpInstr
.endm

.macro jumpifholdeffect battler:req, holdEffect:req, jumpInstr:req
callnative BS_JumpIfHoldEffect
Expand Down Expand Up @@ -2028,11 +2034,6 @@
.4byte \jumpInstr
.endm

.macro jumpifcantfling battler:req, jumpInstr:req
various \battler, VARIOUS_JUMP_IF_CANT_FLING
.4byte \jumpInstr
.endm

.macro curecertainstatuses battler:req
various \battler, VARIOUS_CURE_CERTAIN_STATUSES
.endm
Expand Down
60 changes: 30 additions & 30 deletions data/battle_scripts_1.s
Original file line number Diff line number Diff line change
Expand Up @@ -836,12 +836,10 @@ BattleScript_SkyDropFlyingAlreadyConfused:
goto BattleScript_ThrashConfuses

BattleScript_EffectFling:
jumpifcantfling BS_ATTACKER, BattleScript_ButItFailedAtkStringPpReduce
jumpifstatus3 BS_ATTACKER, STATUS3_EMBARGO, BattleScript_ButItFailedAtkStringPpReduce
jumpifword CMP_COMMON_BITS, gFieldStatuses, STATUS_FIELD_MAGIC_ROOM, BattleScript_ButItFailedAtkStringPpReduce
attackcanceler
jumpifcantfling BS_ATTACKER, BattleScript_FailedFromAtkString
setlastuseditem BS_ATTACKER
removeitem BS_ATTACKER
attackcanceler
accuracycheck BattleScript_PrintMoveMissed, ACC_CURR_MOVE
attackstring
pause B_WAIT_TIME_SHORT
Expand Down Expand Up @@ -883,6 +881,10 @@ BattleScript_FlingEnd:
tryfaintmon BS_TARGET
trysymbiosis
goto BattleScript_MoveEnd

BattleScript_FlingFailConsumeItem::
removeitem BS_ATTACKER
goto BattleScript_FailedFromAtkString

BattleScript_FlingFlameOrb:
setmoveeffect MOVE_EFFECT_BURN
Expand Down Expand Up @@ -971,7 +973,7 @@ BattleScript_EffectClangorousSoul:

BattleScript_EffectOctolock:
attackcanceler
jumpifsubstituteblocks BattleScript_ButItFailedAtkStringPpReduce
jumpifsubstituteblocks BattleScript_FailedFromAtkString
accuracycheck BattleScript_PrintMoveMissed, ACC_CURR_MOVE
attackstring
ppreduce
Expand Down Expand Up @@ -1019,9 +1021,9 @@ BattleScript_EffectPoltergeist:

BattleScript_EffectTarShot:
attackcanceler
jumpifsubstituteblocks BattleScript_ButItFailedAtkStringPpReduce
jumpifsubstituteblocks BattleScript_FailedFromAtkString
accuracycheck BattleScript_PrintMoveMissed, ACC_CURR_MOVE
cantarshotwork BS_TARGET, BattleScript_ButItFailedAtkStringPpReduce
cantarshotwork BS_TARGET, BattleScript_FailedFromAtkString
attackstring
ppreduce
setstatchanger STAT_SPEED, 1, TRUE
Expand Down Expand Up @@ -1502,7 +1504,7 @@ BattleScript_PurifyWorks:
BattleScript_EffectStrengthSap:
setstatchanger STAT_ATK, 1, TRUE
attackcanceler
jumpifsubstituteblocks BattleScript_ButItFailedAtkStringPpReduce
jumpifsubstituteblocks BattleScript_FailedFromAtkString
accuracycheck BattleScript_PrintMoveMissed, ACC_CURR_MOVE
attackstring
ppreduce
Expand Down Expand Up @@ -2070,7 +2072,7 @@ BattleScript_EffectDefog:
jumpifsubstituteblocks BattleScript_DefogIfCanClearHazards
jumpifstat BS_TARGET, CMP_NOT_EQUAL, STAT_EVASION, MIN_STAT_STAGE, BattleScript_DefogWorks
BattleScript_DefogIfCanClearHazards:
defogclear BS_ATTACKER, FALSE, BattleScript_ButItFailedAtkStringPpReduce
defogclear BS_ATTACKER, FALSE, BattleScript_FailedFromAtkString
BattleScript_DefogWorks:
accuracycheck BattleScript_PrintMoveMissed, ACC_CURR_MOVE
attackstring
Expand Down Expand Up @@ -2216,9 +2218,9 @@ BattleScript_EffectClearSmog:
BattleScript_EffectToxicThread:
setstatchanger STAT_SPEED, 2, TRUE
attackcanceler
jumpifsubstituteblocks BattleScript_ButItFailedAtkStringPpReduce
jumpifsubstituteblocks BattleScript_FailedFromAtkString
jumpifstat BS_TARGET, CMP_NOT_EQUAL, STAT_SPEED, MIN_STAT_STAGE, BattleScript_ToxicThreadWorks
jumpifstatus BS_TARGET, STATUS1_PSN_ANY, BattleScript_ButItFailedAtkStringPpReduce
jumpifstatus BS_TARGET, STATUS1_PSN_ANY, BattleScript_FailedFromAtkString
BattleScript_ToxicThreadWorks:
accuracycheck BattleScript_PrintMoveMissed, ACC_CURR_MOVE
attackstring
Expand Down Expand Up @@ -2572,7 +2574,7 @@ BattleScript_EffectSpeedUpHit:
BattleScript_EffectMeFirst:
attackcanceler
attackstring
trymefirst BattleScript_ButItFailedPpReduce
trymefirst BattleScript_FailedFromPpReduce
attackanimation
waitanimation
setbyte sB_ANIM_TURN, 0
Expand Down Expand Up @@ -2738,7 +2740,7 @@ BattleScript_EffectSimpleBeam:

BattleScript_EffectSuckerPunch:
attackcanceler
suckerpunchcheck BattleScript_ButItFailedAtkStringPpReduce
suckerpunchcheck BattleScript_FailedFromAtkString
accuracycheck BattleScript_PrintMoveMissed, ACC_CURR_MOVE
goto BattleScript_HitFromAtkString

Expand All @@ -2755,7 +2757,7 @@ BattleScript_EffectLuckyChant:

BattleScript_EffectMetalBurst:
attackcanceler
metalburstdamagecalculator BattleScript_ButItFailedAtkStringPpReduce
metalburstdamagecalculator BattleScript_FailedFromAtkString
accuracycheck BattleScript_PrintMoveMissed, ACC_CURR_MOVE
attackstring
ppreduce
Expand All @@ -2766,7 +2768,7 @@ BattleScript_EffectMetalBurst:

BattleScript_EffectHealingWish:
attackcanceler
jumpifcantswitch SWITCH_IGNORE_ESCAPE_PREVENTION | BS_ATTACKER, BattleScript_ButItFailedAtkStringPpReduce
jumpifcantswitch SWITCH_IGNORE_ESCAPE_PREVENTION | BS_ATTACKER, BattleScript_FailedFromAtkString
attackstring
ppreduce
attackanimation
Expand Down Expand Up @@ -3126,9 +3128,9 @@ BattleScript_EffectRoost:
BattleScript_EffectCaptivate:
setstatchanger STAT_SPATK, 2, TRUE
attackcanceler
jumpifsubstituteblocks BattleScript_ButItFailedAtkStringPpReduce
jumpifsubstituteblocks BattleScript_FailedFromAtkString
jumpifoppositegenders BattleScript_CaptivateCheckAcc
goto BattleScript_ButItFailedAtkStringPpReduce
goto BattleScript_FailedFromAtkString
BattleScript_CaptivateCheckAcc:
accuracycheck BattleScript_PrintMoveMissed, ACC_CURR_MOVE
goto BattleScript_StatDownFromAttackString
Expand Down Expand Up @@ -3706,7 +3708,7 @@ BattleScript_EffectEvasionDown:
setstatchanger STAT_EVASION, 1, TRUE
BattleScript_EffectStatDown:
attackcanceler
jumpifsubstituteblocks BattleScript_ButItFailedAtkStringPpReduce
jumpifsubstituteblocks BattleScript_FailedFromAtkString
accuracycheck BattleScript_PrintMoveMissed, ACC_CURR_MOVE
BattleScript_StatDownFromAttackString:
attackstring
Expand Down Expand Up @@ -4601,7 +4603,7 @@ BattleScript_EffectPsywave::

BattleScript_EffectCounter::
attackcanceler
counterdamagecalculator BattleScript_ButItFailedAtkStringPpReduce
counterdamagecalculator BattleScript_FailedFromAtkString
accuracycheck BattleScript_PrintMoveMissed, ACC_CURR_MOVE
attackstring
ppreduce
Expand Down Expand Up @@ -4908,7 +4910,7 @@ BattleScript_DoGhostCurse::

BattleScript_EffectMatBlock::
attackcanceler
jumpifnotfirstturn BattleScript_ButItFailedAtkStringPpReduce
jumpifnotfirstturn BattleScript_FailedFromAtkString
goto BattleScript_ProtectLikeAtkString

BattleScript_EffectProtect::
Expand All @@ -4926,7 +4928,7 @@ BattleScript_ProtectLikeAtkString:

BattleScript_EffectSpikes::
attackcanceler
trysetspikes BattleScript_ButItFailedAtkStringPpReduce
trysetspikes BattleScript_FailedFromAtkString
attackstring
ppreduce
attackanimation
Expand Down Expand Up @@ -5324,7 +5326,7 @@ BattleScript_EffectPsychUp::

BattleScript_EffectMirrorCoat::
attackcanceler
mirrorcoatdamagecalculator BattleScript_ButItFailedAtkStringPpReduce
mirrorcoatdamagecalculator BattleScript_FailedFromAtkString
accuracycheck BattleScript_PrintMoveMissed, ACC_CURR_MOVE
attackstring
ppreduce
Expand Down Expand Up @@ -5542,15 +5544,13 @@ BattleScript_AlreadyAtFullHp::

BattleScript_EffectFakeOut::
attackcanceler
jumpifnotfirstturn BattleScript_ButItFailedAtkStringPpReduce
jumpifnotfirstturn BattleScript_FailedFromAtkString
setmoveeffect MOVE_EFFECT_FLINCH
goto BattleScript_EffectHit

BattleScript_ButItFailedAtkCanceler::
attackcanceler
BattleScript_ButItFailedAtkStringPpReduce::
BattleScript_FailedFromAtkString::
attackstring
BattleScript_ButItFailedPpReduce::
BattleScript_FailedFromPpReduce::
ppreduce
BattleScript_ButItFailed::
pause B_WAIT_TIME_SHORT
Expand Down Expand Up @@ -5940,7 +5940,7 @@ BattleScript_EffectWish::
BattleScript_EffectAssist:
attackcanceler
attackstring
assistattackselect BattleScript_ButItFailedPpReduce
assistattackselect BattleScript_FailedFromPpReduce
attackanimation
waitanimation
setbyte sB_ANIM_TURN, 0
Expand Down Expand Up @@ -5968,7 +5968,7 @@ BattleScript_EffectCloseCombat:

BattleScript_EffectMagicCoat:
attackcanceler
trysetmagiccoat BattleScript_ButItFailedAtkStringPpReduce
trysetmagiccoat BattleScript_FailedFromAtkString
attackstring
ppreduce
attackanimation
Expand Down Expand Up @@ -6126,7 +6126,7 @@ BattleScript_EffectGrudge:

BattleScript_EffectSnatch:
attackcanceler
trysetsnatch BattleScript_ButItFailedAtkStringPpReduce
trysetsnatch BattleScript_FailedFromAtkString
attackstring
ppreduce
attackanimation
Expand Down
3 changes: 2 additions & 1 deletion include/battle_scripts.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ extern const u8 BattleScript_MakeMoveMissed[];
extern const u8 BattleScript_PrintMoveMissed[];
extern const u8 BattleScript_MoveMissedPause[];
extern const u8 BattleScript_MoveMissed[];
extern const u8 BattleScript_ButItFailedAtkStringPpReduce[];
extern const u8 BattleScript_FlingFailConsumeItem[];
extern const u8 BattleScript_FailedFromAtkString[];
extern const u8 BattleScript_ButItFailed[];
extern const u8 BattleScript_StatUp[];
extern const u8 BattleScript_StatDown[];
Expand Down
2 changes: 1 addition & 1 deletion include/battle_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ bool32 SetIllusionMon(struct Pokemon *mon, u32 battlerId);
bool8 ShouldGetStatBadgeBoost(u16 flagId, u8 battlerId);
u8 GetBattleMoveSplit(u32 moveId);
bool32 TestMoveFlags(u16 move, u32 flag);
bool32 CanFling(u8 battlerId);
bool32 CanFling(u32 battlerId);
bool32 IsTelekinesisBannedSpecies(u16 species);
bool32 IsHealBlockPreventingMove(u32 battler, u32 move);
bool32 HasEnoughHpToEatBerry(u32 battlerId, u32 hpFraction, u32 itemId);
Expand Down
1 change: 0 additions & 1 deletion include/constants/battle_script_commands.h
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,6 @@
#define VARIOUS_SET_SKY_DROP 138
#define VARIOUS_CLEAR_SKY_DROP 139
#define VARIOUS_SKY_DROP_YAWN 140
#define VARIOUS_JUMP_IF_CANT_FLING 141
AsparagusEduardo marked this conversation as resolved.
Show resolved Hide resolved
#define VARIOUS_JUMP_IF_HOLD_EFFECT 142
#define VARIOUS_CURE_CERTAIN_STATUSES 143
#define VARIOUS_TRY_RESET_NEGATIVE_STAT_STAGES 144
Expand Down
32 changes: 20 additions & 12 deletions src/battle_script_commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -1600,9 +1600,15 @@ static void Cmd_attackcanceler(void)
}

gHitMarker |= HITMARKER_OBEYS;
if (NoTargetPresent(gBattlerAttacker, gCurrentMove) && (!IsTwoTurnsMove(gCurrentMove) || (gBattleMons[gBattlerAttacker].status2 & STATUS2_MULTIPLETURNS)))
// Check if no available target present on the field.
if (NoTargetPresent(gBattlerAttacker, gCurrentMove)
&& (!IsTwoTurnsMove(gCurrentMove) || (gBattleMons[gBattlerAttacker].status2 & STATUS2_MULTIPLETURNS)))
{
gBattlescriptCurrInstr = BattleScript_ButItFailedAtkStringPpReduce;
if (gBattleMoves[gCurrentMove].effect == EFFECT_FLING) // Edge case for removing a mon's item when there is no target available after using Fling.
gBattlescriptCurrInstr = BattleScript_FlingFailConsumeItem;
else
gBattlescriptCurrInstr = BattleScript_FailedFromAtkString;

if (!IsTwoTurnsMove(gCurrentMove) || (gBattleMons[gBattlerAttacker].status2 & STATUS2_MULTIPLETURNS))
CancelMultiTurnMoves(gBattlerAttacker);
return;
Expand Down Expand Up @@ -10905,15 +10911,6 @@ static void Cmd_various(void)
gBattlescriptCurrInstr = cmd->failInstr;
return;
}
case VARIOUS_JUMP_IF_CANT_FLING:
{
VARIOUS_ARGS(const u8 *jumpInstr);
if (!CanFling(gActiveBattler))
gBattlescriptCurrInstr = cmd->jumpInstr;
else
gBattlescriptCurrInstr = cmd->nextInstr;
return;
}
case VARIOUS_CURE_CERTAIN_STATUSES:
{
VARIOUS_ARGS();
Expand Down Expand Up @@ -16158,11 +16155,22 @@ void BS_CalcMetalBurstDmg(void)
}
}

void BS_JumpIfCantFling(void)
{
NATIVE_ARGS(u8 battler, const u8 *jumpInstr);

u32 battler = GetBattlerForBattleScript(cmd->battler);
if (!CanFling(battler))
gBattlescriptCurrInstr = cmd->jumpInstr;
else
gBattlescriptCurrInstr = cmd->nextInstr;
}

AsparagusEduardo marked this conversation as resolved.
Show resolved Hide resolved
void BS_JumpIfMoreThanHalfHP(void)
{
NATIVE_ARGS(u8 battler, const u8 *jumpInstr);

u8 battler = GetBattlerForBattleScript(cmd->battler);
u32 battler = GetBattlerForBattleScript(cmd->battler);
if (gBattleMons[battler].hp > (gBattleMons[battler].maxHP + 1) / 2)
gBattlescriptCurrInstr = cmd->jumpInstr;
else
Expand Down
15 changes: 10 additions & 5 deletions src/battle_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -6594,8 +6594,9 @@ static u8 DamagedStatBoostBerryEffect(u8 battlerId, u8 statId, u8 split)
if (IsBattlerAlive(battlerId)
&& TARGET_TURN_DAMAGED
&& CompareStat(battlerId, statId, MAX_STAT_STAGE, CMP_LESS_THAN)
&& !DoesSubstituteBlockMove(gBattlerAttacker, battlerId, gCurrentMove)
&& GetBattleMoveSplit(gCurrentMove) == split)
&& (gBattleScripting.overrideBerryRequirements
|| (!DoesSubstituteBlockMove(gBattlerAttacker, battlerId, gCurrentMove) && GetBattleMoveSplit(gCurrentMove) == split))
)
{
BufferStatChange(battlerId, statId, STRINGID_STATROSE);

Expand Down Expand Up @@ -6801,6 +6802,12 @@ static u8 ItemEffectMoveEnd(u32 battlerId, u16 holdEffect)
case HOLD_EFFECT_SP_DEFENSE_UP:
effect = StatRaiseBerry(battlerId, gLastUsedItem, STAT_SPDEF, FALSE);
break;
case HOLD_EFFECT_KEE_BERRY: // consume and boost defense if used physical move
effect = DamagedStatBoostBerryEffect(battlerId, STAT_DEF, SPLIT_PHYSICAL);
break;
case HOLD_EFFECT_MARANGA_BERRY: // consume and boost sp. defense if used special move
effect = DamagedStatBoostBerryEffect(battlerId, STAT_SPDEF, SPLIT_SPECIAL);
break;
case HOLD_EFFECT_RANDOM_STAT_UP:
effect = RandomStatRaiseBerry(battlerId, gLastUsedItem, FALSE);
break;
Expand Down Expand Up @@ -10493,11 +10500,9 @@ static u8 GetFlingPowerFromItemId(u16 itemId)
return ItemId_GetFlingPower(itemId);
}

// Make sure the input bank is any bank on the specific mon's side
bool32 CanFling(u8 battlerId)
bool32 CanFling(u32 battlerId)
{
u16 item = gBattleMons[battlerId].item;
u16 itemEffect = ItemId_GetHoldEffect(item);

if (item == ITEM_NONE
#if B_KLUTZ_FLING_INTERACTION >= GEN_5
Expand Down
Loading