From 3bd248f7ae391af34a588987bd50990833378720 Mon Sep 17 00:00:00 2001 From: PhallenTree <168426989+PhallenTree@users.noreply.github.com> Date: Mon, 6 Jan 2025 12:31:43 +0000 Subject: [PATCH] Review --- src/battle_controller_player.c | 24 ++++++++++-------------- src/battle_dynamax.c | 8 ++++---- 2 files changed, 14 insertions(+), 18 deletions(-) diff --git a/src/battle_controller_player.c b/src/battle_controller_player.c index 4356756adf..f641d61759 100644 --- a/src/battle_controller_player.c +++ b/src/battle_controller_player.c @@ -1410,6 +1410,14 @@ void Task_PlayerController_RestoreBgmAfterCry(u8 taskId) #define tExpTask_gainedExp_2 data[4] // Stored as two half-words containing a word. #define tExpTask_frames data[10] +static void DynamaxModifyHPLevelUp(struct Pokemon *mon, u32 battler, u32 oldMaxHP) +{ + ApplyDynamaxHPMultiplier(mon); + gBattleScripting.levelUpHP = GetMonData(mon, MON_DATA_MAX_HP) - oldMaxHP; // overwrite levelUpHP since it overflows + gBattleMons[battler].hp += gBattleScripting.levelUpHP; + SetMonData(mon, MON_DATA_HP, &gBattleMons[battler].hp); +} + static s32 GetTaskExpValue(u8 taskId) { return (u16)(gTasks[taskId].tExpTask_gainedExp_1) | (gTasks[taskId].tExpTask_gainedExp_2 << 16); @@ -1437,13 +1445,7 @@ static void Task_GiveExpToMon(u8 taskId) // Reapply Dynamax HP multiplier after stats are recalculated. if (GetActiveGimmick(battler) == GIMMICK_DYNAMAX && monId == gBattlerPartyIndexes[battler]) - { - ApplyDynamaxHPMultiplier(mon); - // overwrite levelUpHP since it overflows - gBattleScripting.levelUpHP = GetMonData(mon, MON_DATA_MAX_HP) - oldMaxHP; - gBattleMons[battler].hp += gBattleScripting.levelUpHP; - SetMonData(mon, MON_DATA_HP, &gBattleMons[battler].hp); - } + DynamaxModifyHPLevelUp(mon, battler, oldMaxHP); gainedExp -= nextLvlExp - currExp; BtlController_EmitTwoReturnValues(battler, BUFFER_B, RET_VALUE_LEVELED_UP, gainedExp); @@ -1524,13 +1526,7 @@ static void Task_GiveExpWithExpBar(u8 taskId) // Reapply Dynamax HP multiplier after stats are recalculated. if (GetActiveGimmick(battler) == GIMMICK_DYNAMAX && monId == gBattlerPartyIndexes[battler]) - { - ApplyDynamaxHPMultiplier(mon); - // overwrite levelUpHP since it overflows - gBattleScripting.levelUpHP = GetMonData(mon, MON_DATA_MAX_HP) - oldMaxHP; - gBattleMons[battler].hp += gBattleScripting.levelUpHP; - SetMonData(mon, MON_DATA_HP, &gBattleMons[battler].hp); - } + DynamaxModifyHPLevelUp(mon, battler, oldMaxHP); gainedExp -= expOnNextLvl - currExp; BtlController_EmitTwoReturnValues(battler, BUFFER_B, RET_VALUE_LEVELED_UP, gainedExp); diff --git a/src/battle_dynamax.c b/src/battle_dynamax.c index 39f66ef5da..0f55b33dab 100644 --- a/src/battle_dynamax.c +++ b/src/battle_dynamax.c @@ -123,7 +123,7 @@ bool32 CanDynamax(u32 battler) // Returns whether a battler is transformed into a Gigantamax form. bool32 IsGigantamaxed(u32 battler) { - struct Pokemon *mon = &GetSideParty(GetBattlerSide(battler))[gBattlerPartyIndexes[battler]]; + struct Pokemon *mon = GetPartyBattlerData(battler); if ((gSpeciesInfo[gBattleMons[battler].species].isGigantamax) && GetMonData(mon, MON_DATA_GIGANTAMAX_FACTOR)) return TRUE; return FALSE; @@ -151,7 +151,7 @@ u16 GetNonDynamaxHP(u32 battler) return gBattleMons[battler].hp; else { - struct Pokemon *mon = &GetSideParty(GetBattlerSide(battler))[gBattlerPartyIndexes[battler]]; + struct Pokemon *mon = GetPartyBattlerData(battler); uq4_12_t mult = GetDynamaxLevelHPMultiplier(GetMonData(mon, MON_DATA_DYNAMAX_LEVEL), TRUE); u32 hp = UQ_4_12_TO_INT((gBattleMons[battler].hp * mult) + UQ_4_12_ROUND); return hp; @@ -165,7 +165,7 @@ u16 GetNonDynamaxMaxHP(u32 battler) return gBattleMons[battler].maxHP; else { - struct Pokemon *mon = &GetSideParty(GetBattlerSide(battler))[gBattlerPartyIndexes[battler]]; + struct Pokemon *mon = GetPartyBattlerData(battler); uq4_12_t mult = GetDynamaxLevelHPMultiplier(GetMonData(mon, MON_DATA_DYNAMAX_LEVEL), TRUE); u32 maxHP = UQ_4_12_TO_INT((gBattleMons[battler].maxHP * mult) + UQ_4_12_ROUND); return maxHP; @@ -510,7 +510,7 @@ void BS_UpdateDynamax(void) { NATIVE_ARGS(); u32 battler = gBattleScripting.battler; - struct Pokemon *mon = &GetSideParty(GetBattlerSide(battler))[gBattlerPartyIndexes[battler]]; + struct Pokemon *mon = GetPartyBattlerData(battler); if (!IsGigantamaxed(battler)) // RecalcBattlerStats will get called on form change. RecalcBattlerStats(battler, mon, GetActiveGimmick(battler) == GIMMICK_DYNAMAX);