Ejemplo n.º 1
0
    public static void collectUpcomingAvailableShips(bool ascending)
    {
        List <LoadedShip> ships1 = MatchDatas.getPlayers()[0].getNextShips(MatchDatas.getCurrentLevel(), ascending);
        List <LoadedShip> ships2 = MatchDatas.getPlayers()[1].getNextShips(MatchDatas.getCurrentLevel(), ascending);
        // TODO add this bit when 3 player rules are getting included!
        //LoadedShip ship3 = MatchDatas.getPlayers()[2].getNextShip(MatchDatas.getCurrentLevel(), ascending);

        bool ship1IsEmpty = ships1 == null || ships1.Capacity == 0;
        bool ship2IsEmpty = ships2 == null || ships2.Capacity == 0;

        if (ship1IsEmpty && ship2IsEmpty)
        {
            PhaseHandlerService.nextPhase();
        }
        else
        {
            if (ship1IsEmpty && !ship2IsEmpty)
            {
                availableShips = ships2;
                MatchDatas.setActivePlayerIndex(1);
            }

            if (ship2IsEmpty && !ship1IsEmpty)
            {
                availableShips = ships1;
                MatchDatas.setActivePlayerIndex(0);
            }

            if (!ship1IsEmpty && !ship2IsEmpty)
            {
                if (ships1[0].getPilot().Level == ships2[0].getPilot().Level)
                {
                    foreach (LoadedShip ship in ships1)
                    {
                        if (!ship.isHasBeenActivatedThisRound() && MatchDatas.getPlayers()[0].getHasInitiative())
                        {
                            availableShips = ships1;
                            MatchDatas.setActivePlayerIndex(0);
                            break;
                        }
                    }

                    foreach (LoadedShip ship in ships2)
                    {
                        if (!ship.isHasBeenActivatedThisRound() && MatchDatas.getPlayers()[1].getHasInitiative())
                        {
                            availableShips = ships2;
                            MatchDatas.setActivePlayerIndex(1);
                            break;
                        }
                    }
                }
                else
                {
                    if (ascending)
                    {
                        if (ships1[0].getPilot().Level < ships2[0].getPilot().Level)
                        {
                            availableShips = ships1;
                            MatchDatas.setActivePlayerIndex(0);
                        }
                        else
                        {
                            availableShips = ships2;
                            MatchDatas.setActivePlayerIndex(1);
                        }
                    }
                    else
                    {
                        if (ships1[0].getPilot().Level > ships2[0].getPilot().Level)
                        {
                            availableShips = ships1;
                            MatchDatas.setActivePlayerIndex(0);
                        }
                        else
                        {
                            availableShips = ships2;
                            MatchDatas.setActivePlayerIndex(1);
                        }
                    }
                }
            }

            if (MatchDatas.getPlayers()[MatchDatas.getActivePlayerIndex()].isAI() && MatchDatas.getCurrentPhase() == MatchDatas.phases.SQUADRON_PLACEMENT)
            {
                moveAIShips(ascending);
            }
        }
    }