Esempio n. 1
0
    public void updateHangar(Hangar hangar)
    {
        SetShips(hangar.GetHangar());
        List <GameObject> activeFleet = hangar.GetFleetList();

        for (int i = 0; i < activeFleet.Count; i++)
        {
            if (activeFleet[i].GetComponent <Ship>().isOnActiveFleet)
            {
                activeFleet[i].GetComponent <Ship>().isOnActiveFleet = false;
            }
        }
        updateSlots();
    }
Esempio n. 2
0
    public void LoadPlayerShips()
    {
        Hangar _hangar = PersistantDataManager.Instance.GetPlayerHangar();

        pShipsToLoad = _hangar.GetFleetList();
        if (_hangar.GetShipList() == null)
        {
            print("ship values in fleet are null");
        }
        for (int i = 0; i < pShipsToLoad.Count; i++)
        {
            Debug.Log("Ship to load is: " + pShipsToLoad[i].name);
            pShipsToLoad[i].SetActive(true);
            pShipsToLoad[i].gameObject.transform.position = PShipPos[i].position;
            pShipsToLoad[i].gameObject.transform.rotation = PShipPos[i].rotation;
            GameObject ship = pShipsToLoad[i];
            ship.GetComponent <Ship>().Side = 1;
        }
    }
Esempio n. 3
0
    IEnumerator SelectTarget(Ship _ship, bool isComputerShip, bool isReselect)
    {
        print("selecting target for" + _ship + " " + isComputerShip);
        if (!isComputerShip)
        {
            if (isReselect)
            {
                text.text = _ship.name + "'s target died reselect your target";
            }
            else if (_ship is SupportClass)
            {
                text.text = "which target would you like: " + _ship.name + " to heal?";
            }
            else
            {
                text.text = "which target would you like: " + _ship.name + " to attack?";
            }
        }
        computerFleet = computer.hangar.GetFleet();
        playerFleet   = playerHangar.GetFleet();

        //target selection
        List <GameObject> attacking    = new List <GameObject>();
        List <GameObject> aliveTargets = new List <GameObject>();
        List <GameObject> defending    = new List <GameObject>();
        List <GameObject> aliveAllies  = new List <GameObject>();



        if (isComputerShip)
        {
            attacking    = checkAttack(playerFleet);
            defending    = checkDefence(playerFleet);
            aliveTargets = playerHangar.GetFleetList();
            aliveAllies  = computer.hangar.GetFleetList();
        }
        else
        {
            attacking    = checkAttack(computerFleet);
            defending    = checkDefence(computerFleet);
            aliveTargets = computer.hangar.GetFleetList();
            aliveAllies  = playerHangar.GetFleetList();
        }

        if (_ship is SwarmClass || _ship is StealthClass)
        {
            _ship.AddTargets(aliveTargets);
        }
        else if (_ship.state == Ship.State.heal)
        {
            _ship.AddTargets(aliveAllies);
        }
        else if (!isComputerShip)
        {
            if (defending.Count >= 1)
            {
                _ship.AddTargets(defending);
            }
            else
            {
                _ship.AddTargets(attacking);
            }
        }

        //get list of possible targets for the ship to select a target for
        List <Ship> shipTargets = new List <Ship>();

        foreach (KeyValuePair <string, GameObject> element in _ship.GetTargets())
        {
            shipTargets.Add(element.Value.GetComponent <Ship>());
        }

        if (_ship is SwarmClass)
        {
            List <string> t = new List <string>();
            foreach (Ship s in shipTargets)
            {
                print("selecting all targets for swarmclass");
                t.Add(s.name);
            }
            _ship.SelectTargets(t);
        }
        else
        {
            //random computer selection
            if (isComputerShip)
            {
                computer.targetSelection(_ship, playerHangar.GetShipList());
            }
            //the logic for activating and deactivating the buttons for each targetable ship
            else
            {
                foreach (Ship s in shipTargets)
                {
                    //activate the button for each targetable ship
                    s.activateButton();
                    s.setButtonText(s.name);
                    s.onTargetPress.AddListener(_ship.OnTargetSelectionCallback);
                }
            }
            while (_ship.GetSelectedTargets().Count < 1)
            {
                yield return(null);
            }

            foreach (Ship s in shipTargets)
            {
                //deactivate the button for each ship
                s.deactivateButton();
                s.onTargetPress.RemoveAllListeners();
            }
        }

        yield return(new WaitForSeconds(1));

        text.text = string.Empty;
    }