private static async Task _calculateDescriptionBasedBaseStats(Gotchi gotchi, GotchiStats stats)
        {
            Species species = await SpeciesUtils.GetSpeciesAsync(gotchi.SpeciesId);

            int weight = 20;

            if (Regex.IsMatch(species.Description, "photosynthesi(s|izes)", RegexOptions.IgnoreCase))
            {
                stats.MaxHp += weight;
            }

            if (Regex.IsMatch(species.Description, "spikes?|claws?|teeth|jaws|fangs", RegexOptions.IgnoreCase))
            {
                stats.Atk += weight;
            }

            if (Regex.IsMatch(species.Description, "shell|carapace|exoskeleton", RegexOptions.IgnoreCase))
            {
                stats.Def += weight;
            }

            foreach (Match m in Regex.Matches(species.Description, "flies|fly|quick|fast|agile|nimble", RegexOptions.IgnoreCase))
            {
                stats.Spd += weight;
            }

            foreach (Match m in Regex.Matches(species.Description, "slow|heavy", RegexOptions.IgnoreCase))
            {
                stats.Spd -= weight;
            }
        }
        public async Task PlusZone(string arg0, string arg1, string arg2)
        {
            // Possible cases:
            // 1. <species> <zone> <notes>
            // 2. <genus> <species> <zone>

            // If a species exists with the given genus/species, assume the user intended case (2).

            Species[] species_list = await SpeciesUtils.GetSpeciesAsync(arg0, arg1);

            if (species_list.Count() == 1)
            {
                // If there is a unqiue species match, proceed with the assumption of case (2).

                await _plusZone(species_list[0], zoneList : arg2, notes : string.Empty, onlyShowErrors : false);
            }
            else if (species_list.Count() > 1)
            {
                // If there are species matches but no unique result, show the user.
                await BotUtils.ReplyValidateSpeciesAsync(Context, species_list);
            }
            else if (species_list.Count() <= 0)
            {
                // If there were no matches, assume the user intended case (1).

                species_list = await SpeciesUtils.GetSpeciesAsync(string.Empty, arg0);

                if (await BotUtils.ReplyValidateSpeciesAsync(Context, species_list))
                {
                    await _plusZone(species_list[0], zoneList : arg1, notes : arg2, onlyShowErrors : false);
                }
            }
        }
Esempio n. 3
0
        private async Task _generateOpponentAsync()
        {
            // Pick a random species from the same zone as the player's gotchi.

            List <Species> species_list = new List <Species>();

            foreach (SpeciesZone zone in await SpeciesUtils.GetZonesAsync(await SpeciesUtils.GetSpeciesAsync(player1.Gotchi.Gotchi.SpeciesId)))
            {
                species_list.AddRange((await ZoneUtils.GetSpeciesAsync(zone.Zone)).Where(x => !x.IsExtinct));
            }

            player2 = new PlayerState();

            if (species_list.Count() > 0)
            {
                player2.Gotchi = await GotchiUtils.GenerateGotchiAsync(new GotchiGenerationParameters {
                    Base            = player1.Gotchi.Gotchi,
                    Species         = species_list[BotUtils.RandomInteger(species_list.Count())],
                    MinLevel        = player1.Gotchi.Stats.Level - 3,
                    MaxLevel        = player1.Gotchi.Stats.Level + 3,
                    GenerateMoveset = true,
                    GenerateStats   = true
                });
            }

            // Set the opponent.

            if (player2.Gotchi != null)
            {
                player2.Gotchi.Gotchi.OwnerId = WildGotchiUserId;
                player2.Gotchi.Gotchi.Id      = WildGotchiId;
            }
        }
        public async Task SetExtinct(string arg0, string arg1)
        {
            // We either have a genus/species, or a species/description.

            Species[] species_list = await SpeciesUtils.GetSpeciesAsync(arg0, arg1);

            if (species_list.Count() > 0)
            {
                // If such a species does exist, assume we have a genus/species.
                await SetExtinct(arg0, arg1, string.Empty);
            }
            else
            {
                // If no such species exists, assume we have a species/description.
                await SetExtinct(string.Empty, arg0, arg1);
            }
        }
Esempio n. 5
0
        private static async Task <WikiLinkList> _generateLinkifyListAsync()
        {
            // Returns a dictionary of substrings that should be turned into page links in page content.

            WikiLinkList list = new WikiLinkList();

            // Add species names to the dictionary.

            Species[] species_list = await SpeciesUtils.GetSpeciesAsync();

            foreach (Species species in species_list)
            {
                list.Add(species.ShortName.ToLower(), species.FullName);
                list.Add(species.FullName.ToLower(), species.FullName);
                list.Add(species.Name.ToLower(), species.FullName);

                if (!string.IsNullOrEmpty(species.CommonName))
                {
                    list.Add(species.CommonName.ToLower(), species.FullName);
                }
            }

            foreach (Species species in species_list)
            {
                // Also linkify binomial names that might be using outdated genera (e.g. Species moved to a new genus since the description was written).
                // Only do this for species that have a unique name-- otherwise, there's no way to know for sure which species to link to!
                // This might create some false-positives, so it could be a good idea to limit matches only to known genera (at the expense of a significantly longer regex).

                if (list.Count(x => x.Value == species.Name.ToLower()) == 1)
                {
                    list.Add(string.Format(WikiPageUtils.UnlinkedWikiTextPatternFormat, @"[A-Z](?:[a-z]+|\.)\s" + Regex.Escape(species.Name.ToLower())), species.FullName, WikiLinkListDataType.Regex);
                }
            }

            // Add zone names to the dictionary.

            Zone[] zones_list = await ZoneUtils.GetZonesAsync();

            foreach (Zone zone in zones_list)
            {
                list.Add(zone.FullName.ToLower(), zone.FullName);
            }

            return(list);
        }
