예제 #1
0
    //activate power up on this tower
    //called by GUI -> PowerUps.cs
    public void ApplyPowerUp(DefensivePowerUp powerup)
    {
        //do not allow multiple powerups at the same time,
        //remove previous powerup differences
        if (this.powerup != null)
        {
            StopCoroutine("PowerUpBoost");
            RemovePowerUp();
        }

        //cache powerup for later remove
        //and start coroutine for boosting this tower
        this.powerup = powerup;
        StartCoroutine("PowerUpBoost");
    }
예제 #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;
    }
예제 #3
0
    //try to execute defensive powerup
    IEnumerator ActivatePowerUp(DefensivePowerUp powerUp)
    {
        //double check for requirements
        if (!powerUp.CheckRequirements())
        {
            yield break;
        }
        else
        {
            //disable powerup
            powerUp.enabled = false;
        }

        //trigger event notification
        if (battlePowerUpActivated != null)
        {
            battlePowerUpActivated(powerUp);
        }
        //let the powerup handle its own effects
        powerUp.InstantiateFX();
        //delay option execution
        yield return(new WaitForSeconds(powerUp.startDelay));

        //handle boost/buff option
        yield return(StartCoroutine(powerUp.BoostTowers()));

        //unset target and position for later reuse
        powerUp.target   = null;
        powerUp.position = Vector3.zero;

        //wait until the cooldown is over
        //before re-enabling the powerup
        yield return(new WaitForSeconds(powerUp.cooldown));

        powerUp.enabled = true;
    }
예제 #4
0
    //try to execute defensive powerup
    IEnumerator ActivatePowerUp(DefensivePowerUp powerUp)
    {
        //do not continue if any of these requirements are not met:
        //the powerup is disabled (has cooldown),
        //a single target is set but the powerup has no target
        if (!powerUp.enabled ||
            !powerUp.area && !powerUp.target)
            yield break;
        else
            //disable powerup
            powerUp.enabled = false;

        //trigger event notification
        powerUpActivated(powerUp);
        //let the powerup handle its own effects
        powerUp.InstantiateFX();
        //delay option execution
        yield return new WaitForSeconds(powerUp.startDelay);

        //handle boost/buff option
        yield return StartCoroutine(powerUp.BoostTowers());

        //unset target and position for later reuse
        powerUp.target = null;
        powerUp.position = Vector3.zero;

        //wait until the cooldown is over
        //before re-enabling the powerup
        yield return new WaitForSeconds(powerUp.cooldown);
        powerUp.enabled = true;
    }
예제 #5
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);
    }
