Esempio n. 1
0
    public void shipSelected(LoadedShip ship)
    {
        Debug.Log("Custom event triggered!");

        GUIHandler guiHandler = new GUIHandler();

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

        guiHandler.showActiveShipsCard(ship);
    }
Esempio n. 2
0
 // To remove an upgrade, make parameter "upgrade" null
 public void addUpgradeToShip(LoadedShip ship, Upgrade upgrade, int slotId)
 {
     foreach (UpgradeSlot slot in ship.getPilot().UpgradeSlots.UpgradeSlot)
     {
         if (slot.upgradeSlotId == slotId)
         {
             slot.upgrade = upgrade;
         }
     }
 }
Esempio n. 3
0
    public bool actionHasBeenUsed(LoadedShip ship, string action)
    {
        foreach (string usedAction in ship.getPreviousActions())
        {
            if (usedAction.Equals(action))
            {
                return(true);
            }
        }

        return(false);
    }
Esempio n. 4
0
    public CustomEventBase getCustomEventAction(string action, LoadedShip owner)
    {
        switch (action)
        {
        case "asd":
            return(new EventActionWedgeAntilles(owner));

            break;

        default:
            return(null);
        }
    }
Esempio n. 5
0
    public GameObject getShipHolderForShip(LoadedShip target)
    {
        GameObject[] shipHolders = GameObject.FindGameObjectsWithTag("SmallShipContainer");

        foreach (GameObject shipHolder in shipHolders)
        {
            if (shipHolder.GetComponent <ShipProperties>().getLoadedShip().Equals(target))
            {
                return(shipHolder);
            }
        }

        return(null);
    }
Esempio n. 6
0
    public void removePilotFromSquadron(Pilot pilot, int pilotId)
    {
        //TODO Test if only one ship gets deleted when pilot is not unique!!
        LoadedShip shipToRemove = new LoadedShip();

        foreach (LoadedShip ls in this.squadron)
        {
            if (ls.getPilot().Name.Equals(pilot.Name) && ls.getPilotId() == pilotId)
            {
                shipToRemove = ls;
                break;
            }
        }

        this.squadron.Remove(shipToRemove);
    }
Esempio n. 7
0
    public void showActiveShipsCard(LoadedShip ship)
    {
        Transform shipCardPrefab = Resources.Load <Transform>(PREFAB_FOLDER_NAME);
        Sprite    shipSprite     = Resources.Load <Sprite>(IMAGE_FOLDER_NAME + "/" + ship.getShip().ShipName.Replace("/", ""));

        Transform shipCard = (Transform)GameObject.Instantiate(
            shipCardPrefab,
            new Vector3(100, 100, 0),
            Quaternion.identity
            );

        shipCard.transform.SetParent(TargetCanvas.transform, false);
        shipCard.transform.Find("Ship Name").gameObject.GetComponent <UnityEngine.UI.Text>().text         = ship.getShip().ShipName.ToString();
        shipCard.transform.Find("Ship Image").gameObject.GetComponent <Image>().sprite                    = shipSprite;
        shipCard.transform.Find("Attack Power Text").gameObject.GetComponent <UnityEngine.UI.Text>().text = ship.getShip().Weapon.ToString();
        shipCard.transform.Find("Agility Text").gameObject.GetComponent <UnityEngine.UI.Text>().text      = ship.getShip().Agility.ToString();
        shipCard.transform.Find("Hull Text").gameObject.GetComponent <UnityEngine.UI.Text>().text         = ship.getShip().Hull.ToString();
        shipCard.transform.Find("Shield Text").gameObject.GetComponent <UnityEngine.UI.Text>().text       = ship.getShip().Shield.ToString();
    }
Esempio n. 8
0
    public void addPilotToSquadron(Pilot pilot)
    {
        bool   canAddPilot = true;
        bool   duplicate   = false;
        string errorMsg    = "";

        foreach (LoadedShip ls in this.squadron)
        {
            if (ls.getPilot().Name.Equals(pilot.Name))
            {
                duplicate = true;
            }
        }

        if (pilot.Unique && duplicate)
        {
            canAddPilot = false;
            errorMsg    = "The selected pilot is unique and has already been added to your squadron!";
        }

        if ((getCumulatedSquadPoints() + pilot.Cost) > this.pointsToSpend)
        {
            canAddPilot = false;
            errorMsg    = "The selected pilot's cost is too high to fit into your current squadron!";
        }

        if (canAddPilot)
        {
            LoadedShip ls = new LoadedShip();
            ls.setShip(this.selectedEmptyShip);
            ls.setPilot(pilot);
            ls.setPilotId(this.currentPilotId);

            squadron.Add(ls);

            currentPilotId++;
        }
        else
        {
            throw new System.ApplicationException(errorMsg);
        }
    }
Esempio n. 9
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++;
                }
            }
        }
    }
Esempio n. 10
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);
            }
        }
    }
Esempio n. 11
0
 public void setShip(LoadedShip ship)
 {
     this.ship = ship;
 }
Esempio n. 12
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);
    }
Esempio n. 13
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);
    }
Esempio n. 14
0
 public void hideActiveShipsCard(LoadedShip ship)
 {
 }
 public EventActionWedgeAntilles(LoadedShip owner) : base(owner, owner.getPilot().Name)
 {
 }
Esempio n. 16
0
 public void setChosenLoadedShip(LoadedShip ship)
 {
     this.chosenLoadedShip = ship;
 }
Esempio n. 17
0
 public void setSelectedShip(LoadedShip ship)
 {
     this.selectedShip = ship;
 }
Esempio n. 18
0
 public void setActiveShip(LoadedShip ship)
 {
     this.activeShip = ship;
 }
Esempio n. 19
0
 public void setTarget(LoadedShip pTarget)
 {
     this.target = pTarget;
 }
Esempio n. 20
0
 public CustomEventBase(LoadedShip pOwner, string pName)
 {
     owner = pOwner;
     name  = pName;
 }
Esempio n. 21
0
 public EventActionExpertHandling(LoadedShip owner) : base(owner, "Expert handling")
 {
 }