diff --git a/include/battle.h b/include/battle.h index 9cc78ed41..bc6031665 100644 --- a/include/battle.h +++ b/include/battle.h @@ -539,6 +539,7 @@ struct BattleStruct u8 lastMoveTarget[MAX_BATTLERS_COUNT]; // The last target on which each mon used a move, for the sake of Instruct u8 debugHoldEffects[MAX_BATTLERS_COUNT]; // These override actual items' hold effects. u8 tracedAbility[MAX_BATTLERS_COUNT]; + u16 hpBefore[MAX_BATTLERS_COUNT]; // Hp of battlers before using a move. For Berserk bool8 spriteIgnore0Hp; struct Illusion illusion[MAX_BATTLERS_COUNT]; }; diff --git a/src/battle_main.c b/src/battle_main.c index d860f87cb..d71ad68f9 100644 --- a/src/battle_main.c +++ b/src/battle_main.c @@ -5068,7 +5068,7 @@ void SetTypeBeforeUsingMove(u16 move, u8 battlerAtk) static void HandleAction_UseMove(void) { - u32 side, moveType, var = 4; + u32 i, side, moveType, var = 4; gBattlerAttacker = gBattlerByTurnOrder[gCurrentTurnActionNumber]; if (gBattleStruct->field_91 & gBitTable[gBattlerAttacker] || !IsBattlerAlive(gBattlerAttacker)) @@ -5316,6 +5316,10 @@ static void HandleAction_UseMove(void) if (gBattleTypeFlags & BATTLE_TYPE_ARENA) BattleArena_AddMindPoints(gBattlerAttacker); + // Record HP of each battler + for (i = 0; i < MAX_BATTLERS_COUNT; i++) + gBattleStruct->hpBefore[i] = gBattleMons[i].hp; + gCurrentActionFuncId = B_ACTION_EXEC_SCRIPT; } diff --git a/src/battle_util.c b/src/battle_util.c index 469fc28a0..6b3b03e93 100644 --- a/src/battle_util.c +++ b/src/battle_util.c @@ -3286,6 +3286,23 @@ u8 AbilityBattleEffects(u8 caseID, u8 battler, u8 ability, u8 special, u16 moveA effect++; } break; + case ABILITY_BERSERK: + if (!(gMoveResultFlags & MOVE_RESULT_NO_EFFECT) + && TARGET_TURN_DAMAGED + && IsBattlerAlive(battler) + // Had more than half of hp before, now has less + && gBattleStruct->hpBefore[battler] > gBattleMons[battler].maxHP / 2 + && gBattleMons[battler].hp < gBattleMons[battler].maxHP / 2 + && (gMultiHitCounter == 0 || gMultiHitCounter == 1) + && !(GetBattlerAbility(gBattlerAttacker) == ABILITY_SHEER_FORCE && gBattleMoves[gCurrentMove].flags & FLAG_SHEER_FORCE_BOOST) + && gBattleMons[battler].statStages[STAT_SPATK] != 12) + { + SET_STATCHANGER(STAT_SPATK, 1, FALSE); + BattleScriptPushCursor(); + gBattlescriptCurrInstr = BattleScript_TargetAbilityStatRaise; + effect++; + } + break; case ABILITY_WEAK_ARMOR: if (!(gMoveResultFlags & MOVE_RESULT_NO_EFFECT) && TARGET_TURN_DAMAGED