Esempio n. 6
0
        private async Task _setTaxonDescriptionAsync(Taxon taxon)
        {
            if (taxon.type == TaxonRank.Species)
            {
                await _setSpeciesDescriptionAsync(await SpeciesUtils.GetSpeciesAsync(taxon.id));
            }

            else if (await BotUtils.ReplyHasPrivilegeAsync(Context, PrivilegeLevel.ServerModerator))   // moderator use only

            {
                Bot.MultiPartMessage p = new Bot.MultiPartMessage(Context)
                {
                    UserData = new string[] { taxon.name },
                    Callback = async(args) => {
                        await BotUtils.Command_SetTaxonDescription(args.Message.Context, taxon, args.ResponseContent);
                    }
                };

                await Bot.DiscordUtils.SendMessageAsync(Context, p,
                                                        string.Format("Reply with the description for {0} **{1}**.\nTo cancel the update, reply with \"cancel\".", taxon.GetTypeName(), taxon.GetName()));
            }
        }
Esempio n. 7
0
        public async Task AddPrey(string genusName, string speciesName, string preyGenusName, string preySpeciesName, string notes = "")
        {
            Species[] species_list = await SpeciesUtils.GetSpeciesAsync(genusName, speciesName);

            Species[] prey_list = await SpeciesUtils.GetSpeciesAsync(preyGenusName, preySpeciesName);

            if (species_list.Count() <= 0)
            {
                await BotUtils.ReplyAsync_SpeciesSuggestions(Context, genusName, speciesName);
            }
            else if (prey_list.Count() <= 0)
            {
                await BotUtils.ReplyAsync_SpeciesSuggestions(Context, preyGenusName, preySpeciesName);
            }
            else if (!await BotUtils.ReplyValidateSpeciesAsync(Context, species_list) || !await BotUtils.ReplyValidateSpeciesAsync(Context, prey_list))
            {
                return;
            }
            else
            {
                await _addPrey(species_list[0], prey_list, notes);
            }
        }
Esempio n. 8
0
        public async Task <bool> CheckAsync(Gotchi gotchi, GotchiRequirements requirements)
        {
            if (requirements is null)
            {
                return(true);
            }

            if (requirements.AlwaysFailValue)
            {
                return(false);
            }

            if (!_checkLevels(gotchi, requirements))
            {
                return(false);
            }

            if (!string.IsNullOrEmpty(requirements.RolePattern) && !await _checkRolesAsync(gotchi, requirements))
            {
                return(false);
            }

            if (!string.IsNullOrEmpty(requirements.TypePattern) && !await _checkTypesAsync(gotchi, requirements))
            {
                return(false);
            }

            Species species = await SpeciesUtils.GetSpeciesAsync(gotchi.SpeciesId);

            if (!string.IsNullOrEmpty(requirements.DescriptionPattern) && !_checkDescription(species, requirements))
            {
                return(false);
            }

            return(true);
        }
Esempio n. 9
0
        public async Task MainAsync(string[] args)
        {
            _log("loading configuration");

            Config config = JsonConvert.DeserializeObject <Config>(System.IO.File.ReadAllText("wikibot-config.json"));

            _log("initializing mediawiki client");

            MediaWikiClient client = new MediaWikiClient {
                Protocol  = config.Protocol,
                Server    = config.Server,
                ApiPath   = config.ApiPath,
                UserAgent = config.UserAgent
            };

            client.Log += _log;

            EditHistory history = new EditHistory();

            if (client.Login(config.Username, config.Password).Success)
            {
                _log("generating link dictionary");

                WikiLinkList LinkifyList = await _generateLinkifyListAsync();

                _log("synchronizing species");
                _log("getting species from database");

                Species[] speciesList = await SpeciesUtils.GetSpeciesAsync();

                _log(string.Format("got {0} results", speciesList.Count()));

                foreach (Species species in speciesList)
                {
                    _log(string.Format("synchronizing species {0}", species.ShortName));

                    // Create the page builder.

                    SpeciesPageBuilder pageBuilder = new SpeciesPageBuilder(species, WikiPageTemplate.Open(SpeciesTemplateFilePath))
                    {
                        AllSpecies = speciesList,
                        LinkList   = LinkifyList
                    };

                    // Attempt to upload the species' picture.

                    pageBuilder.PictureFilenames.Add(await UploadSpeciesPictureAsync(client, history, species));
                    pageBuilder.PictureFilenames.AddRange(await UploadSpeciesGalleryAsync(client, history, species));
                    pageBuilder.PictureFilenames.RemoveAll(x => string.IsNullOrWhiteSpace(x));

                    // Generate page content.

                    WikiPage wikiPage = await pageBuilder.BuildAsync();

                    string pageTitle      = wikiPage.Title;
                    bool   createRedirect = pageTitle != species.FullName;

                    // Upload page content.

                    await _editSpeciesPageAsync(client, history, species, pageTitle, wikiPage.Body);

                    // Attempt to create the redirect page for the species (if applicable).

                    if (createRedirect)
                    {
                        string redirect_page_title = species.FullName;

                        if (await _editPageAsync(client, history, redirect_page_title, string.Format("#REDIRECT [[{0}]]", pageTitle) + "\n" + BotFlag))
                        {
                            await history.AddRedirectRecordAsync(redirect_page_title, pageTitle);
                        }
                    }

                    _log(string.Format("finished synchronizing species {0}", species.ShortName));
                }
            }
            else
            {
                _log("mediawiki login failed");
            }

            _log("synchronizing complete");

            await Task.Delay(-1);
        }