예제 #1
0
        public async Task Feed()
        {
            Gotchi gotchi = await Db.GetGotchiAsync(Context.User.ToCreator());

            if (await this.ReplyValidateGotchiAsync(gotchi))
            {
                if (!gotchi.IsAlive)
                {
                    await ReplyInfoAsync(string.Format("You went to feed **{0}**, but it looks like it's too late...", StringUtilities.ToTitleCase(gotchi.Name)));
                }
                else if (gotchi.IsSleeping)
                {
                    await ReplyInfoAsync(string.Format("Shhh, do not disturb! **{0}** is currently asleep. Try feeding them again later.", StringUtilities.ToTitleCase(gotchi.Name)));
                }
                else
                {
                    await Db.FeedGotchisAsync(Global.GotchiContext, Context.User.Id);

                    if (await Db.GetGotchiCountAsync(Context.User.ToCreator()) > 1)
                    {
                        await ReplySuccessAsync("Fed everyone some delicious Suka-Flakes™!");
                    }
                    else
                    {
                        await ReplySuccessAsync(string.Format("Fed **{0}** some delicious Suka-Flakes™!", StringUtilities.ToTitleCase(gotchi.Name)));
                    }
                }
            }
        }
        public static async Task <Gotchi> GetGotchiAsync(this SQLiteDatabase database, ICreator creator)
        {
            GotchiUserInfo userData = await database.GetUserInfoAsync(creator);

            // Get this user's primary Gotchi.

            Gotchi gotchi = await database.GetGotchiAsync(userData.PrimaryGotchiId);

            // If this user's primary gotchi doesn't exist (either it was never set or no longer exists), pick a primary gotchi from their current gotchis.

            if (gotchi is null)
            {
                IEnumerable <Gotchi> gotchis = await database.GetGotchisAsync(userData.UserId);

                if (gotchis.Count() > 0)
                {
                    gotchi = gotchis.First();

                    userData.PrimaryGotchiId = gotchi.Id;

                    await database.UpdateUserInfoAsync(userData);
                }
            }

            return(gotchi);
        }
        public static async Task SetGotchiNameAsync(this SQLiteDatabase database, Gotchi gotchi, string name)
        {
            using (SQLiteCommand cmd = new SQLiteCommand("UPDATE Gotchi SET name = $name WHERE owner_id = $owner_id AND id = $id")) {
                cmd.Parameters.AddWithValue("$name", name.ToLowerInvariant());
                cmd.Parameters.AddWithValue("$owner_id", gotchi.OwnerId);
                cmd.Parameters.AddWithValue("$id", gotchi.Id);

                await database.ExecuteNonQueryAsync(cmd);
            }
        }
예제 #4
0
        public async Task Name(string name)
        {
            Gotchi gotchi = await Db.GetGotchiAsync(Context.User.ToCreator());

            if (await this.ReplyValidateGotchiAsync(gotchi))
            {
                await Db.SetGotchiNameAsync(gotchi, name);

                await ReplySuccessAsync(string.Format("Sucessfully set {0}'s name to **{1}**.", StringUtilities.ToTitleCase(gotchi.Name), StringUtilities.ToTitleCase(name)));
            }
        }
예제 #5
0
        // Public members

        public static async Task <Gotchi> GetGotchiOrReplyAsync(this OfcModuleBase moduleBase, ICreator creator)
        {
            Gotchi gotchi = await moduleBase.Db.GetGotchiAsync(creator);

            if (await moduleBase.ReplyValidateGotchiAsync(gotchi))
            {
                return(gotchi);
            }

            return(null);
        }
예제 #6
0
        public async Task Release()
        {
            Gotchi gotchi = await Db.GetGotchiAsync(Context.User.ToCreator());

            if (gotchi.IsValid())
            {
                await ReleaseGotchiAsync(gotchi);
            }
            else
            {
                await ReplyErrorAsync("You do not have a gotchi to release.");
            }
        }
예제 #7
0
        public async Task Release(string name)
        {
            // Find the Gotchi with the given name.

            Gotchi gotchi = await Db.GetGotchiAsync(Context.User.Id, name);

            if (gotchi.IsValid())
            {
                await ReleaseGotchiAsync(gotchi);
            }
            else
            {
                await ReplyErrorAsync(string.Format("No Gotchi with the name \"{0}\" exists.", name));
            }
        }
