public void PrepareDefence(IEnumerable <AttackAction> attacksToDefend) { if (registeredDefences.Any()) { PerformedDefence = CurrentCombatStrategy.PrepareDefence(attacksToDefend, registeredDefences.Where(x => x.IsAvailable)); } }
private DefenceAction SelectDefence(AttackAction attack, IEnumerable <DefenceAction> availableDefences) { DefenceAction selectedDefence = null; List <DefensiveActionData> possibleDefences = attack.ActionData.PossibleDefences; int bestDefenceIndex = int.MaxValue, currentIndex; foreach (var defence in availableDefences) { if ((currentIndex = possibleDefences.IndexOf(defence.ActionData)) < bestDefenceIndex) { bestDefenceIndex = currentIndex; selectedDefence = defence; } } return(selectedDefence); }