public override void cleanup()
 {
     if (MatchDatas.getPlayers()[MatchDatas.getActivePlayerIndex()].getActiveShip().Equals(owner))
     {
         owner.getTarget().getShip().Agility++;
     }
 }
Example #2
0
    private void afterManeuver()
    {
        MatchHandlerUtil.applyManeuverBonus(target, maneuverToComplete.Difficulty);

        // TODO Make player chosen an action (if available)
        if (target.transform.GetComponent <ShipProperties>().getLoadedShip().getTokenIdByType(typeof(StressToken)) == 0)
        {
            target.transform.GetComponent <ShipProperties>().getLoadedShip().setNumOfActions(1);
            //Action choser.....
            //target.transform.GetComponent<ShipProperties>().getLoadedShip().setBeforeAction(true);

            GameObject actionChoserPopup = null;
            int        actionIndex       = 0;

            foreach (GameObject go in Resources.FindObjectsOfTypeAll(typeof(GameObject)))
            {
                if (go.name.Equals("ActionChoserPopup"))
                {
                    actionChoserPopup = go;
                }
            }

            if (actionChoserPopup != null)
            {
                // TODO outsource this fragment to UI handler!!!!!!!
                foreach (String action in MatchDatas.getPlayers()[MatchDatas.getActivePlayerIndex()].getActiveShip().getShip().Actions.Action)
                {
                    Image  image  = null;
                    Sprite sprite = Resources.Load <Sprite>(SquadBuilderConstants.IMAGE_FOLDER_NAME + "/" + action.Replace(" ", "-"));

                    Transform     actionIconPrefab = Resources.Load <Transform>(SquadBuilderConstants.PREFABS_FOLDER_NAME + "/" + SquadBuilderConstants.ACTION_ICON);
                    RectTransform rt = (RectTransform)actionIconPrefab;
                    float         actionIconWidth = rt.rect.width;

                    Transform actionIcon = (Transform)GameObject.Instantiate(
                        actionIconPrefab,
                        new Vector3((actionIndex * actionIconWidth) + SquadBuilderConstants.UPGRADE_IMAGE_X_OFFSET + 15, SquadBuilderConstants.UPGRADE_IMAGE_Y_OFFSET - 30, SquadBuilderConstants.UPGRADE_IMAGE_Z_OFFSET),
                        Quaternion.identity
                        );

                    Image actionIconImage = actionIcon.gameObject.GetComponent <Image>();

                    actionIcon.gameObject.AddComponent <ActionSelectorEvents>();
                    actionIcon.gameObject.GetComponent <ActionSelectorEvents>().setActionName(action);
                    actionIcon.transform.SetParent(actionChoserPopup.transform, false);
                    actionIconImage.sprite = sprite;
                    actionIconImage.color  = new Color(actionIconImage.color.r, actionIconImage.color.g, actionIconImage.color.b, 1.0f);

                    actionIndex++;
                }

                actionChoserPopup.SetActive(true);
                PhaseHandlerService.initActionPhase();
            }
        }

        maneuverToComplete = null;
        target             = null;
    }
Example #3
0
 public static void deleteSelectedManeuvers()
 {
     foreach (Player player in MatchDatas.getPlayers())
     {
         foreach (LoadedShip ship in player.getSquadron())
         {
             ship.setPlannedManeuver(null);
         }
     }
 }
 public override void doEventAction()
 {
     if (MatchDatas.getPlayers()[MatchDatas.getActivePlayerIndex()].getActiveShip().Equals(owner))
     {
         if (owner.getTarget().getShip().Agility - 1 > 0)
         {
             owner.getTarget().getShip().Agility--;
         }
     }
 }
    public void shipSelected(LoadedShip ship)
    {
        Debug.Log("Custom event triggered!");

        GUIHandler guiHandler = new GUIHandler();

        MatchDatas.getPlayers()[MatchDatas.getActivePlayerIndex()].setActiveShip(ship);

        guiHandler.showActiveShipsCard(ship);
    }
Example #6
0
    private static bool isMatchOver()
    {
        foreach (Player player in MatchDatas.getPlayers())
        {
            if (player.isDefeated())
            {
                return(true);
            }
        }

        return(false);
    }