예제 #8
0
        public async Task Stats()
        {
            // Get this user's gotchi.

            Gotchi gotchi = await Db.GetGotchiAsync(Context.User.ToCreator());

            if (await this.ReplyValidateGotchiAsync(gotchi))
            {
                ISpecies sp = await Db.GetSpeciesAsync(gotchi.SpeciesId);

                if (sp.IsValid())
                {
                    // Calculate stats for this gotchi.
                    // If the user is currently in battle, show their battle stats instead.

                    GotchiStats stats;

                    GotchiBattleState battle_state = GotchiBattleState.GetBattleStateByUserId(Context.User.Id);

                    if (!(battle_state is null))
                    {
                        stats = battle_state.GetGotchiStats(gotchi);
                    }
                    else
                    {
                        stats = await new GotchiStatsCalculator(Db, Global.GotchiContext).GetStatsAsync(gotchi);
                    }

                    // Create the embed.

                    EmbedBuilder stats_page = new EmbedBuilder();

                    stats_page.WithTitle(string.Format("{0}'s {2}, **Level {1}** (Age {3})", Context.User.Username, stats.Level, TaxonFormatter.GetString(sp, false), gotchi.Age));
                    stats_page.WithThumbnailUrl(sp.GetPictureUrl());
                    stats_page.WithFooter(string.Format("{0} experience points until next level", stats.ExperienceToNextLevel));

                    stats_page.AddField("❤ Hit points", stats.Hp, inline: true);
                    stats_page.AddField("💥 Attack", stats.Atk, inline: true);
                    stats_page.AddField("🛡 Defense", stats.Def, inline: true);
                    stats_page.AddField("💨 Speed", stats.Spd, inline: true);

                    await ReplyAsync(embed : stats_page.Build());
                }
            }
예제 #9
0
 public static bool IsValid(this Gotchi gotchi)
 {
     return(gotchi != null);
 }
 public static async Task SetViewedTimestampAsync(this SQLiteDatabase database, Gotchi gotchi, long viewedTimestamp)
 {
     await database.SetViewedTimestampAsync(gotchi.Id, viewedTimestamp);
 }
        public static async Task <string> CreateGotchiGifAsync(this SQLiteDatabase database, Gotchi gotchi)
        {
            GotchiGifCreatorParams p = new GotchiGifCreatorParams {
                gotchi = gotchi,
                auto   = true
            };

            return(await database.CreateGotchiGifAsync(new GotchiGifCreatorParams[] { p },
                                                       new GotchiGifCreatorExtraParams { backgroundFileName = await database.GetGotchiBackgroundFilenameAsync(gotchi) }));
        }
        public static async Task <bool> EvolveAndUpdateGotchiAsync(this SQLiteDatabase database, Gotchi gotchi, string desiredEvo)
        {
            bool evolved = false;

            if (string.IsNullOrEmpty(desiredEvo))
            {
                // Find all descendatants of this species.

                using (SQLiteCommand cmd = new SQLiteCommand("SELECT species_id FROM Ancestors WHERE ancestor_id=$ancestor_id;")) {
                    List <long> descendant_ids = new List <long>();

                    cmd.Parameters.AddWithValue("$ancestor_id", gotchi.SpeciesId);

                    foreach (DataRow row in await database.GetRowsAsync(cmd))
                    {
                        descendant_ids.Add(row.Field <long>("species_id"));
                    }

                    // Pick an ID at random.

                    if (descendant_ids.Count > 0)
                    {
                        gotchi.SpeciesId = descendant_ids[NumberUtilities.GetRandomInteger(descendant_ids.Count)];

                        evolved = true;
                    }
                }
            }
            else
            {
                // Get the desired evo.
                IEnumerable <ISpecies> sp = await database.GetSpeciesAsync(desiredEvo);

                if (sp is null || sp.Count() != 1)
                {
                    return(false);
                }

                // Ensure that the species evolves into the desired evo.

                using (SQLiteCommand cmd = new SQLiteCommand("SELECT COUNT(*) FROM Ancestors WHERE ancestor_id = $ancestor_id AND species_id = $species_id")) {
                    cmd.Parameters.AddWithValue("$ancestor_id", gotchi.SpeciesId);
                    cmd.Parameters.AddWithValue("$species_id", sp.First().Id);

                    if (await database.GetScalarAsync <long>(cmd) <= 0)
                    {
                        return(false);
                    }

                    gotchi.SpeciesId = (long)sp.First().Id;

                    evolved = true;
                }
            }

            // Update the gotchi in the database.

            if (evolved)
            {
                using (SQLiteCommand cmd = new SQLiteCommand("UPDATE Gotchi SET species_id=$species_id, evolved_ts=$evolved_ts WHERE id=$id;")) {
                    cmd.Parameters.AddWithValue("$species_id", gotchi.SpeciesId);

                    // The "last evolved" timestamp is now only updated in the event the gotchi evolves (in order to make the "IsEvolved" check work correctly).
                    // Note that this means that the background service will attempt to evolve the gotchi at every iteration (unless it evolves by leveling).

                    cmd.Parameters.AddWithValue("$evolved_ts", DateTimeOffset.UtcNow.ToUnixTimeSeconds());

                    cmd.Parameters.AddWithValue("$id", gotchi.Id);

                    await database.ExecuteNonQueryAsync(cmd);
                }
            }

            return(evolved);
        }
 public static async Task <bool> EvolveAndUpdateGotchiAsync(this SQLiteDatabase database, Gotchi gotchi)
 {
     return(await database.EvolveAndUpdateGotchiAsync(gotchi, string.Empty));
 }
예제 #14
0
        public async Task Gotchi()
        {
            // Get this user's primary Gotchi.

            Gotchi gotchi = await Db.GetGotchiAsync(Context.User.ToCreator());

            if (!await this.ReplyValidateGotchiAsync(gotchi))
            {
                return;
            }

            // Create the gotchi GIF.

            string gifUrl = await this.ReplyUploadGotchiGifAsync(gotchi);

            if (string.IsNullOrEmpty(gifUrl))
            {
                return;
            }

            // Get the gotchi's species.

            ISpecies species = await Db.GetSpeciesAsync(gotchi.SpeciesId);

            // Pick status text.

            string status = "{0} is feeling happy!";

            switch (gotchi.State)
            {
            case GotchiState.Dead:
                status = "Oh no... {0} has died...";
                break;

            case GotchiState.Evolved:
                status = "Congratulations, {0} " + string.Format("evolved into {0}!", species.GetShortName());
                break;

            case GotchiState.Sleeping:
                long hours_left = gotchi.HoursOfSleepLeft();
                status = "{0} is taking a nap. " + string.Format("Check back in {0} hour{1}.", hours_left, hours_left > 1 ? "s" : string.Empty);
                break;

            case GotchiState.Hungry:
                status = "{0} is feeling hungry!";
                break;

            case GotchiState.Eating:
                status = "{0} is enjoying some delicious Suka-Flakes™!";
                break;

            case GotchiState.Energetic:
                status = "{0} is feeling rowdy!";
                break;

            case GotchiState.Tired:
                status = "{0} is getting a bit sleepy...";
                break;
            }

            // Update the viewed timestamp.

            await Db.SetViewedTimestampAsync(gotchi, DateUtilities.GetCurrentTimestampUtc());

            // Send the message.

            EmbedBuilder embed = new EmbedBuilder();

            embed.WithTitle(string.Format("{0}'s \"{1}\"", Context.User.Username, gotchi.Name.ToTitle()));
            embed.WithDescription(string.Format("{0}, age {1}", species.GetShortName(), gotchi.Age));
            embed.WithImageUrl(gifUrl);
            embed.WithFooter(string.Format(status, StringUtilities.ToTitleCase(gotchi.Name)));

            await ReplyAsync(embed : embed.Build());
        }
예제 #15
0
        public static async Task <string> ReplyUploadGotchiGifAsync(this OfcModuleBase moduleBase, Gotchi gotchi)
        {
            string filePath = await moduleBase.Db.CreateGotchiGifAsync(gotchi);

            string uploadUrl = string.Empty;

            if (!string.IsNullOrEmpty(filePath))
            {
                uploadUrl = await moduleBase.ReplyUploadFileToScratchChannelAsync(filePath);
            }

            if (string.IsNullOrEmpty(filePath))
            {
                await moduleBase.ReplyErrorAsync("The gotchi image could not be created.");
            }
            else if (string.IsNullOrEmpty(uploadUrl))
            {
                await moduleBase.ReplyErrorAsync("The gotchi image could not be uploaded.");
            }

            return(uploadUrl);
        }
예제 #16
0
        public static async Task <bool> ReplyValidateGotchiAsync(this OfcModuleBase moduleBase, Gotchi gotchi)
        {
            if (!gotchi.IsValid())
            {
                await moduleBase.ReplyInfoAsync("You don't have a gotchi yet! Get one with `gotchi get <species>`.");

                return(false);
            }

            return(true);
        }