Exemple #1
0
        public int GetReputation(FactionRecord factionEntry)
        {
            // Faction without recorded reputation. Just ignore.
            if (factionEntry == null)
            {
                return(0);
            }

            FactionState state = GetState(factionEntry);

            if (state != null)
            {
                return(GetBaseReputation(factionEntry) + state.Standing);
            }

            return(0);
        }
Exemple #2
0
        ReputationRank ReputationToRank(FactionRecord factionEntry, int standing)
        {
            ReputationRank rank = ReputationRank.Min;

            var friendshipReactions = Global.DB2Mgr.GetFriendshipRepReactions(factionEntry.FriendshipRepID);

            if (!friendshipReactions.Empty())
            {
                rank = ReputationToRankHelper(friendshipReactions, standing, (FriendshipRepReactionRecord frr) => { return(frr.ReactionThreshold); });
            }
            else
            {
                rank = ReputationToRankHelper(ReputationRankThresholds, standing, (int threshold) => { return(threshold); });
            }

            return(rank);
        }
Exemple #3
0
        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);
                }
            }
        }
Exemple #4
0
        ReputationFlags GetDefaultStateFlags(FactionRecord factionEntry)
        {
            ReputationFlags flags = ReputationFlags.None;

            int dataIndex = GetFactionDataIndexForRaceAndClass(factionEntry);

            if (dataIndex > 0)
            {
                flags = (ReputationFlags)factionEntry.ReputationFlags[dataIndex];
            }

            if (Global.DB2Mgr.GetParagonReputation(factionEntry.Id) != null)
            {
                flags |= ReputationFlags.ShowPropagated;
            }

            return(flags);
        }
Exemple #5
0
        private void AddCrimeToRecord(FactionRecord record, FactionReport report)
        {
            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);
        }
Exemple #6
0
        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);

            if (record == null)
            {
                record = AddRecord(@event.faction);
            }
            AddCrimeToRecord(record, report);
        }
Exemple #7
0
        int GetMaxReputation(FactionRecord factionEntry)
        {
            ParagonReputationRecord paragonReputation = Global.DB2Mgr.GetParagonReputation(factionEntry.Id);

            if (paragonReputation != null)
            {
                // has reward quest, cap is just before threshold for another quest reward
                // for example: if current reputation is 12345 and questa are given every 10000 and player has unclaimed reward
                // then cap will be 19999

                // otherwise cap is one theshold level larger
                // if current reputation is 12345 and questa are given every 10000 and player does NOT have unclaimed reward
                // then cap will be 29999

                int reputation = GetReputation(factionEntry);
                int cap        = reputation + paragonReputation.LevelThreshold - reputation % paragonReputation.LevelThreshold - 1;

                if (_player.GetQuestStatus((uint)paragonReputation.QuestID) == QuestStatus.None)
                {
                    cap += paragonReputation.LevelThreshold;
                }

                return(cap);
            }

            var friendshipReactions = Global.DB2Mgr.GetFriendshipRepReactions(factionEntry.FriendshipRepID);

            if (!friendshipReactions.Empty())
            {
                return(friendshipReactions.LastOrDefault().ReactionThreshold);
            }

            int dataIndex = GetFactionDataIndexForRaceAndClass(factionEntry);

            if (dataIndex >= 0)
            {
                return(factionEntry.ReputationMax[dataIndex]);
            }

            return(ReputationRankThresholds.LastOrDefault());
        }
Exemple #8
0
        int GetFactionDataIndexForRaceAndClass(FactionRecord factionEntry)
        {
            if (factionEntry == null)
            {
                return(-1);
            }

            long  raceMask  = SharedConst.GetMaskForRace(_player.GetRace());
            short classMask = (short)_player.GetClassMask();

            for (int i = 0; i < 4; i++)
            {
                if ((factionEntry.ReputationRaceMask[i].HasAnyFlag(raceMask) || (factionEntry.ReputationRaceMask[i] == 0 && factionEntry.ReputationClassMask[i] != 0)) &&
                    (factionEntry.ReputationClassMask[i].HasAnyFlag(classMask) || factionEntry.ReputationClassMask[i] == 0))
                {
                    return(i);
                }
            }

            return(-1);
        }
