Exemplo n.º 1
0
    //enable tooltip menu and disable upgrade menu if active
    public void ShowTooltipMenu(int index)
    {
        //fade in tooltip panel, fade out upgrade panel
        gui.StartCoroutine("FadeIn", panels.tooltip);
        gui.StartCoroutine("FadeOut", panels.upgradeMenu);
        //toggle upgrade menu visibility value
        SV.showUpgrade = false;
        CancelInvoke("UpdateUpgradeMenu");

        TowerBase  baseOptions = null;
        UpgOptions upgOptions  = null;

        //store tower base properties from TowerManager lists,
        //also store necessary upgrade option info for later use
        //(in case we haven't instantiated a tower because it
        //wasn't affordable, we can't access an instance and
        //have to use these components pre-stored in TowerManager.cs)
        if (SV.selection)
        {
            baseOptions = gui.towerBase;
            upgOptions  = gui.upgrade.options[0];
        }
        else
        {
            baseOptions = gui.towerScript.towerBase[index];
            upgOptions  = gui.towerScript.towerUpgrade[index].options[0];
        }

        //set all information related to tower properties,
        //such as tower name, properties and initial price
        labels.headerName.text = gui.towerScript.towerNames[index];
        labels.properties.text = "Projectile:" + "\n" +
                                 "Radius:" + "\n" +
                                 "Damage:" + "\n" +
                                 "Delay:" + "\n" +
                                 "Targets:";
        //visualize current tower stats
        labels.stats.text = baseOptions.projectile.name + "\n" +
                            upgOptions.radius + "\n" +
                            upgOptions.damage + "\n" +
                            upgOptions.shootDelay + "\n" +
                            baseOptions.myTargets;

        //set visible label price text for each resource
        for (int i = 0; i < GameHandler.resources.Length; i++)
        {
            labels.price[i].text = "$" + upgOptions.cost[i];
        }
    }
Exemplo n.º 2
0
    //remove the current powerup, undo all the changes
    //see the previous method PowerUpBoost() for comments
    void RemovePowerUp()
    {
        shotAngle         /= powerup.buff.shotAngle;
        controlMultiplier /= powerup.buff.controlMultiplier;

        for (int i = 0; i < upgrade.options.Count; i++)
        {
            UpgOptions opt = upgrade.options[i];
            opt.radius      += tempOptions[i].radius;
            opt.damage      += tempOptions[i].damage;
            opt.shootDelay  += tempOptions[i].shootDelay;
            opt.targetCount += tempOptions[i].targetCount;
        }

        //unspawn buff fx if we instantiated one
        if (tempPowerup.buffFx)
        {
            PoolManager.Pools["Particles"].Despawn(tempPowerup.buffFx);
        }

        upgrade.RangeChange();

        //restart shot timer, again
        CancelInvoke("CheckRange");
        float newDelay   = upgrade.options[upgrade.curLvl].shootDelay;
        float remainTime = lastShot + newDelay - Time.time;

        if (remainTime < 0)
        {
            remainTime = 0;
        }

        if (remainTime > newDelay)
        {
            StartInvoke(newDelay);
        }
        else
        {
            StartInvoke(remainTime);
        }
        //unset powerup references
        powerup     = null;
        tempPowerup = null;
    }
Exemplo n.º 3
0
    IEnumerator PowerUpBoost()
    {
        //Debug.Log("buff started: " + Time.time);

        //buff TowerBase variables
        shotAngle         *= powerup.buff.shotAngle;
        controlMultiplier *= powerup.buff.controlMultiplier;
        //create new powerup instance for cleaning up later
        tempPowerup = new DefensivePowerUp();
        tempOptions = new List <UpgOptions>();
        //iterate over upgrade settings and buff every option in each level
        //(even if the user upgrades a tower, this will still ensure buffed values)
        for (int i = 0; i < upgrade.options.Count; i++)
        {
            UpgOptions opt = upgrade.options[i];
            tempOptions.Add(new UpgOptions());
            tempOptions[i].radius      = opt.radius;
            tempOptions[i].damage      = opt.damage;
            tempOptions[i].shootDelay  = opt.shootDelay;
            tempOptions[i].targetCount = opt.targetCount;
            //first cache buff difference, then set new values
            //when the buff ends we substract the difference again
            tempOptions[i].radius      -= opt.radius *= powerup.buff.radius;
            tempOptions[i].damage      -= opt.damage *= powerup.buff.damage;
            tempOptions[i].shootDelay  -= opt.shootDelay /= powerup.buff.shootDelay;
            tempOptions[i].targetCount -= opt.targetCount += powerup.buff.targetCount;
        }

        //if an effect is set, spawn buff fx and
        //cache the particle gameobject reference in our temporary instance
        if (powerup.buffFx)
        {
            tempPowerup.buffFx = PoolManager.Pools["Particles"].Spawn(powerup.buffFx, transform.position, Quaternion.identity);
        }

        //update tower range collider/indicator
        upgrade.RangeChange();

        //restart shot timer with new values (shootDelay)
        CancelInvoke("CheckRange");
        float newDelay = upgrade.options[upgrade.curLvl].shootDelay;
        //calculate time when this tower can shoot again
        float remainTime = lastShot + newDelay - Time.time;

        if (remainTime < 0)
        {
            remainTime = 0;
        }
        //and take the minimum value as new invoke delay
        if (remainTime > newDelay)
        {
            StartInvoke(newDelay);
        }
        else
        {
            StartInvoke(remainTime);
        }

        //wait until the powerup is over before removing it
        yield return(new WaitForSeconds(powerup.duration));

        RemovePowerUp();

        //Debug.Log("buff ended: " + Time.time);
    }
