/// <summary> /// Resolve an attack against the target unit stack /// </summary> /// <param name="target">Target unit stack</param> /// <param name="attackRollResult">Attack roll result representing the attack</param> /// <param name="useEstimates">Whether estimated results will be used or honest rolls will be made</param> /// <returns>Whether the attack was successfully resolved</returns> private bool ResolveAnAttackAgainstTarget(UnitStack target, AttackRollResult attackRollResult, bool useEstimates) { if (!IsValidAttackTarget(target, attackRollResult)) { return(false); } int positiveDieRoll = CombatHelper.Instance.RollDie(); int negativeDieRoll = CombatHelper.Instance.RollDie(); int defenseRoll = positiveDieRoll - negativeDieRoll; int defensiveSkill = CombatHelper.Instance.CalculateDefensiveSkill(attackRollResult.Attack, target); int shield = CombatHelper.Instance.CalculateShieldValue(attackRollResult.Attack, target); AttackResolutionEvent data = new AttackResolutionEvent(attackRollResult, target, positiveDieRoll, negativeDieRoll, defensiveSkill, shield); int totalDefense = defenseRoll + defensiveSkill + shield; int armor = CombatHelper.Instance.CalculateArmorValue(attackRollResult.Attack, target, attackRollResult.IsCritical); data.SetArmor(armor); int damage = 0; if (useEstimates) { damage = CombatHelper.Instance.EstimateAttackDamage(attackRollResult, target); } else { damage = CombatHelper.Instance.CalculateDamage(attackRollResult, target, totalDefense, armor); } data.SetDamage(damage); target.TakeDamage(damage); int totalAttack = attackRollResult.AttackRoll + attackRollResult.AttackSkill; if (useEstimates) { FileLogger.Trace("COMBAT", "Simulation: estimated damage = " + damage); } else { FileLogger.Trace("COMBAT", "Attack: " + totalAttack + ", defense: " + totalDefense + ", weapon damage: " + attackRollResult.FullDamage + ", armor: " + armor + ", resulting damage: " + damage); } bool deleted = false; for (int i = 0; i < _attackerRollResults.Count; i++) { if (_attackerRollResults[i].Contains(attackRollResult)) { bool removed = _attackerRollResults[i].RemoveAttackRollResult(attackRollResult); if (!removed) { FileLogger.Trace("COMBAT", "Failed to remove an attack roll result from a collection!"); } if (_attackerRollResults[i].Count == 0) { _attackerRollResults.RemoveAt(i); } deleted = true; break; } } if (!deleted) { for (int i = 0; i < _defenderRollResults.Count; i++) { if (_defenderRollResults[i].Contains(attackRollResult)) { bool removed = _defenderRollResults[i].RemoveAttackRollResult(attackRollResult); if (!removed) { FileLogger.Trace("COMBAT", "Failed to remove an attack roll result from a collection!"); } if (_defenderRollResults[i].Count == 0) { _defenderRollResults.RemoveAt(i); } break; } } } if (AttackResolved != null) { AttackResolved(this, data); } return(true); }