Exemple #9
0
        // this allows calculating base reputations to offline players, just by race and class
        public static int GetBaseReputationOf(FactionRecord factionEntry, Race race, Class playerClass)
        {
            if (factionEntry == null)
            {
                return(0);
            }

            ulong raceMask  = (1ul << ((int)race - 1));
            uint  classMask = (1u << ((int)playerClass - 1));

            for (int i = 0; i < 4; i++)
            {
                if ((factionEntry.ReputationClassMask[i] == 0 || factionEntry.ReputationClassMask[i].HasAnyFlag((short)classMask)) &&
                    (factionEntry.ReputationRaceMask[i] == 0 || factionEntry.ReputationRaceMask[i].HasAnyFlag((uint)raceMask)))
                {
                    return(factionEntry.ReputationBase[i]);
                }
            }

            return(0);
        }
Exemple #10
0
        private void _handleBondAwardedEvent(BondAwardedEvent @event)
        {
            string currentSystem = EDDI.Instance?.CurrentStarSystem?.systemname;

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

            FactionReport report = new FactionReport(@event.timestamp, false, 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)
                                   ?? AddRecord(@event.awardingfaction);

            record.factionReports.Add(report);
            record.claims += @event.reward;
        }
Exemple #11
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)
                                   ?? AddRecord(@event.faction);

            AddCrimeToRecord(record, report);
        }
Exemple #12
0
        public void Faction_tests()
        {
            _repo.FactionUpdated += FactionUpdated;

            var factionRecord = new FactionRecord(0, 0, 0);

            _repo.Add(factionRecord);
            var id = factionRecord.Id;

            factionRecord = _repo.GetFactionById(id);

            Assert.AreEqual(id, factionRecord.Id);
            Assert.AreEqual(0, factionRecord.RaceTypeId.Value);
            Assert.AreEqual(0, factionRecord.GoldInTreasury.Value);
            Assert.AreEqual(0, factionRecord.ManaInTreasury.Value);

            var updatedFaction = new FactionRecord(factionRecord, new GoldInTreasury(10), new ManaInTreasury(20));

            _repo.Update(updatedFaction);
            factionRecord = _repo.GetFactionById(id);
            Assert.AreEqual(0, factionRecord.RaceTypeId.Value);
            Assert.AreEqual(10, factionRecord.GoldInTreasury.Value);
            Assert.AreEqual(20, factionRecord.ManaInTreasury.Value);

            updatedFaction = new FactionRecord(factionRecord, new GoldInTreasury(25));
            _repo.Update(updatedFaction);
            factionRecord = _repo.GetFactionById(id);
            Assert.AreEqual(0, factionRecord.RaceTypeId.Value);
            Assert.AreEqual(25, factionRecord.GoldInTreasury.Value);
            Assert.AreEqual(20, factionRecord.ManaInTreasury.Value);

            updatedFaction = new FactionRecord(factionRecord, new ManaInTreasury(50));
            _repo.Update(updatedFaction);
            factionRecord = _repo.GetFactionById(id);
            Assert.AreEqual(0, factionRecord.RaceTypeId.Value);
            Assert.AreEqual(25, factionRecord.GoldInTreasury.Value);
            Assert.AreEqual(50, factionRecord.ManaInTreasury.Value);
        }
Exemple #13
0
        uint GetDefaultStateFlags(FactionRecord factionEntry)
        {
            if (factionEntry == null)
            {
                return(0);
            }

            ulong raceMask  = _player.GetRaceMask();
            uint  classMask = _player.GetClassMask();

            for (int i = 0; i < 4; i++)
            {
                if ((Convert.ToBoolean(factionEntry.ReputationRaceMask[i] & raceMask) ||
                     (factionEntry.ReputationRaceMask[i] == 0 &&
                      factionEntry.ReputationClassMask[i] != 0)) &&
                    (Convert.ToBoolean(factionEntry.ReputationClassMask[i] & classMask) ||
                     factionEntry.ReputationClassMask[i] == 0))
                {
                    return(factionEntry.ReputationFlags[i]);
                }
            }
            return(0);
        }
Exemple #14
0
        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 = DataProviderService.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);
                if (record == null)
                {
                    record = AddRecord(reward.faction);
                }
                record.factionReports.Add(report);
                record.claims += amount;
            }
        }
Exemple #15
0
        public int GetBaseReputation(FactionRecord factionEntry)
        {
            if (factionEntry == null)
            {
                return(0);
            }

            ulong raceMask  = _player.GetRaceMask();
            uint  classMask = _player.GetClassMask();

            for (var i = 0; i < 4; i++)
            {
                if ((Convert.ToBoolean(factionEntry.ReputationRaceMask[i] & raceMask) ||
                     (factionEntry.ReputationRaceMask[i] == 0 && factionEntry.ReputationClassMask[i] != 0)) &&
                    (Convert.ToBoolean(factionEntry.ReputationClassMask[i] & classMask) ||
                     factionEntry.ReputationClassMask[i] == 0))
                {
                    return(factionEntry.ReputationBase[i]);
                }
            }

            // in faction.dbc exist factions with (RepListId >=0, listed in character reputation list) with all BaseRepRaceMask[i] == 0
            return(0);
        }
