public async override Task <bool> CheckTrophyAsync(ITrophyScannerContext context)
        {
            // Check if the user has any species with these roles.

            IEnumerable <ISpecies> ownedSpecies = await context.Database.GetSpeciesAsync(context.Creator);

            foreach (ISpecies species in ownedSpecies)
            {
                IEnumerable <IRole> roles = await context.Database.GetRolesAsync(species);

                bool allPatternsMatched = true;

                foreach (string pattern in patterns)
                {
                    if (!roles.Any(role => Regex.IsMatch(role.Name, pattern, RegexOptions.IgnoreCase)))
                    {
                        allPatternsMatched = false;

                        break;
                    }
                }

                if (allPatternsMatched)
                {
                    return(true);
                }
            }

            return(false);
        }
        public async override Task <bool> CheckTrophyAsync(ITrophyScannerContext context)
        {
            if (context.Creator.UserId.HasValue)
            {
                // Check if the user has any species that were the first in their genus.
                // If the ancestor species has a different genus (or doesn't exist), the trophy will be awarded.

                IEnumerable <ISpecies> ownedSpecies = await context.Database.GetSpeciesAsync(context.Creator);

                foreach (ISpecies species in ownedSpecies)
                {
                    if (species.Genus != null)
                    {
                        ISpecies ancestor = await context.Database.GetAncestorAsync(species);

                        if (ancestor is null || (ancestor.Genus != null && !ancestor.Genus.Name.Equals(species.Genus.Name, StringComparison.OrdinalIgnoreCase)))
                        {
                            return(true);
                        }
                    }
                }
            }

            return(false);
        }
Beispiel #3
0
        public async override Task <bool> CheckTrophyAsync(ITrophyScannerContext context)
        {
            // Get zone types.

            IEnumerable <IZoneType> zoneTypes = (await context.Database.GetZoneTypesAsync())
                                                .Where(type => patterns.Any(pattern => Regex.IsMatch(type.Name, pattern, RegexOptions.IgnoreCase)));

            // Get zones.

            IEnumerable <IZone> zones = (await context.Database.GetZonesAsync())
                                        .Where(zone => zoneTypes.Any(type => type.Id == zone.TypeId));

            // Check if the user has any species in these zones.

            IEnumerable <ISpecies> ownedSpecies = await context.Database.GetSpeciesAsync(context.Creator);

            foreach (ISpecies species in ownedSpecies)
            {
                IEnumerable <ISpeciesZoneInfo> speciesZones = await context.Database.GetZonesAsync(species, GetZoneOptions.Fast);

                if (zoneTypes.All(type => speciesZones.Any(zoneInfo => zoneInfo.Zone.TypeId == type.Id)))
                {
                    return(true);
                }
            }

            return(false);
        }
        public async override Task <bool> CheckTrophyAsync(ITrophyScannerContext context)
        {
            // The minimum number of simultaneous extinctions to be considered an "exinction event"
            long extinction_threshold = 5;
            // The extinction threshold must be reached within the given number of hours
            long ts_threshold = 24 * 60 * 60; // 24 hours

            long current_threshold = 0;
            long current_ts        = 0;

            using (SQLiteCommand cmd = new SQLiteCommand("SELECT timestamp FROM Extinctions ORDER BY timestamp ASC")) {
                int row_index = 0;

                IEnumerable <DataRow> rows = await context.Database.GetRowsAsync(cmd);

                foreach (DataRow row in rows)
                {
                    long ts = (long)row.Field <decimal>("timestamp");

                    if (current_ts == 0)
                    {
                        current_ts = ts;
                    }

                    if (ts - current_ts > ts_threshold || row_index == rows.Count() - 1)
                    {
                        // To make this process more efficient, we'll check the trophy condition at the end of an extinction event.
                        // The check will also occur when we reach the end of the extinction records, in case it ended on an extinction event.

                        if (current_threshold >= extinction_threshold)
                        {
                            // The user has a species that survived the extinction event if the species existed before the event, and still exists.

                            using (SQLiteCommand cmd2 = new SQLiteCommand("SELECT COUNT(*) FROM Species WHERE user_id = $user_id AND timestamp <= $timestamp AND id NOT IN (SELECT species_id FROM Extinctions)")) {
                                cmd2.Parameters.AddWithValue("$user_id", context.Creator.UserId);
                                cmd2.Parameters.AddWithValue("$timestamp", current_ts);

                                if (await context.Database.GetScalarAsync <long>(cmd2) > 0)
                                {
                                    return(true);
                                }
                            }
                        }

                        current_ts        = ts;
                        current_threshold = 0;
                    }
                    else
                    {
                        ++current_threshold;
                    }

                    ++row_index;
                }
            }

            return(false);
        }
        public async override Task <bool> CheckTrophyAsync(ITrophyScannerContext context)
        {
            IEnumerable <ISpecies> ownedSpecies = await context.Database.GetSpeciesAsync(context.Creator);

            foreach (ISpecies species in ownedSpecies)
            {
                if (species.Status.IsExinct)
                {
                    return(true);
                }
            }

            return(false);
        }
