예제 #1
0
    private void Start()
    {
        HandleObservable();

        currentHealth = maxHealth;
        OnHealthChanged.Invoke(currentHealth, maxHealth);
    }
예제 #2
0
    public void Damage(float dmg, Effect.AbilityEffect effect, bool crit, GameObject abilityOwner)
    {
        if (crit)
        {
            dmg *= 1.25f;
        }

        health -= dmg;                       // remove damage from health
        health  = health < 0 ? 0f : health;  // do not allow below 0

        if (health <= 0 && !isDead)
        {
            // inform player that it was killed
            abilityOwner.GetComponent <Player>().AddExperience(1200000); // TODO
            int experience = 1200000;
            print("Killed " + name + ": Gained " + experience + " experience");

            Kill();
        }

        damageTaken?.Invoke(dmg, new Effect.AbilityEffect(), crit); // inform subscribers that HP has changed
        healthChanged?.Invoke();
        _behaviorManager.Damaged(abilityOwner, dmg);

        if (effect.effectType != Effect.EffectType.Basic)
        {
            ApplyEffect(effect, abilityOwner);
        }
    }
예제 #3
0
    void UpdateStatDisplay()
    {
        string stats = "Basic Stats\n";

        foreach (Attributes.Stat a in _attributes.GetStats())
        {
            stats += $"{a.statType.ToString() + ":", -15} <color=#08ff02>{a.value}</color>\n";
        }

        stats += $"\nOffensive Attributes\n";
        int toIgnore = 3;// ignore the basic stats available to weapons

        foreach (Weapon.Stat a in _attributes.GetWeaponStats())
        {
            if (toIgnore > 0)
            {
                toIgnore--;
                continue;
            }

            string percent = a._flatValue ? "" : "%";
            stats += $"{a._stat.ToString() + ":",-25} {a._value, -1}{percent, 1}\n";
        }

        stats   += $"\nDefensive Attributes\n";
        toIgnore = 2; // ignore the basic stats available to armor

        foreach (Armor.Stat a in _attributes.GetArmorStats())
        {
            if (toIgnore > 0)
            {
                toIgnore--;
                continue;
            }

            stats += $"{a._stat.ToString() + ":",-25} {a._value}\n";
        }

        // set the stats textbox text
        _statsText.text = stats;

        // update any attributes that are affected by stat changes
        _maxHealth = (int)((float)_attributes.GetStat(Attributes.StatTypes.Stamina).value *Attributes.StamToHP + _attributes.GetArmorStat(Armor.Stats.Health)._value);

        _maxMana = (int)((float)_attributes.GetStat(Attributes.StatTypes.Spirit).value *Attributes.SpiritToMP + _attributes.GetArmorStat(Armor.Stats.Mana)._value);

        if (_health > _maxHealth)
        {
            _health = _maxHealth;
        }
        if (_mana > _maxMana)
        {
            _mana = _maxMana;
        }

        D_HealthChanged?.Invoke();
        D_ManaChanged?.Invoke();
    }
예제 #4
0
        public void AddHealth(float healthAmount)
        {
            _currentHealthAmount =
                _currentHealthAmount + healthAmount > maxHealthAmount
                    ? maxHealthAmount
                    : _currentHealthAmount + healthAmount;

            healthChanged?.Invoke();
        }
예제 #5
0
        public void ChangeHealth(float amount)
        {
            m_CurrentHealth += amount;
            if (m_CurrentHealth > maxHealth)
            {
                m_CurrentHealth = maxHealth;
            }
            HealthChanged?.Invoke(m_CurrentHealth / maxHealth);

            if (m_CurrentHealth <= 0 && !dead)
            {
                dead = true;
                if (destroyOnDeath)
                {
                    Died?.Invoke();
                    if (deathEffects.Length > 0)             // Unused, prob not ready for working
                    {
                        var p = transform.position;
                        Pool.Despawn(
                            Pool.Spawn(deathEffects.AnyItem(),
                                       new Vector3(p.x, p.y, p.z),
                                       new Quaternion(0, 0, 0, 0)), 3);
                    }
                }

                if (dyingAnimations.Length > 0)
                {
                    // If there is death animations for this object
                    m_Animator.SetBool(dyingAnimations.AnyItem(),
                                       true);  // TODO: not rly useful if destroyed ... (maybe should add death delay idk)
                }
            }
        }
