diff --git a/include/random.h b/include/random.h index 283813b1b1..de0f406fe5 100644 --- a/include/random.h +++ b/include/random.h @@ -214,6 +214,7 @@ enum RandomTag RNG_AI_ASSUME_ALL_STATUS, RNG_AI_REFRESH_TRICK_ROOM_ON_LAST_TURN, RNG_AI_APPLY_TAILWIND_ON_LAST_TURN_OF_TRICK_ROOM, + RNG_WRAP, }; #define RandomWeighted(tag, ...) \ diff --git a/src/battle_end_turn.c b/src/battle_end_turn.c index fcb485ed95..d0f504ae5a 100644 --- a/src/battle_end_turn.c +++ b/src/battle_end_turn.c @@ -763,8 +763,9 @@ static bool32 HandleEndTurnWrap(u32 battler) if (gBattleMons[battler].volatiles.wrapped && IsBattlerAlive(battler)) { - if (--gDisableStructs[battler].wrapTurns != 0) + if (gDisableStructs[battler].wrapTurns != 0) { + gDisableStructs[battler].wrapTurns--; if (IsAbilityAndRecord(battler, GetBattlerAbility(battler), ABILITY_MAGIC_GUARD)) return effect; diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c index f271bc4c28..6f48ce8463 100755 --- a/src/battle_script_commands.c +++ b/src/battle_script_commands.c @@ -3173,7 +3173,7 @@ void SetMoveEffect(u32 battler, u32 effectBattler, bool32 primary, bool32 certai if (GetBattlerHoldEffect(gBattlerAttacker, TRUE) == HOLD_EFFECT_GRIP_CLAW) gDisableStructs[gEffectBattler].wrapTurns = B_BINDING_TURNS >= GEN_5 ? 7 : 5; else - gDisableStructs[gEffectBattler].wrapTurns = B_BINDING_TURNS >= GEN_5 ? (Random() % 2) + 4 : (Random() % 4) + 2; + gDisableStructs[gEffectBattler].wrapTurns = B_BINDING_TURNS >= GEN_5 ? RandomUniform(RNG_WRAP, 4, 5) : RandomUniform(RNG_WRAP, 2, 5); gBattleStruct->wrappedMove[gEffectBattler] = gCurrentMove; gBattleStruct->wrappedBy[gEffectBattler] = gBattlerAttacker; diff --git a/test/battle/move_effect_secondary/wrap.c b/test/battle/move_effect_secondary/wrap.c new file mode 100644 index 0000000000..dc05bbe288 --- /dev/null +++ b/test/battle/move_effect_secondary/wrap.c @@ -0,0 +1,86 @@ +#include "global.h" +#include "test/battle.h" + +ASSUMPTIONS +{ + ASSUME(MoveHasAdditionalEffect(MOVE_WRAP, MOVE_EFFECT_WRAP)); +} + +SINGLE_BATTLE_TEST("Wrap can damage the wrapped mon for 5 turns 50% of the time") +{ + PASSES_RANDOMLY(50, 100, RNG_WRAP); + GIVEN { + PLAYER(SPECIES_WOBBUFFET); + OPPONENT(SPECIES_WOBBUFFET); + } WHEN { + TURN { MOVE(player, MOVE_WRAP); } + TURN {} + TURN {} + TURN {} + TURN {} + TURN {} + } SCENE { + ANIMATION(ANIM_TYPE_MOVE, MOVE_WRAP, player); + HP_BAR(opponent); // Direct damage + + HP_BAR(opponent); // Residual Damage + HP_BAR(opponent); // Residual Damage + HP_BAR(opponent); // Residual Damage + HP_BAR(opponent); // Residual Damage + HP_BAR(opponent); // Residual Damage + NOT HP_BAR(opponent); // Residual Damage + } +} + +SINGLE_BATTLE_TEST("Wrap can damage the wrapped mon for 4 turns 50% of the time") +{ + PASSES_RANDOMLY(50, 100, RNG_WRAP); + GIVEN { + PLAYER(SPECIES_WOBBUFFET); + OPPONENT(SPECIES_WOBBUFFET); + } WHEN { + TURN { MOVE(player, MOVE_WRAP); } + TURN {} + TURN {} + TURN {} + TURN {} + } SCENE { + ANIMATION(ANIM_TYPE_MOVE, MOVE_WRAP, player); + HP_BAR(opponent); // Direct damage + + HP_BAR(opponent); // Residual Damage + HP_BAR(opponent); // Residual Damage + HP_BAR(opponent); // Residual Damage + HP_BAR(opponent); // Residual Damage + NOT HP_BAR(opponent); // Residual Damage + } +} + +SINGLE_BATTLE_TEST("Wrap can damage the wrapped mon 7 turns while holding a Grip Claw") +{ + GIVEN { + PLAYER(SPECIES_WOBBUFFET) { Item(ITEM_GRIP_CLAW); } + OPPONENT(SPECIES_WOBBUFFET); + } WHEN { + TURN { MOVE(player, MOVE_WRAP); } + TURN {} + TURN {} + TURN {} + TURN {} + TURN {} + TURN {} + TURN {} + } SCENE { + ANIMATION(ANIM_TYPE_MOVE, MOVE_WRAP, player); + HP_BAR(opponent); // Direct damage + + HP_BAR(opponent); // Residual Damage + HP_BAR(opponent); // Residual Damage + HP_BAR(opponent); // Residual Damage + HP_BAR(opponent); // Residual Damage + HP_BAR(opponent); // Residual Damage + HP_BAR(opponent); // Residual Damage + HP_BAR(opponent); // Residual Damage + NOT HP_BAR(opponent); // Residual Damage + } +}