/// <summary> /// Track the mission in the <see cref="PilotState"/> because some mission relevant details are only /// available in this journal entry. /// </summary> /// <param name="pilotState"> /// A <see cref="PilotState"/> representing data associated with the pilot, such as the current station or system. /// </param> /// <param name="galaxyState"> /// A <see cref="GalaxyState"/> reoresenting the Elite: Dangerous universe the pilot plays in. /// </param> /// <param name="supportedMinorFaction"> /// The supported minor faction name. This must <b>exactly</b> match the name in the journal. /// </param> /// <param name="entry"> /// A <see cref="JObject"/> representing the journal entry. /// </param> /// <returns> /// Will never return <see cref="SummaryEntry"/> objects. /// </returns> /// <exception cref="ArgumentNullException"> /// No argument can be null. /// </exception> public override IEnumerable <SummaryEntry> Process(PilotState pilotState, GalaxyState galaxyState, string supportedMinorFaction, JObject entry) { if (pilotState is null) { throw new ArgumentNullException(nameof(pilotState)); } if (galaxyState is null) { throw new ArgumentNullException(nameof(galaxyState)); } if (supportedMinorFaction is null) { throw new ArgumentNullException(nameof(supportedMinorFaction)); } if (entry is null) { throw new ArgumentNullException(nameof(entry)); } pilotState.Missions.Add( entry.Value <long>("MissionID"), new Mission( entry.Value <long>("MissionID"), entry.Value <string>("LocalisedName"), entry.Value <string>("Influence")) ); return(Enumerable.Empty <SummaryEntry>()); }
public override IEnumerable <SummaryEntry> Process(PilotState pilotState, GalaxyState galaxyState, string supportedMinorFaction, JObject entry) { if (pilotState is null) { throw new ArgumentNullException(nameof(pilotState)); } if (galaxyState is null) { throw new ArgumentNullException(nameof(galaxyState)); } if (supportedMinorFaction is null) { throw new ArgumentNullException(nameof(supportedMinorFaction)); } if (entry is null) { throw new ArgumentNullException(nameof(entry)); } galaxyState.Systems[entry.Value <long>("SystemAddress")] = new StarSystem( entry.Value <long>("SystemAddress"), entry.Value <string>("StarSystem"), entry["Factions"]?.Select(o => o.Value <string>("Name"))); return(Enumerable.Empty <SummaryEntry>()); }
/// <summary> /// Track the mission in the <see cref="PilotState"/> because some mission relevant details are only /// available in this journal entry. /// </summary> /// <param name="pilotState"> /// A <see cref="PilotState"/> representing data associated with the pilot, such as the current station or system. /// </param> /// <param name="galaxyState"> /// A <see cref="GalaxyState"/> reoresenting the Elite: Dangerous universe the pilot plays in. /// </param> /// <param name="supportedMinorFaction"> /// The supported minor faction name. This must <b>exactly</b> match the name in the journal. /// </param> /// <param name="entry"> /// A <see cref="JObject"/> representing the journal entry. /// </param> /// <returns> /// Will never return <see cref="SummaryEntry"/> objects. /// </returns> /// <exception cref="ArgumentNullException"> /// No argument can be null. /// </exception> public override IEnumerable <SummaryEntry> Process(PilotState pilotState, GalaxyState galaxyState, string supportedMinorFaction, JObject entry) { if (pilotState is null) { throw new ArgumentNullException(nameof(pilotState)); } if (galaxyState is null) { throw new ArgumentNullException(nameof(galaxyState)); } if (supportedMinorFaction is null) { throw new ArgumentNullException(nameof(supportedMinorFaction)); } if (entry is null) { throw new ArgumentNullException(nameof(entry)); } // Create a new station instead of looking it up because the "Docked" event may be received before the "Location" event. pilotState.LastDockedStation = new Station( entry.Value <string>("StationName"), long.Parse(entry.Value <string>("SystemAddress")), entry["StationFaction"].Value <string>("Name") ); return(Enumerable.Empty <SummaryEntry>()); }
public void Constructor() { GalaxyState galaxyState = new GalaxyState(); Assert.That(galaxyState.Stations, Is.Empty); Assert.That(galaxyState.Systems, Is.Empty); }
public void GetStation_MissSystemAddress() { GalaxyState galaxyState = new GalaxyState(); Station station = new Station("A", 1, "F1"); galaxyState.AddOrUpdateStation(station); Assert.That(galaxyState.GetStation(station.Name, station.SystemAddress + 1), Is.Null); }
public void AddOrUpdateStation_Empty() { GalaxyState galaxyState = new GalaxyState(); Station station = new Station("A", 1, "F1"); galaxyState.AddOrUpdateStation(station); Assert.That(galaxyState.Stations, Is.EquivalentTo(new[] { station })); Assert.That(galaxyState.Systems, Is.Empty); }
public void AddOrUpdateStation_Add() { GalaxyState galaxyState = new GalaxyState(); Station station1 = new Station("A", 1, "F1"); Station station2 = new Station("A", 2, "F2"); galaxyState.AddOrUpdateStation(station1); galaxyState.AddOrUpdateStation(station2); Assert.That(galaxyState.Stations, Is.EquivalentTo(new[] { station1, station2 })); Assert.That(galaxyState.Systems, Is.Empty); }
public void GetStation_Hit() { GalaxyState galaxyState = new GalaxyState(); Station station1 = new Station("A", 1, "F1"); Station station2 = new Station("B", 2, "F2"); galaxyState.AddOrUpdateStation(station1); galaxyState.AddOrUpdateStation(station2); Assert.That(galaxyState.GetStation(station1.Name, station1.SystemAddress), Is.EqualTo(station1)); Assert.That(galaxyState.GetStation(station2.Name, station2.SystemAddress), Is.EqualTo(station2)); }
public void ProcessSingleEntry(string journalEntry, string minorFaction, Mission mission, StarSystem system, IEnumerable <MissionSummaryEntry> expectedSummaryEntries) { MissionCompletedEntryProcessor missionCompletedEventProcessor = new MissionCompletedEntryProcessor(); PilotState pilotState = new PilotState(); // pilotState.Missions.Add(mission.Id, mission); GalaxyState galaxyState = new GalaxyState(); // galaxyState.Systems.Add(system.SystemAdddress, system); JObject entry = new JournalEntryParser().Parse(journalEntry); IEnumerable <SummaryEntry> entries = missionCompletedEventProcessor.Process(pilotState, galaxyState, minorFaction, entry); Assert.That(entries, Is.Empty); }
public void ProcessSingleEntry(string journalEntry, string supportedMinorFaction, IEnumerable <RedeemVoucherSummaryEntry> expectedSummaryEntries) { RedeemVoucherEntryProcessor dockedEventProcessor = new RedeemVoucherEntryProcessor(); PilotState pilotState = new PilotState(); pilotState.LastDockedStation = new Station("Quetelet Dock", 1, "The Sovereign Justice Collective"); GalaxyState galaxyState = new GalaxyState(); galaxyState.Systems[1] = new StarSystem(1, "Afli", new string[] { "The Sovereign Justice Collective", "Afli Silver Universal Exchange" }); JObject entry = new JournalEntryParser().Parse(journalEntry); Assert.That( dockedEventProcessor.Process(pilotState, galaxyState, supportedMinorFaction, entry).Cast <RedeemVoucherSummaryEntry>(), Is.EquivalentTo(expectedSummaryEntries)); }
/// <summary> /// Add the bounty if it is relevant to the minor faction. /// </summary> /// <param name="pilotState"> /// A <see cref="PilotState"/> representing data associated with the pilot, such as the current station or system. /// </param> /// <param name="galaxyState"> /// A <see cref="GalaxyState"/> reoresenting the Elite: Dangerous universe the pilot plays in. /// </param> /// <param name="supportedMinorFaction"> /// The supported minor faction name. This must <b>exactly</b> match the name in the journal. /// </param> /// <param name="entry"> /// A <see cref="JObject"/> representing the journal entry. /// </param> /// <returns> /// Will never return <see cref="SummaryEntry"/> objects. /// </returns> /// <exception cref="ArgumentNullException"> /// No argument can be null. /// </exception> public override IEnumerable <SummaryEntry> Process(PilotState pilotState, GalaxyState galaxyState, string supportedMinorFaction, JObject entry) { if (supportedMinorFaction is null) { throw new ArgumentNullException(nameof(supportedMinorFaction)); } if (entry is null) { throw new ArgumentNullException(nameof(entry)); } if (pilotState.LastDockedStation == null) { throw new InvalidOperationException("Has not docked at a station"); } if (!galaxyState.Systems.ContainsKey(pilotState.LastDockedStation.SystemAddress)) { throw new InvalidOperationException($"System address { pilotState.LastDockedStation.SystemAddress } not found"); } string systemName = galaxyState.GetSystemName(pilotState.LastDockedStation.SystemAddress); Station station = pilotState.LastDockedStation; List <SummaryEntry> result = new List <SummaryEntry>(); if (entry.Value <string>(TypePropertyName) == BountyValue) { var categorizedEntries = entry.Value <JArray>(FactionsPropertyName) .Select(e => (JObject)e) .Select(e => new { Entry = e, FactionInfluence = GetFactionInfluence(supportedMinorFaction, e.Value <string>(FactionPropertyName), station.ControllingMinorFaction, galaxyState.Systems[pilotState.LastDockedStation.SystemAddress].MinorFactions) }); result.AddRange(categorizedEntries .Where(e => e.FactionInfluence == FactionInfluence.Increase) .Select(e => new RedeemVoucherSummaryEntry(GetTimeStamp(entry), systemName, true, entry.Value <string>(TypePropertyName), e.Entry.Value <int>(AmountPropertyName)))); result.AddRange(categorizedEntries .Where(e => e.FactionInfluence == FactionInfluence.Decrease) .Select(e => new RedeemVoucherSummaryEntry(GetTimeStamp(entry), systemName, false, entry.Value <string>(TypePropertyName), e.Entry.Value <int>(AmountPropertyName)))); } else { FactionInfluence factionInfluence = GetFactionInfluence(supportedMinorFaction, entry.Value <string>(FactionPropertyName), station.ControllingMinorFaction, galaxyState.Systems[pilotState.LastDockedStation.SystemAddress].MinorFactions); if (factionInfluence != FactionInfluence.None) { result.Add(new RedeemVoucherSummaryEntry(GetTimeStamp(entry), systemName, factionInfluence == FactionInfluence.Increase, entry.Value <string>(TypePropertyName), entry.Value <int>(AmountPropertyName))); } } return(result); }
public void ProcessSingleEntry(string journalEntry, string minorFaction, string expectedStationName, long expectedSystemAddress, string expectedControllingMinorFaction) { DockedEntryProcessor dockedEventProcessor = new DockedEntryProcessor(); PilotState pilotState = new PilotState(); GalaxyState galaxyState = new GalaxyState(); Station station = new Station(expectedStationName, expectedSystemAddress, expectedControllingMinorFaction); galaxyState.AddOrUpdateStation(station); JObject entry = new JournalEntryParser().Parse(journalEntry); IEnumerable <SummaryEntry> entries = dockedEventProcessor.Process(pilotState, galaxyState, minorFaction, entry); Assert.That(entries, Is.Empty); Assert.That(pilotState.Missions, Is.Empty); Assert.That(pilotState.LastDockedStation, Is.EqualTo(station)); }
public void Test(string journal, SummaryEntry[] expectedSummaryEntries) { PilotState pilotState = new PilotState(); GalaxyState galaxyState = new GalaxyState(); string supportedMinorFaction = "EDA Kunti League"; Assert.That( new StringJournalSource(journal).Entries .Select(new JournalEntryParser().Parse) .SelectMany(entry => new Summarizer( Assembly.GetAssembly(typeof(JournalEntryProcessor)) .GetTypes() .Where(t => t != typeof(JournalEntryProcessor) && t.IsAssignableFrom(typeof(JournalEntryProcessor))) .Select(t => t.GetConstructor(new Type[0]).Invoke(new object[0])) .Cast <JournalEntryProcessor>()) .Convert(pilotState, galaxyState, supportedMinorFaction, entry)), Is.EquivalentTo(expectedSummaryEntries)); }
public void ProcessSingleEntry(string journalEntry, string minorFaction, long expectedMissionID, string expectedName, string expectedSourceMinorFactionName, string expectedTargetMinorFactionName, string expectedDestinationSystem) { MissionAcceptedEntryProcessor missionAcceptedEventProcessor = new MissionAcceptedEntryProcessor(); PilotState pilotState = new PilotState(); GalaxyState galaxyState = new GalaxyState(); JObject entry = new JournalEntryParser().Parse(journalEntry); IEnumerable <SummaryEntry> entries = missionAcceptedEventProcessor.Process(pilotState, galaxyState, minorFaction, entry); Assert.That(entries, Is.Empty); Assert.That(pilotState.LastDockedStation, Is.Null); Assert.That(pilotState.Missions, Has.Count.EqualTo(1)); Assert.That(pilotState.Missions.ContainsKey(expectedMissionID), Is.True); Assert.That(pilotState.Missions[expectedMissionID], Has.Property("Id").EqualTo(expectedMissionID)); Assert.That(pilotState.Missions[expectedMissionID], Has.Property("Name").EqualTo(expectedName)); // TODO: Fix // Assert.That(pilotState.Missions[expectedMissionID], Has.Property("Influence").EqualTo(expectedInfluence)); //Assert.That(pilotState.Missions[expectedMissionID], Has.Property("SourceMinorFactionName").EqualTo(expectedSourceMinorFactionName)); //Assert.That(pilotState.Missions[expectedMissionID], Has.Property("TargetMinorFactionName").EqualTo(expectedTargetMinorFactionName)); //Assert.That(pilotState.Missions[expectedMissionID], Has.Property("DestinationSystem").EqualTo(expectedDestinationSystem)); }
public void ProcessSingleEntry(string journalEntry, string minorFaction, string expectedStationName, long expectedSystemAddress, string expectedSystemName, string expectedStationControllingMinorFaction, string[] expectedMinorFactions, string expectedSystemMinorFaction) { LocationEntryProcessor locationEntryProcessor = new LocationEntryProcessor(); PilotState pilotState = new PilotState(); GalaxyState galaxyState = new GalaxyState(); JObject entry = new JournalEntryParser().Parse(journalEntry); IEnumerable <SummaryEntry> entries = locationEntryProcessor.Process(pilotState, galaxyState, minorFaction, entry); Assert.That(entries, Is.Empty); Assert.That(pilotState.Missions, Is.Empty); Assert.That(pilotState.LastDockedStation, Is.Not.Null); Assert.That(pilotState.LastDockedStation.Name, Is.EqualTo(expectedStationName)); Assert.That(pilotState.LastDockedStation.SystemAddress, Is.EqualTo(expectedSystemAddress)); Assert.That(pilotState.LastDockedStation.ControllingMinorFaction, Is.EqualTo(expectedStationControllingMinorFaction)); Assert.That(galaxyState.Systems, Has.Count.EqualTo(1)); Assert.That(galaxyState.Systems[expectedSystemAddress], Is.EqualTo(new StarSystem(expectedSystemAddress, expectedSystemName, expectedMinorFactions))); Assert.That(galaxyState.Stations, Has.Count.EqualTo(1)); Assert.That(galaxyState.Stations, Is.EquivalentTo(new[] { new Station(expectedStationName, expectedSystemAddress, expectedStationControllingMinorFaction) })); }
public override IEnumerable <SummaryEntry> Process(PilotState pilotState, GalaxyState galaxyState, string supportedMinorFaction, JObject entry) { if (pilotState is null) { throw new ArgumentNullException(nameof(pilotState)); } if (galaxyState is null) { throw new ArgumentNullException(nameof(galaxyState)); } if (supportedMinorFaction is null) { throw new ArgumentNullException(nameof(supportedMinorFaction)); } if (entry is null) { throw new ArgumentNullException(nameof(entry)); } List <SummaryEntry> result = new List <SummaryEntry>(); string missionName = pilotState.Missions.TryGetValue(entry.Value <long>("MissionID"), out Mission mission) ? mission.Name : entry.Value <string>("Name"); foreach (JObject influenceObject in entry.Value <JArray>(FactionEffectsSectionName) .SelectMany(e => e.Value <JArray>("Influence").Children <JObject>())) { string influenceFaction = influenceObject.Parent.Parent.Parent.Value <string>("Faction"); string entryFaction = entry.Value <string>("Faction"); string faction = string.IsNullOrWhiteSpace(influenceFaction) ? entryFaction : influenceFaction; string entryTargetFaction = entry.Value <string>("TargetFaction"); if (influenceObject.HasValues) { string systemName = galaxyState.Systems.TryGetValue(influenceObject.Value <long>("SystemAddress"), out StarSystem system) ? system.Name : influenceObject.Value <string>("SystemAddress"); string influence = influenceObject.Value <string>("Influence"); bool influenceIncrease = influenceObject.Value <string>("Trend") == "UpGood"; DateTime timeStamp = GetTimeStamp(entry); if (faction == supportedMinorFaction) { result.Add(new MissionSummaryEntry( timeStamp, missionName, systemName, influenceIncrease, influence)); } else if (system != null && system.MinorFactions.Contains(supportedMinorFaction)) { // && influenceIncrease // Note that inclureases and decreases to minor faction influence other than the supported faction are harder to quantify. result.Add(new MissionSummaryEntry( timeStamp, missionName, systemName, !influenceIncrease, influence)); } } } return(result); }
public void GetStation_Empty() { GalaxyState galaxyState = new GalaxyState(); Assert.That(galaxyState.GetStation("a", 1), Is.Null); }
/// <summary> /// Process the journal entry. /// </summary> /// <param name="pilotState"> /// A <see cref="PilotState"/> representing data associated with the pilot, such as the current station or system. /// </param> /// <param name="galaxyState"> /// A <see cref="GalaxyState"/> reoresenting the Elite: Dangerous universe the pilot plays in. /// </param> /// <param name="supportedMinorFaction"> /// The supported minor faction name. This must <b>exactly</b> match the name in the journal. /// </param> /// <param name="entry"> /// A <see cref="JObject"/> representing the journal entry. /// </param> /// <returns> /// Zero or more <see cref="SummaryEntry"/> objects representing actions that impact the supported minor faction. /// </returns> /// <exception cref="ArgumentNullException"> /// No argument can be null. /// </exception> public abstract IEnumerable <SummaryEntry> Process(PilotState pilotState, GalaxyState galaxyState, string supportedMinorFaction, JObject entry);