Exemple #1
0
        // ========================================================
        // ========================================================
        // ========================================================


        void OnEnable()
        {
            currentHealth = startingHealth;

            onHealthSet.Invoke(this);

            DisableInvulnerability();
        }
Exemple #2
0
    private void OnEnable()
    {
        m_CurrentHealth = startingHealth;

        OnHealthSet.Invoke(this);

        DisableInvulnerability();
    }
Exemple #3
0
        void OnEnable()
        {
            PersistentDataManager.RegisterPersister(this);
            m_CurrentHealth = startingHealth;

            OnHealthSet.Invoke(this);

            DisableInvulnerability();
        }
Exemple #4
0
    public void SetInitialHealth()
    {
        //  set initial health point
        m_CurrentHealth = startingHealth;

        //  call back on health set
        OnHealthSet.Invoke(this);

        //  disable invulnerability
        DisableInvulnerability();

        Debug.Log("onHealthSet");
    }
    public virtual void TakeDamage(int dmg, GameObject src = null)
    {
        if (!isInvincible && currentHP > 0)
        {
            currentHP -= dmg;
            OnHealthChanged.Invoke(currentHP);
            AudioManager.Instance.PlayClip("Player", "Damage");

            if (src)
            {
                Vector3 dif = src.transform.position - gameObject.transform.position;
                transform.position -= dif.normalized * 0.25f;
            }
        }
    }
Exemple #6
0
    // Update is called once per frame
    void Update()
    {
        // We divide decreasePerMinute by 60 to turn it into deacreasePerSecond.
        // We then multiply it by Time.deltaTime, which is the time, in seconds,
        // since Update was last called.
        energy -= decreasePerMinute * Time.deltaTime / 60f;
        if (healthEvent != null)
        {
            healthEvent.Invoke(energy);
        }
        //int c = health;
        //hp_text.text = "Halo 2 " + (hp).ToString();
        if (energy <= 0)
        {
            energy = 0;
        }
        else if (energy >= 100.1f)
        {
            energy = 100.1f;
            //fullPanel.gameObject.SetActive(true);
        }
        else if (energy <= 100)
        {
            //fullPanel.gameObject.SetActive(false);
        }

        PlayerPrefs.SetFloat("energy", Energy.energy);
        PlayerPrefs.Save();
    }
    private void GiveHealth(GameObject player)
    {
        HealthScript playerHealth = player.GetComponent <HealthScript>();                        // Noah: get the players health

        if (playerHealth == null)
        {
            return;
        }

        // Noah: Add to the players health
        playerHealth._currentHealth += _gainAmount;
        if (playerHealth._currentHealth < _maxHealth)
        {
            playerHealth._currentHealth = _maxHealth;
        }

        // Noah: update the health bar
        HealthEvent?.Invoke(HealthPercentage);
        HealthBar.RuntimeSOBar.HealthBarRef.UpdateBar(playerHealth.HealthPercentage);

        // Noah: Instantiate the particles and lerp them to the enemies position
        enemyPosition    = transform.position;
        _healthParticles = Instantiate(_healthParticles, transform.position, transform.rotation);
        _healthParticles.GetComponent <ParticleLerp>().Particle      = _healthParticles;
        _healthParticles.GetComponent <ParticleLerp>().EnemyPosition = enemyPosition;
        AkSoundEngine.PostEvent(_playerGainMana, gameObject);
    }
Exemple #8
0
    public void DeductHealth(float amount)
    {
        //Zeroed the damage received XD
        if (IsUndead == true)
        {
            amount = 0;
        }

        if (CheckUndeadBuffExist() == true && Health - amount <= 0)
        {
            IsUndead = true;
        }

        //Reduce damage if applicable
        amount -= (amount * Shield);
        amount  = Mathf.Clamp(amount, 0, amount);

        //RoundOff Damage
        amount = (float)Math.Round(amount, 1);

        Health -= amount;
        Health  = Mathf.Clamp(Health, 0, maxHealth);

        //Bool Variable
        if (Health <= 0 && !IsUndead)
        {
            IsAlive = false;
        }

        OnDeductHealth.Invoke(amount);
        StartCoroutine(this.GetComponent <CustomCharacterController>().TakeDamageAnimation());
    }
Exemple #9
0
    public void TakeDamage(float damageTaken)
    {
        if (damageTaken > _armor)        // If damage is higher than the damage negation the entity has
        {
            if (OnTakeDamage != null)
            {
                OnTakeDamage.Invoke();
            }
            _health -= damageTaken;
        }

        if (_health <= 0)
        {
            if (OnDie != null)
            {
                OnDie.Invoke();
            }
            _isAlive = false;
        }

        if (healthBar != null)
        {
            healthBar.fillAmount = _health / _maxHealth;                        // Displays health as a bar
        }
    }
