Example #1
0
        public async Task SpinNewWheelAsync(CommandContext ctx)
        {
            DiscordContext context = new DiscordContext();
            Users          user    = await context.Users.FindAsync(Convert.ToInt64(ctx.Message.Author.Id));

            UserSettings userSettings = await context.UserSettings.FindAsync(Convert.ToInt64(ctx.Message.Author.Id));

            SabrinaSettings sabrinaSettings = await context.SabrinaSettings.FindAsync(Convert.ToInt64(ctx.Guild.Id));

            if (sabrinaSettings == null)
            {
                sabrinaSettings = new SabrinaSettings
                {
                    GuildId      = Convert.ToInt64(ctx.Guild.Id),
                    WheelChannel = Convert.ToInt64(ctx.Channel.Id)
                };

                await context.SabrinaSettings.AddAsync(sabrinaSettings);

                await context.SaveChangesAsync();
            }

            if (sabrinaSettings.WheelChannel == null)
            {
                sabrinaSettings.WheelChannel = Convert.ToInt64(ctx.Channel.Id);
                await context.SaveChangesAsync();
            }

            if (Convert.ToInt64(ctx.Channel.Id) != sabrinaSettings.WheelChannel.Value)
            {
                DiscordChannel channel =
                    await ctx.Client.GetChannelAsync(Convert.ToUInt64(sabrinaSettings.WheelChannel));

                await ctx.RespondAsync(
                    $"You cannot issue this command from this Channel. Please use {channel.Mention}");

                return;
            }

            if (user == null)
            {
                user = new Users();
            }

            if (userSettings == null)
            {
                userSettings = new UserSettings();
            }

            WheelChances chances = await context.WheelChances.FindAsync(userSettings.WheelDifficulty ?? 2);

            if (user.LockTime != null && user.LockTime > DateTime.Now)
            {
                TimeSpan?timeUntilFree = user.LockTime - DateTime.Now;

                TimeSpan newTimeUntilFree =
                    TimeSpan.FromTicks(timeUntilFree.Value.Ticks * Helpers.RandomGenerator.RandomInt(1, 4));

                if (newTimeUntilFree > TimeSpan.FromDays(365))
                {
                    await ctx.RespondAsync("F**k off");

                    return;
                }

                if (Helpers.RandomGenerator.RandomInt(0, 4) > 0)
                {
                    await ctx.RespondAsync(
                        "Oho, it seems like I told you to stay away from spinning the wheel...\n" +
                        $"That means you get some more extra time of no spinning {DiscordEmoji.FromName(ctx.Client, Config.Emojis.Blush)}");

                    user.LockTime += newTimeUntilFree;
                    await context.SaveChangesAsync();

                    return;
                }

                await ctx.RespondAsync(
                    "I believe i have told you not to spin the wheel.\n" +
                    $"But since i'm awesome, you won't get punishment for it... Today. {DiscordEmoji.FromName(ctx.Client, Config.Emojis.Blush)}");
            }

            var addedChance = 0;

            var outcomeChanceValue = Helpers.RandomGenerator.RandomInt(
                0,
                chances.Denial + chances.Task + chances.Ruin + chances.O****m);

            Console.WriteLine("Chance Rolled: " + outcomeChanceValue);
            Console.WriteLine("Denial Chance: " + chances.Denial);
            Console.WriteLine("TaskChance Chance: " + chances.Task);
            Console.WriteLine("RuinChance Chance: " + chances.Ruin);
            Console.WriteLine("OrgasmChance Chance: " + chances.O****m);
            Console.WriteLine("addedChance Chance: " + addedChance);
            SlaveReportsExtension.Outcome outcome = SlaveReportsExtension.Outcome.Task;
            if (outcomeChanceValue < chances.Denial)
            {
                outcome = SlaveReportsExtension.Outcome.Denial;
            }
            else if (outcomeChanceValue < chances.Denial + chances.Task)
            {
                outcome = SlaveReportsExtension.Outcome.Task;
            }
            else if (outcomeChanceValue < chances.Denial + chances.Task + chances.Ruin)
            {
                outcome = SlaveReportsExtension.Outcome.Ruin;
            }
            else
            {
                outcome = SlaveReportsExtension.Outcome.O****m;
            }

            if (user.DenialTime != null && user.DenialTime > DateTime.Now)
            {
                TimeSpan?timeUntilFree = user.DenialTime - DateTime.Now;
                if (outcome.HasFlag(SlaveReportsExtension.Outcome.O****m) ||
                    outcome.HasFlag(SlaveReportsExtension.Outcome.Ruin))
                {
                    await ctx.RespondAsync(
                        "Haha, I would\'ve let you cum this time, but since you\'re still denied, "
                        + $"that won't happen {DiscordEmoji.FromName(ctx.Client, Config.Emojis.Blush)}.\n" +
                        "As a punishment, you\'re gonna do your Task anyways though.");
                }
                else
                {
                    await ctx.RespondAsync(
                        "Well, i told you, that you\'d be denied now.\n"
                        + "You still want to do something? Then here you go."
                        + $"\nAnd as a bonus, if i decide so, you'll get even more denial! {DiscordEmoji.FromName(ctx.Client, Config.Emojis.Blush)}");
                }

                await Task.Delay(1500);

                outcome = SlaveReportsExtension.Outcome.Denial | SlaveReportsExtension.Outcome.Task;
            }

            WheelOutcome wheelOutcome = null;

            while (wheelOutcome == null)
            {
                wheelOutcomes = ReflectiveEnumerator.GetEnumerableOfType <WheelOutcome>(outcome, userSettings, context)
                                .ToList();

                wheelOutcomes = wheelOutcomes.Where(e => outcome.HasFlag(e.Outcome)).ToList();

                if (wheelOutcomes.Count < 1)
                {
                    continue;
                }

                // Choose an outcome by summing up the chance values of all possible outcomes and then generating a random number inside those.
                var combinedChance = 0;

                foreach (WheelOutcome currentOutcome in wheelOutcomes)
                {
                    combinedChance += currentOutcome.Chance;
                }

                var chance    = 0;
                var minChance = Helpers.RandomGenerator.RandomInt(0, combinedChance);

                foreach (WheelOutcome currentOutcome in wheelOutcomes)
                {
                    chance += currentOutcome.Chance;
                    if (minChance < chance)
                    {
                        wheelOutcome = currentOutcome;
                        break;
                    }
                }
            }

            if (user.DenialTime == null)
            {
                user.DenialTime = DateTime.Now;
            }

            if (user.LockTime == null)
            {
                user.LockTime = DateTime.Now;
            }

            if (user.DenialTime < DateTime.Now)
            {
                user.DenialTime = DateTime.Now;
            }

            if (user.LockTime < DateTime.Now)
            {
                user.LockTime = DateTime.Now;
            }

            user.DenialTime += wheelOutcome.DenialTime;
            user.LockTime   += wheelOutcome.WheelLockedTime;
            await context.SaveChangesAsync();

            if (wheelOutcome.Embed != null)
            {
                await ctx.RespondAsync(embed : wheelOutcome.Embed);
            }
            else
            {
                await ctx.RespondAsync(wheelOutcome.Text);
            }
        }