Exemplo n.º 4
0
    public void ApplyToTower(TowerBase tBase, Upgrade upg)
    {
        //only affect selected towers
        if (!selectedTowers.Contains(tBase.transform.parent.name))
        {
            return;
        }

        //TowerBase variables
        //target type
        if (towerProperties.targets.enabled)
        {
            tBase.myTargets = towerProperties.targets.type;
        }
        //shot angle
        if (towerProperties.shotAngle.enabled)
        {
            if (towerProperties.shotAngle.type == TDValue.fix)
            {
                tBase.shotAngle += towerProperties.shotAngle.value;
            }
            else
            {
                tBase.shotAngle = Round(tBase.shotAngle, towerProperties.shotAngle.value);
            }
        }
        //control multiplier
        if (towerProperties.controlMultiplier.enabled)
        {
            if (towerProperties.controlMultiplier.type == TDValue.fix)
            {
                tBase.controlMultiplier += towerProperties.controlMultiplier.value;
            }
            else
            {
                tBase.controlMultiplier = Round(tBase.controlMultiplier, towerProperties.controlMultiplier.value);
            }
        }

        //Upgrade variables, looping through all upgrades
        for (int i = 0; i < upg.options.Count; i++)
        {
            //cache current option
            UpgOptions cur = upg.options[i];

            //damage
            if (towerProperties.damage.enabled)
            {
                if (towerProperties.damage.type == TDValue.fix)
                {
                    cur.damage += towerProperties.damage.value;
                }
                else
                {
                    cur.damage = Round(cur.damage, towerProperties.damage.value);
                }
            }

            //radius
            if (towerProperties.radius.enabled)
            {
                if (towerProperties.radius.type == TDValue.fix)
                {
                    cur.radius += towerProperties.radius.value;
                }
                else
                {
                    cur.radius = Round(cur.radius, towerProperties.radius.value);
                }
            }

            //shot delay
            if (towerProperties.shotDelay.enabled)
            {
                if (towerProperties.shotDelay.type == TDValue.fix)
                {
                    cur.shootDelay += towerProperties.shotDelay.value;
                }
                else
                {
                    cur.shootDelay = Round(cur.shootDelay, towerProperties.shotDelay.value);
                }
            }

            //target count
            if (towerProperties.targetCount.enabled)
            {
                cur.targetCount += towerProperties.targetCount.value;
            }

            //cost
            if (towerProperties.cost.enabled)
            {
                float curValue = towerProperties.cost.initialValue;
                if (i > 0)
                {
                    curValue = towerProperties.cost.value;
                }

                for (int j = 0; j < cur.cost.Length; j++)
                {
                    if (towerProperties.cost.type == TDValue.fix)
                    {
                        cur.cost[j] += curValue;
                    }
                    else if (towerProperties.cost.costType == CostType.intValue)
                    {
                        cur.cost[j] = (int)(cur.cost[j] * curValue);
                    }
                    else
                    {
                        cur.cost[j] = Round(cur.cost[j], curValue);
                    }
                }
            }
        }

        //update tower range collider
        if (towerProperties.radius.enabled)
        {
            upg.RangeChange();
        }
    }
