Пример #1
0
    public void ForceTurn(GscTurn playerTurn, GscTurn opponentTurn = null, bool speedTieWin = true)
    {
        int playerMoveIndex = Array.IndexOf(BattleMon.Moves, Moves[playerTurn.Move]);

        GscMove enemyMove         = opponentTurn != null ? Moves[opponentTurn.Move] : EnemyMon.Moves.Where(m => m.Name != "QUICK ATTACK").First();
        int     opponentMoveIndex = Array.IndexOf(EnemyMon.Moves, enemyMove);

        CpuWrite("wCurEnemyMoveNum", (byte)opponentMoveIndex);
        CpuWrite("wCurEnemyMove", enemyMove.Id);

        ChooseMenuItem(0);
        ChooseMenuItem(playerMoveIndex);

        int  speedTie    = RunUntil("DetermineMoveOrder.player_first", "DetermineMoveOrder.enemy_first", "DetermineMoveOrder.speed_tie");
        bool playerFirst = speedTie == SYM["DetermineMoveOrder.player_first"];

        if (speedTie == SYM["DetermineMoveOrder.speed_tie"])
        {
            RunUntil(SYM["DetermineMoveOrder.speed_tie"] + 0x9);
            A           = speedTieWin ? 0x00 : 0xff;
            playerFirst = speedTieWin;
        }

        if (playerFirst)
        {
            ForceTurnInternal(playerTurn);
            if (opponentTurn != null)
            {
                ForceTurnInternal(opponentTurn);
            }
        }
        else
        {
            ForceTurnInternal(opponentTurn);
            ForceTurnInternal(playerTurn);
        }

        ClearText();
    }
Пример #2
0
    public void ForceTurnInternal(GscTurn turn)
    {
        int playerTurnDone = SYM["PlayerTurn_EndOpponentProtectEndureDestinyBond"] + 0xc;
        int enemyTurnDone  = SYM["EnemyTurn_EndOpponentProtectEndureDestinyBond"] + 0xc;
        int random         = SYM["BattleRandom"] + 0x11;

        int ret;

        while ((ret = ClearTextUntil(Joypad.None, random, playerTurnDone, enemyTurnDone)) == random)
        {
            int    addr  = 0xd << 16 | CpuReadLE <ushort>(SP);
            string label = SYM[addr];

            if (label.StartsWith("BattleCommand_Critical"))
            {
                A = (turn.Flags & Crit) > 0 ? 0x00 : 0xff;
            }
            else if (label.StartsWith("BattleCommand_DamageVariation"))
            {
                int roll = turn.Flags & 0x3f;
                if (roll < 1)
                {
                    roll = 1;
                }
                if (roll > 39)
                {
                    roll = 39;
                }
                roll += 216;
                A     = (byte)((roll << 1) | (roll >> 7)); // rotate left to counter a rrca instruction
            }
            else if (label.StartsWith("BattleCommand_CheckHit"))
            {
                A = (turn.Flags & Miss) > 0 ? 0xff : 0x00;
            }
            else if (label.StartsWith("BattleCommand_StatDown.ComputerMiss") || label.StartsWith("BattleCommand_Poison"))
            {
                A = (turn.Flags & Miss) > 0 ? 0x00 : 0xff;
            }
            else if (label.StartsWith("BattleCommand_EffectChance"))
            {
                A = (turn.Flags & SideEffect) > 0 ? 0x00 : 0xff;
            }
            else if (label.StartsWith("BattleCommand_Spite"))
            {
                int pp = turn.Flags & 0x3f;
                if (pp < 2)
                {
                    pp = 2;
                }
                if (pp > 5)
                {
                    pp = 5;
                }
                A = pp - 2;
            }
            else
            {
                Console.WriteLine("Unhandled BattleRandom call coming from " + label);
            }

            RunFor(1);
        }

        RunFor(1);
    }