/// <summary> /// Apply damage to the Health. /// </summary> /// <param name="dmg">The damage to apply.</param> /// <returns>The actual damage amount dealt.</returns> public virtual float Damage(Damage dmg) { if (enabled && dmg.amount > 0 && hitInvulnTimer.Use()) { DamageModifier?.Invoke(ref dmg); float prevHealth = health; health -= dmg.amount; health = Mathf.Max(health, 0); dmg.amount = prevHealth - health; healthRegenTimer.Set(); SendMessage("OnDamage", dmg, SendMessageOptions.DontRequireReceiver); Damaged?.Invoke(dmg); if (damageSound) { damageSound.Play(); } if (health == 0 && !dead) { dead = true; SendMessage("OnZeroHealth", SendMessageOptions.DontRequireReceiver); ZeroHealth?.Invoke(); } } else { dmg.amount = 0; } return(dmg.amount); }
public void Damage(int amount) { var prev = CurrentHealth; CurrentHealth = Mathf.Max(CurrentHealth - amount, 0); Damaged?.Invoke(this, new DamagedEventArgs(prev - CurrentHealth)); }
/// <inheritdoc /> public void TakeDamage(DamageType damageType, int amount, IEntity source = null, IEntity sourceMob = null) { if (damageType == DamageType.Total) { throw new ArgumentException("Cannot take damage for DamageType.Total"); } InitializeDamageType(damageType); int oldValue = _currentDamage[damageType]; int oldTotalValue = -1; if (amount == 0) { return; } amount = Resistances.CalculateDamage(damageType, amount); _currentDamage[damageType] = Math.Max(0, _currentDamage[damageType] + amount); UpdateForDamageType(damageType, oldValue); Damaged?.Invoke(this, new DamageEventArgs(damageType, amount, source, sourceMob)); if (Resistances.AppliesToTotal(damageType)) { oldTotalValue = _currentDamage[DamageType.Total]; _currentDamage[DamageType.Total] = Math.Max(0, _currentDamage[DamageType.Total] + amount); UpdateForDamageType(DamageType.Total, oldTotalValue); } }
public void TakeDamage(float damage) { if (_canTakeDamage) { _health -= damage; Damaged?.Invoke(); } }
private void OnDamaged() { if (_onDamaged.IsAssigned()) { _onDamaged.Invoke(); } Damaged?.Invoke(this); }
protected virtual void OnDamaged(HealthAgentDamageArgs args) { Damaged?.Invoke(args); if (!IsAlive) { OnDied(new HealthAgentDeathArgs(_delegator, args.Agressor, args.Amount)); } }
public void Damage(IEnumerable <IDamagable> damagables) { DamageArgs damageArgs = new DamageArgs(Origin, gameObject, damage); foreach (var damagable in damagables) { damagable.TakeDamage(damageArgs); } Damaged?.Invoke(damagables); }
private void DealDamage(int amount) { health -= 10; if (health - amount < 0) { health = 0; } Damaged?.Invoke(amount); }
public void AddDamage(int damageAddition, HitInfo hit) { hit.damageChangeInfo.oldDamage = CurrentDamage; CurrentDamage += Mathf.Abs(damageAddition); CurrentDamage = Mathf.Clamp(CurrentDamage, 0, maxDamage); hit.damageChangeInfo.oldDamage = CurrentDamage; Damaged?.Invoke(hit); }
public void TakeDamage(int amount) { CurrentHealth = Mathf.Max(CurrentHealth - amount, 0); _animator.SetTrigger("TakeDamage"); Damaged?.Invoke(this, new HealthEventArgs(CurrentHealth / (float)MaximumHealth)); if (CurrentHealth <= 0) { GameManager.instance.UnitDefeated(this); } }
public void Apply(float amount) { health -= amount; Damaged?.Invoke(amount); if (!Alive) { print($"{name} died."); } }
public void AcceptDamage(int damage) { CurrHealth -= damage; if (CurrHealth <= 0) { Died?.Invoke(); } Damaged?.Invoke(this); }
public void Damage(DamageInfo damage) { if (damage.Damage > 0) { health.Damage(damage.Damage); Damaged?.Invoke(); } else { UndamagedHit?.Invoke(); } }
public void OnDamaged(Unit emeny) { if (_isStandUp == false) { return; } _rigidbody.isKinematic = false; _enemy = emeny; Damaged?.Invoke(); StartCoroutine(OnStandUpDelay()); }
public void ApplyDamage(int amount) { Health -= amount; if (Health > 0) { Damaged?.Invoke(this); } else { MarkedForDestruction = true; } }
public virtual void Ride() { Damaged += delegate { Console.WriteLine("This Vehicle is broken, repair it first"); Console.ReadKey(); }; EmptyFuel += delegate { Console.WriteLine("You are out of fuel."); Console.ReadKey(); }; if (Fuel <= 0) { EmptyFuel?.Invoke(); return; } if (IsBroken) { Damaged?.Invoke(); return; } Random rand = new Random(); Console.WriteLine("Riding for 1 hour..."); Thread.Sleep(1000); Distance += Speed; int chance = rand.Next(1, 4); IsBroken = chance == 2 ? true : false; if (IsBroken) { Console.Clear(); Damaged?.Invoke(); } Fuel -= Consumption; if (Fuel <= 0) { EmptyFuel?.Invoke(); Console.ReadKey(); } }
public virtual void ApplyDamage(float value) { _inflictedDamage += value; if (_visual != null) { _visual.ApplyDamageVisual(); } Damaged?.Invoke(this, value); if (Health <= 0) { Destroy(); } }
public void AddDamageEffect(PeriodicDamageEffect damageEffect) { void applyDamage() { Damaged?.Invoke(this, damageEffect.DamagePerTick); } Coroutine coroutine = _coroutineOwner.StartCoroutine( PeriodicEffectCoroutine( damageEffect.TicksPerSecond, damageEffect.FirstTickImmediately, applyDamage ) ); AddPeriodicEffect(coroutine, _periodicDamageEffects, damageEffect.DurationSeconds); }
public Level(string name, Map map) { Name = name; Map = map; Map.CellChange += (x, y, creature) => CellChange?.Invoke(x, y, creature); Map.Die += (x, y, creature) => Die?.Invoke(x, y, creature); Map.Damaged += (x, y, creature, damage) => Damaged?.Invoke(x, y, creature, damage); Map.DoingStarted += (x, y, character, doing) => DoingStarted?.Invoke(x, y, character, doing); Map.DoingEnd += (x, y, character, doing) => DoingEnd?.Invoke(x, y, character, doing); Map.Die += (x, y, creature) => { if (creature is Base _base) { EndWin?.Invoke(!_base.IsPlayerCreature); IsEnd = true; } }; }
public Level(string name) { Name = name; Map = new Map(File.ReadAllLines(GetFolderName() + "\\map.txt")); Map.CellChange += (x, y, creature) => CellChange?.Invoke(x, y, creature); Map.Die += (x, y, creature) => Die?.Invoke(x, y, creature); Map.Damaged += (x, y, creature, damage) => Damaged?.Invoke(x, y, creature, damage); Map.DoingStarted += (x, y, character, doing) => DoingStarted?.Invoke(x, y, character, doing); Map.DoingEnd += (x, y, character, doing) => DoingEnd?.Invoke(x, y, character, doing); Map.Die += (x, y, creature) => { if (creature is Base _base) { EndWin?.Invoke(!_base.IsPlayerCreature); IsEnd = true; } }; }
public void Damage(DamageInfo damage) { if (enemy.Element == damage.Element) { if (damage.Damage > 0) { health.Damage(damage.Damage); Damaged?.Invoke(); } else { UndamagedHit?.Invoke(); } } else { UndamagedHit?.Invoke(); } }
public void TakeDamage(float amount) { Health -= amount; _regen = false; //Restart the regen timer _regenTimer.Stop(); _beforeRegenTimer.Restart(); Damaged?.Invoke(amount); if (Health < 0) { Health = 0; Destroyed?.Invoke(); return; } }
public void ApplyDamage(float damage) { _inflictedDamage += damage; if (_visual != null) { _visual.ApplyDamageVisual(); } Damaged?.Invoke(this, damage); if (Health <= 0) { IsDestroyed = true; if (_visual != null) { _visual.ApplyDestroyVisual(); } } }
public void Damage(float amount) { bool shieldDamaged = false; float damageRemaining = amount; if (!isDead) { if (currentShield > 0) { if (currentShield <= damageRemaining) { damageRemaining -= currentShield; currentShield = 0; } else { currentShield -= damageRemaining; damageRemaining = 0; } shieldDamaged = true; } if (damageRemaining > 0) { damageRemaining = Mathf.Clamp(damageRemaining - healthyInterface.Armor, 1, damageRemaining); } if (damageRemaining > 0) { Hitpoints -= damageRemaining; } Damaged?.Invoke(shieldDamaged, amount); if (Hitpoints <= 0) { isDead = true; } } }
private void CheckIfDamaged() { if (_health._playerDamaged) { Damaged?.Invoke(); Debug.Log("Damaged"); if (_damageParticles != null) { _damageParticles.Play(); } if (_damageSound != null) { AudioHelper.PlayClip2D(_damageSound, 1f); } } _health._playerDamaged = false; _isDamaged = true; if (_health._playerDamaged == false) { CheckIfStoppedMoving(); } }
public void TakeDamage(int amount) { if (_impulse != null) { _impulse.GenerateImpulse(); } _iFrames = true; StartCoroutine(IFramesWait()); _currentHealth -= amount; if (_currentHealth <= 0) { Kill(); } else { if (_damageSound != null) { Instantiate(_damageSound, transform.position, Quaternion.identity, transform); } Damaged?.Invoke(); } }
/// <inheritdoc /> public void TakeDamage(DamageType damageType, int amount, IEntity source = null, IEntity sourceMob = null) { if (damageType == DamageType.Total) { foreach (DamageType e in Enum.GetValues(typeof(DamageType))) { if (e == damageType) { continue; } TakeDamage(e, amount, source, sourceMob); } return; } InitializeDamageType(damageType); int oldValue = _currentDamage[damageType]; int oldTotalValue = -1; if (amount == 0) { return; } amount = Resistances.CalculateDamage(damageType, amount); _currentDamage[damageType] = Math.Max(0, _currentDamage[damageType] + amount); UpdateForDamageType(damageType, oldValue); Damaged?.Invoke(this, new DamageEventArgs(damageType, amount, source, sourceMob)); if (Resistances.AppliesToTotal(damageType)) { oldTotalValue = _currentDamage[DamageType.Total]; _currentDamage[DamageType.Total] = Math.Max(0, _currentDamage[DamageType.Total] + amount); UpdateForDamageType(DamageType.Total, oldTotalValue); } }
public void TakeDamage(float damage, Soldier shooter = null) { if (isDead) { return; } health -= damage; getHurtAudioSource.Play(); if (shooter)//not take because not in safe zone { Damaged?.Invoke(shooter); } if (health <= 0) { isDead = true; nav.isStopped = true; audioSource.Stop(); anim.SetTrigger(HashIDs.deadTrigger); } }
public void AddCharacter(Character character) { if (character.IsPlayerCreature && PlayerCharactersQueue.Count < 50) { PlayerCharactersQueue.Enqueue(character); } else if (EnemyCharactersQueue.Count < 50) { EnemyCharactersQueue.Enqueue(character); } character.Die += (x, y, creature) => { if (this[x, y] == null) { return; } this[x, y] = null; Die?.Invoke(x, y, creature); }; character.Damaged += (x, y, creature, damage) => Damaged?.Invoke(x, y, creature, damage); character.StartDoing += (x, y, creature, doing) => DoingStarted?.Invoke(x, y, creature, doing); character.EndDoing += (x, y, creature, doing) => DoingEnd?.Invoke(x, y, creature, doing); SpawnCharactersInQueue(); }
public void Damage(IDamagable damagable) { damagable.TakeDamage(new DamageArgs(Origin, gameObject, damage)); Damaged?.Invoke(damagable); }