Esempio n. 1
0
        protected virtual void ApplyHealthModification()
        {
            var modifiedHealth = GetModifiedHealth();

            if (modifiedHealth < _hitpoints.health)
            {
                var damageAmount = _hitpoints.health - modifiedHealth;
                _hitpoints.Damage(new Damage(damageAmount));
            }
            else if (modifiedHealth > _hitpoints.health)
            {
                var healAmount = modifiedHealth - _hitpoints.health;
                _hitpoints.Heal(new Heal(healAmount));
            }
        }
        /// <summary> Performs the automatic regeneration. </summary>
        protected virtual IEnumerator Regenerate()
        {
            _isRegenerating = true;
            while (_isRegenerating && _interval > 0)
            {
                _nextRegeneration += _interval;
                UpdateRegenerationValues();
                while (_nextRegeneration > 0)
                {
                    yield return(new WaitForEndOfFrame());

                    _nextRegeneration -= Time.deltaTime;
                }
                if (_isRegenerating)
                {
                    UpdateRegenerationValues();
                    var heal = new Heal(_regeneration, null, _regenerationEvent);
                    _hitpointsController.Heal(heal, _hitpointsController.entity);
                }
            }
            _isRegenerating   = false;
            _nextRegeneration = 0;
        }