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);
if (CanMegaEvolve(gActiveBattler)) // If opponent can mega evolve, do it.
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
BtlController_EmitTwoReturnValues(BUFFER_B, 10, (chosenMoveId) | (gBattlerTarget << 8));
}

View file

@ -2898,16 +2898,18 @@ static void PlayerHandleChooseMove(void)
gBattleStruct->mega.triggerSpriteId = 0xFF;
if (CanMegaEvolve(gActiveBattler))
CreateMegaTriggerSprite(gActiveBattler, 0);
if (!IsZMoveTriggerSpriteActive())
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);
gBattleStruct->zmove.viable = IsZMoveUsable(gActiveBattler, gMoveSelectionCursor[gActiveBattler]);
CreateZMoveTriggerSprite(gActiveBattler, gBattleStruct->zmove.viable);
if (!IsDynamaxTriggerSpriteActive())
gBattleStruct->dynamax.triggerSpriteId = 0xFF;
if (CanDynamax(gActiveBattler))
CreateDynamaxTriggerSprite(gActiveBattler, 0);
gBattlerControllerFuncs[gActiveBattler] = HandleChooseMoveAfterDma3;
}
}

View file

@ -7,6 +7,7 @@
#include "battle_script_commands.h"
#include "data.h"
#include "graphics.h"
#include "item.h"
#include "pokemon.h"
#include "random.h"
#include "sprite.h"
@ -16,6 +17,7 @@
#include "constants/battle_move_effects.h"
#include "constants/battle_string_ids.h"
#include "constants/hold_effects.h"
#include "constants/items.h"
#include "constants/moves.h"
// 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).
u16 species = gBattleMons[battlerId].species;
u16 holdEffect = ItemId_GetHoldEffect(gBattleMons[battlerId].item);
if (!gBattleStruct->dynamax.alreadyDynamaxed[GetBattlerSide(battlerId)]
&& !gBattleStruct->dynamax.dynamaxed[battlerId]
&& !gBattleStruct->dynamax.dynamaxed[BATTLE_PARTNER(battlerId)]
&& !gBattleStruct->dynamax.toDynamax[BATTLE_PARTNER(battlerId)]
&& species != SPECIES_ZACIAN && species != SPECIES_ZACIAN_CROWNED_SWORD
&& species != SPECIES_ZAMAZENTA && species != SPECIES_ZAMAZENTA_CROWNED_SHIELD
&& species != SPECIES_ETERNATUS && species != SPECIES_ETERNATUS_ETERNAMAX)
&& !gBattleStruct->dynamax.dynamaxed[battlerId]
&& !gBattleStruct->dynamax.dynamaxed[BATTLE_PARTNER(battlerId)]
&& !gBattleStruct->dynamax.toDynamax[BATTLE_PARTNER(battlerId)]
&& species != SPECIES_ZACIAN && species != SPECIES_ZACIAN_CROWNED_SWORD
&& species != SPECIES_ZAMAZENTA && species != SPECIES_ZAMAZENTA_CROWNED_SHIELD
&& species != SPECIES_ETERNATUS && species != SPECIES_ETERNATUS_ETERNAMAX
&& holdEffect != HOLD_EFFECT_MEGA_STONE && holdEffect != HOLD_EFFECT_Z_CRYSTAL)
return TRUE;
return FALSE;
}
@ -121,7 +125,9 @@ bool32 CanDynamax(u16 battlerId)
void ApplyDynamaxHPMultiplier(u16 battlerId, struct Pokemon* mon)
{
if (gBattleMons[battlerId].species == SPECIES_SHEDINJA)
{
return;
}
else
{
u16 mult = UQ_4_12(1.5); // placeholder
@ -136,7 +142,9 @@ void ApplyDynamaxHPMultiplier(u16 battlerId, struct Pokemon* mon)
u16 GetNonDynamaxHP(u16 battlerId)
{
if (!IsDynamaxed(battlerId) || gBattleMons[battlerId].species == SPECIES_SHEDINJA)
{
return gBattleMons[battlerId].hp;
}
else
{
u16 mult = UQ_4_12(1.0/1.5); // placeholder
@ -149,7 +157,9 @@ u16 GetNonDynamaxHP(u16 battlerId)
u16 GetNonDynamaxMaxHP(u16 battlerId)
{
if (!IsDynamaxed(battlerId) || gBattleMons[battlerId].species == SPECIES_SHEDINJA)
{
return gBattleMons[battlerId].maxHP;
}
else
{
u16 mult = UQ_4_12(1.0/1.5); // placeholder