예제 #6
0
    public void LoadPlayer()
    {
        PlayerData data = SaveSystem.LoadPlayer();

        currentHealth = data.health;
        HealthChanged.Invoke(currentHealth);
    }
 private void OnHealthChanged(float newHealth)
 {
     if (HealthChanged != null)
     {
         HealthChanged.Invoke(newHealth);
     }
 }
예제 #8
0
    void Regen()
    {
        float remainingHealth = originalHealth - currentHealth;

        //adds health
        currentHealth += regenAmount;
        //if health is maxxed out set to max and cancel regeneration
        if (currentHealth >= originalHealth)
        {
            currentHealth = originalHealth;
            CancelInvoke("Regen");
        }
        //Send message for script to update UI
        if (HealthChanged != null && showHealth)
        {
            float amount;
            if (remainingHealth < regenAmount)
            {
                amount = remainingHealth;
            }
            else
            {
                amount = regenAmount;
            }
            if (HealthChanged != null)
            {
                HealthChanged.Invoke(amount);
            }
        }
    }
예제 #9
0
    public void TakeDamage(float damage)
    {
        if (_shield)
        {
            if (_shield.canTakeDamage)
            {
                currentHealth -= damage;
            }
            else
            {
                currentHealth += healthRegeneration * Time.deltaTime * 3f;
            }
        }
        else
        {
            currentHealth -= damage;
        }

        OnHealthChanged?.Invoke(maxHealth, currentHealth);

        if (currentHealth <= 0.0f)
        {
            OnUnitDied?.Invoke();
        }
        else if (currentHealth > maxHealth)
        {
            currentHealth = maxHealth;
        }
    }
예제 #10
0
    private void Start()
    {
        _currenthealth = _maxHealth;

        StartCoroutine(ShootWithDelay(_shootPoint, _secondsBetweenShoot));
        HealthChanged?.Invoke(_currenthealth);
    }
예제 #11
0
        public void AddHealth(float amount)
        {
            m_CurrentHealth += amount;
            if (m_CurrentHealth > maxHealth)
            {
                m_CurrentHealth = maxHealth;
            }
            HealthChanged?.Invoke(m_CurrentHealth / maxHealth);

            if (m_CurrentHealth <= 1 && !dead)
            {
                dead = true;
                // if (destroyOnDeath)
                // {
                Died?.Invoke();
                // }

                if (dyingAnimations.Length > 0)
                {
                    // If there is death animations for this object
                    m_Animator.SetBool(dyingAnimations.AnyItem(),
                                       true);  // TODO: not rly useful if destroyed ... (maybe should add death delay idk)
                }
            }
        }
예제 #12
0
 public void Healing()
 {
     if (_curentHealth + _variableValue <= _maxHealth)
     {
         _curentHealth += _variableValue;
         HealthChanged?.Invoke();
     }
 }
예제 #13
0
 public void Heal(int heal)
 {
     if (hp < maxHp)
     {
         hp += heal;
         HealthChanged?.Invoke(this, hp);
     }
 }
예제 #14
0
 public void TakeDamage()
 {
     if (_curentHealth - _variableValue >= 0)
     {
         _curentHealth -= _variableValue;
         HealthChanged?.Invoke();
     }
 }
예제 #15
0
 public void ReduceHealth(int damage)
 {
     _health = Math.Max(0, _health - damage);
     HealthChanged?.Invoke(_health);
     if (_health == 0)
     {
         HealthIsZero?.Invoke();
     }
 }
