using System; using System.ComponentModel; using System.Collections.Generic; using System.Collections.Specialized; using System.Linq; using System.Text; using System.Threading.Tasks; using NonaBGS.Journal; namespace NonaBGS.BGS { public class Report { private List objectives = new List(); public delegate void OnLogDelegate(string log); public event OnLogDelegate OnLog; public List Objectives { get { return objectives; } set { objectives = value; } } public bool AddObjective(Objective objective) { var found = objectives.Find(x => x == objective); bool added = false; if (found == null) { objectives.Add(objective); added = true; } return added; } private bool IsRelevant(Entry e) { return e.Is(Events.MissionCompleted) || e.Is(Events.Docked) || e.Is(Events.FSDJump) || e.Is(Events.MultiSellExplorationData) || e.Is(Events.SellMicroResources) || e.Is(Events.RedeemVoucher) ; } public void Scan(PlayerJournal journal, DateTime start, DateTime end) { var entries = from file in journal.Files where file.NormalisedTimestamp >= start && file.NormalisedTimestamp <= end select file.Entries ; var relevant = from log in entries.SelectMany(array => array) where IsRelevant(log) select log ; string current_system = null; string current_station = null; string controlling_faction = null; this.objectives.ForEach(x => x.LogEntries.Clear()); foreach (var e in relevant) { LogEntry entry = null; if (e.Is(Events.Docked)) { /* gleem the current station from this message */ current_station = (e as DockedEntry).StationName; } else if (e.Is(Events.FSDJump)) { current_system = (e as FSDJumpEntry).StarSystem; controlling_faction = (e as FSDJumpEntry).SystemFaction; } else if (e.Is(Events.MissionCompleted)) { var completed = e as MissionCompletedEntry; entry = new MissionCompleted(completed, current_system, current_station); if (completed.HumanReadableNameWasGenerated) { OnLog?.Invoke("Human readable name for mission \"" + completed.Name + "\" was generated, please report this."); } } else if (e.Is(Events.MultiSellExplorationData)) { entry = new Cartographics(e as MultiSellExplorationDataEntry, current_system, current_station); entry.Faction = controlling_faction; } else if (e.Is(Events.RedeemVoucher)) { entry = new Vouchers(); entry.Entries.Add(e); entry.System = current_system; entry.Station = current_station; entry.Faction = controlling_faction; } else if (e.Is(Events.SellMicroResources)) { entry = new SellMicroResources(current_system, current_station); entry.Entries.Add(e); } if (entry == null) { continue; } var matches = objectives .Where(x => x.Matches(entry) > 0) .OrderBy(x => x.Matches(entry)) ; if (matches == null || matches.Count() <= 0) { continue; } var objective = matches .OrderBy(x => x.Matches(entry)) .Reverse() .First() ; if (objective != null) { objective.LogEntries.Add(entry); } } } public void Scan(PlayerJournal journal) { Scan(journal, DateTime.Now, DateTime.Now); } } }