Ejemplo n.º 1
0
        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.
        }
Ejemplo n.º 2
0
 private bool IsVulnerable(DamageType damageType)
 {
     return(Vulnerabilities.Contains(damageType));
 }