示例#1
0
        public async Task GuildWeeklyAsync(CommandContext e)
        {
            var database = e.GetService <MikiDbContext>();

            LocalExperience thisUser = await database.LocalExperience.FindAsync(e.Guild.Id.ToDbLong(), e.Author.Id.ToDbLong());

            GuildUser thisGuild = await database.GuildUsers.FindAsync(e.Guild.Id.ToDbLong());

            Timer timer = await database.Timers.FindAsync(e.Guild.Id.ToDbLong(), e.Author.Id.ToDbLong());

            if (thisUser == null)
            {
                throw new UserNullException();
            }

            if (thisGuild == null)
            {
                return;
            }

            if (thisUser.Experience >= thisGuild.MinimalExperienceToGetRewards)
            {
                if (timer == null)
                {
                    timer = (await database.Timers.AddAsync(new Timer()
                    {
                        GuildId = e.Guild.Id.ToDbLong(),
                        UserId = e.Author.Id.ToDbLong(),
                        Value = DateTime.Now.AddDays(-30)
                    })).Entity;
                    await database.SaveChangesAsync();
                }

                if (timer.Value.AddDays(7) <= DateTime.Now)
                {
                    GuildUser rival = await thisGuild.GetRivalOrDefaultAsync(database);

                    if (rival == null)
                    {
                        throw new RivalNullException();
                    }

                    if (rival.Experience > thisGuild.Experience)
                    {
                        await new EmbedBuilder()
                        .SetTitle(e.Locale.GetString("miki_terms_weekly"))
                        .SetDescription(e.Locale.GetString("guildweekly_error_low_level"))
                        .ToEmbed().QueueToChannelAsync(e.Channel);
                        return;
                    }

                    int mekosGained = (int)Math.Round((((MikiRandom.NextDouble() + thisGuild.GuildHouseMultiplier) * 0.5) * 10) * thisGuild.CalculateLevel(thisGuild.Experience));

                    User user = await database.Users.FindAsync(e.Author.Id.ToDbLong());

                    if (user == null)
                    {
                        throw new UserNullException();
                    }

                    await user.AddCurrencyAsync(mekosGained, e.Channel);

                    await new EmbedBuilder()
                    .SetTitle(e.Locale.GetString("miki_terms_weekly"))
                    .AddInlineField("Mekos", mekosGained.ToFormattedString())
                    .ToEmbed().QueueToChannelAsync(e.Channel);

                    timer.Value = DateTime.Now;
                    await database.SaveChangesAsync();
                }
                else
                {
                    await new EmbedBuilder()
                    .SetTitle(e.Locale.GetString("miki_terms_weekly"))
                    .SetDescription(e.Locale.GetString("guildweekly_error_timer_running", (timer.Value.AddDays(7) - DateTime.Now).ToTimeString(e.Locale)))
                    .ToEmbed().QueueToChannelAsync(e.Channel);
                }
            }
            else
            {
                await new EmbedBuilder()
                .SetTitle(e.Locale.GetString("miki_terms_weekly"))
                .SetDescription(e.Locale.GetString("miki_guildweekly_insufficient_exp", thisGuild.MinimalExperienceToGetRewards.ToFormattedString()))
                .ToEmbed().QueueToChannelAsync(e.Channel);
            }
        }
示例#2
0
        public async Task GuildWeekly(EventContext context)
        {
            using (MikiContext database = new MikiContext())
            {
                Locale          locale   = Locale.GetEntity(context.Channel.Id);
                LocalExperience thisUser = await database.LocalExperience.FindAsync(context.Guild.Id.ToDbLong(), context.Author.Id.ToDbLong());

                GuildUser thisGuild = await database.GuildUsers.FindAsync(context.Guild.Id.ToDbLong());

                Timer timer = await database.Timers.FindAsync(context.Guild.Id.ToDbLong(), context.Author.Id.ToDbLong());

                if (thisUser == null)
                {
                    Log.ErrorAt("Guildweekly", "User is null");
                    return;
                }

                if (thisGuild == null)
                {
                    Log.ErrorAt("Guildweekly", "Guild is null");
                    return;
                }

                if (thisUser.Experience >= thisGuild.MinimalExperienceToGetRewards)
                {
                    if (timer == null)
                    {
                        timer = (await database.Timers.AddAsync(new Timer()
                        {
                            GuildId = context.Guild.Id.ToDbLong(),
                            UserId = context.Author.Id.ToDbLong(),
                            Value = DateTime.Now.AddDays(-30)
                        })).Entity;
                        await database.SaveChangesAsync();
                    }

                    if (timer.Value.AddDays(7) <= DateTime.Now)
                    {
                        SocketGuild guild = Bot.instance.Client.GetGuild(thisGuild.Id.FromDbLong());

                        GuildUser rival = await thisGuild.GetRival();

                        if (rival == null)
                        {
                            await Utils.Embed
                            .SetTitle(locale.GetString("miki_terms_weekly"))
                            .SetDescription(context.GetResource("guildweekly_error_no_rival"))
                            .QueueToChannel(context.Channel);

                            return;
                        }

                        if (rival.Experience > thisGuild.Experience)
                        {
                            await Utils.Embed
                            .SetTitle(locale.GetString("miki_terms_weekly"))
                            .SetDescription(context.GetResource("guildweekly_error_low_level"))
                            .QueueToChannel(context.Channel);

                            return;
                        }

                        int mekosGained = (int)Math.Round((((MikiRandom.NextDouble() + 1.25) * 0.5) * 10) * thisGuild.CalculateLevel(thisGuild.Experience));

                        User user = await database.Users.FindAsync(context.Author.Id.ToDbLong());

                        if (user == null)
                        {
                            // TODO: Add response
                            return;
                        }

                        await user.AddCurrencyAsync(mekosGained, context.Channel);

                        await Utils.Embed
                        .SetTitle(locale.GetString("miki_terms_weekly"))
                        .AddInlineField("Mekos", mekosGained.ToString())
                        .QueueToChannel(context.Channel);

                        timer.Value = DateTime.Now;
                        await database.SaveChangesAsync();
                    }
                    else
                    {
                        await Utils.Embed
                        .SetTitle(locale.GetString("miki_terms_weekly"))
                        .SetDescription(context.GetResource("guildweekly_error_timer_running", (timer.Value.AddDays(7) - DateTime.Now).ToTimeString(locale)))
                        .QueueToChannel(context.Channel);
                    }
                }
                else
                {
                    await Utils.Embed
                    .SetTitle(locale.GetString("miki_terms_weekly"))
                    .SetDescription(locale.GetString("miki_guildweekly_insufficient_exp", thisGuild.MinimalExperienceToGetRewards))
                    .QueueToChannel(context.Channel);
                }
            }
        }
示例#3
0
 private int CalculateWeeklyClaimAmount(float multiplier, int guildLevel)
 => (int)Math.Round(
     (MikiRandom.NextDouble() + multiplier)
     * 0.5 * 10 * guildLevel);