Beispiel #6
0
        public async override Task <bool> CheckTrophyAsync(ITrophyScannerContext context)
        {
            // Find a species with a matching description.

            IEnumerable <ISpecies> ownedSpecies = await context.Database.GetSpeciesAsync(context.Creator);

            foreach (ISpecies species in ownedSpecies)
            {
                if (Regex.IsMatch(species.Description, pattern, RegexOptions.IgnoreCase))
                {
                    return(true);
                }
            }

            return(false);
        }
        public async override Task <bool> CheckTrophyAsync(ITrophyScannerContext context)
        {
            if (context.Creator.UserId.HasValue)
            {
                // Check if the user has any species with a direct descendant created by that user.

                IEnumerable <ISpecies> ownedSpecies = await context.Database.GetSpeciesAsync(context.Creator);

                foreach (ISpecies species in ownedSpecies)
                {
                    if ((await context.Database.GetDirectDescendantsAsync(species)).Any(evo => evo.Creator?.UserId == context.Creator.UserId))
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
Beispiel #8
0
        public int ScanDelay => 60 * 5; // 5 minutes

        public async Task <bool> EnqueueAsync(ITrophyScannerContext context, bool scanImmediately = false)
        {
            // If the user already exists in the queue, don't add them again.

            if (context.Creator.UserId.HasValue && !queue.Any(item => item.Context.Creator.UserId == context.Creator.UserId))
            {
                // Add the user to the scanner queue.

                queue.Enqueue(new QueueItem {
                    Context   = context,
                    DateAdded = scanImmediately ? DateTimeOffset.MinValue : DateUtilities.GetCurrentDate()
                });

                // Since there's something in the queue, start the trophy scanner (nothing will happen if it's already active).

                await StartScannerAsync();

                return(true);
            }

            return(false);
        }
Beispiel #9
0
        public async override Task <bool> CheckTrophyAsync(ITrophyScannerContext context)
        {
            // Get all zones.

            List <IZone> zones = new List <IZone>(await context.Database.GetZonesAsync());

            // Filter list so we only have zones with matching descriptions.

            zones.RemoveAll(zone => !Regex.IsMatch(zone.Description, pattern, RegexOptions.IgnoreCase));

            // Check if the user has any species in these zones.

            IEnumerable <ISpecies> ownedSpecies = await context.Database.GetSpeciesAsync(context.Creator);

            foreach (ISpecies species in ownedSpecies)
            {
                if ((await context.Database.GetZonesAsync(species)).Any(zone => zones.Any(z => z.Id == zone.Zone.Id)))
                {
                    return(true);
                }
            }

            return(false);
        }
 public TrophyUnlockedArgs(ITrophyScannerContext context, IUnlockedTrophyInfo trophyInfo)
 {
     this.Context    = context;
     this.TrophyInfo = trophyInfo;
 }
Beispiel #11
0
 public virtual async Task <bool> CheckTrophyAsync(ITrophyScannerContext context)
 {
     return(await Task.FromResult(false));
 }