Exemple #10
0
    public int Heal(int hp)
    {
        this.hp = Mathf.Clamp((this.hp + hp), 0, maxHp);
        OnChanged?.Invoke(this);
        OnHeal?.Invoke(this);

        return(this.hp);
    }
Exemple #11
0
    public void AddHealth(float amount)
    {
        Health += amount;

        Health = Mathf.Clamp(Health, 0, maxHealth);

        OnAddHealth.Invoke(amount);
    }
 public void ApplyDamage(float damage)
 {
     health -= damage;
     onTakeDamage.Invoke(health);
     if (health <= 0)
     {
         Die();
     }
 }
Exemple #13
0
        public void TakeDamage(Damager p_damager, bool p_ignoreInvulnerability = false)
        {
            if (m_invulnerable && !p_ignoreInvulnerability || m_currentHealth <= 0)
            {
                return;
            }

            if (!m_invulnerable)
            {
                m_currentHealth -= p_damager.DamageValue;
                OnHealthSet?.Invoke(this);
            }

            m_damageDirection = transform.position + (Vector3)CenterOffset - p_damager.transform.position;

            OnTakeDamage?.Invoke(p_damager, this);

            CheckDeath(p_damager);
        }
Exemple #14
0
    public void GainHealth(float healthGained)
    {
        if (_health > 0)
        {
            if (healthGained + _health > _maxHealth)
            {
                _health = _maxHealth;
                if (OnRestore != null)
                {
                    OnRestore.Invoke();
                }
            }

            else if (_health + healthGained <= +_maxHealth)
            {
                _health += healthGained;
                if (OnRestore != null)
                {
                    OnRestore.Invoke();
                }
            }
        }

        else if (_health <= 0)
        {
            if (OnRevive != null)
            {
                OnRevive.Invoke();
            }
            _health += healthGained;
            _isAlive = true;
        }

        else
        {
            return;
        }

        if (healthBar != null)
        {
            healthBar.fillAmount = _health / _maxHealth;
        }
    }
Exemple #15
0
        /// <summary>
        /// Takes the given amount of damage from the specified source.
        /// </summary>
        /// <param name="damage">The amount of damage to take.</param>
        /// <param name="source">The source that caused the damage.</param>
        public virtual void TakeDamage(float damage, Transform source)
        {
            if (Invincible || IsDead)
            {
                return;
            }

            Health -= damage;
            OnHurt.Invoke(new HealthEventArgs {
                Damage = damage, Source = source
            });

            if (Animator != null)
            {
                if (HurtDamageFloatHash != 0)
                {
                    Animator.SetFloat(HurtDamageFloatHash, damage);
                }
                if (HurtTriggerHash != 0)
                {
                    Animator.SetTrigger(HurtTriggerHash);
                }
            }

            if (Health > 0f)
            {
                return;
            }

            Health = 0f;
            OnDeath.Invoke(new HealthEventArgs {
                Damage = damage, Source = source
            });

            if (Animator != null && DeathTriggerHash != 0)
            {
                Animator.SetTrigger(DeathTrigger);
            }
        }
Exemple #16
0
    public virtual void DeductHp(float amt)
    {
        if (isInvulnerable)
        {
            return;
        }

        if (amt <= 0)
        {
            amt = 0;
        }
        //if(!isServer) return;
        health -= amt;
        if (health <= 0)
        {
            health = 0;
            EventOnHealthDepleted.Invoke();
            if (destroyOnHealthDepleted)
            {
                OnHealthDepeleted();
            }
            Debug.Log("Depleted");
        }
        Debug.Log("Hit");
        EventOnHealthChange.Invoke();
        EventReceivedDamage.Invoke(amt);
        if (!isInvulnerable && amt > 0)
        {
            if (!isInvulnerabilityTimerStarted)
            {
                isInvulnerable = true;
                invulTimer     = InvulnerabilityTimer();
                StartCoroutine(invulTimer);
            }
        }
    }
Exemple #17
0
 private void HealthChanged(float prevHitPoints, float nextHitPoints)
 {
     if (Mathf.Approximately(nextHitPoints, 0f))
     {
         OnHealthZero.Invoke(prevHitPoints, 0f);
     }
     else if (Mathf.Approximately(nextHitPoints, hitPoints))
     {
         OnHealthFull.Invoke(prevHitPoints, hitPoints);
     }
     else
     {
         OnHealthChanged.Invoke(prevHitPoints, nextHitPoints);
     }
 }
Exemple #18
0
    public void Damage(float amount)
    {
        _currentHealth = Mathf.Max(0, _currentHealth - amount);
        _onDamageEvent.Invoke(amount);

        if (_currentHealth <= 0)
        {
            _onDeathEvent.Invoke();

            DoDeathActions();

            if (_destroyOnDeath)
            {
                Destroy(gameObject);
            }
        }
    }
