Example #1
0
    public void AddPerk(Perk perk)
    {
        PerkData settings = perk.settings;

        // stash perk settings
        _perks[settings.type] = settings;

        // apply modifiers
        if (settings.speedMod > 0.0f)
        {
            _playerSpeed.speedMultiplier = settings.speedMod;
        }

        _playerHealth.Heal(settings.healthMod);
        _playerWeapons.SetBuff(settings.fireRateMod, settings.damageMod, settings.reloadMod);

        if (settings.shield)
        {
            _playerHealth.immune = true;
            shield.gameObject.SetActive(true);
            shield.ResetShield();
        }

        if (settings.gunDrop != null)
        {
            if (_playerWeapons.weapons.Count >= 2)
            {
                _playerWeapons.RemoveSpecialWeapon();
            }

            _playerWeapons.weapons.Add(settings.gunDrop);
            _playerWeapons.perk = settings;
            _playerWeapons.NewSpecialWeapon();
        }

        if (settings.duration > 0.0f)
        {
            // cancel existing coroutine
            if (_perkEnding.ContainsKey(settings.type))
            {
                //StopCoroutine( _perkEnding[settings.type] ); // This is causing unity (the editor) to crash. It's a bug within unity, we'll have to work around it.
            }

            // start new coroutine
            _perkEnding[settings.type] = StartCoroutine(RemoveAfterDelay(settings));
        }
    }