Ejemplo n.º 1
0
    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);
    }
Ejemplo n.º 2
0
 public override void cleanup()
 {
     if (MatchDatas.getPlayers()[MatchDatas.getActivePlayerIndex()].getActiveShip().Equals(owner))
     {
         owner.getTarget().getShip().Agility++;
     }
 }
Ejemplo n.º 3
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;
    }
Ejemplo n.º 4
0
    private static void startPlanningPhase()
    {
        MatchDatas.setCurrentPhase(MatchDatas.phases.PLANNING);

        MatchHandlerUtil.hideForceFields();
        MatchHandlerUtil.deleteSelectedManeuvers();
        MatchHandlerUtil.setAIManeuvers();
    }
Ejemplo n.º 5
0
 public static void endActionPhase()
 {
     if (MatchDatas.getCurrentPhase().Equals(MatchDatas.phases.ACTION) && !prevPhase.Equals(MatchDatas.phases.NONE))
     {
         MatchDatas.setCurrentPhase(prevPhase);
         prevPhase = MatchDatas.phases.NONE;
     }
 }
Ejemplo n.º 6
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);
    }
Ejemplo n.º 7
0
    public void shipSelected(LoadedShip ship)
    {
        Debug.Log("Custom event triggered!");

        GUIHandler guiHandler = new GUIHandler();

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

        guiHandler.showActiveShipsCard(ship);
    }
Ejemplo n.º 8
0
 public override void doEventAction()
 {
     if (MatchDatas.getPlayers()[MatchDatas.getActivePlayerIndex()].getActiveShip().Equals(owner))
     {
         if (owner.getTarget().getShip().Agility - 1 > 0)
         {
             owner.getTarget().getShip().Agility--;
         }
     }
 }
Ejemplo n.º 9
0
 public static void deleteSelectedManeuvers()
 {
     foreach (Player player in MatchDatas.getPlayers())
     {
         foreach (LoadedShip ship in player.getSquadron())
         {
             ship.setPlannedManeuver(null);
         }
     }
 }
Ejemplo n.º 10
0
    private static bool isMatchOver()
    {
        foreach (Player player in MatchDatas.getPlayers())
        {
            if (player.isDefeated())
            {
                return(true);
            }
        }

        return(false);
    }
Ejemplo n.º 11
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);
    }
Ejemplo n.º 12
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]);
             }
         }
     }
 }
Ejemplo n.º 13
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++;
            }
            ;
        }
    }
Ejemplo n.º 14
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"));
            }
        }
    }
Ejemplo n.º 15
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);
    }
Ejemplo n.º 16
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);
    }
Ejemplo n.º 17
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);
    }
Ejemplo n.º 18
0
    void OnMouseDrag()
    {
        if (target == null)
        {
            RaycastHit hitInfo;
            target = ReturnClickedObject(out hitInfo);
        }

        float moveX = Input.GetAxis("Mouse X");
        float moveY = Input.GetAxis("Mouse Y");

        if (target.GetComponent <ShipProperties>() != null)
        {
            if (MatchDatas.getCurrentPhase() == MatchDatas.phases.SQUADRON_PLACEMENT && shipCanBeMoved())
            {
                Vector3 newPos = new Vector3(transform.position.x + (moveX * dragSpeedMultiplier), transform.position.y, transform.position.z + (moveY * dragSpeedMultiplier));

                transform.position = newPos;

                /*Prototype to highlight setup field boundaries when ship is not inside them. POLISH!!!!*/
                if (!GameObject.Find("Player1SetupField").GetComponent <Collider>().bounds.Contains(target.transform.position))
                {
                    GameObject.Find("Player1SetupField/New Sprite").gameObject.GetComponent <SpriteRenderer>().color = new Color(1.0f, 0.0f, 0.0f, 0.31f);
                }
                else
                {
                    GameObject.Find("Player1SetupField/New Sprite").gameObject.GetComponent <SpriteRenderer>().color = new Color(1.0f, 1.0f, 1.0f, 0.31f);
                }
                /*Prototype to highlight setup field boundaries when ship is not inside them. POLISH!!!!*/
            }
        }

        if (target.GetComponent <AsteroidProperties>() != null)
        {
            if (MatchDatas.getCurrentPhase() == MatchDatas.phases.ASTEROIDS_PLACEMENT && asteroidCanBeMoved())
            {
                Vector3 newPos = new Vector3(transform.position.x + (moveX * dragSpeedMultiplier), transform.position.y, transform.position.z + (moveY * dragSpeedMultiplier));

                transform.position = newPos;
            }
        }
    }
Ejemplo n.º 19
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);
        }
    }
Ejemplo n.º 20
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);
    }
Ejemplo n.º 21
0
    // TODO Make this class handle all phase changes and the required checks, cleanups, inits, etc.....

    public static void nextPhase()
    {
        Debug.Log("Initiating next phase from " + MatchDatas.getCurrentPhase());
        switch (MatchDatas.getCurrentPhase())
        {
        case MatchDatas.phases.INITIATIVE_ROLL:
            startAsteroidPlacementPhase();
            break;

        case MatchDatas.phases.ASTEROIDS_PLACEMENT:
            startSquadronPlacementPhase();
            break;

        case MatchDatas.phases.SQUADRON_PLACEMENT:
            startPlanningPhase();
            break;

        case MatchDatas.phases.PLANNING:
            startActivationPhase();
            break;

        case MatchDatas.phases.ACTIVATION:
            startAttackPhase();
            break;

        case MatchDatas.phases.ATTACK:
            startEndPhase();
            break;

        case MatchDatas.phases.END:
            if (!isMatchOver())
            {
                startPlanningPhase();
            }
            else
            {
                // TODO Finish game!
            }
            break;
        }
    }