Exemple #16
0
 public FactionState GetState(FactionRecord factionEntry)
 {
     return(factionEntry.CanHaveReputation() ? GetState(factionEntry.ReputationIndex) : null);
 }
Exemple #17
0
        public bool SetReputation(FactionRecord factionEntry, int standing, bool incremental = false, bool noSpillover = false)
        {
            Global.ScriptMgr.OnPlayerReputationChange(_player, factionEntry.Id, standing, incremental);
            bool res = false;

            if (!noSpillover)
            {
                // if spillover definition exists in DB, override DBC
                RepSpilloverTemplate repTemplate = Global.ObjectMgr.GetRepSpillover(factionEntry.Id);
                if (repTemplate != null)
                {
                    for (uint i = 0; i < 5; ++i)
                    {
                        if (repTemplate.faction[i] != 0)
                        {
                            if (_player.GetReputationRank(repTemplate.faction[i]) <= (ReputationRank)repTemplate.faction_rank[i])
                            {
                                // bonuses are already given, so just modify standing by rate
                                int spilloverRep = (int)(standing * repTemplate.faction_rate[i]);
                                SetOneFactionReputation(CliDB.FactionStorage.LookupByKey(repTemplate.faction[i]), spilloverRep, incremental);
                            }
                        }
                    }
                }
                else
                {
                    float spillOverRepOut = standing;
                    // check for sub-factions that receive spillover
                    var flist = Global.DB2Mgr.GetFactionTeamList(factionEntry.Id);
                    // if has no sub-factions, check for factions with same parent
                    if (flist == null && factionEntry.ParentFactionID != 0 && factionEntry.ParentFactionMod[1] != 0.0f)
                    {
                        spillOverRepOut *= factionEntry.ParentFactionMod[1];
                        FactionRecord parent = CliDB.FactionStorage.LookupByKey(factionEntry.ParentFactionID);
                        if (parent != null)
                        {
                            var parentState = _factions.LookupByKey(parent.ReputationIndex);
                            // some team factions have own reputation standing, in this case do not spill to other sub-factions
                            if (parentState != null && parentState.Flags.HasAnyFlag(FactionFlags.Special))
                            {
                                SetOneFactionReputation(parent, (int)spillOverRepOut, incremental);
                            }
                            else    // spill to "sister" factions
                            {
                                flist = Global.DB2Mgr.GetFactionTeamList(factionEntry.ParentFactionID);
                            }
                        }
                    }
                    if (flist != null)
                    {
                        // Spillover to affiliated factions
                        foreach (var id in flist)
                        {
                            FactionRecord factionEntryCalc = CliDB.FactionStorage.LookupByKey(id);
                            if (factionEntryCalc != null)
                            {
                                if (factionEntryCalc == factionEntry || GetRank(factionEntryCalc) > (ReputationRank)factionEntryCalc.ParentFactionMod[0])
                                {
                                    continue;
                                }
                                int spilloverRep = (int)(spillOverRepOut * factionEntryCalc.ParentFactionMod[0]);
                                if (spilloverRep != 0 || !incremental)
                                {
                                    res = SetOneFactionReputation(factionEntryCalc, spilloverRep, incremental);
                                }
                            }
                        }
                    }
                }
            }

            // spillover done, update faction itself
            var faction = _factions.LookupByKey(factionEntry.ReputationIndex);

            if (faction != null)
            {
                res = SetOneFactionReputation(factionEntry, standing, incremental);
                // only this faction gets reported to client, even if it has no own visible standing
                SendState(faction);
            }
            return(res);
        }
Exemple #18
0
 public bool ModifyReputation(FactionRecord factionEntry, int standing, bool noSpillover = false)
 {
     return(SetReputation(factionEntry, standing, true, noSpillover));
 }
Exemple #19
0
        ReputationRank GetBaseRank(FactionRecord factionEntry)
        {
            int reputation = GetBaseReputation(factionEntry);

            return(ReputationToRank(reputation));
        }
