internal static IEnumerable <List <Output> > RunBattlefield(EcsRegistrar rgs, long globalId, long battlefieldId, Func <CombatChoicesAndTargets, ActionChosen> receivePlayerInput) { while (true) { var battlefieldContainer = rgs.GetPartSingle <Parts.Container>(battlefieldId); var battlefieldEntityIds = battlefieldContainer.EntityIds.ToList(); foreach (var agentId in battlefieldEntityIds) { var battlefieldAgent = rgs.GetPartSingleOrDefault <Parts.Agent>(agentId); if (battlefieldAgent == null) { continue; } if (battlefieldAgent.CombatStatusTags.Intersect(Vals.CombatStatusTag.CombatTerminalStatuses).Any()) { continue; } ActionChosen agentActionChosen; if (battlefieldAgent.ActiveCombatAI == Vals.AI.PlayerChoice) { var possibleActions = Agent.GetPossibleActions(rgs, globalId, agentId, battlefieldEntityIds); agentActionChosen = receivePlayerInput(possibleActions); } else { agentActionChosen = Agent.GetAgentAICombatAction(rgs, globalId, battlefieldAgent.ActiveCombatAI, agentId, battlefieldEntityIds); } var results = Combat.ProcessAgentAction(rgs, agentId, agentActionChosen); var output = Narrator.OutputForCombatMessages(rgs, results); yield return(output); } var endOfBattleOutputs = GetEndOfBattleOutputs(rgs, battlefieldEntityIds); if (endOfBattleOutputs.Any()) { yield return(endOfBattleOutputs); yield break; } } }