Fix no targets issue and switching faint issu
This commit is contained in:
parent
cda75bca70
commit
63355d6a3b
2 changed files with 26 additions and 30 deletions
|
@ -5092,13 +5092,10 @@ void SetTypeBeforeUsingMove(u16 move, u8 battlerAtk)
|
||||||
|
|
||||||
static void HandleAction_UseMove(void)
|
static void HandleAction_UseMove(void)
|
||||||
{
|
{
|
||||||
u8 side;
|
u32 side, moveType, var = 4;
|
||||||
u8 var = 4;
|
|
||||||
u32 moveType;
|
|
||||||
|
|
||||||
gBattlerAttacker = gBattlerByTurnOrder[gCurrentTurnActionNumber];
|
gBattlerAttacker = gBattlerByTurnOrder[gCurrentTurnActionNumber];
|
||||||
|
if (gBattleStruct->field_91 & gBitTable[gBattlerAttacker] || !IsBattlerAlive(gBattlerAttacker))
|
||||||
if (*(&gBattleStruct->field_91) & gBitTable[gBattlerAttacker])
|
|
||||||
{
|
{
|
||||||
gCurrentActionFuncId = B_ACTION_FINISHED;
|
gCurrentActionFuncId = B_ACTION_FINISHED;
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -1990,6 +1990,13 @@ bool8 HandleFaintedMonActions(void)
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case 3:
|
case 3:
|
||||||
|
// Don't switch mons until all pokemon performed their actions or the battle's over.
|
||||||
|
if (gBattleOutcome == 0
|
||||||
|
&& !NoAliveMonsForEitherParty()
|
||||||
|
&& gCurrentTurnActionNumber != gBattlersCount)
|
||||||
|
{
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
gBattleStruct->faintedActionsBattlerId = 0;
|
gBattleStruct->faintedActionsBattlerId = 0;
|
||||||
gBattleStruct->faintedActionsState++;
|
gBattleStruct->faintedActionsState++;
|
||||||
// fall through
|
// fall through
|
||||||
|
@ -4585,11 +4592,24 @@ void HandleAction_RunBattleScript(void) // identical to RunBattleScriptCommands
|
||||||
gBattleScriptingCommandsTable[*gBattlescriptCurrInstr]();
|
gBattleScriptingCommandsTable[*gBattlescriptCurrInstr]();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
u32 SetRandomTarget(u32 battlerId)
|
||||||
|
{
|
||||||
|
static const u8 targets[2][2] =
|
||||||
|
{
|
||||||
|
[B_SIDE_PLAYER] = {B_POSITION_OPPONENT_LEFT, B_POSITION_OPPONENT_RIGHT},
|
||||||
|
[B_SIDE_OPPONENT] = {B_POSITION_PLAYER_LEFT, B_POSITION_PLAYER_RIGHT},
|
||||||
|
};
|
||||||
|
u32 target = GetBattlerAtPosition(targets[GetBattlerSide(battlerId)][Random() % 2]);
|
||||||
|
if (!IsBattlerAlive(target))
|
||||||
|
target ^= BIT_FLANK;
|
||||||
|
|
||||||
|
return target;
|
||||||
|
}
|
||||||
|
|
||||||
u8 GetMoveTarget(u16 move, u8 setTarget)
|
u8 GetMoveTarget(u16 move, u8 setTarget)
|
||||||
{
|
{
|
||||||
u8 targetBattler = 0;
|
u8 targetBattler = 0;
|
||||||
u8 moveTarget;
|
u32 i, moveTarget, side;
|
||||||
u8 side;
|
|
||||||
|
|
||||||
if (setTarget)
|
if (setTarget)
|
||||||
moveTarget = setTarget - 1;
|
moveTarget = setTarget - 1;
|
||||||
|
@ -4606,11 +4626,7 @@ u8 GetMoveTarget(u16 move, u8 setTarget)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
side = GetBattlerSide(gBattlerAttacker);
|
targetBattler = SetRandomTarget(gBattlerAttacker);
|
||||||
do
|
|
||||||
{
|
|
||||||
targetBattler = Random() % gBattlersCount;
|
|
||||||
} while (targetBattler == gBattlerAttacker || side == GetBattlerSide(targetBattler) || !IsBattlerAlive(targetBattler));
|
|
||||||
if (gBattleMoves[move].type == TYPE_ELECTRIC
|
if (gBattleMoves[move].type == TYPE_ELECTRIC
|
||||||
&& IsAbilityOnOpposingSide(gBattlerAttacker, ABILITY_LIGHTNING_ROD)
|
&& IsAbilityOnOpposingSide(gBattlerAttacker, ABILITY_LIGHTNING_ROD)
|
||||||
&& gBattleMons[targetBattler].ability != ABILITY_LIGHTNING_ROD)
|
&& gBattleMons[targetBattler].ability != ABILITY_LIGHTNING_ROD)
|
||||||
|
@ -4642,24 +4658,7 @@ u8 GetMoveTarget(u16 move, u8 setTarget)
|
||||||
if (gSideTimers[side].followmeTimer && gBattleMons[gSideTimers[side].followmeTarget].hp)
|
if (gSideTimers[side].followmeTimer && gBattleMons[gSideTimers[side].followmeTarget].hp)
|
||||||
targetBattler = gSideTimers[side].followmeTarget;
|
targetBattler = gSideTimers[side].followmeTarget;
|
||||||
else if (gBattleTypeFlags & BATTLE_TYPE_DOUBLE && moveTarget & MOVE_TARGET_RANDOM)
|
else if (gBattleTypeFlags & BATTLE_TYPE_DOUBLE && moveTarget & MOVE_TARGET_RANDOM)
|
||||||
{
|
targetBattler = SetRandomTarget(gBattlerAttacker);
|
||||||
if (GetBattlerSide(gBattlerAttacker) == B_SIDE_PLAYER)
|
|
||||||
{
|
|
||||||
if (Random() & 1)
|
|
||||||
targetBattler = GetBattlerAtPosition(B_POSITION_OPPONENT_LEFT);
|
|
||||||
else
|
|
||||||
targetBattler = GetBattlerAtPosition(B_POSITION_OPPONENT_RIGHT);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (Random() & 1)
|
|
||||||
targetBattler = GetBattlerAtPosition(B_POSITION_PLAYER_LEFT);
|
|
||||||
else
|
|
||||||
targetBattler = GetBattlerAtPosition(B_POSITION_PLAYER_RIGHT);
|
|
||||||
}
|
|
||||||
if (!IsBattlerAlive(targetBattler))
|
|
||||||
targetBattler ^= BIT_FLANK;
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
targetBattler = GetBattlerAtPosition((GetBattlerPosition(gBattlerAttacker) & BIT_SIDE) ^ BIT_SIDE);
|
targetBattler = GetBattlerAtPosition((GetBattlerPosition(gBattlerAttacker) & BIT_SIDE) ^ BIT_SIDE);
|
||||||
break;
|
break;
|
||||||
|
|
Loading…
Reference in a new issue