コード例 #1
0
        private bool _handleBondRedeemedEvent(BondRedeemedEvent @event)
        {
            bool update = false;

            FactionRecord record = new FactionRecord();

            // Calculate amount, broker fees
            decimal percentage = (100 - (@event.brokerpercentage ?? 0)) / 100;
            long    amount     = Convert.ToInt64(Math.Ceiling(@event.rewards[0].amount / percentage));

            // Handle journal event from Interstellar Factors transaction (FDEV bug)
            if (string.IsNullOrEmpty(@event.rewards[0].faction))
            {
                List <string> systemFactions = EDDI.Instance.CurrentStarSystem?.factions.Select(f => f.name).ToList();

                // Get record which matches a system faction and the bond claims amount
                record = criminalrecord
                         .Where(r => systemFactions.Contains(r.faction))
                         .FirstOrDefault(r => r.bondsAmount == amount);
            }
            else
            {
                record = GetRecordWithFaction(@event.rewards[0].faction);
            }

            if (record != null)
            {
                // Get all bond claims, excluding the discrepancy report
                List <FactionReport> reports = record.factionReports
                                               .Where(r => !r.bounty && r.crimeDef == Crime.None).ToList();
                if (reports?.Any() ?? false)
                {
                    long total = reports.Sum(r => r.amount);

                    // Check for discrepancy in logged bond claims
                    if (total < amount)
                    {
                        // Adjust the discrepancy report & remove when zeroed out
                        FactionReport report = record.factionReports
                                               .FirstOrDefault(r => r.crimeDef == Crime.Claim);
                        if (report != null)
                        {
                            report.amount -= Math.Min(amount - total, report.amount);
                            if (report.amount == 0)
                            {
                                reports.Add(report);
                            }
                        }
                    }
                    // Remove associated bonds claims
                    record.factionReports = record.factionReports.Except(reports).ToList();
                }
                // Adjust the total claims
                record.claims -= Math.Min(amount, record.claims);

                RemoveRecord(record);
                update = true;
            }
            return(update);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
ファイル: CrimeMonitor.cs プロジェクト: jpacelli62/EDDI
        private void _handleBountyAwardedEvent(BountyAwardedEvent @event, bool test = false)
        {
            // 20% bonus for Arissa Lavigny-Duval 'controlled' and 'exploited' systems
            StarSystem currentSystem = EDDI.Instance?.CurrentStarSystem;

            if (currentSystem != null)
            {
                currentSystem = LegacyEddpService.SetLegacyData(currentSystem, true, false, false);
            }

            // Default to 1.0 for unit testing
            double bonus = (!test && currentSystem?.Power == Power.FromEDName("ALavignyDuval")) ? 1.2 : 1.0;

            // Get the victim faction data
            Faction faction = bgsService.GetFactionByName(@event.faction);

            foreach (Reward reward in @event.rewards.ToList())
            {
                int           shipId = EDDI.Instance?.CurrentShip?.LocalId ?? 0;
                long          amount = Convert.ToInt64(reward.amount * bonus);
                FactionReport report = new FactionReport(@event.timestamp, true, shipId, Crime.None, currentSystem?.systemname, amount)
                {
                    station          = EDDI.Instance?.CurrentStation?.name,
                    body             = EDDI.Instance?.CurrentStellarBody?.bodyname,
                    victim           = @event.faction,
                    victimAllegiance = (faction.Allegiance ?? Superpower.None).invariantName
                };

                FactionRecord record = GetRecordWithFaction(reward.faction)
                                       ?? AddRecord(reward.faction);
                record.factionReports.Add(report);
                record.claims += amount;
            }
        }
コード例 #4
0
ファイル: CrimeMonitorTests.cs プロジェクト: vadark1976/EDDI
        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();
        }
コード例 #5
0
ファイル: CrimeMonitor.cs プロジェクト: rodan123/EDDI
        private void _AddReportToRecord(FactionRecord record, FactionReport report)
        {
            record.factionReports.Add(report);
            if (report.bounty)
            {
                record.bounties += report.amount;
            }
            else
            {
                record.fines += report.amount;
            }

            // When a bounty is incurred, we convert any pending fines to bounties
            if (report.bounty && report.crimeDef != Crime.None)
            {
                var fineReports = record.factionReports
                                  .Where(r => r.crimeDef != Crime.None && r.crimeDef != Crime.Claim && !r.bounty)
                                  .ToList();
                if (fineReports.Any())
                {
                    foreach (var fineReport in fineReports)
                    {
                        fineReport.bounty = true;
                    }
                    record.fines    -= Math.Min(record.fines, fineReports.Sum(r => r.amount));
                    record.bounties += fineReports.Sum(r => r.amount);
                }
            }
        }