Example #7
0
 public static void setAIManeuvers()
 {
     foreach (Player player in MatchDatas.getPlayers())
     {
         if (player.isAI())
         {
             foreach (LoadedShip ship in player.getSquadron())
             {
                 ship.setPlannedManeuver(ship.getShip().Maneuvers.Maneuver[0]);
             }
         }
     }
 }
    public void instantiateShips()
    {
        foreach (Player player in MatchDatas.getPlayers())
        {
            int     loopIndex        = 0;
            Vector3 startingPosition = MatchHandlerUtil.getShipCollectionHolderPosition(player.getPlayerID());

            foreach (LoadedShip loadedShip in player.getSquadron())
            {
                Ship       ship             = loadedShip.getShip();
                string     shipType         = ship.ShipId;
                GameObject shipHolderPrefab = (GameObject)Resources.Load(MatchHandlerConstants.PREFABS_FOLDER + "/SmallShipContainerPrefab", typeof(GameObject));
                GameObject shipPrefab       = (GameObject)Resources.Load(MatchHandlerConstants.PREFABS_FOLDER + "/" + shipType, typeof(GameObject));

                //TODO Tweak these coordinates!
                float posX = startingPosition.x + (loopIndex * MatchHandlerConstants.offsetX);
                float posY = startingPosition.y;
                float posZ = startingPosition.z;

                GameObject shipHolderGameObject = (GameObject)GameObject.Instantiate(
                    shipHolderPrefab,
                    new Vector3(posX, posY, posZ),
                    Quaternion.identity
                    );

                // TODO change models, so offset is not needed anymore!
                Vector3 shipOffset = new Vector3(2.81896f * 500.0f, 0.0f, 3.286796f * 500.0f);

                GameObject shipGameObject = (GameObject)GameObject.Instantiate(
                    shipPrefab,
                    shipHolderGameObject.GetComponent <Renderer>().bounds.center + shipOffset,
                    Quaternion.identity
                    );

                shipGameObject.transform.SetParent(shipHolderGameObject.transform, true);

                shipHolderGameObject.GetComponent <ShipProperties>().setLoadedShip(loadedShip);

                /***********************************/
                FiringArc arc = new FiringArc();
                arc.leftBoundary  = -45.0f;
                arc.rightBoundary = 45.0f;
                /***********************************/

                generateFiringArc(shipHolderGameObject, arc);

                loopIndex++;
            }
            ;
        }
    }
Example #9
0
    public void MENU_ACTION_setPlayerInitiative()
    {
        Debug.Log("Setting player initiative!");
        string playerName = this.transform.GetComponentInChildren <Text>().text;

        foreach (Player player in MatchDatas.getPlayers())
        {
            if (player.getPlayerName().Equals(playerName))
            {
                player.setInitiative();
                Debug.Log(player.getPlayerName() + " now has initiative!");
                PhaseHandlerService.nextPhase();

                Destroy(GameObject.Find("Initiative panel"));
            }
        }
    }
Example #10
0
    public static bool maneuversPlanned()
    {
        bool result = true;

        foreach (Player player in MatchDatas.getPlayers())
        {
            foreach (LoadedShip ship in player.getSquadron())
            {
                if (ship.getPlannedManeuver() == null)
                {
                    result = false;
                    break;
                }
            }
        }

        return(result);
    }
Example #11
0
    public static Player getPlayerWithLowestSquadScore()
    {
        Player result = null;

        foreach (Player player in MatchDatas.getPlayers())
        {
            if (result == null)
            {
                result = player;
            }
            else
            {
                result = result.getCumulatedSquadPoints() > player.getCumulatedSquadPoints() ? player : result;
            }
        }

        return(result);
    }
Example #12
0
    public static bool squadScoresAreEqual()
    {
        if (MatchDatas.getPlayers().Count == 2)
        {
            if (MatchDatas.getPlayers()[0].getCumulatedSquadPoints() == MatchDatas.getPlayers()[1].getCumulatedSquadPoints())
            {
                return(true);
            }
        }
        else if (MatchDatas.getPlayers().Count == 3)
        {
            if (MatchDatas.getPlayers()[0].getCumulatedSquadPoints() == MatchDatas.getPlayers()[1].getCumulatedSquadPoints() && MatchDatas.getPlayers()[0].getCumulatedSquadPoints() == MatchDatas.getPlayers()[2].getCumulatedSquadPoints())
            {
                return(true);
            }
        }

        return(false);
    }
