public bool _handleMissionFine(DateTime timestamp, Mission mission, long fine) { bool update = false; if (mission?.faction != null) { int shipId = EDDI.Instance?.CurrentShip?.LocalId ?? 0; Crime crime = Crime.FromEDName("missionFine"); string currentSystem = EDDI.Instance?.CurrentStarSystem?.systemname; FactionReport report = new FactionReport(timestamp, false, shipId, crime, currentSystem, fine) { station = EDDI.Instance?.CurrentStation?.name, body = EDDI.Instance?.CurrentStellarBody?.bodyname, }; FactionRecord record = GetRecordWithFaction(mission.faction); if (record == null) { record = AddRecord(mission.faction); } AddCrimeToRecord(record, report); update = true; } return(update); }
public void TestCrimeConfig() { // Save original data CrimeMonitorConfiguration data = CrimeMonitorConfiguration.FromFile(); CrimeMonitorConfiguration config = CrimeMonitorConfiguration.FromJsonString(crimeConfigJson); Assert.AreEqual(3, config.criminalrecord.Count); Assert.AreEqual(275915, config.claims); Assert.AreEqual(400, config.fines); record = config.criminalrecord.ToList().FirstOrDefault(r => r.faction == "Calennero State Industries"); Assert.AreEqual(Superpower.Empire, record.Allegiance); Assert.AreEqual("Empire", record.allegiance); Assert.AreEqual(105168, record.bountiesAmount); Assert.AreEqual(400, record.finesIncurred.Sum(r => r.amount)); // Verify faction report object Assert.AreEqual(2, record.factionReports.Count); report = record.factionReports[0]; Assert.IsTrue(report.bounty); Assert.AreEqual(Crime.None, report.crimeDef); Assert.AreEqual("HIP 20277", report.system); Assert.AreEqual(105168, report.amount); report = record.factionReports[1]; Assert.IsFalse(report.bounty); Assert.AreEqual(Crime.FromEDName("dockingMinorTresspass"), report.crimeDef); Assert.AreEqual("Fabian City", report.station); // Restore original data data.ToFile(); }
private void _handleBountyIncurredEvent(BountyIncurredEvent @event) { int shipId = EDDI.Instance?.CurrentShip?.LocalId ?? 0; Crime crime = Crime.FromEDName(@event.crimetype); string currentSystem = EDDI.Instance?.CurrentStarSystem?.systemname; // Get victim allegiance from the 'Ship targeted' data Target target = shipTargets.FirstOrDefault(t => t.name == @event.victim); FactionReport report = new FactionReport(@event.timestamp, true, shipId, crime, currentSystem, @event.bounty) { station = EDDI.Instance?.CurrentStation?.name, body = EDDI.Instance?.CurrentStellarBody?.bodyname, victim = @event.victim, victimAllegiance = (target?.Allegiance ?? Superpower.None).invariantName }; FactionRecord record = GetRecordWithFaction(@event.faction); if (record == null) { record = AddRecord(@event.faction); } AddCrimeToRecord(record, report); }
public BountyIncurredEvent(DateTime timestamp, string crimetype, string faction, string victim, long bounty) : base(timestamp, NAME) { this.crimetype = crimetype; this.crime = Crime.FromEDName(crimetype).localizedName; this.faction = faction; this.victim = victim; this.bounty = bounty; }
public FineIncurredEvent(DateTime timestamp, string crimetype, string faction, string victim, long fine) : base(timestamp, NAME) { this.crimetype = crimetype; this.crime = Crime.FromEDName(crimetype).localizedName; this.faction = faction; this.victim = victim; this.fine = fine; }
private void _handleFineIncurredEvent(FineIncurredEvent @event) { int shipId = EDDI.Instance?.CurrentShip?.LocalId ?? 0; Crime crime = Crime.FromEDName(@event.crimetype); string currentSystem = EDDI.Instance?.CurrentStarSystem?.systemname; FactionReport report = new FactionReport(@event.timestamp, false, shipId, crime, currentSystem, @event.fine) { station = EDDI.Instance?.CurrentStation?.name, body = EDDI.Instance?.CurrentStellarBody?.bodyname, victim = @event.victim }; FactionRecord record = GetRecordWithFaction(@event.faction) ?? AddRecord(@event.faction); AddCrimeToRecord(record, report); }
private void _handleBountyIncurredEvent(BountyIncurredEvent @event) { crimeAuthorityFaction = @event.faction; var crime = Crime.FromEDName(@event.crimetype); var currentSystem = EDDI.Instance?.CurrentStarSystem?.systemname; // Get victim allegiance from the 'Ship targeted' data var target = shipTargets.FirstOrDefault(t => t.name == @event.victim); // Create a bounty report and add it to our record var report = new FactionReport(@event.timestamp, true, crime, currentSystem, @event.bounty) { station = EDDI.Instance?.CurrentStation?.name, body = EDDI.Instance?.CurrentStellarBody?.bodyname, victim = @event.victim, victimAllegiance = (target?.Allegiance ?? Superpower.None).invariantName }; var record = GetRecordWithFaction(@event.faction) ?? AddRecord(@event.faction); AddReportToRecord(record, report); }
public void TestMissionEventsScenario() { // Save original data MissionMonitorConfiguration missionData = MissionMonitorConfiguration.FromFile(); missionMonitor.initializeMissionMonitor(new MissionMonitorConfiguration()); //MissionsEvent line = @"{""timestamp"":""2018-08-25T23:27:21Z"", ""event"":""Missions"", ""Active"":[ { ""MissionID"":413563499, ""Name"":""Mission_Courier_Elections_name"", ""PassengerMission"":false, ""Expires"":48916 }, { ""MissionID"":413563678, ""Name"":""Mission_Delivery_name"", ""PassengerMission"":false, ""Expires"":48917 }, { ""MissionID"":413563829, ""Name"":""Mission_Salvage_Planet_name"", ""PassengerMission"":false, ""Expires"":264552 } ], ""Failed"":[ ], ""Complete"":[ ] }"; events = JournalMonitor.ParseJournalEntry(line); Assert.IsTrue(events.Count == 1); missionMonitor._handleMissionsEvent((MissionsEvent)events[0]); Assert.AreEqual(3, missionMonitor.missions.Count); Assert.AreEqual(3, missionMonitor.missions.Where(m => m.statusEDName == "Active").Count()); //CargoDepotEvent - 'Shared' line = @"{ ""timestamp"":""2018-08-26T02:55:10Z"", ""event"":""CargoDepot"", ""MissionID"":413748365, ""UpdateType"":""WingUpdate"", ""CargoType"":""Gold"", ""Count"":20, ""StartMarketID"":0, ""EndMarketID"":3224777216, ""ItemsCollected"":0, ""ItemsDelivered"":20, ""TotalItemsToDeliver"":54, ""Progress"":0.000000 }"; events = JournalMonitor.ParseJournalEntry(line); Assert.IsTrue(events.Count == 1); missionMonitor._handleCargoDepotEvent((CargoDepotEvent)events[0]); mission = missionMonitor.missions.ToList().FirstOrDefault(m => m.missionid == 413748365); Assert.AreEqual(4, missionMonitor.missions.Count); Assert.AreEqual("CollectWing", mission.typeEDName); Assert.AreEqual("Active", mission.statusEDName); Assert.IsTrue(mission.originreturn); Assert.IsTrue(mission.wing); Assert.IsTrue(mission.shared); line = @"{ ""timestamp"":""2018-08-26T02:56:16Z"", ""event"":""CargoDepot"", ""MissionID"":413748365, ""UpdateType"":""Deliver"", ""CargoType"":""Gold"", ""Count"":34, ""StartMarketID"":0, ""EndMarketID"":3224777216, ""ItemsCollected"":0, ""ItemsDelivered"":54, ""TotalItemsToDeliver"":54, ""Progress"":0.000000 }"; events = JournalMonitor.ParseJournalEntry(line); missionMonitor._handleCargoDepotEvent((CargoDepotEvent)events[0]); Assert.AreEqual(3, missionMonitor.missions.Count); //MissionAbandonedEvent line = @"{ ""timestamp"":""2018-08-26T00:50:48Z"", ""event"":""MissionAbandoned"", ""Name"":""Mission_Courier_Elections_name"", ""Fine"":50000, ""MissionID"":413563499 }"; events = JournalMonitor.ParseJournalEntry(line); Assert.IsTrue(events.Count == 1); missionMonitor.handleMissionAbandonedEvent((MissionAbandonedEvent)events[0]); Assert.AreEqual("Failed", missionMonitor.missions.SingleOrDefault(m => m.missionid == 413563499)?.statusEDName); missionMonitor._postHandleMissionAbandonedEvent((MissionAbandonedEvent)events[0]); Assert.AreEqual(2, missionMonitor.missions.Count); //MissionAcceptedEvent - 'AltruismCredits' line = "{ \"timestamp\":\"2018-09-17T02:54:16Z\", \"event\":\"MissionAccepted\", \"Faction\":\"Merope Expeditionary Fleet\", \"Name\":\"Mission_AltruismCredits\", \"LocalisedName\":\"Donate 450,000 Cr to the cause\", \"Donation\":\"450000\", \"Expiry\":\"2018-09-17T05:01:28Z\", \"Wing\":false, \"Influence\":\"Med\", \"Reputation\":\"Med\", \"MissionID\":419646649 }"; events = JournalMonitor.ParseJournalEntry(line); Assert.IsTrue(events.Count == 1); missionMonitor._handleMissionAcceptedEvent((MissionAcceptedEvent)events[0]); mission = missionMonitor.missions.ToList().FirstOrDefault(m => m.missionid == 419646649); Assert.AreEqual(3, missionMonitor.missions.Count); Assert.IsTrue(mission.originreturn); //MissionAcceptedEvent - 'Collect' line = @"{ ""timestamp"":""2018-08-26T00:50:48Z"", ""event"":""MissionAccepted"", ""Faction"":""Calennero State Industries"", ""Name"":""Mission_Collect_Industrial"", ""LocalisedName"":""Industry needs 54 units of Tantalum"", ""Commodity"":""$Tantalum_Name;"", ""Commodity_Localised"":""Tantalum"", ""Count"":54, ""DestinationSystem"":""HIP 20277"", ""DestinationStation"":""Fabian City"", ""Expiry"":""2018-08-27T00:48:38Z"", ""Wing"":false, ""Influence"":""Med"", ""Reputation"":""Med"", ""Reward"":1909532, ""MissionID"":413748324 }"; events = JournalMonitor.ParseJournalEntry(line); Assert.IsTrue(events.Count == 1); missionMonitor._handleMissionAcceptedEvent((MissionAcceptedEvent)events[0]); mission = missionMonitor.missions.ToList().FirstOrDefault(m => m.missionid == 413748324); Assert.AreEqual(4, missionMonitor.missions.Count); Assert.AreEqual("Collect", mission.typeEDName); Assert.AreEqual("Active", mission.statusEDName); Assert.IsTrue(mission.originreturn); Assert.IsTrue(mission.legal); Assert.IsFalse(mission.wing); // Verify duplication protection events = JournalMonitor.ParseJournalEntry(line); Assert.IsTrue(events.Count == 1); missionMonitor._handleMissionAcceptedEvent((MissionAcceptedEvent)events[0]); Assert.AreEqual(1, missionMonitor.missions.ToList().Where(m => m.missionid == 413748324).Count()); Assert.AreEqual(4, missionMonitor.missions.Count); //CargoDepotEvent - 'Collect' line = @"{ ""timestamp"":""2018-08-26T02:55:10Z"", ""event"":""CargoDepot"", ""MissionID"":413748324, ""UpdateType"":""Deliver"", ""CargoType"":""Tantalum"", ""Count"":54, ""StartMarketID"":0, ""EndMarketID"":3224777216, ""ItemsCollected"":0, ""ItemsDelivered"":54, ""TotalItemsToDeliver"":54, ""Progress"":0.000000 }"; events = JournalMonitor.ParseJournalEntry(line); Assert.IsTrue(events.Count == 1); missionMonitor._handleCargoDepotEvent((CargoDepotEvent)events[0]); mission = missionMonitor.missions.ToList().FirstOrDefault(m => m.missionid == 413748324); Assert.AreEqual("Complete", mission.statusEDName); //MissionAcceptedEvent - 'Permit' line = "{ \"timestamp\":\"2018-09-19T01:12:57Z\", \"event\":\"MissionAccepted\", \"Faction\":\"Sublime Order of van Maanen's Star\", \"Name\":\"MISSION_genericPermit1\", \"LocalisedName\":\"Permit Acquisition Opportunity\", \"Wing\":false, \"Influence\":\"None\", \"Reputation\":\"None\", \"MissionID\":420098082 }"; events = JournalMonitor.ParseJournalEntry(line); Assert.IsTrue(events.Count == 1); missionMonitor._handleMissionAcceptedEvent((MissionAcceptedEvent)events[0]); mission = missionMonitor.missions.ToList().FirstOrDefault(m => m.missionid == 420098082); Assert.AreEqual(5, missionMonitor.missions.Count); //MissionAcceptedEvent - 'Smuggle' line = @"{ ""timestamp"":""2018-08-29T20:51:56Z"", ""event"":""MissionAccepted"", ""Faction"":""Gcirithang Crimson Mafia"", ""Name"":""Mission_Smuggle_Famine"", ""LocalisedName"":""Smuggle 36 units of Narcotics to combat famine"", ""Commodity"":""$BasicNarcotics_Name;"", ""Commodity_Localised"":""Narcotics"", ""Count"":36, ""DestinationSystem"":""Carcinus"", ""DestinationStation"":""Wye-Delta Station"", ""Expiry"":""2018-08-30T20:55:33Z"", ""Wing"":false, ""Influence"":""Med"", ""Reputation"":""Med"", ""Reward"":180818, ""MissionID"":414732731 }"; events = JournalMonitor.ParseJournalEntry(line); Assert.IsTrue(events.Count == 1); missionMonitor._handleMissionAcceptedEvent((MissionAcceptedEvent)events[0]); mission = missionMonitor.missions.ToList().FirstOrDefault(m => m.missionid == 414732731); Assert.AreEqual(6, missionMonitor.missions.Count); Assert.AreEqual("Smuggle", mission.typeEDName); Assert.IsFalse(mission.originreturn); Assert.IsFalse(mission.legal); //MissionCompletedEvent line = @"{ ""timestamp"":""2018-08-26T00:40:14Z"", ""event"":""MissionCompleted"", ""Faction"":""HIP 20277 Inc"", ""Name"":""Mission_Salvage_Planet_name"", ""MissionID"":413563829, ""Commodity"":""$Landmines_Name;"", ""Commodity_Localised"":""Landmines"", ""Count"":4, ""DestinationSystem"":""Carthage"", ""Reward"":465824, ""FactionEffects"":[ { ""Faction"":""HIP 20277 Inc"", ""Effects"":[ { ""Effect"":""$MISSIONUTIL_Interaction_Summary_civilUnrest_down;"", ""Effect_Localised"":""$#MinorFaction; are happy to report improved civil contentment, making a period of civil unrest unlikely."", ""Trend"":""DownGood"" } ], ""Influence"":[ { ""SystemAddress"":84053791442, ""Trend"":""UpGood"" } ], ""Reputation"":""UpGood"" } ] }"; events = JournalMonitor.ParseJournalEntry(line); Assert.IsTrue(events.Count == 1); missionMonitor.handleMissionCompletedEvent((MissionCompletedEvent)events[0]); Assert.AreEqual("Complete", missionMonitor.missions.SingleOrDefault(m => m.missionid == 413563829)?.statusEDName); missionMonitor._postHandleMissionCompletedEvent((MissionCompletedEvent)events[0]); Assert.AreEqual(5, missionMonitor.missions.Count); //MissionFailedEvent line = @"{ ""timestamp"":""2018-08-26T00:50:48Z"", ""event"":""MissionFailed"", ""Name"":""Mission_Collect_Industrial"", ""Fine"":50000, ""MissionID"":413748324 }"; events = JournalMonitor.ParseJournalEntry(line); Assert.IsTrue(events.Count == 1); CrimeMonitorConfiguration crimeData = CrimeMonitorConfiguration.FromFile(); CrimeMonitor crimeMonitor = new CrimeMonitor(); mission = missionMonitor.missions.ToList().FirstOrDefault(m => m.missionid == 413748324); long fine = ((MissionFailedEvent)events[0]).fine; crimeMonitor._handleMissionFine(events[0].timestamp, mission, fine); FactionRecord record = crimeMonitor.criminalrecord.ToList().FirstOrDefault(r => r.faction == mission.faction); Assert.IsNotNull(record); Assert.AreEqual(50000, record.fines); FactionReport report = record.factionReports.FirstOrDefault(r => r.crimeDef == Crime.FromEDName("missionFine")); Assert.IsNotNull(report); Assert.AreEqual(50000, report.amount); crimeData.ToFile(); missionMonitor.handleMissionFailedEvent((MissionFailedEvent)events[0]); Assert.AreEqual("Failed", missionMonitor.missions.SingleOrDefault(m => m.missionid == 413748324)?.statusEDName); missionMonitor._postHandleMissionFailedEvent((MissionFailedEvent)events[0]); Assert.AreEqual(4, missionMonitor.missions.Count); //MissionCompletedEvent - Donation line = @"{ ""timestamp"":""2018-12-18T19:14:32Z"", ""event"":""MissionCompleted"", ""Faction"":""Movement for Rabakshany Democrats"", ""Name"":""Mission_AltruismCredits_name"", ""MissionID"":442085549, ""Donation"":""1000000"", ""Donated"":1000000, ""FactionEffects"":[ { ""Faction"":""Movement for Rabakshany Democrats"", ""Effects"":[ { ""Effect"":""$MISSIONUTIL_Interaction_Summary_EP_up;"", ""Effect_Localised"":""The economic status of $#MinorFaction; has improved in the $#System; system."", ""Trend"":""UpGood"" } ], ""Influence"":[ { ""SystemAddress"":8605201797850, ""Trend"":""UpGood"", ""Influence"":""+++++"" } ], ""ReputationTrend"":""UpGood"", ""Reputation"":""++"" } ] }"; events = JournalMonitor.ParseJournalEntry(line); Assert.IsTrue(events.Count == 1); MissionCompletedEvent mcEvent = (MissionCompletedEvent)events[0]; Assert.AreEqual(1000000, mcEvent.donation); // Restore original data missionData.ToFile(); }