Пример #1
0
        /// <summary>
        ///     Go trough the delegacy changes to filter out the suspicious ones. A suspicious change is one where the
        ///     new delegate just moved into the region before becoming delegate, which commonly happens during tag raids
        ///     and detags, or during surprise invasions on small regions. This method cannot filter out big raids,
        ///     defences and sieges which happen over the course of multiple days.
        /// </summary>
        /// <returns> A dictionary with region-name, OpType pairs </returns>
        private async Task <List <DelegacyChange> > FilterOps(List <DelegacyChange> delegacyChanges, double since,
                                                              Dictionary <string, string> userTags, bool interactiveLog = false)
        {
            // Get regions with tag
            var invaders = await api.TaggedInvader();

            var imperialists = await api.TaggedImperialist();

            var defenders = await api.TaggedDefender();

            var independents = await api.TaggedIndependent();

            var ops = new List <DelegacyChange>();

            // For each delegacy change
            foreach (var c in delegacyChanges)
            {
                var change = c;

                // Delegate nation name
                var delegateName = change.NewDelegate;
                // Get the last moves made by that nation since ...
                var delMoves = await LastMoves(delegateName, since);

                // If the nation moved since ...
                if (delMoves.Count > 0)
                {
                    // Get the move right before becoming delegate
                    var moveBeforeBecomingWaD =
                        MoveBeforeBecomingDelegate(delMoves, change.ChangeTimeStamp);

                    // Skip change if nation didn't move before becoming delegate (it might have moved after)
                    if (moveBeforeBecomingWaD == null)
                    {
                        continue;
                    }

                    var movedFrom = moveBeforeBecomingWaD.Find("%%(.*?)%%");

                    // Determine operation type
                    change.OpType = OpTypeFromOrigin(movedFrom, invaders, imperialists, defenders, independents,
                                                     userTags);
                    if (change.OpType == OpType.Suspicious)
                    {
                        change.OpType = OpTypeFromEmbassies(change.Region);
                    }

                    // Add change to operations
                    ops.Add(change);

                    if (interactiveLog)
                    {
                        var type = change.OpType.ToString();
                        Console.Write($"* {type} activity in {change.Region}\n");
                    }
                }
            }

            return(ops);
        }