private int CalcDamage(DealDamage damage) { // First check for immunities, then resistance, then vulnerability (p. 197 Player's Handbook) if (Immunities.Contains(damage.DamageType)) { return(0); } int actualHpDamage = damage.Hp; // Resistances and vulnerabilities do not stack, so one does as much as multiple. if (Resistances.Contains(damage.DamageType)) { actualHpDamage /= 2; // integer division correctly rounds down } // It is technically possible to have a resistance and a vulnerability for the same damage type. // https://rpg.stackexchange.com/a/167448 if (Vulnerabilities.Contains(damage.DamageType)) { actualHpDamage *= 2; } return(actualHpDamage); // Possible future refactor: It's a little bit inefficient to check all of the // lists every time, especially since this function is called from in a loop. }
public bool IsImmune(ImmunityType type) { if (Immunities == null) { return(false); } return(Immunities.Contains(type)); }
public int HowMuchWouldYouHitMe(Group s) { if (Immunities.Contains(s.AttackType)) { return(0); } else if (Weaknesses.Contains(s.AttackType)) { return(s.EffectivePower * 2); } { return(s.EffectivePower); } }
public int CalculateDamageDone(string incomingAttackType, int effectivePower) { if (Immunities != null && Immunities.Contains(incomingAttackType)) { return(0); } if (Weaknesses != null && Weaknesses.Contains(incomingAttackType)) { return(effectivePower * 2); } return(effectivePower); }
/// <summary> /// Calculate Damage amount from damage and DamageType /// Taking into consideration Resistances and Immunities /// </summary> /// <param name="damage"></param> /// <param name="damageType"></param> /// <returns></returns> public int CalculateDamage(int damage, DamageType damageType) { double totalDamage = 0d; if (Resistances.Contains(damageType)) { totalDamage = Math.Floor((double)damage / 2d); } else if (Immunities.Contains(damageType)) { } else { totalDamage = damage; } return(Convert.ToInt32(totalDamage)); }
public int GetDamage(BattleGroup attackingGroup) { if (attackingGroup.Type == Type) { return(0); } int damage = attackingGroup.EffectivePower; if (Immunities.Contains(attackingGroup.AttackType)) { damage = 0; } if (Weaknesses.Contains(attackingGroup.AttackType)) { damage *= 2; } return(damage); }
private bool IsImmune(DamageType damageType) { return(Immunities.Contains(damageType)); }
public int CalculateHitPointChange(List <DamageSet> damageSets) { int hpChange = 0; List <DamageSet> damageDone = new List <DamageSet>(); foreach (DamageSet damageSet in damageSets) { damageDone.Add(new DamageSet(damageSet)); } List <DamageReduction> damageReductions = DamageReductions.ToList(); damageReductions.Sort((dr1, dr2) => dr2.Value.CompareTo(dr1.Value)); List <EnergyResistance> energyResistances = EnergyResistances.ToList(); foreach (DamageSet damageSet in damageDone) { foreach (EnergyResistance energyResistance in energyResistances) { if (damageSet.DamageDescriptorSet.IsEnergyDamage() && damageSet.DamageDescriptorSet.Contains(energyResistance.EnergyType)) { int numEnergyTypes = damageSet.DamageDescriptorSet.Count; int thisEnergyDamage = damageSet.Amount / numEnergyTypes; int thisEnergyDamageAfterResistance = thisEnergyDamage - energyResistance.Value; if (thisEnergyDamageAfterResistance < 0) { thisEnergyDamageAfterResistance = 0; } int difference = thisEnergyDamage - thisEnergyDamageAfterResistance; damageSet.Amount -= difference; if (damageSet.Amount < 0) { damageSet.Amount = 0; } } } } foreach (DamageSet damageSet in damageDone) { if (damageSet.DamageDescriptorSet.IsTyped()) { foreach (Types.Damage damageType in damageSet.DamageDescriptorSet.ToList()) { if (Immunities.Contains(damageType)) { damageSet.Amount = 0; } } foreach (DamageReduction dr in damageReductions) { if (!dr.IsBypassedBy(damageSet.DamageDescriptorSet)) { damageSet.Amount -= dr.Value; break; } } if (damageSet.Amount < 0) { damageSet.Amount = 0; } } } foreach (DamageSet damageSet in damageDone) { hpChange -= damageSet.Amount; } return(hpChange); }
public bool IsImmuneTo(Attack attack) => Immunities.Contains(attack);