Beispiel #1
0
 internal bool IsSettingRallyPoint()
 {
     if (selectedLymphNodeForRallyPoint != null && selectedLymphNodeForRallyPoint.GetTowerComponent() as MeleeTower != null)
     {
         return(((MeleeTower)selectedLymphNodeForRallyPoint.GetTowerComponent()).IsSettingRallyPoint());
     }
     return(false);
 }
Beispiel #2
0
    /// <summary> Sells (destroys) the tower built on the currently selected lymph node,
    /// and returns money to the player. </summary>
    /// <remark>Throws an exception if there is no lymph node selected or if there is no tower on it.</remark>
    internal void SellTower()
    {
        if (selectedLymphNode == null || selectedLymphNode.IsVacant())
        {
            throw new Exception("Error! There's no selected lymph node or no tower on it.");
        }

        Tower currentTowerComponent = selectedLymphNode.GetTowerComponent();

        if (currentTowerComponent == null)
        {
            throw new Exception("Error! This lymph node's tower is null.");
        }

        Player.AddMoney(currentTowerComponent.GetCurrentSellValue());
        selectedLymphNode.DestroyTower();
        DeselectLymphNode();
    }
Beispiel #3
0
    internal GameObject ShowInfoPanel(Transform menu, SelectedAction sa, Tower newTower)
    {
        GameObject infoPanel = Instantiate(menuSelectionInfoPrefab, new Vector3(0f, 0f, -1.2f), activeGameUIPanel.rotation);

        // set the menu as this panel's parent (so that it scrolls together with it)
        infoPanel.transform.SetParent(menu, false);

        ///////////////////////////

        // gather the data for the info panel
        string name        = "";
        string description = "";
        int    cost        = 0;
        int    level       = -1;
        int    maxLevel    = -1;
        //int health = -1;
        float damage  = -1;
        int   defense = -1;

        LymphNode selectedLymphNode = null;
        Tower     currentTower      = null;

        switch (sa)
        {
        case SelectedAction.BuildTower1:
        case SelectedAction.BuildTower2:
        case SelectedAction.BuildTower3:
        case SelectedAction.BuildTower4:
        {
            if (newTower != null)
            {
                name        = newTower.towerName;
                description = newTower.description;
                level       = 1;   // todo: does this even make sense? towers should always start at level 1
                cost        = newTower.GetBaseLevelCost();
                maxLevel    = newTower.GetNumberOfLevels();
                //health = newTower.GetBaseLevelHealth();
                damage = newTower.GetBaseLevelDamage();
                //defense = newTower.getDefen
            }
        }
        break;

        case SelectedAction.SellTower:
        {
            selectedLymphNode = BuildManager.instance.GetSelectedLymphNode();
            if (selectedLymphNode != null)
            {
                currentTower = selectedLymphNode.GetTowerComponent();
            }
            if (currentTower != null)
            {
                name        = "Sell tower";
                cost        = -currentTower.GetCurrentSellValue();
                description = "Sell this tower. You will receive " + (-cost) + " ATP, and you'll be able to build another tower on the same spot.";
            }
        }
        break;

        case SelectedAction.UpgradeTower:
        {
            selectedLymphNode = BuildManager.instance.GetSelectedLymphNode();

            if (selectedLymphNode != null)
            {
                currentTower = selectedLymphNode.GetTowerComponent();
            }
            if (currentTower != null)
            {
                name        = currentTower.GetNextLevelName();
                description = currentTower.GetNextLevelDescription();
                cost        = currentTower.GetNextLevelCost();
                level       = currentTower.GetCurrentLevel() + 1;
                maxLevel    = currentTower.GetNumberOfLevels();
                //health = currentTower.GetNextLevelHealth();
                damage = currentTower.GetNextLevelDamage();
                //defense = tower1.GetNextLevelDe();
            }
        }
        break;
        }

        //infoPanel.GetComponent<InfoPanel>().SetAll(name, description, level, maxLevel, cost, health, damage, defense);
        infoPanel.GetComponent <InfoPanel>().SetAll(name, description, level, maxLevel, cost, damage, defense);

        ///////////////////////////

        // no conversion is done now, because param menu is already a UI element
        RectTransform panelRT = infoPanel.GetComponent <RectTransform>();
        RectTransform menuRT  = menu.GetComponent <RectTransform>();

        // calculate the panel's x position so that it appears to the right of the menu
        float panelHalfWidth = panelRT.sizeDelta.x / 2;
        float menuHalfWidth  = menuRT.sizeDelta.x / 2;
        float xPos           = menuHalfWidth + panelHalfWidth;

        // if there's not enough space on the right, show it on the left
        // i.e. if the panel's width is longer than the space between xPos and right screen boundary
        Canvas canvas = activeGameUIPanel.parent.GetComponent <Canvas>(); // this assumes that this panel is the child of the top-level UI panel
        // calculate the right end of the panel as menuPosX + panelPosX + panelWidth
        // however, the UI elements are scalable according to screen size, so their size needs to be multiplied by the scaleFactor
        float panelRight = menuRT.localPosition.x + (canvas.scaleFactor * xPos) + (canvas.scaleFactor * panelRT.sizeDelta.x);

        if (panelRight > Screen.width / 2f)
        {
            xPos = 0 - menuHalfWidth - panelHalfWidth;
        }

        panelRT.localPosition = new Vector3(xPos, panelRT.localPosition.y, menu.position.z);

        return(infoPanel);
    }