コード例 #6
0
        private void _handleBondAwardedEvent(BondAwardedEvent @event)
        {
            int    shipId        = EDDI.Instance?.CurrentShip?.LocalId ?? 0;
            string currentSystem = EDDI.Instance?.CurrentStarSystem?.systemname;

            // Get the victim faction data
            Faction faction = DataProviderService.GetFactionByName(@event.victimfaction);

            FactionReport report = new FactionReport(@event.timestamp, false, shipId, Crime.None, currentSystem, @event.reward)
            {
                station          = EDDI.Instance?.CurrentStation?.name,
                body             = EDDI.Instance?.CurrentStellarBody?.bodyname,
                victim           = @event.victimfaction,
                victimAllegiance = (faction?.Allegiance ?? Superpower.None).invariantName
            };

            FactionRecord record = GetRecordWithFaction(@event.awardingfaction);

            if (record == null)
            {
                record = AddRecord(@event.awardingfaction);
            }
            record.factionReports.Add(report);
            record.claims += @event.reward;
        }
コード例 #7
0
        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);
        }
コード例 #8
0
        private bool _handleBountyRedeemedEvent(BountyRedeemedEvent @event)
        {
            bool update = false;

            foreach (Reward reward in @event.rewards.ToList())
            {
                FactionRecord record = new FactionRecord();

                // Calculate amount, before broker fees
                decimal percentage = (100 - (@event.brokerpercentage ?? 0)) / 100;
                long    amount     = Convert.ToInt64(Math.Ceiling(reward.amount / percentage));

                // Handle journal event from Interstellar Factors transaction (FDEV bug)
                if (string.IsNullOrEmpty(reward.faction))
                {
                    record = criminalrecord.FirstOrDefault(r => r.bountiesAmount == amount);
                }
                else
                {
                    record = GetRecordWithFaction(reward.faction);
                }

                if (record != null)
                {
                    // Get all bounty claims, excluding the discrepancy report
                    List <FactionReport> reports = record.factionReports
                                                   .Where(r => r.bounty && r.crimeDef == Crime.None).ToList();
                    if (reports?.Any() ?? false)
                    {
                        long total = reports.Sum(r => r.amount);

                        // Check for discrepancy in logged bounty claims
                        if (total < amount)
                        {
                            // Adjust the discrepancy report & remove when zeroed out
                            FactionReport report = record.factionReports
                                                   .FirstOrDefault(r => r.crimeDef == Crime.Claim);
                            if (report != null)
                            {
                                report.amount -= Math.Min(amount - total, report.amount);
                                if (report.amount == 0)
                                {
                                    reports.Add(report);
                                }
                            }
                        }
                        // Remove associated bounty claims
                        record.factionReports = record.factionReports.Except(reports).ToList();
                    }
                    // Adjust the total claims
                    record.claims -= Math.Min(amount, record.claims);

                    RemoveRecord(record);
                    update = true;
                }
            }
            return(update);
        }
コード例 #9
0
 private void _AddCrimeToRecord(FactionRecord record, FactionReport report)
 {
     record.factionReports.Add(report);
     if (report.bounty)
     {
         record.bounties += report.amount;
     }
     else
     {
         record.fines += report.amount;
     }
 }
コード例 #10
0
ファイル: CrimeMonitor.cs プロジェクト: jpacelli62/EDDI
        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);
        }
コード例 #11
0
        private void AddCrimeToRecord(FactionRecord record, FactionReport report)
        {
            if (record is null || report is null)
            {
                return;
            }

            long          total       = record.fines + record.bounties + report.amount;
            FactionRecord powerRecord = GetRecordWithFaction(record.allegiance);

            // Minor faction crimes are converted to an interstellar bounty, owned by the faction's aligned
            // superpower, when total fines & bounties incurred exceed 2 million credits
            if (powerRecord != null || total > 2000000)
            {
                // Check if an interstellar bounty is active for the minor faction
                if (powerRecord?.interstellarBountyFactions.Contains(record.faction) ?? false)
                {
                    _AddCrimeToRecord(powerRecord, report);
                    return;
                }
                else if (powerRecord == null)
                {
                    powerRecord = AddRecord(record.allegiance);
                }

                // Collect all minor faction fines and bounties incurred
                List <FactionReport> reports = record.factionReports
                                               .Where(r => r.crimeDef != Crime.None && r.crimeDef != Crime.Claim).ToList();

                // Transfer existing fines and bounties incurred to the power record
                powerRecord.factionReports.AddRange(reports);
                powerRecord.fines    += record.fines;
                powerRecord.bounties += record.bounties;
                powerRecord.interstellarBountyFactions.Add(record.faction);
                record.factionReports = record.factionReports.Except(reports).ToList();
                record.fines          = 0;
                record.bounties       = 0;

                // Add new report to the power record and remove minor faction record if no pending claims
                _AddCrimeToRecord(powerRecord, report);
                RemoveRecord(record);

                return;
            }
            // Criteria not met. Add new report to the minor faction record
            _AddCrimeToRecord(record, report);
        }