예제 #6
0
    //draws a list for all battle powerups
    void DrawBattlePowerUpsSelector()
    {
        EditorGUILayout.BeginVertical(GUILayout.Width(270));

        //begin a scrolling view inside GUI, pass in current Vector2 scroll position
        scrollPosBattleSelector = EditorGUILayout.BeginScrollView(scrollPosBattleSelector, true, true, GUILayout.Height(325), GUILayout.Width(270));

        //iterate over all battle powerups in the main list
        for (int i = 0; i < powerUpScript.battlePowerUps.Count; i++)
        {
            //get the current powerup
            BattlePowerUp powerup = powerUpScript.battlePowerUps[i];

            //differentiate between offensive and defensive powerup,
            //set the gui color correspondingly
            if (powerup is OffensivePowerUp)
            {
                GUI.backgroundColor = offensiveColor;
            }
            else if (powerup is DefensivePowerUp)
            {
                GUI.backgroundColor = defensiveColor;
            }

            //draw a box with the color defined above
            //and reset the color to white
            GUI.Box(new Rect(5, i * 28, 25, 25), i + " ");
            GUI.backgroundColor = Color.white;

            //compare powerup in the list with the currently selected one
            //if it's the selected one, tint the background yellow
            if (powerup == selectedBattle)
            {
                GUI.backgroundColor = Color.yellow;
            }
            GUI.Box(new Rect(25, i * 28, 225, 25), "");
            GUI.backgroundColor = Color.white;
        }

        //draw the list of offensive powerups,
        //then draw the list of defensive powerups below
        if (Event.current.type != EventType.ValidateCommand)
        {
            DrawBattlePowerUps(script.FindProperty("battleOffensive"), powerUpScript.battleOffensive);
            DrawBattlePowerUps(script.FindProperty("battleDefensive"), powerUpScript.battleDefensive);
        }

        //ends the scrollview defined above
        EditorGUILayout.EndScrollView();

        //start button layout at the bottom of the left side
        //draw box with the background color defined at the beginning
        //begin with the offensive powerup add button
        EditorGUILayout.BeginHorizontal();
        GUI.backgroundColor = offensiveColor;
        GUILayout.Box("", GUILayout.Width(20), GUILayout.Height(15));
        GUI.backgroundColor = Color.white;

        //add a new offensive powerup to the list
        if (GUILayout.Button("Add Offensive Power Up"))
        {
            Undo.RecordObject(powerUpScript, "AddOffensive");
            Undo.RecordObject(this, "AddOffensive");

            //create new instance
            OffensivePowerUp newOff = new OffensivePowerUp();
            //insert new powerup at the end of the offensive list
            //also add the new powerup to the main list of battle powerups
            powerUpScript.battlePowerUps.Insert(powerUpScript.battleOffensive.Count, newOff);
            powerUpScript.battleOffensive.Add(newOff);
            //mark that the gui changed and update the script values
            guiChange = true;
            script.Update();
            //select the newly created powerup,
            //also select the powerup as active selection for editing
            selectedBattle      = newOff;
            battlePowerUpToEdit = script.FindProperty("battleOffensive").GetArrayElementAtIndex(powerUpScript.battleOffensive.Count - 1);
        }

        EditorGUILayout.EndHorizontal();
        //continue with the offensive powerup add button
        EditorGUILayout.BeginHorizontal();
        GUI.backgroundColor = defensiveColor;
        GUILayout.Box("", GUILayout.Width(20), GUILayout.Height(15));
        GUI.backgroundColor = Color.white;

        //add a new defensive powerup to the list
        if (GUILayout.Button("Add Defensive Power Up"))
        {
            Undo.RecordObject(powerUpScript, "AddDefensive");
            Undo.RecordObject(this, "AddDefensive");

            //create new instance
            DefensivePowerUp newDef = new DefensivePowerUp();
            //add new powerup to the end of the defensive list
            //also add the new powerup to the main list of battle powerups
            powerUpScript.battlePowerUps.Add(newDef);
            powerUpScript.battleDefensive.Add(newDef);
            //mark that the gui changed and update the scipt values
            guiChange = true;
            script.Update();
            //select the newly created powerup as active selection and for editing
            selectedBattle      = newDef;
            battlePowerUpToEdit = script.FindProperty("battleDefensive").GetArrayElementAtIndex(powerUpScript.battleDefensive.Count - 1);
        }

        EditorGUILayout.EndHorizontal();
        EditorGUILayout.EndVertical();
    }
예제 #7
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 /= powerup.buff.radius;
            opt.damage /= powerup.buff.damage;
            opt.shootDelay *= powerup.buff.shootDelay;
            opt.targetCount -= powerup.buff.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;
    }
예제 #8
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();

        //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];
            opt.radius *= powerup.buff.radius;
            opt.damage *= powerup.buff.damage;
            opt.shootDelay /= powerup.buff.shootDelay;
            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);
    }
예제 #9
0
    //activate power up on this tower
    //called by GUI -> PowerUps.cs
    public void ApplyPowerUp(DefensivePowerUp powerup)
    {
        //remove previous powerup
        if (this.powerup != null)
        {
            StopCoroutine("PowerUpBoost");
            RemovePowerUp();
        }

        //cache powerup for later remove
        //and start coroutine for boosting this tower
        this.powerup = powerup;
        StartCoroutine("PowerUpBoost");
    }