Exemplo n.º 5
0
    //calculation method for auto-fill
    void Overwrite()
    {
        //abort without upgrade script
        if (script == null)
        {
            Debug.LogWarning("UpgradeHelper: Upgrade script has not been set. Aborting.");
            return;
        }

        //break prefab connection before applying new values,
        //because starting the game (play mode) would reset them on prefabs
        PrefabUtility.DisconnectPrefabInstance(script.gameObject);
        //remove existing upgrade levels and values
        script.options.Clear();

        //create initial option (first level)
        //and add it to the script
        UpgOptions initOpt = new UpgOptions();

        initOpt.cost        = initCost;
        initOpt.radius      = initRadius;
        initOpt.damage      = initDamage;
        initOpt.shootDelay  = initDelay;
        initOpt.targetCount = initTargets;
        script.options.Add(initOpt);

        //add remaining level options (empty, for now)
        for (int i = 1; i < levelSize; i++)
        {
            script.options.Add(new UpgOptions());
        }
        //set first upgrade price on the second level
        if (levelSize > 1)
        {
            script.options[1].cost = initUpgradeCost;
        }

        //fill increasing upgrade options for remaining levels
        for (int i = 1; i < levelSize; i++)
        {
            //get the current and last option
            UpgOptions opt  = script.options[i];
            UpgOptions last = script.options[i - 1];

            //calculate new values based on fixed or percentual value entered in the widget.
            //fixed values consider the current level number when calculating the current value.
            //percentual values consider the last level and multiply it with the value entered
            if (incRadiusType == TDValue.fix)
            {
                opt.radius = initRadius + i * incRadius;
            }
            else
            {
                opt.radius = Mathf.Round(last.radius * (1f + incRadius) * 100f) / 100f;
            }

            if (incDamageType == TDValue.fix)
            {
                opt.damage = initDamage + i * incDamage;
            }
            else
            {
                opt.damage = Mathf.Round(last.damage * (1f + incDamage) * 100f) / 100f;
            }

            if (incDelayType == TDValue.fix)
            {
                opt.shootDelay = initDelay + i * incDelay;
            }
            else
            {
                opt.shootDelay = Mathf.Round(last.shootDelay * (1f + incDelay) * 100f) / 100f;
            }

            if (incTargetsType == TDValue.fix)
            {
                opt.targetCount = Mathf.RoundToInt(initTargets + i * incTargets);
            }
            else
            {
                opt.targetCount = Mathf.RoundToInt(last.targetCount * (1f + incTargets));
            }
        }

        //fill resource cost values starting from the third level
        //(as they are based on the initial upgrade price on the second level)
        for (int i = 2; i < levelSize; i++)
        {
            //get the current and last option
            //and create temporary array
            UpgOptions opt  = script.options[i];
            UpgOptions last = script.options[i - 1];
            float[]    cost = new float[costSize];

            //loop over costs for each level
            for (int j = 0; j < costSize; j++)
            {
                float value;
                //with fixed costs, we multiply the current level number with the cost value
                //and add the initial cost. percentual values always increase the last price
                if (incCostType[j] == TDValue.fix)
                {
                    value = initUpgradeCost[j] + (i - 1) * incCost[j];
                }
                else
                {
                    value = last.cost[j] * (1f + incCost[j]);
                }
                //round resource value calculated above based on selected cost type:
                //integer rounds to whole number, floating-point rounds to 2 decimals
                if (costType == CostType.intValue)
                {
                    value = (int)value;
                }
                else
                {
                    value = Mathf.Round(value * 100f) / 100f;
                }
                //assign the calculated value for this resource
                cost[j] = value;
            }
            //assign the calculated resources for this level
            opt.cost = cost;
        }
    }
Exemplo n.º 6
0
    void UpdateUpgradeMenu()
    {
        //store current upgrade level
        int curLvl = gui.upgrade.curLvl;
        //store necessary upgrade option info for later use
        UpgOptions upgOptions = gui.upgrade.options[curLvl];

        //set UI label properties with information of this tower
        labels.headerName.text = gui.upgrade.gameObject.name;
        labels.properties.text = "Level:" + "\n" +
                                 "Radius:" + "\n" +
                                 "Damage:" + "\n" +
                                 "Delay:" + "\n" +
                                 "Targets:";
        //visualize current tower stats
        //round floats to 2 decimal places
        labels.stats.text = +curLvl + "\n" +
                            (Mathf.Round(upgOptions.radius * 100f) / 100f) + "\n" +
                            (Mathf.Round(upgOptions.damage * 100f) / 100f) + "\n" +
                            (Mathf.Round(upgOptions.shootDelay * 100f) / 100f) + "\n" +
                            upgOptions.targetCount;

        //visualize tower stats on the next level if the label was set,
        //and round floats to 2 decimal places
        if (labels.upgradeInfo)
        {
            //check if we have a level to upgrade left
            if (curLvl < gui.upgrade.options.Count - 1)
            {
                //get upgrade option for the next level and display stats
                UpgOptions nextUpg = gui.upgrade.options[curLvl + 1];
                labels.upgradeInfo.text = "= " + (curLvl + 1) + "\n" +
                                          "= " + (Mathf.Round(nextUpg.radius * 100f) / 100f) + "\n" +
                                          "= " + (Mathf.Round(nextUpg.damage * 100f) / 100f) + "\n" +
                                          "= " + (Mathf.Round(nextUpg.shootDelay * 100f) / 100f) + "\n" +
                                          "= " + nextUpg.targetCount;
            }
            else
            {
                //don't display anything on the last level
                labels.upgradeInfo.text = "";
            }
        }

        //initialize upgrade and sell price array value for multiple resources
        float[] sellPrice    = gui.GetSellPrice();
        float[] upgradePrice = gui.GetUpgradePrice();
        //only display the upgrade button, if there IS a level for upgrading left
        //and we have enough money for upgrading to the next level, check every resource
        //initialize boolean as true
        bool affordable = true;

        for (int i = 0; i < upgradePrice.Length; i++)
        {
            //set sell price resource label to the actual value
            labels.sellPrice[i].text = "$" + sellPrice[i];

            //check if we can buy another upgrade level
            //if not, erase price values
            if (!gui.AvailableUpgrade())
            {
                affordable           = false;
                labels.price[i].text = "";
                continue;
            }

            //set price label for upgrading to the next level
            labels.price[i].text = "$" + upgradePrice[i];
        }

        //there is a level to upgrade left, so check if we can afford this tower upgrade
        if (affordable)
        {
            affordable = gui.AffordableUpgrade();
        }

        //the upgrade is still affordable
        if (affordable)
        {
            //in case the upgrade button was deactivated we activate it here again
            buttons.button_upgrade.SetActive(true);
        }
        else
        {
            //we can't afford an upgrade, disable upgrade button
            buttons.button_upgrade.SetActive(false);
        }
    }