コード例 #12
0
ファイル: CrimeMonitor.cs プロジェクト: rodan123/EDDI
        private bool _handleFinePaidEvent(FinePaidEvent @event)
        {
            // This event may trigger for both bounties paid and fines paid (FDev bug)
            bool update = false;

            foreach (FactionRecord record in criminalrecord.ToList())
            {
                if (@event.allfines || record.faction == @event.faction)
                {
                    // Get all fines incurred, excluding the discrepancy report
                    List <FactionReport> reports = record.factionReports
                                                   .Where(r => r.crimeDef != Crime.None && r.crimeDef != Crime.Fine)
                                                   .ToList();
                    long total = reports.Sum(r => r.amount);

                    // Check for discrepancy in logged fines incurred
                    if (total < @event.amount)
                    {
                        // Adjust the discrepancy report & remove when zeroed out
                        FactionReport report = record.factionReports
                                               .FirstOrDefault(r => r.crimeDef == Crime.Fine);
                        if (report != null)
                        {
                            report.amount -= Math.Min(@event.amount - total, report.amount);
                            if (report.amount == 0)
                            {
                                reports.Add(report);
                            }
                        }
                    }
                    // Remove associated records
                    record.factionReports = record.factionReports.Except(reports).ToList();

                    // Adjust the total fines incurred amount
                    record.fines -= Math.Min(@event.amount, record.fines);

                    RemoveRecordIfEmpty(record);
                    update = true;
                    if (record.faction == @event.faction)
                    {
                        break;
                    }
                }
            }
            return(update);
        }
コード例 #13
0
ファイル: CrimeMonitor.cs プロジェクト: jpacelli62/EDDI
        private void AddCrimeToRecord(FactionRecord record, FactionReport report)
        {
            if (record is null || report is null)
            {
                return;
            }

            var total       = record.fines + record.bounties + report.amount;
            var powerRecord = GetRecordWithFaction(record.allegiance);

            if (powerRecord == null && total <= 2000000)
            {
                // Add new report to the minor faction record
                _AddCrimeToRecord(record, report);
            }
            else
            {
                // Minor faction crimes are converted to an interstellar power record, owned by the faction's aligned
                // superpower, when total fines & bounties incurred exceed 2 million credits
                if (powerRecord == null)
                {
                    // Add a new interstellar bounty.
                    // Transfer existing fines and bounties incurred to the interstellar power record
                    // Collect all minor faction fines and bounties incurred
                    powerRecord = AddRecord(record.allegiance);
                    List <FactionReport> reports = record.factionReports
                                                   .Where(r => r.crimeDef != Crime.None && r.crimeDef != Crime.Claim).ToList();
                    powerRecord.factionReports.AddRange(reports);
                    powerRecord.fines    += record.fines;
                    powerRecord.bounties += record.bounties;
                    powerRecord.interstellarBountyFactions.Add(record.faction);
                    record.factionReports = record.factionReports.Except(reports).ToList();
                    record.fines          = 0;
                    record.bounties       = 0;

                    // Add new report to the interstellar power record and remove minor faction record if no pending claims
                    _AddCrimeToRecord(powerRecord, report);
                    RemoveRecord(record);
                }
                else if (powerRecord.interstellarBountyFactions.Contains(record.faction))
                {
                    // An interstellar power record is already active, update it
                    _AddCrimeToRecord(powerRecord, report);
                }
            }
        }
