Improve how test involving ball throw work (#7774)

This commit is contained in:
FosterProgramming 2025-09-22 20:44:12 +02:00 committed by GitHub
parent 5fad32decc
commit 1d11a2cb0a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 19 additions and 15 deletions

View File

@ -215,6 +215,8 @@ enum RandomTag
RNG_AI_REFRESH_TRICK_ROOM_ON_LAST_TURN,
RNG_AI_APPLY_TAILWIND_ON_LAST_TURN_OF_TRICK_ROOM,
RNG_WRAP,
RNG_BALLTHROW_CRITICAL,
RNG_BALLTHROW_SHAKE,
};
#define RandomWeighted(tag, ...) \

View File

@ -1005,6 +1005,8 @@ struct ItemContext
u16 explicitPartyIndex:1;
u16 move;
u16 explicitMove:1;
struct TurnRNG rng;
u16 explicitRNG:1;
};
void OpenTurn(u32 sourceLine);

View File

@ -13943,19 +13943,16 @@ static void Cmd_handleballthrow(void)
{
odds = Sqrt(Sqrt(16711680 / odds));
odds = 1048560 / odds;
for (shakes = 0; shakes < maxShakes && Random() < odds; shakes++);
for (shakes = 0; shakes < maxShakes; shakes++)
{
if (RandomUniform(RNG_BALLTHROW_SHAKE, 0, MAX_u16) < odds)
break;
}
}
BtlController_EmitBallThrowAnim(gBattlerAttacker, B_COMM_TO_CONTROLLER, shakes);
MarkBattlerForControllerExec(gBattlerAttacker);
#if TESTING
if (gTestRunnerEnabled)
{
shakes = 0; // Force failure for tests. TODO: make capture RNG flag
}
#endif
if (shakes == maxShakes) // mon caught, copy of the code above
{
if (IsCriticalCapture())
@ -14752,8 +14749,7 @@ static bool32 CriticalCapture(u32 odds)
odds = (odds * (100 + B_CATCHING_CHARM_BOOST)) / 100;
odds /= 6;
if ((Random() % 255) < odds)
if (RandomUniform(RNG_BALLTHROW_CRITICAL, 0, MAX_u8) < odds)
return TRUE;
return FALSE;

View File

@ -15,7 +15,8 @@ WILD_BATTLE_TEST("Ball Fetch causes the Pokémon to pick up the last failed Ball
PLAYER(SPECIES_YAMPER) { Ability(ABILITY_BALL_FETCH); }
OPPONENT(SPECIES_METAGROSS);
} WHEN {
TURN { USE_ITEM(player, item); }
TURN { USE_ITEM(player, item, WITH_RNG(RNG_BALLTHROW_SHAKE, 0) );}
TURN {}
} SCENE {
if (item != ITEM_X_ACCURACY)
ABILITY_POPUP(player, ABILITY_BALL_FETCH);
@ -40,7 +41,7 @@ WILD_BATTLE_TEST("Ball Fetch doesn't trigger if the Pokémon is already holding
PLAYER(SPECIES_YAMPER) { Ability(ABILITY_BALL_FETCH); Item(item); }
OPPONENT(SPECIES_METAGROSS);
} WHEN {
TURN { USE_ITEM(player, ITEM_GREAT_BALL); }
TURN { USE_ITEM(player, ITEM_GREAT_BALL, WITH_RNG(RNG_BALLTHROW_SHAKE, 0)); }
} SCENE {
if (item == ITEM_NONE)
{
@ -79,9 +80,9 @@ WILD_BATTLE_TEST("Ball Fetch only picks up the first failed ball, once per battl
PLAYER(SPECIES_YAMPER) { Ability(ABILITY_BALL_FETCH); }
OPPONENT(SPECIES_METAGROSS);
} WHEN {
TURN { USE_ITEM(player, item); }
TURN { USE_ITEM(player, item, WITH_RNG(RNG_BALLTHROW_SHAKE, 0)); }
TURN { MOVE(player, MOVE_BESTOW); }
TURN { USE_ITEM(player, item2); }
TURN { USE_ITEM(player, item2, WITH_RNG(RNG_BALLTHROW_SHAKE, 0)); }
} SCENE {
MESSAGE("You used Great Ball!");
ABILITY_POPUP(player, ABILITY_BALL_FETCH);
@ -109,7 +110,7 @@ SINGLE_BATTLE_TEST("Ball Fetch doesn't trigger in Trainer Battles")
PLAYER(SPECIES_YAMPER) { Ability(ABILITY_BALL_FETCH); }
OPPONENT(SPECIES_METAGROSS);
} WHEN {
TURN { USE_ITEM(player, item); }
TURN { USE_ITEM(player, item, WITH_RNG(RNG_BALLTHROW_SHAKE, 0)); }
} SCENE {
NOT ABILITY_POPUP(player, ABILITY_BALL_FETCH);
} THEN {

View File

@ -2520,6 +2520,9 @@ void UseItem(u32 sourceLine, struct BattlePokemon *battler, struct ItemContext c
{
i = 0;
}
if (ctx.explicitRNG)
DATA.battleRecordTurns[DATA.turns][battlerId].rng = ctx.rng;
PushBattlerAction(sourceLine, battlerId, RECORDED_ACTION_TYPE, B_ACTION_USE_ITEM);
PushBattlerAction(sourceLine, battlerId, RECORDED_ITEM_ID, (ctx.itemId >> 8) & 0xFF);
PushBattlerAction(sourceLine, battlerId, RECORDED_ITEM_ID, ctx.itemId & 0xFF);