Skip to content

Commit

Permalink
Fixed Z-Moves+Obedience bugged behavior
Browse files Browse the repository at this point in the history
  • Loading branch information
Hedara committed Aug 23, 2024
1 parent bd38c64 commit 4774b2f
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 14 deletions.
2 changes: 1 addition & 1 deletion include/battle.h
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ struct SpecialStatus
u8 faintedHasReplacement:1;
u8 focusBanded:1;
u8 focusSashed:1;
u8 unused:1;
u8 isNotObedient:2;
// End of byte
u8 sturdied:1;
u8 stormDrainRedirected:1;
Expand Down
1 change: 1 addition & 0 deletions include/battle_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ void ClearVariousBattlerFlags(u32 battler);
void HandleAction_RunBattleScript(void);
u32 SetRandomTarget(u32 battler);
u32 GetMoveTarget(u16 move, u8 setTarget);
u8 GetMonObedienceForTurn(u32 battler);
u8 IsMonDisobedient(void);
u32 GetBattlerHoldEffect(u32 battler, bool32 checkNegating);
u32 GetBattlerHoldEffectIgnoreAbility(u32 battler, bool32 checkNegating);
Expand Down
70 changes: 57 additions & 13 deletions src/battle_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ void HandleAction_UseMove(void)
return;
}

gSpecialStatuses[gBattlerAttacker].isNotObedient = GetMonObedienceForTurn(gBattlerAttacker);

gIsCriticalHit = FALSE;
gBattleStruct->atkCancellerTracker = 0;
gMoveResultFlags = 0;
Expand Down Expand Up @@ -3566,7 +3568,8 @@ u8 AtkCanceller_UnableToUseMove(u32 moveType)
gBattleStruct->atkCancellerTracker++;
break;
case CANCELLER_Z_MOVES:
if (GetActiveGimmick(gBattlerAttacker) == GIMMICK_Z_MOVE)
if (GetActiveGimmick(gBattlerAttacker) == GIMMICK_Z_MOVE
&& gSpecialStatuses[gBattlerAttacker].isNotObedient == 0)
{
// For Z-Mirror Move, so it doesn't play the animation twice.
bool32 alreadyUsed = HasTrainerUsedGimmick(gBattlerAttacker, GIMMICK_Z_MOVE);
Expand Down Expand Up @@ -8330,12 +8333,7 @@ u32 GetMoveTarget(u16 move, u8 setTarget)
return targetBattler;
}

static bool32 IsBattlerModernFatefulEncounter(u32 battler)
{
return TRUE;
}

u8 IsMonDisobedient(void)
u8 GetMonObedienceForTurn(u32 battler)
{
s32 rnd;
s32 calc;
Expand All @@ -8347,7 +8345,7 @@ u8 IsMonDisobedient(void)
if (BattlerHasAi(gBattlerAttacker))
return 0;

if (IsBattlerModernFatefulEncounter(gBattlerAttacker)) // only false if illegal Mew or Deoxys
if (TRUE) // This used to be a check to see if the mon in question was a fateful encounter (Mew or Deoxys)
{
if (gBattleTypeFlags & BATTLE_TYPE_INGAME_PARTNER && GetBattlerPosition(gBattlerAttacker) == B_POSITION_PLAYER_RIGHT)
return 0;
Expand Down Expand Up @@ -8379,7 +8377,7 @@ u8 IsMonDisobedient(void)
}

if (B_OBEDIENCE_MECHANICS >= GEN_8
&& !IsOtherTrainer(gBattleMons[gBattlerAttacker].otId, gBattleMons[gBattlerAttacker].otName))
&& !IsOtherTrainer(gBattleMons[gBattlerAttacker].otId, gBattleMons[gBattlerAttacker].otName))
levelReferenced = gBattleMons[gBattlerAttacker].metLevel;
else
levelReferenced = gBattleMons[gBattlerAttacker].level;
Expand All @@ -8391,18 +8389,64 @@ u8 IsMonDisobedient(void)
if (calc < obedienceLevel)
return 0;

// is not obedient
rnd = (Random() & 255);
calc = (levelReferenced + obedienceLevel) * rnd >> 8;

if (calc < obedienceLevel)
return 3;
else
return 1;
}

u8 IsMonDisobedient(void)
{
s32 calc;
u8 obedienceLevel = 0;
u8 levelReferenced;

if (gSpecialStatuses[gBattlerAttacker].isNotObedient == 0)
return 0;

// Clear out the Z-Move flags since the mon isn't obeying and won't be using the Z-Move
if (GetActiveGimmick(gBattlerAttacker) == GIMMICK_Z_MOVE)
{
gBattleStruct->gimmick.activated[gBattlerAttacker][GIMMICK_Z_MOVE] = FALSE;
gBattleStruct->gimmick.activeGimmick[GetBattlerSide(gBattlerAttacker)][gBattlerPartyIndexes[gBattlerAttacker]] = GIMMICK_NONE;
}
obedienceLevel = 10;

if (FlagGet(FLAG_BADGE01_GET)) // Stone Badge
obedienceLevel = 20;
if (FlagGet(FLAG_BADGE02_GET)) // Knuckle Badge
obedienceLevel = 30;
if (FlagGet(FLAG_BADGE03_GET)) // Dynamo Badge
obedienceLevel = 40;
if (FlagGet(FLAG_BADGE04_GET)) // Heat Badge
obedienceLevel = 50;
if (FlagGet(FLAG_BADGE05_GET)) // Balance Badge
obedienceLevel = 60;
if (FlagGet(FLAG_BADGE06_GET)) // Feather Badge
obedienceLevel = 70;
if (FlagGet(FLAG_BADGE07_GET)) // Mind Badge
obedienceLevel = 80;

if (B_OBEDIENCE_MECHANICS >= GEN_8
&& !IsOtherTrainer(gBattleMons[gBattlerAttacker].otId, gBattleMons[gBattlerAttacker].otName))
levelReferenced = gBattleMons[gBattlerAttacker].metLevel;
else
levelReferenced = gBattleMons[gBattlerAttacker].level;

if (gCurrentMove == MOVE_RAGE)
gBattleMons[gBattlerAttacker].status2 &= ~STATUS2_RAGE;

if (gBattleMons[gBattlerAttacker].status1 & STATUS1_SLEEP && (gCurrentMove == MOVE_SNORE || gCurrentMove == MOVE_SLEEP_TALK))
{
gBattlescriptCurrInstr = BattleScript_IgnoresWhileAsleep;
return 1;
}

rnd = (Random() & 255);
calc = (levelReferenced + obedienceLevel) * rnd >> 8;
if (calc < obedienceLevel)
//if (calc < obedienceLevel)
if (gSpecialStatuses[gBattlerAttacker].isNotObedient == 3)
{
calc = CheckMoveLimitations(gBattlerAttacker, gBitTable[gCurrMovePos], MOVE_LIMITATIONS_ALL);
if (calc == ALL_MOVES_MASK) // all moves cannot be used
Expand Down

0 comments on commit 4774b2f

Please sign in to comment.