using System.Collections.Generic; using System.Linq; using System.Text; namespace EliteBGS.BGS.LogGenerator { public class MissionFormat : LogFormatter { public string GenerateLog(Objective objective) { Dictionary> collated = new Dictionary>(); StringBuilder output = new StringBuilder(); int total_influence = 0; var missions = objective.LogEntries .OfType() .Where(x => x.IsEnabled) ; if (missions == null) { return ""; } foreach (MissionCompleted m in missions) { if (!collated.ContainsKey(m.MissionName)) { collated[m.MissionName] = new Dictionary(); } if (!collated[m.MissionName].ContainsKey(m.Influence)) { collated[m.MissionName][m.Influence] = 0; } ++collated[m.MissionName][m.Influence]; total_influence += m.Influence.Length; } foreach (var mission in collated) { if (objective.Faction != null) { output.AppendFormat("{0} for {1}\n", mission.Key, objective.Faction); } else { output.AppendFormat("{0}\n", mission.Key); } output.Append("("); foreach (var influence in mission.Value.OrderBy(x => x.Key.Length)) { output.AppendFormat("Inf{0} x{1}, ", influence.Key, influence.Value); } output.Remove(output.Length - 2, 2); // remove last ", " output.Append(")\n\n"); } var support = objective.LogEntries.OfType(); foreach (InfluenceSupport inf in support) { output.Append(inf.ToString()); output.Append("\n"); total_influence += inf.Influence.Length; } if (support.Count() > 0) { output.Append("\n"); } if (total_influence > 0) { output.AppendFormat("Total Influence: {0}", total_influence); } return output.ToString().Trim(); } } }