private void Start() { HandleObservable(); currentHealth = maxHealth; OnHealthChanged.Invoke(currentHealth, maxHealth); }
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); } }
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(); }
public void AddHealth(float healthAmount) { _currentHealthAmount = _currentHealthAmount + healthAmount > maxHealthAmount ? maxHealthAmount : _currentHealthAmount + healthAmount; healthChanged?.Invoke(); }
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) } } }
public void LoadPlayer() { PlayerData data = SaveSystem.LoadPlayer(); currentHealth = data.health; HealthChanged.Invoke(currentHealth); }
private void OnHealthChanged(float newHealth) { if (HealthChanged != null) { HealthChanged.Invoke(newHealth); } }
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); } } }
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; } }
private void Start() { _currenthealth = _maxHealth; StartCoroutine(ShootWithDelay(_shootPoint, _secondsBetweenShoot)); HealthChanged?.Invoke(_currenthealth); }
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) } } }
public void Healing() { if (_curentHealth + _variableValue <= _maxHealth) { _curentHealth += _variableValue; HealthChanged?.Invoke(); } }
public void Heal(int heal) { if (hp < maxHp) { hp += heal; HealthChanged?.Invoke(this, hp); } }
public void TakeDamage() { if (_curentHealth - _variableValue >= 0) { _curentHealth -= _variableValue; HealthChanged?.Invoke(); } }
public void ReduceHealth(int damage) { _health = Math.Max(0, _health - damage); HealthChanged?.Invoke(_health); if (_health == 0) { HealthIsZero?.Invoke(); } }
public void ApplyDamage(int damage) { _currentHealth -= damage; HealthChanged?.Invoke(_currentHealth, _health); if (_currentHealth <= 0) { Destroy(gameObject); } }
public void Heal(int healthAmount) { health += healthAmount; if (health >= maxHealth) { health = maxHealth; } HealthChanged?.Invoke(); }
private void UpdateHealth() { HealthChanged?.Invoke(_currentHealth); if (_currentHealth <= 0) { GameOver(); } }
public void ApplyDamage(int damage) { _health -= damage; HealthChanged?.Invoke(_health); if (_health <= 0) { Die(); } }
// Use this for initialization void Start() { currentHealth = originalHealth; //Send message for script to update UI if (HealthChanged != null && showHealth) { HealthChanged.Invoke(0); } }
public void TakeDamage(float damage) { if (_currentHealth > 0) { _currentHealth -= damage; PlayAnimation(); PlayEffect(); HealthChanged?.Invoke(_currentHealth, _maxHealth); } }
public void GeDamage(float hp) { if (_currentHealth - hp < 0) { return; } _currentHealth -= hp; HealthChanged.Invoke(_currentHealth); }
public void TakeDamage(int damage) { _currentHealth -= damage; HealthChanged?.Invoke(_currentHealth, _health); if (_currentHealth <= 0) { Debug.Log("Defete"); } }
private void OnHealth() { health--; if (health == 0) { // ads.StartCoroutine("ShowAd"); menuController.LoseGame(); } HealthChanged?.Invoke(health); }
public void Reset() { currentHealth = originalHealth; isDead = false; //Send message for script to update UI if (HealthChanged != null && showHealth) { HealthChanged.Invoke(0); } }
public void TakeDamage(int damage) { _health -= damage; if (_health <= 0) { Die(); } HealthChanged?.Invoke(_health); }
public void ApplyDamage(int value) { if (_currentHealth + value >= 0 && _currentHealth + value <= _health) { _currentHealth += value; HealthChanged?.Invoke(_currentHealth, _health); SetAnimation(value); } }
private void HandleHealthChange(bool fireZeroHealthEvent = true) { healthChanged?.Invoke(_currentHealth, _maxHealth); if (fireZeroHealthEvent && _currentHealth <= 0 && !_zeroHealthEventFired) { zeroHealth?.Invoke(); _zeroHealthEventFired = true; } }
private void ApplyDamage() { _health--; HealthChanged?.Invoke(_health); if (_health <= 0) { Died?.Invoke(); gameObject.SetActive(false); } }
private void EnemyFinished(GameObject enemy) { var enemyComp = enemy.GetComponent <Enemy>(); Health -= enemyComp.Damage; HealthChanged?.Invoke(Health); enemyComp.OnDied -= EnemyDied; CheckIfLastEnemyDiedOrFinished(); }