コード例 #14
0
        private bool _handleFinePaidEvent(FinePaidEvent @event)
        {
            bool update = false;

            foreach (FactionRecord record in criminalrecord.ToList())
            {
                // If paid at 'Legal Facilities', fines are grouped by superpower
                bool match = @event.brokerpercentage == null ? record.faction == @event.faction : record.Allegiance.invariantName == @event.faction;
                if (@event.allfines || match)
                {
                    // Get all fines incurred, excluding the discrepancy report
                    // Note that all fines are assigned to the ship, not the commander
                    List <FactionReport> reports = record.factionReports
                                                   .Where(r => !r.bounty && r.crimeDef != Crime.None && r.crimeDef != Crime.Fine && r.shipId == @event.shipid)
                                                   .ToList();
                    long total = reports?.Sum(r => r.amount) ?? 0;

                    // Check for discrepancy in logged fines incurred
                    if (total < @event.amount)
                    {
                        // Adjust the discrepancy report & remove when zeroed out
                        FactionReport report = record.factionReports
                                               .FirstOrDefault(r => r.crimeDef == Crime.Fine);
                        if (report != null)
                        {
                            report.amount -= Math.Min(@event.amount - total, report.amount);
                            if (report.amount == 0)
                            {
                                reports.Add(report);
                            }
                        }
                    }
                    // Remove associated fines
                    record.factionReports = record.factionReports.Except(reports).ToList();

                    // Adjust the total fines incurred amount
                    record.fines -= Math.Min(@event.amount, record.fines);

                    RemoveRecord(record);
                    update = true;
                }
            }
            return(update);
        }
コード例 #15
0
ファイル: CrimeMonitor.cs プロジェクト: rodan123/EDDI
        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);
        }
コード例 #16
0
        private void criminalRecordUpdated(object sender, DataTransferEventArgs e)
        {
            if (e.Source is DataGrid)
            {
                FactionRecord record = (FactionRecord)((DataGrid)e.Source).CurrentItem;
                if (record != null)
                {
                    FactionReport report = new FactionReport();

                    int column = ((DataGrid)e.Source).CurrentColumn.DisplayIndex;
                    switch (column)
                    {
                    case 3:     // Claims column
                    {
                        // All claims, including discrepancy report
                        long claims = record.factionReports
                                      .Where(r => r.crimeDef == Crime.None || r.crimeDef == Crime.Claim)
                                      .Sum(r => r.amount);
                        if (record.claims != claims)
                        {
                            // Create/modify 'discrepancy' report if total claims does not equal sum of claim reports
                            long amount = record.claims - claims;
                            report = record.factionReports
                                     .FirstOrDefault(r => r.crimeDef == Crime.Claim);
                            if (report == null)
                            {
                                report = new FactionReport(DateTime.UtcNow, false, 0, Crime.Claim, null, 0);
                                record.factionReports.Add(report);
                            }
                            report.amount += amount;
                            if (report.amount == 0)
                            {
                                record.factionReports.Remove(report);
                            }
                        }
                    }
                    break;

                    case 4:     // Fines column
                    {
                        // All fines, including discrepancy report
                        long fines = record.factionReports
                                     .Where(r => !r.bounty && r.crimeDef != Crime.None)
                                     .Sum(r => r.amount);
                        if (record.fines != fines)
                        {
                            // Create/modify 'discrepancy' report if total fines does not equal sum of fine reports
                            long amount = record.fines - fines;
                            report = record.factionReports.FirstOrDefault(r => r.crimeDef == Crime.Fine);
                            if (report == null)
                            {
                                report = new FactionReport(DateTime.UtcNow, false, 0, Crime.Fine, null, 0);
                                record.factionReports.Add(report);
                            }
                            report.amount += amount;
                            if (report.amount == 0)
                            {
                                record.factionReports.Remove(report);
                            }
                        }
                    }
                    break;

                    case 5:     // Bounties column
                    {
                        // All bounties, including discrepancy report
                        long bounties = record.factionReports
                                        .Where(r => r.bounty && r.crimeDef != Crime.None)
                                        .Sum(r => r.amount);
                        if (record.bounties != bounties)
                        {
                            // Create/modify 'discrepancy' report if total bounties does not equal sum of bonty reports
                            long amount = record.bounties - bounties;
                            report = record.factionReports
                                     .FirstOrDefault(r => r.crimeDef == Crime.Bounty);
                            if (report == null)
                            {
                                report = new FactionReport(DateTime.UtcNow, true, 0, Crime.Bounty, null, 0);
                                record.factionReports.Add(report);
                            }
                            report.amount += amount;
                            if (report.amount == 0)
                            {
                                record.factionReports.Remove(report);
                            }
                        }
                    }
                    break;
                    }
                }
            }
            // Update the crime monitor's information
            crimeMonitor()?.writeRecord();
        }
コード例 #17
0
ファイル: MissionMonitorTests.cs プロジェクト: JPVenson/EDDI
        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();
        }