Example #13
0
    private static void startActivationPhase()
    {
        MatchHandlerUtil.hideActiveShipHighlighters();
        MatchDatas.setCurrentPhase(MatchDatas.phases.ACTIVATION);
        MatchDatas.setCurrentLevel(0);

        foreach (Player player in MatchDatas.getPlayers())
        {
            foreach (LoadedShip ship in player.getSquadron())
            {
                ship.setHasBeenActivatedThisRound(false);
            }
        }

        MatchHandler.collectUpcomingAvailableShips(true);

        // TODO Active player index is not always right/sufficient!!
        MatchDatas.getPlayers()[MatchDatas.getActivePlayerIndex()].setActiveShip(null);
        MatchDatas.getPlayers()[MatchDatas.getActivePlayerIndex()].setSelectedShip(null);
    }
Example #14
0
    void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            RaycastHit hit;

            if (Physics.Raycast(ray, out hit))
            {
                GameObject target      = hit.transform.gameObject;
                LoadedShip clickedShip = new LoadedShip();

                int playerIndex = 0;

                foreach (Player player in MatchDatas.getPlayers())
                {
                    foreach (LoadedShip ship in player.getSquadron())
                    {
                        if (ship.getPilot().Equals(target.GetComponent <ShipProperties>().getLoadedShip().getPilot()))
                        {
                            clickedShip.setShip(target.GetComponent <ShipProperties>().getLoadedShip().getShip());
                            clickedShip.setPilot(target.GetComponent <ShipProperties>().getLoadedShip().getPilot());

                            MatchDatas.getPlayers()[playerIndex].setSelectedShip(clickedShip);

                            // TODO IF! this part is needed, get the player ID who clicked on the ship!!
                            if (player.getPlayerID() == 1)
                            {
                                player.setActiveShip(clickedShip);
                            }
                        }
                    }

                    playerIndex++;
                }
            }
        }
    }
Example #15
0
    public IEnumerator RollAttackDice(System.Action <Player> callBack)
    {
        // TODO change the first param to be dynamic!
        DiceRollerBase.showDiceArea(1, true);
        Rigidbody[] GOS         = FindObjectsOfType(typeof(Rigidbody)) as Rigidbody[];
        bool        allSleeping = false;

        while (!allSleeping)
        {
            allSleeping = true;

            foreach (Rigidbody GO in GOS)
            {
                if (!GO.IsSleeping())
                {
                    allSleeping = false;
                    yield return(null);

                    break;
                }
            }
        }

        DiceRollerBase.getDiceResults(GOS);

        Player result = null;

        if (LocalDataWrapper.getPlayer().getLastDiceResults()[0] == DiceRollerBase.DICE_RESULT_HIT_OR_EVADE || LocalDataWrapper.getPlayer().getLastDiceResults()[0] == DiceRollerBase.DICE_RESULT_CRIT)
        {
            result = MatchDatas.getPlayers()[0];
        }
        else
        {
            result = MatchDatas.getPlayers()[1];
        }

        callBack(result);
    }
Example #16
0
    public static void displayInitiativeChoser(Player player)
    {
        int playerIndex = 0;

        if (LocalDataWrapper.getPlayer().getPlayerName().Equals(player.getPlayerName()))
        {
            foreach (Player currentPlayer in MatchDatas.getPlayers())
            {
                Transform InitiativeButtonPrefab = Resources.Load <Transform>(MatchHandlerConstants.PREFABS_FOLDER + MatchHandlerConstants.INITIATIVE_BUTTON_PREFAB_NAME);
                Transform InitiativeButton       = (Transform)GameObject.Instantiate(
                    InitiativeButtonPrefab,
                    new Vector3(InitiativeButtonPrefab.position.x, InitiativeButtonPrefab.position.y - playerIndex * 85, InitiativeButtonPrefab.position.z),
                    Quaternion.identity
                    );

                InitiativeButton.GetComponentInChildren <Text>().text = currentPlayer.getPlayerName();
                InitiativeButton.transform.SetParent(initiativePanel.transform, false);

                playerIndex++;
            }

            initiativePanel.SetActive(true);
        }
    }
    public void OnPointerClick(PointerEventData eventData)
    {
        Debug.Log("Action name: " + this.actionName);
        Debug.Log("PHASE: " + MatchDatas.getCurrentPhase());

        if (MatchDatas.getCurrentPhase() == MatchDatas.phases.ACTION)
        {
            IToken token = null;

            switch (this.actionName)
            {
            case "focus":
                token = new FocusToken();
                break;

            case "evade":
                token = new EvadeToken();
                break;

            case "target lock":
                break;

            case "boost":
                break;

            case "barrel roll":
                break;

            case "slam":
                break;

            case "reinforce":
                break;

            case "cloak":
                break;

            case "decloak":
                break;

            case "coordinate":
                break;

            case "jam":
                break;

            case "recover":
                break;

            case "reload":
                break;

            case "rotate arc":
                break;
            }

            if (token != null)
            {
                Debug.Log("Adding token...");
                MatchDatas.getPlayers()[MatchDatas.getActivePlayerIndex()].getActiveShip().addToken(token);
                MatchDatas.getPlayers()[MatchDatas.getActivePlayerIndex()].getActiveShip().registerPreviousAction(this.actionName);
            }

            // TODO Check if multiple actions can be chosen!
            // TODO Deactivate actions!!!!
        }

        if (GameObject.Find("ActionChoserPopup") != null && MatchDatas.getPlayers()[MatchDatas.getActivePlayerIndex()].getActiveShip().getNumOfActions() == 0)
        {
            GameObject.Find("ActionChoserPopup").gameObject.SetActive(false);
            PhaseHandlerService.endActionPhase();
        }
    }
Example #18
0
    public void showPilotCard(GameObject target)
    {
        LoadedShip ship = MatchDatas.getPlayers()[MatchDatas.getActivePlayerIndex()].getSelectedhip();
        string     side = "";
        Image      image;
        Sprite     sprite;

        foreach (Player player in MatchDatas.getPlayers())
        {
            foreach (LoadedShip ls in player.getSquadron())
            {
                if (ls.getShip().ShipId == ship.getShip().ShipId&& ls.getPilot().Name.Equals(ship.getPilot().Name))
                {
                    side = player.getChosenSide();
                    break;
                }

                if (!side.Equals(""))
                {
                    break;
                }
            }
        }

        target.transform.Find("PilotName").gameObject.GetComponent <UnityEngine.UI.Text>().text                = ship.getPilot().Name.ToLower();
        target.transform.Find("ShipType").gameObject.GetComponent <UnityEngine.UI.Text>().text                 = ship.getShip().ShipName.ToLower();
        target.transform.Find("Description").gameObject.GetComponent <UnityEngine.UI.Text>().text              = ship.getPilot().Text.ToLower();
        target.transform.Find("BaseCostHolder/BaseCost").gameObject.GetComponent <UnityEngine.UI.Text>().text  = ship.getPilot().Cost.ToString();
        target.transform.Find("ShieldValueHolder/Value").gameObject.GetComponent <UnityEngine.UI.Text>().text  = ship.getShip().Shield.ToString();
        target.transform.Find("HullValueHolder/Value").gameObject.GetComponent <UnityEngine.UI.Text>().text    = ship.getShip().Hull.ToString();
        target.transform.Find("AgilityValueHolder/Value").gameObject.GetComponent <UnityEngine.UI.Text>().text = ship.getShip().Agility.ToString();
        target.transform.Find("PowerValueHolder/Value").gameObject.GetComponent <UnityEngine.UI.Text>().text   = ship.getShip().Weapon.ToString();
        target.transform.Find("PilotLevelHolder/Value").gameObject.GetComponent <UnityEngine.UI.Text>().text   = ship.getPilot().Level.ToString();

        int actionIndex = 0;


        // TODO use prefabs instead???
        foreach (string action in ship.getShip().Actions.Action)
        {
            image  = null;
            sprite = Resources.Load <Sprite>(SquadBuilderConstants.IMAGE_FOLDER_NAME + "/" + action.Replace(" ", "-"));

            Transform     actionIconPrefab = Resources.Load <Transform>(SquadBuilderConstants.PREFABS_FOLDER_NAME + "/" + SquadBuilderConstants.ACTION_ICON);
            RectTransform rt = (RectTransform)actionIconPrefab;
            float         actionIconWidth = rt.rect.width;

            Transform actionIcon = (Transform)GameObject.Instantiate(
                actionIconPrefab,
                new Vector3((actionIndex * actionIconWidth) + SquadBuilderConstants.UPGRADE_IMAGE_X_OFFSET, SquadBuilderConstants.UPGRADE_IMAGE_Y_OFFSET, SquadBuilderConstants.UPGRADE_IMAGE_Z_OFFSET),
                Quaternion.identity
                );

            Transform actionsBar      = target.transform.Find("ActionIcons");
            Image     actionIconImage = actionIcon.gameObject.GetComponent <Image>();

            actionIcon.transform.SetParent(actionsBar, false);
            actionIconImage.sprite = sprite;
            actionIconImage.color  = new Color(actionIconImage.color.r, actionIconImage.color.g, actionIconImage.color.b, 1.0f);

            /*if (ship.getNumOfActions() > 0 && ship.isBeforeAction() && !actionHasBeenUsed(ship, action))
             * {
             *  addActionToSelector(target, action, actionIndex);
             * }*/

            actionIndex++;
        }

        sprite = Resources.Load <Sprite>(SquadBuilderConstants.IMAGE_FOLDER_NAME + "/" + side + "_pilot_card");
        target.transform.Find("CardImage").gameObject.GetComponent <Image>().sprite = sprite;
        image       = target.transform.Find("CardImage").gameObject.GetComponent <Image>();
        image.color = new Color(image.color.r, image.color.g, image.color.b, 1.0f);

        sprite = Resources.Load <Sprite>(SquadBuilderConstants.IMAGE_FOLDER_NAME + "/" + ship.getShip().ShipId);
        target.transform.Find("CardImage/ShipImage").gameObject.GetComponent <Image>().sprite = sprite;
        image       = target.transform.Find("CardImage/ShipImage").gameObject.GetComponent <Image>();
        image.color = new Color(image.color.r, image.color.g, image.color.b, 1.0f);

        target.transform.Find("ShipDataManeuvers").gameObject.SetActive(false);

        target.SetActive(true);
    }
Example #19
0
    void Start()
    {
        mocker.mockPlayerSquadrons();
        DiceRollerBase.setUpDiceRollerBase(ForceMode.VelocityChange, 10.0f);

        string total = "squadron size: " + MatchDatas.getTotalSquadPoints();

        // TODO Show each player's name, squad point total, chosen side, chosen ships (images...)
        int playerIndex = 0;

        foreach (Player player in MatchDatas.getPlayers())
        {
            Transform     playerPanelPrefab = Resources.Load <Transform>(PLAYER_PANEL_PREFAB_NAME);
            RectTransform rt = (RectTransform)playerPanelPrefab;
            float         playerPanelWidth = rt.rect.width;

            Transform playerPanel = (Transform)GameObject.Instantiate(
                playerPanelPrefab,
                new Vector3((playerIndex * playerPanelWidth) + PLAYER_PANEL_X_OFFSET, PLAYER_PANEL_Y_OFFSET, DEFAULT_Z_OFFSET),
                Quaternion.identity
                );

            playerPanel.transform.SetParent(mainCanvas.transform, false);

            /*PilotRemoveEvents pilotRemoveEvent = shipPanel.transform.Find("DeleteButton").gameObject.GetComponent<PilotRemoveEvents>();
             * pilotRemoveEvent.setPilot(loadedShip.getPilot());*/

            /*Sprite sprite = Resources.Load<Sprite>(SquadBuilderConstants.IMAGE_FOLDER_NAME + "/" + loadedShip.getShip().ShipId);
             * shipPanel.transform.Find("Avatar").gameObject.GetComponent<Image>().sprite = sprite;
             * Image image = shipPanel.transform.Find("Avatar").gameObject.GetComponent<Image>();
             * image.color = new Color(image.color.r, image.color.g, image.color.b, 1.0f);*/

            playerPanel.transform.Find("PlayerName").gameObject.GetComponent <UnityEngine.UI.Text>().text = player.getPlayerName();
            playerPanel.transform.Find("PlayerSide").gameObject.GetComponent <UnityEngine.UI.Text>().text = player.getChosenSide();
            playerPanel.transform.Find("SquadTotal").gameObject.GetComponent <UnityEngine.UI.Text>().text = TEXT_SQUAD_TOTAL + player.getCumulatedSquadPoints() + TEXT_POINTS;

            int rowIndex = 0;
            int colIndex = 0;

            foreach (LoadedShip ship in player.getSquadron())
            {
                Transform shipIconPrefab = Resources.Load <Transform>(SHIP_ICON_PREFAB_NAME);

                Transform shipIcon = (Transform)GameObject.Instantiate(
                    shipIconPrefab,
                    new Vector3((colIndex * SHIP_ICON_WIDTH) + SHIP_ICON_X_OFFSET, (rowIndex * SHIP_ICON_HEIGHT) + SHIP_ICON_Y_OFFSET, DEFAULT_Z_OFFSET),
                    Quaternion.identity
                    );

                shipIcon.transform.SetParent(playerPanel.transform.Find("ShipIcons"), false);

                Sprite sprite = Resources.Load <Sprite>(SquadBuilderConstants.IMAGE_FOLDER_NAME + "/" + ship.getShip().ShipId);
                shipIcon.gameObject.GetComponent <Image>().sprite = sprite;
                Image image = shipIcon.gameObject.GetComponent <Image>();
                image.color = new Color(image.color.r, image.color.g, image.color.b, 1.0f);

                if (colIndex < 5)
                {
                    colIndex++;
                }
                else
                {
                    colIndex = 0;
                    rowIndex++;
                }
            }

            playerIndex++;
        }
    }
Example #20
0
 public static void determineInitiative()
 {
     if (squadScoresAreEqual())
     {
         PointerClickCallback callback = GameObject.Find("ScriptHolder").GetComponent <CoroutineHandler>().rollAttackDiceCallback;
         SystemMessageService.showErrorMsg(MatchHandlerConstants.EQUAL_SQUAD_SCORE_TEXT + " " + MatchDatas.getPlayers()[0].getPlayerName() + MatchHandlerConstants.EQUAL_SQUAD_SCORE_TEXT_ENDING, GameObject.Find("SystemMessagePanel"), 1, callback);
     }
     else
     {
         PointerClickCallback callback = displayInitiativeChooserCallback;
         SystemMessageService.showErrorMsg(getPlayerWithLowestSquadScore().getPlayerName() + MatchHandlerConstants.NOT_EQUAL_SQUAD_SCORE_TEXT, GameObject.Find("SystemMessagePanel"), 1, callback);
     }
 }
Example #21
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);
            }
        }
    }
Example #22
0
    // TODO Can we make the method calls inside to run only ONCE(!), when necessary?? Custom eventhandling maybe????
    void Update()
    {
        matchHandlerService.levitateShips();
        matchHandlerService.rotateAsteroids();

        if (Input.GetKey("escape"))
        {
            // TODO Not active player, LOCAL PLAYER!!! (Maybe simply hiding the panel on the client side is enough....)
            MatchDatas.getPlayers()[MatchDatas.getActivePlayerIndex()].setSelectedShip(null);
            //guiHandler.hideGameObject(PilotCardPanel);
        }

        //THIS IS ONLY FOR TESTING MOVEMENTS!!!!!! DELETE LATER ON!!!! (Also, ADD UNIQUE IDs during squad building to ships and pilots!!!! [use something like: playerIndex_shipIndex])
        Maneuver man = new Maneuver();

        man.Difficulty = "1";

        for (int i = 0; i < keyCodes.Length; i++)
        {
            if (Input.GetKeyDown(keyCodes[i]))
            {
                int  n;
                bool isNumeric = int.TryParse(keyCodes[i], out n);

                if (isNumeric)
                {
                    int s = Int32.Parse(keyCodes[i]);
                    if (s < 6)
                    {
                        man.Bearing = "straight";
                        man.Speed   = keyCodes[i];
                    }
                    else
                    {
                        man.Bearing = "koiogran";
                        man.Speed   = (s - 5).ToString();
                    }
                }
                else
                {
                    switch (keyCodes[i])
                    {
                    case "v":
                    case "g":
                    case "t":
                    case "i":
                    case "k":
                    case "m":
                        man.Bearing = "turn_left";
                        man.Speed   = "1";

                        if (keyCodes[i].Equals("i") || keyCodes[i].Equals("k") || keyCodes[i].Equals("m"))
                        {
                            man.Bearing = "turn_right";
                        }

                        if (keyCodes[i].Equals("g") || keyCodes[i].Equals("k"))
                        {
                            man.Speed = "2";
                        }

                        if (keyCodes[i].Equals("t") || keyCodes[i].Equals("i"))
                        {
                            man.Speed = "3";
                        }

                        break;

                    case "b":
                    case "h":
                    case "z":
                    case "u":
                    case "j":
                    case "n":
                        man.Bearing = "bank_left";
                        man.Speed   = "1";

                        if (keyCodes[i].Equals("u") || keyCodes[i].Equals("j") || keyCodes[i].Equals("n"))
                        {
                            man.Bearing = "bank_right";
                        }

                        if (keyCodes[i].Equals("h") || keyCodes[i].Equals("j"))
                        {
                            man.Speed = "2";
                        }

                        if (keyCodes[i].Equals("z") || keyCodes[i].Equals("u"))
                        {
                            man.Speed = "3";
                        }

                        break;
                    }
                }
            }
        }

        //THIS IS ONLY FOR TESTING MOVEMENTS!!!!!! DELETE LATER ON!!!!
        //StartCoroutine(GameObject.Find("ScriptHolder").GetComponent<CoroutineHandler>().MoveShipOverTime(GameObject.FindGameObjectsWithTag("SmallShipContainer")[1], man));
        //THIS IS ONLY FOR TESTING MOVEMENTS!!!!!! DELETE LATER ON!!!!

        if (MatchDatas.getPlayers()[MatchDatas.getActivePlayerIndex()].getSelectedhip() != null)
        {
            //TODO Check if comparing pilot names is enough/the right way!!!!!!!
            if (!PilotCardPanel.transform.Find("PilotName").gameObject.GetComponent <UnityEngine.UI.Text>().text.Equals(MatchDatas.getPlayers()[MatchDatas.getActivePlayerIndex()].getSelectedhip().getPilot().Name.ToLower()))
            {
                guiHandler.hideGameObject(PilotCardPanel);
            }

            if (!PilotCardPanel.activeSelf)
            {
                guiHandler.showPilotCard(PilotCardPanel);
                matchHandlerService.showFiringArc(matchHandlerService.getShipHolderForShip(MatchDatas.getPlayers()[MatchDatas.getActivePlayerIndex()].getSelectedhip()));

                if (MatchDatas.getCurrentPhase() == MatchDatas.phases.PLANNING && MatchHandlerUtil.isPlayersOwnShip())
                {
                    guiHandler.showManeuverSelector(PilotCardPanel);
                }
            }
        }
        else
        {
            MatchHandlerUtil.hideActiveShipHighlighters();
            MatchHandlerUtil.hideFiringArcs();
            MatchDatas.setActiveShip(null);
            guiHandler.hideGameObject(PilotCardPanel);
        }

        if (MatchDatas.getCurrentPhase() == MatchDatas.phases.SQUADRON_PLACEMENT)
        {
            updateInfoPanel(SQUADRON_PLACEMENT_INFO);
        }

        if (MatchDatas.getCurrentPhase() == MatchDatas.phases.PLANNING)
        {
            updateInfoPanel(PLANNING_INFO);

            if (MatchHandlerUtil.maneuversPlanned())
            {
                updateInfoPanel(EMPTY_TEXT);
                PhaseHandlerService.nextPhase();
            }
        }

        if (MatchDatas.getCurrentPhase() == MatchDatas.phases.ACTIVATION)
        {
            // TODO Only show this to the current player!!
            if (availableShips.Count > 1)
            {
                foreach (LoadedShip ship in availableShips)
                {
                    foreach (GameObject go in GameObject.FindGameObjectsWithTag("SmallShipContainer"))
                    {
                        if (go.transform.GetComponent <ShipProperties>().getLoadedShip().getShip().ShipId.Equals(ship.getShip().ShipId) && go.transform.GetComponent <ShipProperties>().getLoadedShip().getPilotId() == ship.getPilotId())
                        {
                            updateInfoPanel(MULTIPLE_AVAILABLE_SHIPS_INFO);
                            MatchHandlerUtil.setShipHighlighters(go, true);
                        }
                    }
                }
            }
            else if (availableShips.Count == 1)
            {
                // DUPLICATED IN GameObjectDragAndDrop!!
                foreach (GameObject go in GameObject.FindGameObjectsWithTag("SmallShipContainer"))
                {
                    if (
                        go.transform.GetComponent <ShipProperties>().getLoadedShip().getShip().ShipId.Equals(availableShips[0].getShip().ShipId) &&
                        go.transform.GetComponent <ShipProperties>().getLoadedShip().getPilotId() == availableShips[0].getPilotId() &&
                        !go.transform.GetComponent <ShipProperties>().getLoadedShip().isHasBeenActivatedThisRound()
                        )
                    {
                        go.transform.GetComponent <ShipProperties>().getLoadedShip().setHasBeenActivatedThisRound(true);
                        StartCoroutine(GameObject.Find("ScriptHolder").GetComponent <CoroutineHandler>().MoveShipOverTime(go, go.transform.GetComponent <ShipProperties>().getLoadedShip().getPlannedManeuver()));
                    }
                }
            }
            else
            {
                updateInfoPanel(EMPTY_TEXT);
                MatchHandlerUtil.hideActiveShipHighlighters();
                PhaseHandlerService.nextPhase();
            }
        }
    }
    void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            RaycastHit hitInfo;
            target = ReturnClickedObject(out hitInfo);

            if (target != null)
            {
                if (!grabbed)
                {
                    if ((MatchDatas.getActiveShip() == null || MatchDatas.getActiveShip() != target) && target.GetComponent <ShipProperties>() != null)
                    {
                        MatchHandlerUtil.hideActiveShipHighlighters();
                        MatchHandlerUtil.hideFiringArcs();

                        LoadedShip     activeShip = new LoadedShip();
                        ShipProperties sp         = target.GetComponent <ShipProperties>();

                        activeShip = sp.getLoadedShip();

                        MatchDatas.getPlayers()[MatchDatas.getActivePlayerIndex()].setActiveShip(activeShip);
                        MatchDatas.getPlayers()[MatchDatas.getActivePlayerIndex()].setSelectedShip(activeShip);

                        MatchHandlerUtil.setShipHighlighters(target, true);
                        MatchDatas.setActiveShip(target);
                    }
                }

                if (MatchDatas.getCurrentPhase() == MatchDatas.phases.SQUADRON_PLACEMENT || MatchDatas.getCurrentPhase() == MatchDatas.phases.ASTEROIDS_PLACEMENT)
                {
                    Cursor.visible = false;
                    grabbed        = true;
                    prevPos        = target.transform.position;
                }
                else if (MatchDatas.getCurrentPhase() == MatchDatas.phases.ACTIVATION && target.GetComponent <ShipProperties>() != null)
                {
                    foreach (LoadedShip ship in MatchHandler.getAvailableShips())
                    {
                        if (
                            target.transform.GetComponent <ShipProperties>().getLoadedShip().getShip().ShipId.Equals(ship.getShip().ShipId) &&
                            target.transform.GetComponent <ShipProperties>().getLoadedShip().getPilotId() == ship.getPilotId() &&
                            !target.transform.GetComponent <ShipProperties>().getLoadedShip().isHasBeenActivatedThisRound()
                            )
                        {
                            target.transform.GetComponent <ShipProperties>().getLoadedShip().setHasBeenActivatedThisRound(true);
                            StartCoroutine(GameObject.Find("ScriptHolder").GetComponent <CoroutineHandler>().MoveShipOverTime(target, target.transform.GetComponent <ShipProperties>().getLoadedShip().getPlannedManeuver()));
                        }
                    }
                }
            }
        }

        if (Input.GetMouseButtonUp(0) && grabbed)
        {
            Cursor.visible = true;
            grabbed        = false;

            if (target.GetComponent <ShipProperties>() != null)
            {
                GameObject shipCollection = GameObject.Find("ShipCollection1");
                GameObject setupField     = GameObject.Find("Player1SetupField");

                // TODO check if this part can be simplyfied....
                if (!shipCollection.GetComponent <Collider>().bounds.Contains(target.transform.position) && !setupField.GetComponent <Collider>().bounds.Contains(target.transform.position))
                {
                    target.transform.position = prevPos;
                }
                else
                {
                    if (setupField.GetComponent <Collider>().bounds.Contains(target.transform.position) && shipCanBeMoved())
                    {
                        togglePositionConfirmButton(true);
                    }
                }

                if (!setupField.GetComponent <Collider>().bounds.Contains(target.transform.position))
                {
                    togglePositionConfirmButton(false);
                }
                // TODO check if this part can be simplyfied....
            }

            if (target.GetComponent <AsteroidProperties>() != null)
            {
                GameObject playField = GameObject.Find("Playfield");

                // TODO Check distance from playfield borders and other asteroids!!
                if (!playField.GetComponent <Collider>().bounds.Contains(target.transform.position) || isAsteroidTooClose())
                {
                    target.transform.position = prevPos;
                }
                else
                {
                    if (allAsteroidsAreInsidePlayfield())
                    {
                        togglePositionConfirmButton(true);
                    }
                }
            }
        }

        if (grabbed && MatchDatas.getCurrentPhase() == MatchDatas.phases.SQUADRON_PLACEMENT && shipCanBeMoved())
        {
            if (Input.GetAxis("Mouse ScrollWheel") > 0f) // forward
            {
                target.transform.RotateAround(target.transform.position, target.transform.TransformDirection(Vector3.up), 2.5f);
            }
            else if (Input.GetAxis("Mouse ScrollWheel") < 0f) // backwards
            {
                target.transform.RotateAround(target.transform.position, target.transform.TransformDirection(Vector3.up), -2.5f);
            }
        }
    }