Exemple #20
0
        static bool Complete(StringArguments args, CommandHandler handler)
        {
            Player player = handler.GetSelectedPlayer();

            if (!player)
            {
                handler.SendSysMessage(CypherStrings.NoCharSelected);
                return(false);
            }

            // .quest complete #entry
            // number or [name] Shift-click form |color|Hquest:quest_id:quest_level:min_level:max_level:scaling_faction|h[name]|h|r
            string cId = handler.ExtractKeyFromLink(args, "Hquest");

            if (!uint.TryParse(cId, out uint entry))
            {
                return(false);
            }

            Quest quest = Global.ObjectMgr.GetQuestTemplate(entry);

            // If player doesn't have the quest
            if (quest == null || player.GetQuestStatus(entry) == QuestStatus.None || Global.DisableMgr.IsDisabledFor(DisableType.Quest, entry, null))
            {
                handler.SendSysMessage(CypherStrings.CommandQuestNotfound, entry);
                return(false);
            }

            for (int i = 0; i < quest.Objectives.Count; ++i)
            {
                QuestObjective obj = quest.Objectives[i];

                switch (obj.Type)
                {
                case QuestObjectiveType.Item:
                {
                    uint curItemCount        = player.GetItemCount((uint)obj.ObjectID, true);
                    List <ItemPosCount> dest = new();
                    InventoryResult     msg  = player.CanStoreNewItem(ItemConst.NullBag, ItemConst.NullSlot, dest, (uint)obj.ObjectID, (uint)(obj.Amount - curItemCount));
                    if (msg == InventoryResult.Ok)
                    {
                        Item item = player.StoreNewItem(dest, (uint)obj.ObjectID, true);
                        player.SendNewItem(item, (uint)(obj.Amount - curItemCount), true, false);
                    }
                    break;
                }

                case QuestObjectiveType.Monster:
                {
                    CreatureTemplate creatureInfo = Global.ObjectMgr.GetCreatureTemplate((uint)obj.ObjectID);
                    if (creatureInfo != null)
                    {
                        for (int z = 0; z < obj.Amount; ++z)
                        {
                            player.KilledMonster(creatureInfo, ObjectGuid.Empty);
                        }
                    }
                    break;
                }

                case QuestObjectiveType.GameObject:
                {
                    for (int z = 0; z < obj.Amount; ++z)
                    {
                        player.KillCreditGO((uint)obj.ObjectID);
                    }
                    break;
                }

                case QuestObjectiveType.MinReputation:
                {
                    int curRep = player.GetReputationMgr().GetReputation((uint)obj.ObjectID);
                    if (curRep < obj.Amount)
                    {
                        FactionRecord factionEntry = CliDB.FactionStorage.LookupByKey(obj.ObjectID);
                        if (factionEntry != null)
                        {
                            player.GetReputationMgr().SetReputation(factionEntry, obj.Amount);
                        }
                    }
                    break;
                }

                case QuestObjectiveType.MaxReputation:
                {
                    int curRep = player.GetReputationMgr().GetReputation((uint)obj.ObjectID);
                    if (curRep > obj.Amount)
                    {
                        FactionRecord factionEntry = CliDB.FactionStorage.LookupByKey(obj.ObjectID);
                        if (factionEntry != null)
                        {
                            player.GetReputationMgr().SetReputation(factionEntry, obj.Amount);
                        }
                    }
                    break;
                }

                case QuestObjectiveType.Money:
                {
                    player.ModifyMoney(obj.Amount);
                    break;
                }

                case QuestObjectiveType.PlayerKills:
                {
                    for (var z = 0; z < obj.Amount; ++z)
                    {
                        player.KilledPlayerCredit(ObjectGuid.Empty);
                    }
                    break;
                }
                }
            }

            player.CompleteQuest(entry);
            return(true);
        }
        static bool Rep(StringArguments args, CommandHandler handler)
        {
            if (args.Empty())
            {
                return(false);
            }

            Player target = handler.getSelectedPlayerOrSelf();

            if (!target)
            {
                handler.SendSysMessage(CypherStrings.PlayerNotFound);
                return(false);
            }

            // check online security
            if (handler.HasLowerSecurity(target, ObjectGuid.Empty))
            {
                return(false);
            }

            string factionTxt = handler.extractKeyFromLink(args, "Hfaction");

            if (string.IsNullOrEmpty(factionTxt))
            {
                return(false);
            }

            uint factionId = uint.Parse(factionTxt);

            int    amount  = 0;
            string rankTxt = args.NextString();

            if (factionId == 0 || rankTxt.IsEmpty())
            {
                return(false);
            }

            amount = int.Parse(rankTxt);
            if ((amount == 0) && !(amount < 0) && !rankTxt.IsNumber())
            {
                string rankStr = rankTxt.ToLower();

                int r = 0;
                amount = -42000;
                for (; r < (int)ReputationRank.Max; ++r)
                {
                    string rank = handler.GetCypherString(ReputationMgr.ReputationRankStrIndex[r]);
                    if (string.IsNullOrEmpty(rank))
                    {
                        continue;
                    }

                    if (rank.Equals(rankStr))
                    {
                        string deltaTxt = args.NextString();
                        if (!string.IsNullOrEmpty(deltaTxt))
                        {
                            int delta = int.Parse(deltaTxt);
                            if ((delta < 0) || (delta > ReputationMgr.PointsInRank[r] - 1))
                            {
                                handler.SendSysMessage(CypherStrings.CommandFactionDelta, (ReputationMgr.PointsInRank[r] - 1));
                                return(false);
                            }
                            amount += delta;
                        }
                        break;
                    }
                    amount += ReputationMgr.PointsInRank[r];
                }
                if (r >= (int)ReputationRank.Max)
                {
                    handler.SendSysMessage(CypherStrings.CommandFactionInvparam, rankTxt);
                    return(false);
                }
            }

            FactionRecord factionEntry = CliDB.FactionStorage.LookupByKey(factionId);

            if (factionEntry == null)
            {
                handler.SendSysMessage(CypherStrings.CommandFactionUnknown, factionId);
                return(false);
            }

            if (factionEntry.ReputationIndex < 0)
            {
                handler.SendSysMessage(CypherStrings.CommandFactionNorepError, factionEntry.Name[handler.GetSessionDbcLocale()], factionId);
                return(false);
            }

            target.GetReputationMgr().SetOneFactionReputation(factionEntry, amount, false);
            target.GetReputationMgr().SendState(target.GetReputationMgr().GetState(factionEntry));
            handler.SendSysMessage(CypherStrings.CommandModifyRep, factionEntry.Name[handler.GetSessionDbcLocale()], factionId, handler.GetNameLink(target), target.GetReputationMgr().GetReputation(factionEntry));

            return(true);
        }