Ejemplo n.º 22
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);
    }
Ejemplo n.º 23
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++;
                }
            }
        }
    }
Ejemplo n.º 24
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);
        }
    }
Ejemplo n.º 25
0
 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);
 }
Ejemplo n.º 26
0
 private static void startSquadronPlacementPhase()
 {
     MatchDatas.setCurrentPhase(MatchDatas.phases.SQUADRON_PLACEMENT);
     MatchHandler.collectUpcomingAvailableShips(true);
 }
Ejemplo n.º 27
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);
    }
Ejemplo n.º 28
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);
     }
 }
Ejemplo n.º 29
0
    public void mockPlayerSquadrons()
    {
        Ships  ships  = XMLLoader.getShips("rebel_ships.xml");
        Pilots pilots = XMLLoader.getPilots("t65xw_pilots.xml");

        LoadedShip ship1 = new LoadedShip();

        ship1.setShip(ships.Ship[0]);
        ship1.setPilot(pilots.Pilot[0]);
        //Adding event actions to be registered for event handling.
        //TODO Is the input parameter correct/enough??????
        ship1.addEventAction(new EventActionWedgeAntilles(ship1));

        LoadedShip ship2 = new LoadedShip();

        ship2.setShip(ships.Ship[0]);
        ship2.setPilot(pilots.Pilot[1]);
        ship2.getPilot().Level = ship1.getPilot().Level;

        //List<LoadedShip> squadron1 = new List<LoadedShip>();

        /*foreach (LoadedShip ship in LocalDataWrapper.getPlayer().getSquadron())
         * {
         *  squadron1.Add(ship);
         *
         *  //Registering event actions...
         *  foreach (CustomEventBase eventAction in ship.getEventActions())
         *  {
         *      EventActionRegister.registerEventAction(eventAction);
         *  }
         * }*/

        LocalDataWrapper.getPlayer().setChosenSide("Rebels");
        LocalDataWrapper.getPlayer().setPLayerID(1);
        LocalDataWrapper.getPlayer().setAI(false);

        if (LocalDataWrapper.getPlayer().getSquadron() == null || LocalDataWrapper.getPlayer().getSquadron().Count == 0)
        {
            LocalDataWrapper.getPlayer().setSelectedEmptyShip(ship1.getShip());
            LocalDataWrapper.getPlayer().addPilotToSquadron(ship1.getPilot());

            LocalDataWrapper.getPlayer().setSelectedEmptyShip(ship2.getShip());
            LocalDataWrapper.getPlayer().addPilotToSquadron(ship2.getPilot());

            //LocalDataWrapper.getPlayer().setSquadron(squadron1);
        }

        //AI PLAYER!!
        Player player2 = new Player();

        player2.setChosenSide("Empire");
        player2.setPlayerName("AI Player");
        player2.setPLayerID(2);

        Ships  ships2  = XMLLoader.getShips("imperial_ships.xml");
        Pilots pilots2 = XMLLoader.getPilots("tief_pilots.xml");

        LoadedShip ship3 = new LoadedShip();

        ship3.setShip(ships2.Ship[0]);
        ship3.setPilot(pilots2.Pilot[0]);
        player2.setSelectedEmptyShip(ship3.getShip());
        player2.addPilotToSquadron(ship3.getPilot());

        LoadedShip ship4 = new LoadedShip();

        ship4.setShip(ships2.Ship[0]);
        ship4.setPilot(pilots2.Pilot[1]);
        player2.setSelectedEmptyShip(ship4.getShip());
        player2.addPilotToSquadron(ship4.getPilot());

        LoadedShip ship5 = new LoadedShip();

        ship5.setShip(ships2.Ship[0]);
        ship5.setPilot(pilots2.Pilot[2]);
        player2.setSelectedEmptyShip(ship5.getShip());
        player2.addPilotToSquadron(ship5.getPilot());

        LoadedShip ship6 = new LoadedShip();

        ship6.setShip(ships2.Ship[0]);
        ship6.setPilot(pilots2.Pilot[0]);
        player2.setSelectedEmptyShip(ship6.getShip());
        player2.addPilotToSquadron(ship6.getPilot());

        LoadedShip ship7 = new LoadedShip();

        ship7.setShip(ships2.Ship[0]);
        ship7.setPilot(pilots2.Pilot[0]);
        player2.setSelectedEmptyShip(ship7.getShip());
        player2.addPilotToSquadron(ship7.getPilot());

        LoadedShip ship8 = new LoadedShip();

        ship8.setShip(ships2.Ship[0]);
        ship8.setPilot(pilots2.Pilot[0]);
        player2.setSelectedEmptyShip(ship8.getShip());
        player2.addPilotToSquadron(ship8.getPilot());

        player2.setAI(true);

        MatchDatas.addPlayer(LocalDataWrapper.getPlayer());
        MatchDatas.addPlayer(player2);
    }
Ejemplo n.º 30
0
    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);
            }
        }
    }