/// <summary> /// Attack another character. Hits if our role is greater than the /// opponent's armor class. /// </summary> /// <param name='opponent'>Whom we are attacking.</param> /// <param name='roll'>An int from 1-20.</param> public AttackResult Attack(Character opponent, int roll) { if(opponent == null) { throw new ArgumentException("opponent cannot be null"); } Helpers.ValidateD20Value("roll", roll); var attackerStrengthModifier = this.modifierTable[this.Attacker.Strength - 1]; var modifiedRoll = roll + attackerStrengthModifier; var modifiedArmorClass = opponent.ArmorClass + this.modifierTable[opponent.Dexterity - 1]; var result = AttackResult.Miss; var damage = 0; if(roll == 20) { result = AttackResult.CriticalHit; damage = 2 + (2 * attackerStrengthModifier); } else if(modifiedRoll >= modifiedArmorClass) { result = AttackResult.Hit; damage = 1 + attackerStrengthModifier; } if((result == AttackResult.Hit || result == AttackResult.CriticalHit) && damage < 1) { damage = 1; } opponent.HitPoints -= damage; return result; }
/// <summary> /// Initializes a new instance of the <see cref="EverCraft.CombatCalculator"/> class. /// </summary> /// <param name='attacker'> /// The attacking character. /// </param> public CombatCalculator(Character attacker) { this.Attacker = attacker; }