Exemple #22
0
        public void TestCrimeEventsScenario()
        {
            // Save original data
            CrimeMonitorConfiguration data = CrimeMonitorConfiguration.FromFile();

            var privateObject = new PrivateObject(crimeMonitor);
            CrimeMonitorConfiguration config = CrimeMonitorConfiguration.FromJsonString(crimeConfigJson);

            crimeMonitor.readRecord(config);

            // Bond Awarded Event
            line   = "{ \"timestamp\":\"2019-04-22T11:51:30Z\", \"event\":\"FactionKillBond\", \"Reward\":32473, \"AwardingFaction\":\"Constitution Party of Aerial\", \"VictimFaction\":\"Ankou Blue Federal Holdings\" }";
            events = JournalMonitor.ParseJournalEntry(line);
            Assert.IsTrue(events.Count == 1);
            privateObject.Invoke("_handleBondAwardedEvent", new object[] { events[0] });
            record = crimeMonitor.criminalrecord.FirstOrDefault(r => r.faction == "Constitution Party of Aerial");
            Assert.AreEqual(3, record.factionReports.Count);
            Assert.AreEqual(94492, record.bondsAmount);

            // Bounty Awarded Event
            line   = "{ \"timestamp\":\"2019-04-22T03:13:36Z\", \"event\":\"Bounty\", \"Rewards\":[ { \"Faction\":\"Calennero State Industries\", \"Reward\":22265 } ], \"Target\":\"adder\", \"TotalReward\":22265, \"VictimFaction\":\"Natural Amemakarna Movement\" }";
            events = JournalMonitor.ParseJournalEntry(line);
            Assert.IsTrue(events.Count == 1);
            privateObject.Invoke("_handleBountyAwardedEvent", new object[] { events[0], true });
            record = crimeMonitor.criminalrecord.FirstOrDefault(r => r.faction == "Calennero State Industries");
            record.factionReports.FirstOrDefault(r => r.amount == 22265).shipId = 10;
            Assert.AreEqual(2, record.factionReports.Where(r => r.bounty && r.crimeDef == Crime.None).Count());
            Assert.AreEqual(127433, record.bountiesAmount);

            // Fine Incurred Event
            line   = "{ \"timestamp\":\"2019-04-22T03:21:46Z\", \"event\":\"CommitCrime\", \"CrimeType\":\"dockingMinorTresspass\", \"Faction\":\"Constitution Party of Aerial\", \"Fine\":400 }";
            events = JournalMonitor.ParseJournalEntry(line);
            Assert.IsTrue(events.Count == 1);
            privateObject.Invoke("_handleFineIncurredEvent", new object[] { events[0] });
            record = crimeMonitor.criminalrecord.FirstOrDefault(r => r.faction == "Constitution Party of Aerial");
            record.factionReports.FirstOrDefault(r => !r.bounty && r.crimeDef != Crime.None).shipId = 10;
            Assert.AreEqual(1, record.factionReports.Where(r => !r.bounty && r.crimeDef != Crime.None).Count());
            Assert.AreEqual(400, record.finesIncurred.Sum(r => r.amount));

            // Bounty Incurred Event
            line   = "{ \"timestamp\":\"2019-04-13T03:58:29Z\", \"event\":\"CommitCrime\", \"CrimeType\":\"assault\", \"Faction\":\"Calennero State Industries\", \"Victim\":\"Christofer\", \"Bounty\":400 }";
            events = JournalMonitor.ParseJournalEntry(line);
            Assert.IsTrue(events.Count == 1);
            privateObject.Invoke("_handleBountyIncurredEvent", new object[] { events[0] });
            record = crimeMonitor.criminalrecord.FirstOrDefault(r => r.faction == "Calennero State Industries");
            record.factionReports.FirstOrDefault(r => r.bounty && r.crimeDef != Crime.None).shipId = 10;
            Assert.AreEqual(1, record.factionReports.Where(r => r.bounty && r.crimeDef != Crime.None).Count());
            Assert.AreEqual(400, record.bountiesIncurred.Sum(r => r.amount));

            // Redeem Bond Event
            line   = "{ \"timestamp\":\"2019-04-09T10:31:31Z\", \"event\":\"RedeemVoucher\", \"Type\":\"CombatBond\", \"Amount\":94492, \"Factions\":[ { \"Faction\":\"Constitution Party of Aerial\", \"Amount\":94492 } ] }";
            events = JournalMonitor.ParseJournalEntry(line);
            Assert.IsTrue(events.Count == 1);
            privateObject.Invoke("_handleBondRedeemedEvent", new object[] { events[0] });
            record = crimeMonitor.criminalrecord.FirstOrDefault(r => r.faction == "Constitution Party of Aerial");
            Assert.AreEqual(0, record.factionReports.Where(r => !r.bounty && r.crimeDef == Crime.None).Count());

            // Redeem Bounty Event - Multiple
            line   = "{ \"timestamp\":\"2019-04-09T10:31:31Z\", \"event\":\"RedeemVoucher\", \"Type\":\"bounty\", \"Amount\":213896, \"Factions\":[ { \"Faction\":\"Calennero State Industries\", \"Amount\":105168 }, { \"Faction\":\"HIP 20277 Inc\", \"Amount\":108728 } ] }";
            events = JournalMonitor.ParseJournalEntry(line);
            Assert.IsTrue(events.Count == 1);
            privateObject.Invoke("_handleBountyRedeemedEvent", new object[] { events[0] });
            record = crimeMonitor.criminalrecord.FirstOrDefault(r => r.faction == "Calennero State Industries");
            Assert.IsNotNull(record);
            Assert.AreEqual(0, record.factionReports.Where(r => r.bounty && r.crimeDef == Crime.None).Count());
            record = crimeMonitor.criminalrecord.FirstOrDefault(r => r.faction == "HIP 20277 Inc");
            Assert.IsNull(record);

            // Fine Paid Event
            line   = "{ \"timestamp\":\"2019-04-09T15:12:10Z\", \"event\":\"PayFines\", \"Amount\":800, \"AllFines\":true, \"ShipID\":10 }";
            events = JournalMonitor.ParseJournalEntry(line);
            Assert.IsTrue(events.Count == 1);
            privateObject.Invoke("_handleFinePaidEvent", new object[] { events[0] });
            record = crimeMonitor.criminalrecord.FirstOrDefault(r => r.faction == "Calennero State Industries");
            Assert.AreEqual(0, record.factionReports.Where(r => !r.bounty && r.crimeDef != Crime.None).Count());
            Assert.AreEqual(0, record.finesIncurred.Sum(r => r.amount));
            record = crimeMonitor.criminalrecord.FirstOrDefault(r => r.faction == "Constitution Party of Aerial");
            Assert.IsNull(record);

            // Bounty Paid Event
            line   = "{ \"timestamp\":\"2019-04-14T04:43:05Z\", \"event\":\"PayBounties\", \"Amount\":400, \"Faction\":\"$faction_Empire;\", \"Faction_Localised\":\"Empire\", \"ShipID\":10, \"BrokerPercentage\":25.000000 }";
            events = JournalMonitor.ParseJournalEntry(line);
            Assert.IsTrue(events.Count == 1);
            privateObject.Invoke("_handleBountyPaidEvent", new object[] { events[0] });
            record = crimeMonitor.criminalrecord.FirstOrDefault(r => r.faction == "Calennero State Industries");
            Assert.IsNull(record);

            // Restore original data
            data.ToFile();
        }
