public void Execute(IDice dice, Combatant attacker, Combatant defender, IList<CombatLogEntry> combatLog) { int attack = attacker.ToHitAttack; int defend = defender.ToHitDefense; var toHitThreshold = ((attack + ((attacker.Level - defender.Level) / 2)) / ((double)attack + defend)).ConstrainWithinBounds(0.20, 0.80); Debug.WriteLine("{0} has a {1:P0} chance to hit {2}", attacker.Name, toHitThreshold, defender.Name); if (dice.Random() < toHitThreshold) { var damage = Math.Max(1, attacker.GetAttackDamage(dice)); defender.LowerHealth(damage); combatLog.Add(new CombatLogEntryFromAction<Attack>(Name) { Text = string.Format("{0} hits {1} with {2} for {3} points!", attacker.Name, defender.Name, Name, damage), Attacker = attacker, CombatEffect = new CombatOutcome() { Damage = damage } }); } else { combatLog.Add( new CombatLogEntry { Text = string.Format("{0} attempts to hit {1} with {2} and fails miserably!", attacker.Name, defender.Name, Name), Attacker = attacker }); } }
public EffectOutcome Execute(IDice dice, Combatant attacker, Combatant defender) { var damage = (int) Math.Round(dice.Roll(Magnitude) * (1 + ((double)attacker.Intelligence.GetStatModifier() / 9)), MidpointRounding.AwayFromZero); defender.LowerHealth(damage); return new EffectOutcome() { Description = string.Format("{0} takes {1} points of damage!", defender.Name, damage), Damage = damage }; }