public uint SubtractHealth(uint value) { // Check for overflow before subtracting: CurrentHealth = value > CurrentHealth ? 0 : CurrentHealth - value; // Invoke listeners: OnHealthChange.Invoke(CurrentHealth); return(CurrentHealth); }
public TouchResponseData Touch(TouchData touchData) { if (_dead || !Game.CheckTeamVsTeam(touchData.teamId, teamId)) { return(TouchResponseData.empty); } Console.WriteLine($"Health {teamId} hurt by team {touchData.teamId}"); int previous = health; health -= touchData.damage; TouchResponseData result; result.damageTaken = touchData.damage; GFXQuick gfx = Main.i.factory.SpawnGFX(GameFactory.Path_GFXBloodImpact); gfx.Spawn(touchData.hitPos, touchData.hitNormal); if (health <= 0) { _dead = true; result.responseType = TouchResponseType.Killed; _onDeath?.Invoke(); } else { int change = health - previous; result.responseType = TouchResponseType.Damaged; _onHealthChange?.Invoke(health, change, touchData); } return(result); }
public void TakeDamage(float damage) { if (!Shielding) { return; } if (CurrentHealth <= 0f) { CurrentHealth = 0f; return; } float shieldAdjust = (CurrentHealth - damage); if (shieldAdjust <= 0) { shieldAdjust = 0; } if (CurrentHealth == shieldAdjust) { return; } CurrentHealth = shieldAdjust; HealthChange?.Invoke(CurrentHealth); }
public TouchResponseData Touch(TouchData touchData) { if (_dead) { return(TouchResponseData.empty); } int previous = _health; _health -= touchData.damage; TouchResponseData result; result.damageTaken = touchData.damage; GFXQuick gfx = Main.i.factory.SpawnGFX(GameFactory.Path_GFXBloodImpact); gfx.Spawn(touchData.hitPos, touchData.hitNormal); if (_health <= 0) { _dead = true; result.responseType = TouchResponseType.Killed; _onDeath?.Invoke(); } else { int change = _health - previous; result.responseType = TouchResponseType.Damaged; _onHealthChange?.Invoke(_health, change, touchData); } return(result); }
private void OnHealthChange(float health) { if (HealthChange != null) { HealthChange.Invoke(health); } }
public virtual void RestoreHealth(float restoreAmount) { m_currentHealth += restoreAmount; m_currentHealth = Mathf.Clamp(m_currentHealth, 0f, m_maxHealth); HealthChange?.Invoke(m_currentHealth); }
public void TakeDamage(int count) { Health = Mathf.Clamp(Health - count, 0, int.MaxValue); if (Health == 0) { Dead(); } HealthChange.Invoke(); }
public void HealPleyer(object obj) { if (Health < 100) { Health += 1; Semaphore.WaitOne(); HealthChange?.Invoke(); Semaphore.Release(); } }
private IEnumerator StartHeal() { float targetValue = _health + 10; while (_health < targetValue && _health != _maxHealth) { _health += _oneStepValue; HealthChange.Invoke(_health); yield return(new WaitForSeconds(_speed)); } }
public void TakeDamage() { this.Health--; print(Health); HealthChange.Invoke(Health); if (Health == 0) { print("You're dead!"); SceneManager.LoadScene("SampleScene"); } }
private IEnumerator StartDamage() { float targetValue = _health - 10; while (_health > targetValue && _health != 0) { _health -= _oneStepValue; HealthChange.Invoke(_health); yield return(new WaitForSeconds(_speed)); } }
public void RestoreHealth(float restoreAmount) { if (CurrentHealth >= m_maxShield) { CurrentHealth = m_maxShield; return; } CurrentHealth += restoreAmount; HealthChange?.Invoke(CurrentHealth); }
// Update is called once per frame void Update() { currentValue -= timeFactor * Time.deltaTime; HealthChange.Invoke(currentValue); if (currentValue <= 0) { GetComponent <IDamageable>().Die(); } else { GetComponent <IDamageable>().Damaged(); } }
public void TakeDamage(float damage) { if (!Shielding) { return; } if (CurrentHealth <= 0f) { CurrentHealth = 0f; return; } CurrentHealth -= damage; HealthChange?.Invoke(CurrentHealth); }
public virtual void RestoreHealth(float restoreAmount) { float restoreAdjust = (m_currentHealth + restoreAmount); if (restoreAmount > m_maxHealth) { restoreAmount = m_maxHealth; } if (m_currentHealth == restoreAdjust) { return; } m_currentHealth = restoreAdjust; HealthChange?.Invoke(m_currentHealth); }
public virtual void TakeDamage(float damage) { if (m_shield) { if (m_shield.Shielding) { return; } } if (m_currentHealth <= 0) { m_currentHealth = 0f; return; } m_currentHealth -= damage; HealthChange?.Invoke(m_currentHealth); }
public virtual void TakeDamage(float damage) { if (m_shield) { if (m_shield.Shielding) { return; } } if (_count > 0) { return; } if (m_currentHealth <= 0) { m_currentHealth = 0f; return; } _count++; float damageAdjust = (m_currentHealth - damage); if (damageAdjust <= 0) { damageAdjust = 0; } if (m_currentHealth == damageAdjust) { return; } m_currentHealth = damageAdjust; HealthChange?.Invoke(m_currentHealth); StopCoroutine(DamageDelay()); StartCoroutine(DamageDelay()); }
public void RestoreHealth(float restoreAmount) { if (CurrentHealth >= m_maxShield) { CurrentHealth = m_maxShield; return; } float shieldAdjust = (CurrentHealth + restoreAmount); if (shieldAdjust > MaxHealth) { shieldAdjust = MaxHealth; } if (CurrentHealth == shieldAdjust) { return; } CurrentHealth = shieldAdjust; HealthChange?.Invoke(CurrentHealth); }
public void AddHP(int ammount) { CurrentHP += ammount; CorrectHP(); HealthChange?.Invoke(PopUpTypes.HealthUp, ammount); }
public void SubstractHP(int ammount) { CurrentHP -= ammount; CorrectHP(); HealthChange?.Invoke(PopUpTypes.HealthDown, ammount); }
/// <summary> /// Constructor for the health class. Sets max and current health to a /// specified value. /// </summary> /// <param name="max">Maximum health of the player.</param> public Health(int max) { Max = max; Current = Max; healthChanged?.Invoke(Current); }