public void Deal(Health health, Resistances resistances) { DamageSources filteredDamageTypes = resistances.FilterDamage(sources); float totalDamage = filteredDamageTypes.CalculateTotalDamage(); health.Subtract(totalDamage); }
/// <summary> /// prevents teammatesFrom blocking attacks /// </summary> /// <param name="damageSorce"></param> /// <param name="damageType"></param> /// <returns></returns> public bool ignoreDamage(DamageSources damageSorce, DamageTypes damageType) { if ((team & damageSorce) == damageSorce) { return(true); } return(false); }
public virtual void Damage(float damage, DamageSources damageSource, Vector2 knockback = default(Vector2)) { if (CanBeDamagedBy(damageSource)) { Health -= damage; if (Health < 0) Die(); } }
public virtual bool CanBeDamagedBy(DamageSources damageSource) { switch (damageSource) { case DamageSources.Player: return DamagedBy.Player; case DamageSources.Crabs: return DamagedBy.Crabs; case DamageSources.Population: return DamagedBy.Population; default: return false; } }
public DamageSources FilterDamage(DamageSources toFilter) { Dictionary <DamageType, DamageSource> .KeyCollection keys = toFilter.Dictionary.Keys; foreach (DamageType rt in keys) { toFilter.Dictionary[rt].value -= (_dictionary[rt].value / 100) * toFilter.Dictionary[rt].value; } return(toFilter); }
public void BuildReturnsCorrectResult() { var expectedCount = FullResultCount; var sut = CreateSut(); var stats = BuildToStats(sut, expectedCount); Assert.That(stats, Has.Exactly(expectedCount).Items); foreach (var(i, attackDamageHand) in AttackDamageHands.Index()) { var expected = $"test.{DamageSource.Attack}.{attackDamageHand}.Skill"; Assert.AreEqual(expected, stats[i].Identity); } var offset = AttackDamageHands.Count; foreach (var(i, damageSource) in DamageSources.Except(DamageSource.Attack).Index()) { var expected = $"test.{damageSource}.Skill"; Assert.AreEqual(expected, stats[i + offset].Identity); } offset += DamageSources.Count - 1; foreach (var attackDamageHand in AttackDamageHands) { foreach (var(i, ailment) in Ailments.Index()) { var expected = $"test.{DamageSource.Attack}.{attackDamageHand}.{ailment}"; Assert.AreEqual(expected, stats[offset + i].Identity); } offset += Ailments.Count; } foreach (var damageSource in DamageSources.Except(DamageSource.Attack, DamageSource.OverTime)) { foreach (var(i, ailment) in Ailments.Index()) { var expected = $"test.{damageSource}.{ailment}"; Assert.AreEqual(expected, stats[offset + i].Identity); } offset += Ailments.Count; } }
/// <summary> /// apply the specified damage to this Actor /// </summary> /// <param name="amount">amount of damage</param> /// <returns>true if damage is taken</returns> public bool takeDamage(float amount, DamageTypes damageType, DamageSources damageSorce) { if (ignoreDamage(damageSorce, damageType)) { return(false); } health -= amount; if (health < health_MIN) { health = health_MIN; } if (health <= 0) { actorDies(); } takeDamageGrapic_flashColor(.8f); if (healthUI != null) { healthUI.updateHealthDispley(health_MAX, health); } return(true); }
/// <summary>Heals this unit and returns the points healed, or -1 if the unit died before it could be healed.</summary> public virtual int ReceiveHeal(Unit caster, uint healAmount, float healHatredScale = 1.0f) { uint oldHealth; uint resultantHealth; if (IsDead || PendingDisposal) { return(-1); } lock (DamageApplicationLock) { if (IsDead) { return(-1); } oldHealth = _health; _health = Math.Min(MaxHealth, _health + healAmount); resultantHealth = _health; if (_health == MaxHealth && oldHealth < MaxHealth) { DamageSources.Clear(); } } if (caster != null) { CbtInterface.OnTakeHeal(caster); caster.CbtInterface.OnDealHeal(this, resultantHealth - oldHealth); } LastHealOid = caster?.Oid ?? Oid; return((int)(resultantHealth - oldHealth)); }
public override void Damage(float damage, DamageSources damageSource, Vector2 knockback = default(Vector2)) { base.Damage(damage, damageSource, knockback); Rigidbody.AddForce(knockback, ForceMode2D.Impulse); }
public bool takeDamage(float amount, DamageTypes damageType, DamageSources damageSorce) { return(false); }
public bool ignoreDamage(DamageSources damageSorce, DamageTypes damageType) { return(false); }
//set methods to update properties with the using actors effects public void setDamage(float damage, DamageTypes damageType, DamageSources team) { damageAmount = damage; this.damageType = damageType; sourceTeam = team; }