added check for AI to use Dynamax on last pokemon

This commit is contained in:
AgustinGDLV 2023-03-23 21:20:35 -07:00
parent 038649594a
commit 40102fe418
3 changed files with 26 additions and 11 deletions

View file

@ -1595,6 +1595,9 @@ static void OpponentHandleChooseMove(void)
QueueZMove(gActiveBattler, chosenMove); QueueZMove(gActiveBattler, chosenMove);
if (CanMegaEvolve(gActiveBattler)) // If opponent can mega evolve, do it. if (CanMegaEvolve(gActiveBattler)) // If opponent can mega evolve, do it.
BtlController_EmitTwoReturnValues(BUFFER_B, 10, (chosenMoveId) | (RET_MEGA_EVOLUTION) | (gBattlerTarget << 8)); BtlController_EmitTwoReturnValues(BUFFER_B, 10, (chosenMoveId) | (RET_MEGA_EVOLUTION) | (gBattlerTarget << 8));
else if (CanDynamax(gActiveBattler) // If opponent can Dynamax and is on final Pokemon, do it.
&& CountAIAliveNonEggMonsExcept(gBattlerPartyIndexes[gActiveBattler]) == 0)
BtlController_EmitTwoReturnValues(BUFFER_B, 10, (chosenMoveId) | (RET_DYNAMAX) | (gBattlerTarget << 8));
else else
BtlController_EmitTwoReturnValues(BUFFER_B, 10, (chosenMoveId) | (gBattlerTarget << 8)); BtlController_EmitTwoReturnValues(BUFFER_B, 10, (chosenMoveId) | (gBattlerTarget << 8));
} }

View file

@ -2898,16 +2898,18 @@ static void PlayerHandleChooseMove(void)
gBattleStruct->mega.triggerSpriteId = 0xFF; gBattleStruct->mega.triggerSpriteId = 0xFF;
if (CanMegaEvolve(gActiveBattler)) if (CanMegaEvolve(gActiveBattler))
CreateMegaTriggerSprite(gActiveBattler, 0); CreateMegaTriggerSprite(gActiveBattler, 0);
if (!IsZMoveTriggerSpriteActive()) if (!IsZMoveTriggerSpriteActive())
gBattleStruct->zmove.triggerSpriteId = 0xFF; gBattleStruct->zmove.triggerSpriteId = 0xFF;
if (!IsDynamaxTriggerSpriteActive())
gBattleStruct->dynamax.triggerSpriteId = 0xFF;
if (CanDynamax(gActiveBattler)) // TODO: handle Dynamax + Mega + Z-Move
CreateDynamaxTriggerSprite(gActiveBattler, 0);
GetUsableZMoves(gActiveBattler, moveInfo->moves); GetUsableZMoves(gActiveBattler, moveInfo->moves);
gBattleStruct->zmove.viable = IsZMoveUsable(gActiveBattler, gMoveSelectionCursor[gActiveBattler]); gBattleStruct->zmove.viable = IsZMoveUsable(gActiveBattler, gMoveSelectionCursor[gActiveBattler]);
CreateZMoveTriggerSprite(gActiveBattler, gBattleStruct->zmove.viable); CreateZMoveTriggerSprite(gActiveBattler, gBattleStruct->zmove.viable);
if (!IsDynamaxTriggerSpriteActive())
gBattleStruct->dynamax.triggerSpriteId = 0xFF;
if (CanDynamax(gActiveBattler))
CreateDynamaxTriggerSprite(gActiveBattler, 0);
gBattlerControllerFuncs[gActiveBattler] = HandleChooseMoveAfterDma3; gBattlerControllerFuncs[gActiveBattler] = HandleChooseMoveAfterDma3;
} }
} }

View file

