Esempio n. 1
0
        public async Task <bool> IsUnlocked(TrophyScanner.ScannerQueueItem item)
        {
            if (_checkUnlocked is null)
            {
                return(false);
            }

            return(await _checkUnlocked(item));
        }
Esempio n. 2
0
        private async Task <bool> _checkTrophy_superiorSurvivor(TrophyScanner.ScannerQueueItem item)
        {
            // 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;"))
                using (DataTable table = await Database.GetRowsAsync(cmd)) {
                    int row_index = 0;

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

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

                        if (ts - current_ts > ts_threshold || row_index == table.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 owner = $owner AND timestamp <= $timestamp AND id NOT IN (SELECT species_id FROM Extinctions);")) {
                                    cmd2.Parameters.AddWithValue("$owner", (await item.Context.Guild.GetUserAsync(item.UserId)).Username);
                                    cmd2.Parameters.AddWithValue("$timestamp", current_ts);

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

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

                        ++row_index;
                    }
                }

            return(false);
        }
Esempio n. 3
0
        private async Task <bool> _checkTrophy_helper_hasSpeciesWithZoneTypeMatch(TrophyScanner.ScannerQueueItem item, string[] zoneTypeNames)
        {
            if (zoneTypeNames.Count() <= 0)
            {
                return(false);
            }

            StringBuilder query_builder = new StringBuilder();

            query_builder.Append("SELECT COUNT(*) FROM Species WHERE owner=$owner");

            foreach (string zone_type_name in zoneTypeNames)
            {
                ZoneType zone_type = await ZoneUtils.GetZoneTypeAsync(zone_type_name);

                // If any of the zone types are invalid, the trophy is automatically invalidated.

                if (zone_type is null || zone_type.Id == ZoneType.NullZoneTypeId)
                {
                    return(false);
                }

                query_builder.Append(string.Format(" AND id IN (SELECT species_id FROM SpeciesZones WHERE zone_id IN (SELECT id FROM Zones WHERE type_id = {0}))", zone_type.Id));
            }

            string username = (await item.Context.Guild.GetUserAsync(item.UserId)).Username;
            bool   unlocked = false;

            using (SQLiteCommand cmd = new SQLiteCommand(query_builder.ToString())) {
                cmd.Parameters.AddWithValue("$owner", username);

                if (await Database.GetScalar <long>(cmd) > 0)
                {
                    return(true);
                }
            }

            return(unlocked);
        }
Esempio n. 4
0
 private async Task <bool> _checkTrophy_naturalSelection(TrophyScanner.ScannerQueueItem item)
 {
     return(await _checkTrophy_helper_hasSpeciesMatchingSQLiteCountQuery(item,
                                                                         @"SELECT COUNT(*) FROM Extinctions WHERE species_id IN (SELECT id FROM Species WHERE owner = $owner);"));
 }
Esempio n. 5
0
 private async Task <bool> _checkTrophy_beneathYou(TrophyScanner.ScannerQueueItem item)
 {
     return(await _checkTrophy_helper_hasSpeciesMatchingSQLiteCountQuery(item,
                                                                         @"SELECT COUNT(*) FROM Species WHERE owner=$owner AND description LIKE ""%burrow%"";"));
 }
Esempio n. 6
0
 private async Task <bool> _checkTrophy_trademarked(TrophyScanner.ScannerQueueItem item)
 {
     return(await _checkTrophy_helper_hasSpeciesMatchingSQLiteCountQuery(item,
                                                                         @"SELECT COUNT(*) FROM (SELECT owner, genus_id, MIN(timestamp) FROM Species GROUP BY genus_id) WHERE owner = $owner"));
 }
Esempio n. 7
0
 private async Task <bool> _checkTrophy_liftOff(TrophyScanner.ScannerQueueItem item)
 {
     return(await _checkTrophy_helper_hasSpeciesMatchingSQLiteCountQuery(item,
                                                                         @"SELECT COUNT(*) FROM Species WHERE owner=$owner AND (description LIKE ""%can fly%"" OR description LIKE ""%flies%"")"));
 }
Esempio n. 8
0
 private async Task <bool> _checkTrophy_polarPower(TrophyScanner.ScannerQueueItem item)
 {
     return(await _checkTrophy_helper_hasSpeciesWithZoneDescriptionMatch(item, "frigid|arctic|cold"));
 }