예제 #16
0
 public void ApplyDamage(int damage)
 {
     _currentHealth -= damage;
     HealthChanged?.Invoke(_currentHealth, _health);
     if (_currentHealth <= 0)
     {
         Destroy(gameObject);
     }
 }
예제 #17
0
 public void Heal(int healthAmount)
 {
     health += healthAmount;
     if (health >= maxHealth)
     {
         health = maxHealth;
     }
     HealthChanged?.Invoke();
 }
예제 #18
0
    private void UpdateHealth()
    {
        HealthChanged?.Invoke(_currentHealth);

        if (_currentHealth <= 0)
        {
            GameOver();
        }
    }
예제 #19
0
파일: Player.cs 프로젝트: Prog84/Runner
 public void ApplyDamage(int damage)
 {
     _health -= damage;
     HealthChanged?.Invoke(_health);
     if (_health <= 0)
     {
         Die();
     }
 }
예제 #20
0
 // Use this for initialization
 void Start()
 {
     currentHealth = originalHealth;
     //Send message for script to update UI
     if (HealthChanged != null && showHealth)
     {
         HealthChanged.Invoke(0);
     }
 }
예제 #21
0
 public void TakeDamage(float damage)
 {
     if (_currentHealth > 0)
     {
         _currentHealth -= damage;
         PlayAnimation();
         PlayEffect();
         HealthChanged?.Invoke(_currentHealth, _maxHealth);
     }
 }
예제 #22
0
    public void GeDamage(float hp)
    {
        if (_currentHealth - hp < 0)
        {
            return;
        }

        _currentHealth -= hp;
        HealthChanged.Invoke(_currentHealth);
    }
예제 #23
0
    public void TakeDamage(int damage)
    {
        _currentHealth -= damage;
        HealthChanged?.Invoke(_currentHealth, _health);

        if (_currentHealth <= 0)
        {
            Debug.Log("Defete");
        }
    }
예제 #24
0
 private void OnHealth()
 {
     health--;
     if (health == 0)
     {
         // ads.StartCoroutine("ShowAd");
         menuController.LoseGame();
     }
     HealthChanged?.Invoke(health);
 }
예제 #25
0
 public void Reset()
 {
     currentHealth = originalHealth;
     isDead        = false;
     //Send message for script to update UI
     if (HealthChanged != null && showHealth)
     {
         HealthChanged.Invoke(0);
     }
 }
예제 #26
0
파일: Player.cs 프로젝트: fes32/Runner
    public void TakeDamage(int damage)
    {
        _health -= damage;
        if (_health <= 0)
        {
            Die();
        }

        HealthChanged?.Invoke(_health);
    }
예제 #27
0
    public void ApplyDamage(int value)
    {
        if (_currentHealth + value >= 0 && _currentHealth + value <= _health)
        {
            _currentHealth += value;
            HealthChanged?.Invoke(_currentHealth, _health);

            SetAnimation(value);
        }
    }
예제 #28
0
        private void HandleHealthChange(bool fireZeroHealthEvent = true)
        {
            healthChanged?.Invoke(_currentHealth, _maxHealth);

            if (fireZeroHealthEvent && _currentHealth <= 0 && !_zeroHealthEventFired)
            {
                zeroHealth?.Invoke();
                _zeroHealthEventFired = true;
            }
        }
예제 #29
0
 private void ApplyDamage()
 {
     _health--;
     HealthChanged?.Invoke(_health);
     if (_health <= 0)
     {
         Died?.Invoke();
         gameObject.SetActive(false);
     }
 }
예제 #30
0
    private void EnemyFinished(GameObject enemy)
    {
        var enemyComp = enemy.GetComponent <Enemy>();

        Health -= enemyComp.Damage;
        HealthChanged?.Invoke(Health);
        enemyComp.OnDied -= EnemyDied;

        CheckIfLastEnemyDiedOrFinished();
    }