From 2ecec9d0a4830cecfa6ab95191b24070a9260a96 Mon Sep 17 00:00:00 2001 From: Kwoth Date: Thu, 12 Jan 2017 20:19:56 +0100 Subject: [PATCH] Now modifyable: Trivia flower win amount (default 0), minimum bet amount (default 3), betflip multiplier (default 1.8), currency drop amount (default 1), betroll multipliers on 67+/91+/100+ (default 2/3/10) --- .../NadekoSqliteContextModelSnapshot.cs | 42 +++++++++++++++++++ .../Gambling/Commands/FlipCoinCommand.cs | 6 +-- src/NadekoBot/Modules/Gambling/Gambling.cs | 6 +-- .../Games/Commands/PlantAndPickCommands.cs | 38 ++++++++++++----- .../Games/Commands/Trivia/TriviaGame.cs | 6 ++- .../Services/Database/Models/BotConfig.cs | 14 ++++++- .../Services/Database/NadekoContext.cs | 7 ++-- 7 files changed, 97 insertions(+), 22 deletions(-) diff --git a/src/NadekoBot/Migrations/NadekoSqliteContextModelSnapshot.cs b/src/NadekoBot/Migrations/NadekoSqliteContextModelSnapshot.cs index 190e425e..4d94b193 100644 --- a/src/NadekoBot/Migrations/NadekoSqliteContextModelSnapshot.cs +++ b/src/NadekoBot/Migrations/NadekoSqliteContextModelSnapshot.cs @@ -96,8 +96,18 @@ namespace NadekoBot.Migrations b.Property("Id") .ValueGeneratedOnAdd(); + b.Property("BetflipMultiplier"); + + b.Property("Betroll100Multiplier"); + + b.Property("Betroll67Multiplier"); + + b.Property("Betroll91Multiplier"); + b.Property("BufferSize"); + b.Property("CurrencyDropAmount"); + b.Property("CurrencyGenerationChance"); b.Property("CurrencyGenerationCooldown"); @@ -118,10 +128,14 @@ namespace NadekoBot.Migrations b.Property("MigrationVersion"); + b.Property("MinimumBetAmount"); + b.Property("RemindMessageFormat"); b.Property("RotatingStatuses"); + b.Property("TriviaCurrencyReward"); + b.HasKey("Id"); b.ToTable("BotConfig"); @@ -191,6 +205,27 @@ namespace NadekoBot.Migrations b.ToTable("CommandCooldown"); }); + modelBuilder.Entity("NadekoBot.Services.Database.Models.CommandPrice", b => + { + b.Property("Id") + .ValueGeneratedOnAdd(); + + b.Property("BotConfigId"); + + b.Property("CommandName"); + + b.Property("Price"); + + b.HasKey("Id"); + + b.HasIndex("BotConfigId"); + + b.HasIndex("Price") + .IsUnique(); + + b.ToTable("CommandPrice"); + }); + modelBuilder.Entity("NadekoBot.Services.Database.Models.ConvertUnit", b => { b.Property("Id") @@ -823,6 +858,13 @@ namespace NadekoBot.Migrations .HasForeignKey("GuildConfigId"); }); + modelBuilder.Entity("NadekoBot.Services.Database.Models.CommandPrice", b => + { + b.HasOne("NadekoBot.Services.Database.Models.BotConfig") + .WithMany("CommandPrices") + .HasForeignKey("BotConfigId"); + }); + modelBuilder.Entity("NadekoBot.Services.Database.Models.EightBallResponse", b => { b.HasOne("NadekoBot.Services.Database.Models.BotConfig") diff --git a/src/NadekoBot/Modules/Gambling/Commands/FlipCoinCommand.cs b/src/NadekoBot/Modules/Gambling/Commands/FlipCoinCommand.cs index 7190eb58..6cb49f71 100644 --- a/src/NadekoBot/Modules/Gambling/Commands/FlipCoinCommand.cs +++ b/src/NadekoBot/Modules/Gambling/Commands/FlipCoinCommand.cs @@ -53,9 +53,9 @@ namespace NadekoBot.Modules.Gambling if (guessStr != "H" && guessStr != "T" && guessStr != "HEADS" && guessStr != "TAILS") return; - if (amount < 3) + if (amount < NadekoBot.BotConfig.MinimumBetAmount) { - await Context.Channel.SendErrorAsync($"You can't bet less than 3{CurrencySign}.") + await Context.Channel.SendErrorAsync($"You can't bet less than {NadekoBot.BotConfig.MinimumBetAmount}{CurrencySign}.") .ConfigureAwait(false); return; } @@ -84,7 +84,7 @@ namespace NadekoBot.Modules.Gambling string str; if (isHeads == result) { - var toWin = (int)Math.Round(amount * 1.8); + var toWin = (int)Math.Round(amount * NadekoBot.BotConfig.BetflipMultiplier); str = $"{Context.User.Mention}`You guessed it!` You won {toWin}{CurrencySign}"; await CurrencyHandler.AddCurrencyAsync(Context.User, "Betflip Gamble", toWin, false).ConfigureAwait(false); } diff --git a/src/NadekoBot/Modules/Gambling/Gambling.cs b/src/NadekoBot/Modules/Gambling/Gambling.cs index 3eaef165..76dbaa06 100644 --- a/src/NadekoBot/Modules/Gambling/Gambling.cs +++ b/src/NadekoBot/Modules/Gambling/Gambling.cs @@ -173,17 +173,17 @@ namespace NadekoBot.Modules.Gambling } else if (rng < 91) { - str += $"Congratulations! You won {amount * 2}{CurrencySign} for rolling above 66"; + str += $"Congratulations! You won {amount * NadekoBot.BotConfig.Betroll67Multiplier}{CurrencySign} for rolling above 66"; await CurrencyHandler.AddCurrencyAsync(Context.User, "Betroll Gamble", amount * 2, false).ConfigureAwait(false); } else if (rng < 100) { - str += $"Congratulations! You won {amount * 3}{CurrencySign} for rolling above 90."; + str += $"Congratulations! You won {amount * NadekoBot.BotConfig.Betroll91Multiplier}{CurrencySign} for rolling above 90."; await CurrencyHandler.AddCurrencyAsync(Context.User, "Betroll Gamble", amount * 3, false).ConfigureAwait(false); } else { - str += $"👑 Congratulations! You won {amount * 10}{CurrencySign} for rolling **100**. 👑"; + str += $"👑 Congratulations! You won {amount * NadekoBot.BotConfig.Betroll100Multiplier}{CurrencySign} for rolling **100**. 👑"; await CurrencyHandler.AddCurrencyAsync(Context.User, "Betroll Gamble", amount * 10, false).ConfigureAwait(false); } diff --git a/src/NadekoBot/Modules/Games/Commands/PlantAndPickCommands.cs b/src/NadekoBot/Modules/Games/Commands/PlantAndPickCommands.cs index e3694b24..5f33df5b 100644 --- a/src/NadekoBot/Modules/Games/Commands/PlantAndPickCommands.cs +++ b/src/NadekoBot/Modules/Games/Commands/PlantAndPickCommands.cs @@ -78,14 +78,32 @@ namespace NadekoBot.Modules.Games { lastGenerations.AddOrUpdate(channel.Id, DateTime.Now, (id, old) => DateTime.Now); - var sent = await channel.SendFileAsync( - File.Open(GetRandomCurrencyImagePath(), FileMode.OpenOrCreate), - "RandomFlower.jpg", - $"❗ A random { NadekoBot.BotConfig.CurrencyName } appeared! Pick it up by typing `{NadekoBot.ModulePrefixes[typeof(Games).Name]}pick`") - .ConfigureAwait(false); - plantedFlowers.AddOrUpdate(channel.Id, new List() { sent }, (id, old) => { old.Add(sent); return old; }); + var dropAmount = NadekoBot.BotConfig.CurrencyDropAmount; + if (dropAmount > 0) + { + var msgs = new List(dropAmount); + string firstPart; + if (dropAmount == 1) + { + firstPart = $"A random { NadekoBot.BotConfig.CurrencyName } appeared!"; + } + else + { + firstPart = $"{dropAmount} random { NadekoBot.BotConfig.CurrencyPluralName } appeared!"; + } + + var sent = await channel.SendFileAsync( + File.Open(GetRandomCurrencyImagePath(), FileMode.OpenOrCreate), + "RandomFlower.jpg", + $"❗ {firstPart} Pick it up by typing `{NadekoBot.ModulePrefixes[typeof(Games).Name]}pick`") + .ConfigureAwait(false); + + msgs.Add(sent); + + plantedFlowers.AddOrUpdate(channel.Id, msgs, (id, old) => { old.AddRange(msgs); return old; }); + } } } catch { } @@ -108,11 +126,11 @@ namespace NadekoBot.Modules.Games List msgs; - try { await Context.Message.DeleteAsync().ConfigureAwait(false); } catch { } - if (!plantedFlowers.TryRemove(channel.Id, out msgs)) - return; + try { await Context.Message.DeleteAsync().ConfigureAwait(false); } catch { } + if (!plantedFlowers.TryRemove(channel.Id, out msgs)) + return; - await Task.WhenAll(msgs.Select(toDelete => toDelete.DeleteAsync())).ConfigureAwait(false); + await Task.WhenAll(msgs.Where(m => m != null).Select(toDelete => toDelete.DeleteAsync())).ConfigureAwait(false); await CurrencyHandler.AddCurrencyAsync((IGuildUser)Context.User, $"Picked {NadekoBot.BotConfig.CurrencyPluralName}", msgs.Count, false).ConfigureAwait(false); var msg = await channel.SendConfirmAsync($"**{Context.User}** picked {msgs.Count}{NadekoBot.BotConfig.CurrencySign}!").ConfigureAwait(false); diff --git a/src/NadekoBot/Modules/Games/Commands/Trivia/TriviaGame.cs b/src/NadekoBot/Modules/Games/Commands/Trivia/TriviaGame.cs index 2c989738..9bc27191 100644 --- a/src/NadekoBot/Modules/Games/Commands/Trivia/TriviaGame.cs +++ b/src/NadekoBot/Modules/Games/Commands/Trivia/TriviaGame.cs @@ -2,6 +2,7 @@ using Discord.Net; using Discord.WebSocket; using NadekoBot.Extensions; +using NadekoBot.Services; using NLog; using System; using System.Collections.Concurrent; @@ -177,7 +178,10 @@ namespace NadekoBot.Modules.Games.Trivia if (Users[guildUser] == WinRequirement) { ShouldStopGame = true; - await channel.SendConfirmAsync("Trivia Game", $"{guildUser.Mention} guessed it and WON the game! The answer was: **{CurrentQuestion.Answer}**").ConfigureAwait(false); + try { await channel.SendConfirmAsync("Trivia Game", $"{guildUser.Mention} guessed it and WON the game! The answer was: **{CurrentQuestion.Answer}**").ConfigureAwait(false); } catch { } + var reward = NadekoBot.BotConfig.TriviaCurrencyReward; + if (reward > 0) + await CurrencyHandler.AddCurrencyAsync(guildUser.Id, "Won trivia", reward).ConfigureAwait(false); return; } await channel.SendConfirmAsync("Trivia Game", $"{guildUser.Mention} guessed it! The answer was: **{CurrentQuestion.Answer}**").ConfigureAwait(false); diff --git a/src/NadekoBot/Services/Database/Models/BotConfig.cs b/src/NadekoBot/Services/Database/Models/BotConfig.cs index b20263c8..38faf9ba 100644 --- a/src/NadekoBot/Services/Database/Models/BotConfig.cs +++ b/src/NadekoBot/Services/Database/Models/BotConfig.cs @@ -18,12 +18,22 @@ namespace NadekoBot.Services.Database.Models public bool RotatingStatuses { get; set; } = false; public string RemindMessageFormat { get; set; } = "❗⏰**I've been told to remind you to '%message%' now by %user%.**⏰❗"; - - + + //currency public string CurrencySign { get; set; } = "🌸"; public string CurrencyName { get; set; } = "Nadeko Flower"; public string CurrencyPluralName { get; set; } = "Nadeko Flowers"; + public int TriviaCurrencyReward { get; set; } = 0; + public int MinimumBetAmount { get; set; } = 3; + public float BetflipMultiplier { get; set; } = 1.8f; + public int CurrencyDropAmount { get; set; } = 1; + public float Betroll67Multiplier { get; set; } = 2; + public float Betroll91Multiplier { get; set; } = 3; + public float Betroll100Multiplier { get; set; } = 10; + public HashSet CommandPrices { get; set; } = new HashSet(); + + public HashSet EightBallResponses { get; set; } = new HashSet(); public HashSet RaceAnimals { get; set; } = new HashSet(); diff --git a/src/NadekoBot/Services/Database/NadekoContext.cs b/src/NadekoBot/Services/Database/NadekoContext.cs index e955409f..c2696b93 100644 --- a/src/NadekoBot/Services/Database/NadekoContext.cs +++ b/src/NadekoBot/Services/Database/NadekoContext.cs @@ -234,9 +234,10 @@ namespace NadekoBot.Services.Database #endregion - #region Protection - - + #region CommandPrice + modelBuilder.Entity() + .HasIndex(cp => cp.Price) + .IsUnique(); #endregion } }