Exemple #19
0
 public int Hurt(int hp)
 {
     if (!IsInvincible)
     {
         if (InvincibleTimer < 0)
         {
             this.hp = Mathf.Clamp((this.hp - hp), 0, maxHp);
             OnHit?.Invoke(this);
             OnChanged?.Invoke(this);
             InvincibleTimer = InvincibleTime;
             if (this.hp <= 0)
             {
                 OnDeath?.Invoke(this);
             }
         }
     }
     return(this.hp);
 }
Exemple #20
0
        public int ReceiveHeal(int amount)
        {
            int pointsBefore = points;

            if (amount > 0 && CanReceiveHeal)
            {
                bool wasAlive = IsAlive;
                points = Mathf.Clamp(points + amount, 0, maxPoints);
                healedEvent.Invoke(gameObject);

                if (IsAlive && !wasAlive)
                {
                    reviveEvent.Invoke(gameObject);
                }
            }

            return(pointsBefore - points);
        }
    // Update is called once per frame
    void Update()
    {
        if (gameObject.tag == "Player" && IsAlive == true)
        {
            MaxHealth -= ConstantDamage * Time.deltaTime;
        }


        if (MaxHealth == 0)
        {
            IsAlive = false;
            Destroy(gameObject);
        }


        if (healthEvent != null)
        {
            healthEvent.Invoke(MaxHealth);
        }
    }
    //Kate: player damage and enemy damage when a resurrected enemy hits a normal enemy
    public void Damage(float amount)
    {
        //Kate:deal damage
        _currentHealth -= amount;


        //Kate:instantiate particles
        if (_hitParticles != null)
        {
            hitParticlesClone = Instantiate(_hitParticles, transform.position, transform.rotation);
        }

        //Kate:check if still alive
        if (_currentHealth <= 0)
        {
            // Debug.Log($"health: {_currentHealth}");
            Death();
        }
        HealthEvent?.Invoke(HealthPercentage);                                      //Noah: when the player damage, updates UI

        if (gameObject.GetComponent <PlayerController>())
        {
            if (SceneManager.GetActiveScene().buildIndex == 2)
            {
                GameMaster.instance._hurtshake2.GenerateImpulse();

                // Noah: play the damaged sound
                AkSoundEngine.PostEvent(_playerDamageSound, this.gameObject);
            }
            else
            {
                GameMaster.instance._hurtshake.GenerateImpulse();
            }
            GetComponent <PlayerController>()._Anim.Play("Hurt");                    //Kate:Play hurt animation for player
        }


        Destroy(hitParticlesClone, _partilceLifetime);                              //destroy particles
    }
Exemple #23
0
        public int ReceiveDamage(int amount, IDamager damager)
        {
            var match = FindObjectOfType <MatchMode>();

            Assert.IsNotNull(match);

            int  pointsBefore = points;
            bool rulesAllow   = match.CanDamage(damager, gameObject);

            if (amount > 0 && rulesAllow && CanReceiveDamage)
            {
                bool wasAlive = IsAlive;
                points = Mathf.Clamp(points - amount, 0, maxPoints);
                damagedEvent.Invoke(gameObject);

                if (!IsAlive && wasAlive)
                {
                    deathEvent.Invoke(gameObject);
                }
            }

            return(pointsBefore - points);
        }
Exemple #24
0
    //  更新生命值
    public void SetHealth(int healthPoint)
    {
        //  若大于最大值则返回
        if (healthPoint > m_MaxHealthAmount)
        {
            return;
        }

        //  更新当前生命值
        this.m_CurHealthAmount = healthPoint;

        //  调用事件
        OnHealthSet.Invoke(this.m_CurHealthAmount);

        if (m_CurHealthAmount <= 0)
        {
            PlayerDie();
        }
        else
        {
            OnDamaged.Invoke();
        }
    }
Exemple #25
0
    // Gets called by the "source" of the damage
    public void DealDamage(float amt, GameObject source)
    {
        CurrHealth -= Mathf.RoundToInt(amt * IncomingDamageMultiplier);
        bool isDead = false;

        if (CurrHealth < 0.0f)
        {
            CurrHealth = 0.0f;
            isDead     = true;
        }

        Vector3 scale = HealthBarBackground.transform.GetChild(0).localScale;

        scale.x = CurrHealth / MaxHealth;

        HealthBarBackground.transform.GetChild(0).localScale = scale;

        onTakeDamage.Invoke(source);

        if (isDead)
        {
            onDeath.Invoke(source);
        }
    }
Exemple #26
0
 void OnEnable()
 {
     resetHealth();
     onHealthSet.Invoke(this);
     DisableInvulnerability();
 }
Exemple #27
0
 public int SetHealth(int hp)
 {
     this.hp = hp;
     OnChanged?.Invoke(this);
     return(this.hp);
 }
 private void Damaged(object sender, HealthEventArgs e)
 {
     onDamaged.Invoke(e);
 }
 private void Healed(object sender, HealthEventArgs e)
 {
     onHealed.Invoke(e);
 }
 protected override void Init()
 {
     OnHealthSet.Invoke(this);
 }