@ -7,6 +7,7 @@
#include "battle_script_commands.h" #include "battle_script_commands.h"
#include "data.h" #include "data.h"
#include "graphics.h" #include "graphics.h"
#include "item.h"
#include "pokemon.h" #include "pokemon.h"
#include "random.h" #include "random.h"
#include "sprite.h" #include "sprite.h"
@ -16,6 +17,7 @@
#include "constants/battle_move_effects.h" #include "constants/battle_move_effects.h"
#include "constants/battle_string_ids.h" #include "constants/battle_string_ids.h"
#include "constants/hold_effects.h" #include "constants/hold_effects.h"
#include "constants/items.h"
#include "constants/moves.h" #include "constants/moves.h"
// Constant Data // Constant Data
@ -106,13 +108,15 @@ bool32 CanDynamax(u16 battlerId)
{ {
// TODO: Requires Dynamax Band if not in a Max Raid (as well as special flag). // TODO: Requires Dynamax Band if not in a Max Raid (as well as special flag).
u16 species = gBattleMons[battlerId].species; u16 species = gBattleMons[battlerId].species;
u16 holdEffect = ItemId_GetHoldEffect(gBattleMons[battlerId].item);
if (!gBattleStruct->dynamax.alreadyDynamaxed[GetBattlerSide(battlerId)] if (!gBattleStruct->dynamax.alreadyDynamaxed[GetBattlerSide(battlerId)]
&& !gBattleStruct->dynamax.dynamaxed[battlerId] && !gBattleStruct->dynamax.dynamaxed[battlerId]
&& !gBattleStruct->dynamax.dynamaxed[BATTLE_PARTNER(battlerId)] && !gBattleStruct->dynamax.dynamaxed[BATTLE_PARTNER(battlerId)]
&& !gBattleStruct->dynamax.toDynamax[BATTLE_PARTNER(battlerId)] && !gBattleStruct->dynamax.toDynamax[BATTLE_PARTNER(battlerId)]
&& species != SPECIES_ZACIAN && species != SPECIES_ZACIAN_CROWNED_SWORD && species != SPECIES_ZACIAN && species != SPECIES_ZACIAN_CROWNED_SWORD
&& species != SPECIES_ZAMAZENTA && species != SPECIES_ZAMAZENTA_CROWNED_SHIELD && species != SPECIES_ZAMAZENTA && species != SPECIES_ZAMAZENTA_CROWNED_SHIELD
&& species != SPECIES_ETERNATUS && species != SPECIES_ETERNATUS_ETERNAMAX) && species != SPECIES_ETERNATUS && species != SPECIES_ETERNATUS_ETERNAMAX
&& holdEffect != HOLD_EFFECT_MEGA_STONE && holdEffect != HOLD_EFFECT_Z_CRYSTAL)
return TRUE; return TRUE;
return FALSE; return FALSE;
} }
@ -121,7 +125,9 @@ bool32 CanDynamax(u16 battlerId)
void ApplyDynamaxHPMultiplier(u16 battlerId, struct Pokemon* mon) void ApplyDynamaxHPMultiplier(u16 battlerId, struct Pokemon* mon)
{ {
if (gBattleMons[battlerId].species == SPECIES_SHEDINJA) if (gBattleMons[battlerId].species == SPECIES_SHEDINJA)
{
return; return;
}
else else
{ {
u16 mult = UQ_4_12(1.5); // placeholder u16 mult = UQ_4_12(1.5); // placeholder
@ -136,7 +142,9 @@ void ApplyDynamaxHPMultiplier(u16 battlerId, struct Pokemon* mon)
u16 GetNonDynamaxHP(u16 battlerId) u16 GetNonDynamaxHP(u16 battlerId)
{ {
if (!IsDynamaxed(battlerId) || gBattleMons[battlerId].species == SPECIES_SHEDINJA) if (!IsDynamaxed(battlerId) || gBattleMons[battlerId].species == SPECIES_SHEDINJA)
{
return gBattleMons[battlerId].hp; return gBattleMons[battlerId].hp;
}
else else
{ {
u16 mult = UQ_4_12(1.0/1.5); // placeholder u16 mult = UQ_4_12(1.0/1.5); // placeholder
@ -149,7 +157,9 @@ u16 GetNonDynamaxHP(u16 battlerId)
u16 GetNonDynamaxMaxHP(u16 battlerId) u16 GetNonDynamaxMaxHP(u16 battlerId)
{ {
if (!IsDynamaxed(battlerId) || gBattleMons[battlerId].species == SPECIES_SHEDINJA) if (!IsDynamaxed(battlerId) || gBattleMons[battlerId].species == SPECIES_SHEDINJA)
{
return gBattleMons[battlerId].maxHP; return gBattleMons[battlerId].maxHP;
}
else else
{ {
u16 mult = UQ_4_12(1.0/1.5); // placeholder u16 mult = UQ_4_12(1.0/1.5); // placeholder