public Task AddCombatantAsync(GridEntity entity, ICombatant combatant, string factionKey = "") { List <IEntity> faction; if (entity.IsPlayer()) { Dead.RemoveAll(d => d.Id == entity.Id); } // some default behaviour will be to find the faction with the matching isPlayer if (string.IsNullOrEmpty(factionKey)) { var testFaction = Factions.FirstOrDefault(o => o.Value.Any(e => e.IsPlayer() == entity.IsPlayer())); if (testFaction.Value == null) { testFaction = Factions.FirstOrDefault(o => o.Value.Count == 0); } if (testFaction.Value == null) { testFaction = Factions.FirstOrDefault(); } faction = testFaction.Value; } else { faction = Factions[factionKey]; } if (faction != null) { faction.Add(entity); } Combatants.Add(entity, combatant); entity.Died += Combatant_Death; return(Task.CompletedTask); }