Esempio n. 9
0
 private async Task <bool> _checkTrophy_deathBringsLife(TrophyScanner.ScannerQueueItem item)
 {
     return(await _checkTrophy_helper_hasSpeciesMatchingSQLiteCountQuery(item, @"SELECT COUNT(*) FROM Species WHERE owner=$owner
         AND id IN(SELECT species_id FROM SpeciesRoles WHERE role_id IN(SELECT id FROM Roles WHERE name = ""scavenger"" OR name = ""decomposer"" OR name = ""detritivore""))"));
 }
Esempio n. 10
0
 private async Task <bool> _checkTrophy_twoCourseMeal(TrophyScanner.ScannerQueueItem item)
 {
     return(await _checkTrophy_helper_hasSpeciesMatchingSQLiteCountQuery(item, @"SELECT COUNT(*) FROM Species WHERE owner=$owner
         AND id IN(SELECT species_id FROM SpeciesRoles WHERE role_id IN(SELECT id FROM Roles WHERE name = ""base-consumer"" OR name = ""herbivore""))
         AND id IN(SELECT species_id FROM SpeciesRoles WHERE role_id IN(SELECT id FROM Roles WHERE name = ""predator"" OR name = ""carnivore""))"));
 }
Esempio n. 11
0
 private async Task <bool> _checkTrophy_bestOfBothWorlds(TrophyScanner.ScannerQueueItem item)
 {
     return(await _checkTrophy_helper_hasSpeciesWithZoneTypeMatch(item, new string[] { "aquatic", "terrestrial" }));
 }
Esempio n. 12
0
 private async Task <bool> _checkTrophy_kissTheGround(TrophyScanner.ScannerQueueItem item)
 {
     return(await _checkTrophy_helper_hasSpeciesWithZoneTypeMatch(item, new string[] { "terrestrial" }));
 }
Esempio n. 13
0
 private async Task <bool> _checkTrophy_atlantean(TrophyScanner.ScannerQueueItem item)
 {
     return(await _checkTrophy_helper_hasSpeciesWithZoneTypeMatch(item, new string[] { "aquatic" }));
 }
Esempio n. 14
0
 private async Task <bool> _checkTrophy_heatingUp(TrophyScanner.ScannerQueueItem item)
 {
     return(await _checkTrophy_helper_hasSpeciesWithZoneDescriptionMatch(item, "warm|hot|desert|tropical"));
 }
Esempio n. 15
0
        private async Task <bool> _checkTrophy_helper_hasSpeciesMatchingSQLiteCountQuery(TrophyScanner.ScannerQueueItem item, string query)
        {
            using (SQLiteCommand cmd = new SQLiteCommand(query)) {
                cmd.Parameters.AddWithValue("$owner", (await item.Context.Guild.GetUserAsync(item.UserId)).Username);

                if (await Database.GetScalar <long>(cmd) > 0)
                {
                    return(true);
                }
            }

            return(false);
        }
Esempio n. 16
0
        private async Task <bool> _checkTrophy_helper_hasSpeciesWithZoneDescriptionMatch(TrophyScanner.ScannerQueueItem item, string regexPattern)
        {
            // Get all zones.
            List <Zone> zones = new List <Zone>(await BotUtils.GetZonesFromDb());

            // Filter list so we only have zones with cold climates.
            zones.RemoveAll(zone => !Regex.IsMatch(zone.Description, regexPattern));

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

            string username = (await item.Context.Guild.GetUserAsync(item.UserId)).Username;
            bool   unlocked = false;

            foreach (Zone zone in zones)
            {
                using (SQLiteCommand cmd = new SQLiteCommand("SELECT COUNT(*) FROM SpeciesZones WHERE zone_id=$zone_id AND species_id IN (SELECT id FROM Species WHERE owner=$owner);")) {
                    cmd.Parameters.AddWithValue("$zone_id", zone.Id);
                    cmd.Parameters.AddWithValue("$owner", username);

                    if (await Database.GetScalar <long>(cmd) > 0)
                    {
                        unlocked = true;
                        break;
                    }
                }
            }

            return(unlocked);
        }
Esempio n. 17
0
 private async Task <bool> _checkTrophy_allMine(TrophyScanner.ScannerQueueItem item)
 {
     return(await _checkTrophy_helper_hasSpeciesMatchingSQLiteCountQuery(item, @"SELECT COUNT(*) FROM Species WHERE owner=$owner
         AND id IN(SELECT species_id FROM SpeciesRoles WHERE role_id IN(SELECT id FROM Roles WHERE name = ""parasite""))"));
 }
Esempio n. 18
0
        private async Task <bool> _checkTrophy_scrapThat(TrophyScanner.ScannerQueueItem item)
        {
            return(await _checkTrophy_helper_hasSpeciesMatchingSQLiteCountQuery(item, @"SELECT COUNT(*) FROM Species WHERE owner=$owner
	            AND id IN (SELECT ancestor_id FROM Ancestors WHERE species_id IN (SELECT id FROM Species WHERE owner=$owner))"    ));
        }
Esempio n. 19
0
 private async Task <bool> _checkTrophy_Placeholder(TrophyScanner.ScannerQueueItem item)
 {
     return(await Task.FromResult(false));
 }