Exemple #23
0
        static bool HandleCharacterReputationCommand(StringArguments args, CommandHandler handler)
        {
            Player target;

            if (!handler.ExtractPlayerTarget(args, out target))
            {
                return(false);
            }

            Locale loc = handler.GetSessionDbcLocale();

            var targetFSL = target.GetReputationMgr().GetStateList();

            foreach (var pair in targetFSL)
            {
                FactionState   faction      = pair.Value;
                FactionRecord  factionEntry = CliDB.FactionStorage.LookupByKey(faction.Id);
                string         factionName  = factionEntry != null ? factionEntry.Name[loc] : "#Not found#";
                ReputationRank rank         = target.GetReputationMgr().GetRank(factionEntry);
                string         rankName     = handler.GetCypherString(ReputationMgr.ReputationRankStrIndex[(int)rank]);
                StringBuilder  ss           = new StringBuilder();
                if (handler.GetSession() != null)
                {
                    ss.AppendFormat("{0} - |cffffffff|Hfaction:{0}|h[{1} {2}]|h|r", faction.Id, factionName, loc);
                }
                else
                {
                    ss.AppendFormat("{0} - {1} {2}", faction.Id, factionName, loc);
                }

                ss.AppendFormat(" {0} ({1})", rankName, target.GetReputationMgr().GetReputation(factionEntry));

                if (faction.Flags.HasAnyFlag(FactionFlags.Visible))
                {
                    ss.Append(handler.GetCypherString(CypherStrings.FactionVisible));
                }
                if (faction.Flags.HasAnyFlag(FactionFlags.AtWar))
                {
                    ss.Append(handler.GetCypherString(CypherStrings.FactionAtwar));
                }
                if (faction.Flags.HasAnyFlag(FactionFlags.PeaceForced))
                {
                    ss.Append(handler.GetCypherString(CypherStrings.FactionPeaceForced));
                }
                if (faction.Flags.HasAnyFlag(FactionFlags.Hidden))
                {
                    ss.Append(handler.GetCypherString(CypherStrings.FactionHidden));
                }
                if (faction.Flags.HasAnyFlag(FactionFlags.InvisibleForced))
                {
                    ss.Append(handler.GetCypherString(CypherStrings.FactionInvisibleForced));
                }
                if (faction.Flags.HasAnyFlag(FactionFlags.Inactive))
                {
                    ss.Append(handler.GetCypherString(CypherStrings.FactionInactive));
                }

                handler.SendSysMessage(ss.ToString());
            }

            return(true);
        }
Exemple #24
0
        public void GetFactionData(FactionRecord record, string homeSystem = null)
        {
            if (record == null || record.faction == null || record.faction == Properties.CrimeMonitor.blank_faction)
            {
                return;
            }

            // Get the faction from Elite BGS and set faction record values
            Faction faction = DataProviderService.GetFactionByName(record.faction);

            if (faction.EDDBID == null)
            {
                record.faction = Properties.CrimeMonitor.blank_faction;
                record.system  = null;
                record.station = null;
                return;
            }
            record.Allegiance = faction.Allegiance ?? Superpower.None;
            List <string> factionSystems = faction.presences.Select(p => p.systemName).ToList();

            factionSystems = faction.presences
                             .OrderByDescending(p => p.influence)
                             .Select(p => p.systemName).ToList();
            record.factionSystems = factionSystems;

            // If 'home system' is desiginated, check if system is part of faction presence
            if (homeSystem != null && factionSystems.Contains(homeSystem))
            {
                record.system  = homeSystem;
                record.station = GetFactionStation(homeSystem);
                if (FindHomeSystem(record.faction, factionSystems) == null && !homeSystems.ContainsKey(record.faction))
                {
                    // Save home system if not part of faction name and not previously saved
                    homeSystems.Add(record.faction, homeSystem);
                }
                return;
            }

            // Check faction with archived home systems
            if (homeSystems.TryGetValue(record.faction, out string result))
            {
                record.system  = result;
                record.station = GetFactionStation(result);
                return;
            }

            // Find 'home system' by matching faction name with presence and check for qualifying station
            homeSystem = FindHomeSystem(record.faction, factionSystems);
            if (homeSystem != null)
            {
                string factionStation = GetFactionStation(homeSystem);

                // Station found meeting game/user requirements
                if (factionStation != null)
                {
                    record.system  = homeSystem;
                    record.station = factionStation;
                    return;
                }
            }

            // Check faction presences, by order of influence, for qualifying station
            foreach (string system in factionSystems)
            {
                string factionStation = GetFactionStation(system);
                if (factionStation != null)
                {
                    record.system  = system;
                    record.station = factionStation;
                    return;
                }
            }

            // Settle for highest influence faction presence, with no station found
            record.system  = factionSystems.FirstOrDefault();
            record.station = null;
        }
Exemple #25
0
        public bool SetOneFactionReputation(FactionRecord factionEntry, int standing, bool incremental)
        {
            var factionState = _factions.LookupByKey((uint)factionEntry.ReputationIndex);

            if (factionState != null)
            {
                int BaseRep = GetBaseReputation(factionEntry);

                if (incremental)
                {
                    // int32 *= float cause one point loss?
                    standing  = (int)(Math.Floor(standing * WorldConfig.GetFloatValue(WorldCfg.RateReputationGain) + 0.5f));
                    standing += factionState.Standing + BaseRep;
                }

                if (standing > GetMaxReputation(factionEntry))
                {
                    standing = GetMaxReputation(factionEntry);
                }
                else if (standing < GetMinReputation(factionEntry))
                {
                    standing = GetMinReputation(factionEntry);
                }

                ReputationRank old_rank = ReputationToRank(factionEntry, factionState.Standing + BaseRep);
                ReputationRank new_rank = ReputationToRank(factionEntry, standing);

                int oldStanding = factionState.Standing + BaseRep;
                int newStanding = standing - BaseRep;

                _player.ReputationChanged(factionEntry, newStanding - factionState.Standing);

                factionState.Standing = newStanding;
                factionState.needSend = true;
                factionState.needSave = true;

                SetVisible(factionState);

                if (new_rank <= ReputationRank.Hostile)
                {
                    SetAtWar(factionState, true);
                }

                if (new_rank > old_rank)
                {
                    _sendFactionIncreased = true;
                }

                ParagonReputationRecord paragonReputation = Global.DB2Mgr.GetParagonReputation(factionEntry.Id);
                if (paragonReputation != null)
                {
                    int oldParagonLevel = oldStanding / paragonReputation.LevelThreshold;
                    int newParagonLevel = standing / paragonReputation.LevelThreshold;
                    if (oldParagonLevel != newParagonLevel)
                    {
                        Quest paragonRewardQuest = Global.ObjectMgr.GetQuestTemplate((uint)paragonReputation.QuestID);
                        if (paragonRewardQuest != null)
                        {
                            _player.AddQuestAndCheckCompletion(paragonRewardQuest, null);
                        }
                    }
                }

                if (factionEntry.FriendshipRepID == 0 && paragonReputation == null)
                {
                    UpdateRankCounters(old_rank, new_rank);
                }

                _player.UpdateCriteria(CriteriaType.TotalFactionsEncountered, factionEntry.Id);
                _player.UpdateCriteria(CriteriaType.ReputationGained, factionEntry.Id);
                _player.UpdateCriteria(CriteriaType.TotalExaltedFactions, factionEntry.Id);
                _player.UpdateCriteria(CriteriaType.TotalReveredFactions, factionEntry.Id);
                _player.UpdateCriteria(CriteriaType.TotalHonoredFactions, factionEntry.Id);

                return(true);
            }
            return(false);
        }
Exemple #26
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();
        }
Exemple #27
0
 public uint GetReputationRankStrIndex(FactionRecord factionEntry)
 {
     return((uint)ReputationRankStrIndex[(int)GetRank(factionEntry)]);
 }
Exemple #28
0
        public ReputationRank GetRank(FactionRecord factionEntry)
        {
            int reputation = GetReputation(factionEntry);

            return(ReputationToRank(factionEntry, reputation));
        }
 bool SetReputation(FactionRecord factionEntry, int standing)
 {
     return(SetReputation(factionEntry, standing, false, false));
 }
Exemple #30
0
        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();
        }