Exemplo n.º 7
0
    //create active selection / floating tower on pressing a tower button
    public void InstantiateTower(int clickedButton)
    {
        //store the TowerManager tower index passed in as parameter
        index = clickedButton;

        //we clicked one of these tower buttons
        //if we already have a floating tower, destroy it and free selections
        if (SV.selection)
        {
            currentGrid  = null;
            currentTower = null;
            Destroy(SV.selection);
        }

        //check if there are free grids left
        //no free grid left (list count is equal to grid count)
        if (gridScript.GridList.Count == gridScript.transform.childCount)
        {
            //print a warning message
            StartCoroutine("DisplayError", "No free grids left for placing a new tower!");
            Debug.Log("No free grids left for placing a new tower!");
            return;
        }

        //initialize price array with total count of resources
        float[] price = new float[GameHandler.resources.Length];
        //cache selected upgrade options for further processment
        UpgOptions opt = towerScript.towerUpgrade[index].options[0];

        //loop through resources
        //get needed resources (buy price) of this tower from upgrade list
        for (int i = 0; i < price.Length; i++)
        {
            price[i] = opt.cost[i];
        }

        //check in case we have not enough resources left, abort purchase
        for (int i = 0; i < price.Length; i++)
        {
            if (GameHandler.resources[i] < price[i])
            {
                StartCoroutine("DisplayError", "Not enough resources for buying this tower!");
                Debug.Log("Not enough resources for buying this tower!");
                //destroy selection. this is a bit hacky: CancelSelection() destroys all selections,
                //but we do want to keep our grid selection on BuildMode Grid, thus we cache it right
                //before calling this method and restore it afterwards
                if (SV.gridSelection)
                {
                    GameObject grid = SV.gridSelection;
                    CancelSelection(true);
                    SV.gridSelection      = grid;
                    grid.renderer.enabled = true;
                }
                else
                {
                    CancelSelection(true);
                }
                return;
            }
        }

        //all checks went through, we are able to purchase this tower
        //instantiate selected tower from TowerManager prefab list and thus create a floating tower
        SV.selection      = (GameObject)Instantiate(towerScript.towerPrefabs[index], SV.outOfView, Quaternion.identity);
        SV.selection.name = towerScript.towerNames[index];
        //get new base properties of this tower instance
        towerBase = SV.selection.GetComponentInChildren <TowerBase>();
        //change name of the gameobject holding this component to the defined one in TowerManager names list
        towerBase.gameObject.name = towerScript.towerNames[index];
        //parent tower to the container gameobject
        SV.selection.transform.parent = towerContainer;
        //get new upgrade properties of this tower instance
        upgrade           = SV.selection.GetComponentInChildren <Upgrade>();
        towerBase.upgrade = upgrade;
        //disable its base properties, so while moving/placing the tower around, it can not attack
        towerBase.enabled = false;
        //show all grid renderers to see where we could (or could not) place the tower
        //but only highlight all of them on BuildMode Tower (where gridSelection is always empty)
        if (!SV.gridSelection)
        {
            gridScript.ToggleVisibility(true);
        }
        //apply passive powerups to this tower
        PowerUpManager.ApplyToSingleTower(towerBase, upgrade);
    }