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

Dynamax Mons gain HP incorrectly when leveling up #4538

Open
WillKolada opened this issue May 9, 2024 · 4 comments · May be fixed by #5933
Open

Dynamax Mons gain HP incorrectly when leveling up #4538

WillKolada opened this issue May 9, 2024 · 4 comments · May be fixed by #5933
Labels
bug Bug category: battle-mechanic Pertains to battle mechanics status: confirmed This bug has been confirmed to exist in the codebase

Comments

@WillKolada
Copy link

WillKolada commented May 9, 2024

Description

In the following example, my Sneasler was Dynamaxed for three turns, during it which it took no damage. When Dynamax reverted, it lost 1 HP. I presume this is a rounding error.

image

EDIT: I reproduced the issue, except this time Sneasler lost 3 HP at the end of a round while still Dynamaxed.

image

EDIT 2: I realized the issue is caused by leveling up while Dynamaxed. The Max HP increases, but not all of the effective HP does to match it, just a portion, which I believe is the incorrect behavior.

EDIT 3: I've also now experienced twice where my Pokemon had taken damage while Dynamaxed, then leveled up and was essentially fully healed. Bizarrely, in one of these instances, it even took a hit and received no damage.

Version

upcoming (Edge)

Upcoming/master Version

0aad2a9

Discord contact info

Special K#8400

@WillKolada WillKolada added bug Bug category: battle-mechanic Pertains to battle mechanics status: unconfirmed This bug has not been reproduced yet labels May 9, 2024
@WillKolada WillKolada changed the title Dynamax Mons sometimes lose 1 HP when Dynamax ends Dynamax Mons only gain Max HP when leveling up May 9, 2024
@WillKolada WillKolada changed the title Dynamax Mons only gain Max HP when leveling up Dynamax Mons gains HP incorrectly when leveling up May 17, 2024
@WillKolada WillKolada changed the title Dynamax Mons gains HP incorrectly when leveling up Dynamax Mons gain HP incorrectly when leveling up May 17, 2024
@hedara90
Copy link
Collaborator

I can confirm that something is not correct regarding HP.
The Bulbasaur leveled up from 7 to 15 and ended up with 2444/82 HP
pokeemerald-1

@hedara90 hedara90 added status: confirmed This bug has been confirmed to exist in the codebase and removed status: unconfirmed This bug has not been reproduced yet labels Jul 26, 2024
@AlexOn1ine
Copy link
Collaborator

I don't really want to test but this might be a possible solution?

diff --git a/include/battle_dynamax.h b/include/battle_dynamax.h
index 20cd4d5e79..80bd982a5b 100644
--- a/include/battle_dynamax.h
+++ b/include/battle_dynamax.h
@@ -62,6 +62,7 @@ void ApplyDynamaxHPMultiplier(u32 battler, struct Pokemon* mon);
 void ActivateDynamax(u32 battler);
 u16 GetNonDynamaxHP(u32 battler);
 u16 GetNonDynamaxMaxHP(u32 battler);
+u16 GetNonDynamaxPartyMonMaxHP(u32 maxHP);
 void UndoDynamax(u32 battler);
 bool32 IsMoveBlockedByMaxGuard(u32 move);
 bool32 IsMoveBlockedByDynamax(u32 move);
diff --git a/src/battle_dynamax.c b/src/battle_dynamax.c
index 073e2c55bc..4c0e1e7ed5 100644
--- a/src/battle_dynamax.c
+++ b/src/battle_dynamax.c
@@ -170,6 +170,18 @@ u16 GetNonDynamaxMaxHP(u32 battler)
     }
 }
 
+u16 GetNonDynamaxPartyMonMaxHP(u32 maxHP)
+{
+    if (GetActiveGimmick(battler) != GIMMICK_DYNAMAX || gBattleMons[battler].species == SPECIES_SHEDINJA)
+        return maxHP;
+    else
+    {
+        u16 mult = UQ_4_12(1.0/1.5); // placeholder
+        u16 maxHP = UQ_4_12_TO_INT((maxHP * mult) + UQ_4_12_ROUND);
+        return maxHP;
+    }
+}
+
 // Sets flags used for Dynamaxing and checks Gigantamax forms.
 void ActivateDynamax(u32 battler)
 {
diff --git a/src/battle_script_commands.c b/src/battle_script_commands.c
index a13e84265a..b6505c74fb 100644
--- a/src/battle_script_commands.c
+++ b/src/battle_script_commands.c
@@ -1988,7 +1988,7 @@ s32 CalcCritChanceStageGen1(u8 battlerAtk, u8 battlerDef, u32 move, bool32 recor
     // Crit scaling
     if (moveCritStage > 0)
         critChance = critChance * highCritRatioScaler * moveCritStage;
-    
+
     if (bonusCritStage > 0)
         critChance = critChance * bonusCritStage;
 
@@ -4615,7 +4615,7 @@ static void Cmd_getexp(void)
             gBattleResources->bufferB[gBattleStruct->expGetterBattlerId][0] = 0;
             if (GetMonData(&gPlayerParty[*expMonId], MON_DATA_HP) && GetMonData(&gPlayerParty[*expMonId], MON_DATA_LEVEL) != MAX_LEVEL)
             {
-                gBattleResources->beforeLvlUp->stats[STAT_HP]    = GetMonData(&gPlayerParty[*expMonId], MON_DATA_MAX_HP);
+                gBattleResources->beforeLvlUp->stats[STAT_HP]    = GetNonDynamaxPartyMonMaxHP(GetMonData(&gPlayerParty[*expMonId], MON_DATA_MAX_HP));

@bnthomason
Copy link

@AlexOn1ine I'll test this for you on a clean repo in a few moments once I get my new repo up and going. I'll return with the results soon...

@AlexOn1ine
Copy link
Collaborator

@AlexOn1ine I'll test this for you on a clean repo in a few moments once I get my new repo up and going. I'll return with the results soon...

sorry forgot to mention but this solution does not work

@PhallenTree PhallenTree linked a pull request Jan 2, 2025 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Bug category: battle-mechanic Pertains to battle mechanics status: confirmed This bug has been confirmed to exist in the codebase
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants