private bool shipCanBeMoved()
    {
        bool result          = false;
        bool shipIsAvailable = false;

        if (MatchDatas.getActiveShip() != null)
        {
            foreach (LoadedShip ship in MatchHandler.getAvailableShips())
            {
                if (ship.getPilotId() == MatchDatas.getActiveShip().GetComponent <ShipProperties>().getLoadedShip().getPilotId())
                {
                    shipIsAvailable = true;
                }
            }

            if (shipIsAvailable && isPlayersOwnShip())
            {
                if (
                    MatchDatas.getActiveShip().GetComponent <ShipProperties>().isMovable() &&
                    !MatchDatas.getActiveShip().GetComponent <ShipProperties>().getLoadedShip().isHasBeenActivatedThisRound()
                    )
                {
                    result = true;
                }
            }
        }

        return(result);
    }
Exemple #2
0
    public void showManeuverSelector(GameObject target)
    {
        resetManeuverSelector();

        // TODO Check why this throws NullReferenceException!!

        /*foreach (Transform child in PilotCardPanel.transform.Find("ShipDataManeuvers/ShipManeuvers"))
         * {
         *  if (child.Find("Image").gameObject.GetComponent<ManeuverSelectionEvent>() != null)
         *  {
         *      Destroy(child.Find("Image").gameObject.GetComponent<ManeuverSelectionEvent>());
         *  }
         * }*/

        // DUPLACTE FRAGMENT!!!!! (also in squadron builder!)
        foreach (Maneuver maneuver in MatchDatas.getActiveShip().GetComponent <ShipProperties>().getLoadedShip().getShip().Maneuvers.Maneuver)
        {
            Image  image              = null;
            Sprite sprite             = Resources.Load <Sprite>(SquadBuilderConstants.IMAGE_FOLDER_NAME + "/" + maneuver.Bearing + "_" + maneuver.Difficulty);
            string maneuverHolderName = maneuver.Speed + "_" + maneuver.Bearing;
            string maneuverHolderPath = "ShipDataManeuvers/ShipManeuvers/Speed" + maneuverHolderName;

            // Maneuver overlay not showing!! Check why....
            Maneuver selectedManeuver = MatchDatas.getActiveShip().GetComponent <ShipProperties>().getLoadedShip().getPlannedManeuver();
            bool     isSelected       = false;

            if (selectedManeuver != null && maneuver.Speed.Equals(selectedManeuver.Speed) && maneuver.Bearing.Equals(selectedManeuver.Bearing))
            {
                isSelected = true;
            }

            if (maneuverHolderName.Contains("koiogran") || maneuverHolderName.Contains("segnor") || maneuverHolderName.Contains("tallon"))
            {
                if (maneuverHolderName.Contains("right"))
                {
                    maneuverHolderPath = "ShipDataManeuvers/ShipManeuvers/Speed" + maneuver.Speed + "_special_right";
                }
                else
                {
                    maneuverHolderPath = "ShipDataManeuvers/ShipManeuvers/Speed" + maneuver.Speed + "_special_left";
                }
            }

            target.transform.Find(maneuverHolderPath + "/Image").gameObject.GetComponent <Image>().sprite = sprite;
            target.transform.Find(maneuverHolderPath + "/Image").gameObject.AddComponent <ManeuverSelectionEvent>();
            target.transform.Find(maneuverHolderPath + "/Image").gameObject.GetComponent <ManeuverSelectionEvent>().setManeuver(maneuver);
            image = target.transform.Find(maneuverHolderPath + "/Image").gameObject.GetComponent <Image>();
            target.transform.Find(maneuverHolderPath + "/ManeuverOverlay").gameObject.SetActive(isSelected);

            if (image != null)
            {
                image.color = new Color(image.color.r, image.color.g, image.color.b, 1.0f);
            }
        }

        target.transform.Find("ShipDataManeuvers").gameObject.SetActive(true);
    }
Exemple #3
0
    // DUPLICATED FRAGMENT!!!
    public static bool isPlayersOwnShip()
    {
        foreach (LoadedShip ship in LocalDataWrapper.getPlayer().getSquadron())
        {
            if (ship.getPilotId() == MatchDatas.getActiveShip().GetComponent <ShipProperties>().getLoadedShip().getPilotId())
            {
                return(true);
            }
        }

        return(false);
    }
Exemple #4
0
    private void setShipLocation()
    {
        MatchDatas.getActiveShip().GetComponent <ShipProperties>().setMovable(false);
        MatchDatas.getActiveShip().GetComponent <ShipProperties>().getLoadedShip().setHasBeenActivatedThisRound(true);

        bool allShipsActivated = true;

        foreach (LoadedShip ship in MatchHandler.getAvailableShips())
        {
            if (!ship.isHasBeenActivatedThisRound())
            {
                allShipsActivated = false;
            }
        }

        if (allShipsActivated)
        {
            MatchHandler.collectUpcomingAvailableShips(true);
        }
    }
    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);
            }
        }
    }
 public void OnPointerClick(PointerEventData eventData)
 {
     Debug.Log("Selected maneuver: " + maneuver.Speed + " - " + maneuver.Bearing);
     MatchDatas.getActiveShip().GetComponent <ShipProperties>().getLoadedShip().setPlannedManeuver(this.maneuver);
     MatchHandler.handleManeuverSelection(this.maneuver);
 }