private static IEnumerable <ICombatEventData> ApplyActionEffect(IAction selectedAction, IActorChangeCalculator actorChangeCalculator) { // Pre-apply copies IInitiativeActor sourceBeforeEffect = selectedAction.Source.Copy(); IReadOnlyList <IInitiativeActor> targetsBeforeEffect = selectedAction.Targets.Select(t => t.Copy()).ToArray(); // Apply selectedAction.Effect.Apply(selectedAction.Source, selectedAction.Targets); // Post-apply comparison foreach (ICombatEventData eventData in actorChangeCalculator.GetChangeEvents(sourceBeforeEffect, selectedAction.Source)) { yield return(eventData); } foreach (var beforeAfterPair in targetsBeforeEffect.ToDictionary( x => x, x => selectedAction.Targets.First(y => y.Id == x.Id))) { foreach (ICombatEventData combatEventData in actorChangeCalculator.GetChangeEvents(beforeAfterPair.Key, beforeAfterPair.Value)) { yield return(combatEventData); } } }
private static IEnumerable <ICombatEventData> ApplyActionCost(IAction selectedAction, IActorChangeCalculator actorChangeCalculator) { // Pre-apply copy IInitiativeActor sourceBeforeCost = selectedAction.Source.Copy(); // Apply selectedAction.Cost.Pay(selectedAction.Source, selectedAction.ActionSource); // Post-apply comparison return(actorChangeCalculator.GetChangeEvents(sourceBeforeCost, selectedAction.Source)); }