From 2b8312c0c636484d69dace22a23e8af9876830e4 Mon Sep 17 00:00:00 2001 From: Lan <50151341+Lannnnnnnnn@users.noreply.github.com> Date: Sun, 8 Nov 2020 19:38:40 +0200 Subject: [PATCH] I have no idea what I changed It has been too long, the things just piled up --- Kehyeedra3/ApplicationDbContext.cs | 1 + Kehyeedra3/Bot.cs | 9 +- Kehyeedra3/Commands/Interactive.cs | 327 +++++++++++------- .../20200531192223_boofboof.Designer.cs | 239 +++++++++++++ .../Migrations/20200531192223_boofboof.cs | 17 + .../20200531193428_oofboof.Designer.cs | 230 ++++++++++++ .../Migrations/20200531193428_oofboof.cs | 75 ++++ .../20200531204543_oofoof.Designer.cs | 233 +++++++++++++ .../Migrations/20200531204543_oofoof.cs | 37 ++ .../ApplicationDbContextModelSnapshot.cs | 20 +- Kehyeedra3/Services/Models/User.cs | 37 +- Kehyeedra3/Services/ReminderService.cs | 105 +++--- 12 files changed, 1135 insertions(+), 195 deletions(-) create mode 100644 Kehyeedra3/Migrations/20200531192223_boofboof.Designer.cs create mode 100644 Kehyeedra3/Migrations/20200531192223_boofboof.cs create mode 100644 Kehyeedra3/Migrations/20200531193428_oofboof.Designer.cs create mode 100644 Kehyeedra3/Migrations/20200531193428_oofboof.cs create mode 100644 Kehyeedra3/Migrations/20200531204543_oofoof.Designer.cs create mode 100644 Kehyeedra3/Migrations/20200531204543_oofoof.cs diff --git a/Kehyeedra3/ApplicationDbContext.cs b/Kehyeedra3/ApplicationDbContext.cs index c5bcf8a..6bd17e6 100644 --- a/Kehyeedra3/ApplicationDbContext.cs +++ b/Kehyeedra3/ApplicationDbContext.cs @@ -12,5 +12,6 @@ namespace Kehyeedra3 public DbSet Reminders { get; set; } public DbSet Fishing { get; set; } public DbSet StoreFronts { get; set; } + public DbSet Battlefish { get; set; } } } diff --git a/Kehyeedra3/Bot.cs b/Kehyeedra3/Bot.cs index 92c6e90..e486a23 100644 --- a/Kehyeedra3/Bot.cs +++ b/Kehyeedra3/Bot.cs @@ -18,6 +18,7 @@ namespace Kehyeedra3 public class Bot { /// Star Vars + public static bool IsReady { get; private set; } public static DiscordSocketClient _bot; public static System.Timers.Timer Clockboy; public static AudioService AudioService; @@ -140,6 +141,7 @@ namespace Kehyeedra3 { try { + _bot.Ready += _bot_Ready; await _bot.LoginAsync(TokenType.Bot, Configuration.Load().Token); await _bot.StartAsync(); Clockboy.Start(); @@ -162,7 +164,12 @@ namespace Kehyeedra3 } } - public static void EnsureConfigExists() + private async Task _bot_Ready() + { + IsReady = true; + } + + public static void EnsureConfigExists() { string storage = Environment.CurrentDirectory; if (!Directory.Exists(Path.Combine(storage, "storage"))) diff --git a/Kehyeedra3/Commands/Interactive.cs b/Kehyeedra3/Commands/Interactive.cs index 3f511a6..bf04236 100644 --- a/Kehyeedra3/Commands/Interactive.cs +++ b/Kehyeedra3/Commands/Interactive.cs @@ -3,12 +3,15 @@ using Discord.Addons.Interactive; using Discord.Commands; using Kehyeedra3.Preconditions; using Kehyeedra3.Services.Models; +using Microsoft.EntityFrameworkCore.Internal; using Microsoft.EntityFrameworkCore.Storage; using System; using System.Collections.Generic; +using System.Collections.ObjectModel; using System.IO.Enumeration; using System.IO.IsolatedStorage; using System.Linq; +using System.Security.Cryptography.X509Certificates; using System.Text; using System.Threading.Channels; using System.Threading.Tasks; @@ -23,34 +26,169 @@ namespace Kehyeedra3.Commands "" }; - [RequireRolePrecondition(AccessLevel.BotOwner)] [Command("battlefish", RunMode = RunMode.Async),Alias("bf"),Summary("Type **bf help** or **bf h** for help with this command.")] public async Task BattleFish(string option = null, [Remainder]string sec = null) { using (var Database = new ApplicationDbContextFactory().CreateDbContext()) { var user = Database.Users.FirstOrDefault(x => x.Id == Context.User.Id); - if (user.BattleFish.Any() == false) + var userfish = Database.Battlefish.Where(x => x.UserId == Context.User.Id); + + int attb = 0; + int defb = 0; + int hpb = 0; + int apb = 0; + int dgb = 0; + + if (!userfish.Any() && option == null) { - await Context.Channel.SendMessageAsync($"{Context.User.Mention}\nYou don't have a battlefish."); + await Context.Channel.SendMessageAsync($"{Context.User.Mention}\nYou don't have any battlefish."); return; } + else + { + var fish = userfish.FirstOrDefault(x => x.FishType == user.CurrentBattlefish); + if (fish == null) + { + fish = userfish.FirstOrDefault(); + } + switch (fish.FishType) + { + case Services.Models.BattleFish.Herring: + { + attb = 9; + defb = 9; + hpb = 9; + apb = 3; + dgb = 2; + } + break; + case Services.Models.BattleFish.Birgus: + { + attb = 10; + defb = 6; + hpb = 5; + apb = 9; + dgb = 4; + } + break; + case Services.Models.BattleFish.Abama: + { + attb = 4; + defb = 3; + hpb = 5; + apb = 18; + dgb = 8; + } + break; + case Services.Models.BattleFish.Pistashrimp: + { + attb = 15; + defb = 4; + hpb = 5; + apb = 6; + dgb = 6; + } + break; + } + } + + + string opt = ""; + + BattleFish type = 0; + if (option != null) + { + opt = option.ToLowerInvariant(); + } + + string bfishlist = ""; + + if (opt == "change" || opt == "c") + { + string bfishlistname = ""; + foreach (var fesh in userfish) + { + string prefix = "Hatchling"; + string suffix = ""; - var fish = user.BattleFish.FirstOrDefault(); + if (fesh.Lvl >= 15) + { + prefix = "Young"; + } + if (fesh.Lvl >= 30) + { + prefix = "Adolescent"; + } + if (fesh.Lvl >= 50) + { + prefix = "Adult"; + } - string species = $""; - string attacks = $""; - int att = 0; - int def = 0; - int dg = 0; - int hp = 0; - int ap = 0; + switch ((int)fesh.FishType) + { + case 1: + { + if (fesh.Lvl >= 100) + { + bfishlistname += $"ton"; + suffix = $"Authentic Masculine"; + } + bfishlistname = $"{prefix} Herring{suffix}"; + } + break; + case 2: + { + if (fesh.Lvl >= 100) + { + prefix = $"Great Sage"; + } + bfishlistname = $"{prefix} Birgus"; + } + break; + case 3: + { + if (fesh.Lvl >= 100) + { + prefix = $"President"; + } + bfishlistname = $"{prefix} Abama"; + } + break; + case 4: + { + if (fesh.Lvl >= 100) + { + suffix += $" XTREME"; + prefix = $"Hardboiled"; + } + bfishlistname = $"{prefix} Pistashrimp{suffix}"; + } + break; + } + bfishlist += $"{(byte)fesh.FishType} : LVL {fesh.Lvl} {bfishlistname}\n"; + + } - double lvm = 20; - double lvmhp = 100; + } if (option == null) { + var fish = userfish.FirstOrDefault(x => x.FishType == user.CurrentBattlefish); + if (fish == null) + { + fish = userfish.FirstOrDefault(); + } + + StringBuilder message = new StringBuilder($"{Context.User.Mention}\n"); + + string species = $""; + string attacks = $""; + + double lvm = 20; + double lvmhp = 100; + int lvdf = 5; + for (int i = 0; i < fish.Lvl; i++) { lvm += Math.Round((Convert.ToDouble(lvm) * 0.01d), 0, MidpointRounding.ToEven) + 5; @@ -58,6 +196,13 @@ namespace Kehyeedra3.Commands } int lvlm = Convert.ToInt32(lvm) / 10; int lvlmhp = Convert.ToInt32(lvmhp) / 10; + + int att = lvlm * attb; + int def = lvdf * defb; + int hp = lvlmhp * hpb; + int ap = lvlmhp * apb; + int dg = lvlm * dgb; + string prefix = "Hatchling"; if (fish.Lvl >= 15) @@ -72,7 +217,7 @@ namespace Kehyeedra3.Commands { prefix = "Adult"; } - switch (fish.FishType) + switch ((int)fish.FishType) { case 0: { @@ -106,12 +251,6 @@ namespace Kehyeedra3.Commands attacks += $"\n5 : **Fairy Nightmare** - {species} executes a devastating ultimate attack."; } - att = 9 * lvlm; - def = 9 * lvlm; - hp = 9 * lvlmhp; - ap = 3 * lvlmhp; - - dg = 2 * lvlm; } break; case 2: @@ -141,12 +280,6 @@ namespace Kehyeedra3.Commands attacks += $"\n5 : **Ecletic Rift** - {species} summons portals to alternate dimensions to call forth an army of raving crabs."; } - att = 10 * lvlm; - def = 6 * lvlm; - hp = 5 * lvlmhp; - ap = 9 * lvlmhp; - - dg = 4 * lvlm; } break; case 3: @@ -176,12 +309,6 @@ namespace Kehyeedra3.Commands attacks += $"\n5 : **Ancestral Wrath** - {species} calls into the depths to unleash its true potential."; } - att = 4 * lvlm; - def = 3 * lvlm; - hp = 5 * lvlmhp; - ap = 18 * lvlmhp; - - dg = 8 * lvlm; } break; case 4: @@ -211,20 +338,27 @@ namespace Kehyeedra3.Commands attacks += $"\n5 : **Dual Jet** - {species} vaporizes the surrounding with its machine gun claws."; } - att = 15 * lvlm; - def = 4 * lvlm; - hp = 5 * lvlmhp; - ap = 6 * lvlmhp; - - dg = 6 * lvlm; } break; - } - await Context.Channel.SendMessageAsync($"{Context.User.Mention}'s LVL {fish.Lvl} **{prefix} {species}**\nName: **{fish.Name}**\nStats: **ATK : {att} DEF : {def} HP : {hp} AP : {ap}**\nActions:\n{attacks}"); - + } + message.AppendLine($"LVL {fish.Lvl} **{prefix} {species}**\nName: **{fish.Name}**\nStats: **ATK : {att} DEF : {def}% HP : {hp} AP : {ap}**\nActions:\n{attacks}\n\n"); + + await Context.Channel.SendMessageAsync(message.ToString()); } - else if (option == "name" && sec != null|| option == "n" && sec != null) + else if (option == "name" && sec != null || option == "n" && sec != null) { + var fish = userfish.FirstOrDefault(x => x.FishType == user.CurrentBattlefish); + if (fish == null) + { + fish = userfish.FirstOrDefault(); + } + + if (fish == null) + { + await Context.Channel.SendMessageAsync($"{Context.User.Mention}\nYou can't name a fish you don't own!"); + return; + } + if (sec.Length > 16) { await Context.Channel.SendMessageAsync($"{Context.User.Mention}\nThe maximum name length is 16 characters. \nStop jassing."); @@ -250,8 +384,13 @@ namespace Kehyeedra3.Commands $"\n3 : **Abama** - A cephalopod rogue with a heavy focus on debuffs. It is very agile.\nModifiers: **ATK 4, DEF 3, HP 5, AP 18**" + $"\n4 : **Pistashrimp** - A crustacean ranger with a heavy focus on DPS. It is somewhat agile.\nModifiers: **ATK 15, DEF 4, HP 5, AP 6**"); var reply = await NextMessageAsync(); - byte rep = byte.Parse(reply.Content); - if (rep > 4 || rep < 1) + BattleFish rep = (BattleFish)byte.Parse(reply.Content); + if (userfish.Any(x => x.FishType == rep)) + { + await Context.Channel.SendMessageAsync($"{Context.User.Mention}\nYou already have one of those, please don't neglect it and make it sad."); + return; + } + if ((int)rep > 4 || (int)rep < 1) { await Context.Channel.SendMessageAsync($"{Context.User.Mention}\nWhat you're looking for does not exist."); return; @@ -261,7 +400,8 @@ namespace Kehyeedra3.Commands await Context.Channel.SendMessageAsync($"Sorry **{Context.User.Mention}**, I can't give credit.\nCome back when you're a little, ***mmmmm***, richer.\n*You're missing {(500 - user.Money)/10000d}%.*"); return; } - switch (rep) + string species = ""; + switch ((int)rep) { case 1: { @@ -293,8 +433,15 @@ namespace Kehyeedra3.Commands await Context.Channel.SendMessageAsync($"{Context.User.Mention}\nBank has no money, convince someone to gamble."); return; } - //create fish here pls let there fish be - fish.FishType = rep; + + var bfish = new User.BattleFishObject + { + FishType = rep, + UserId = Context.User.Id + }; + + Database.Battlefish.Add(bfish); + await Context.Channel.SendMessageAsync($"{Context.User.Mention}\nThank you for your purchase."); await Database.SaveChangesAsync(); } @@ -341,7 +488,19 @@ namespace Kehyeedra3.Commands } else if (option == "change" || option == "c") { - + await Context.Channel.SendMessageAsync($"{Context.User.Mention}\nPlease select your battlefish\n{bfishlist}"); + var fens = await NextMessageAsync(); + type = (BattleFish)byte.Parse(fens.Content); + if (userfish.Any(x => x.FishType == type)) + { + user.CurrentBattlefish = type; + await Database.SaveChangesAsync(); + await Context.Channel.SendMessageAsync($"{Context.User.Mention}\nBattlefish changed."); + } + else + { + await Context.Channel.SendMessageAsync($"{Context.User.Mention}\nYou don't own that."); + } } else { @@ -703,76 +862,6 @@ namespace Kehyeedra3.Commands - [RequireRolePrecondition(AccessLevel.BotOwner)] - [Command("setbf")] - public async Task SetBattleFish(byte type, IUser usar = null) - { - string species = ""; - switch (type) - { - case 0: - { - species = "None"; - } - break; - case 1: - { - species = "Herring"; - } - break; - case 2: - { - species = "Birgus"; - } - break; - case 3: - { - species = "Abama"; - } - break; - case 4: - { - species = "Pistashrimp"; - } - break; - } - using (var Database = new ApplicationDbContextFactory().CreateDbContext()) - { - if (usar == null) - { - var user = Database.Users.FirstOrDefault(x => x.Id == Context.User.Id).BattleFish.FirstOrDefault(); - user.FishType = type; - await Context.Channel.SendMessageAsync($"Changed **{Context.User.Username}**'s bf type to {species}."); - } - else - { - var user = Database.Users.FirstOrDefault(x => x.Id == usar.Id).BattleFish.FirstOrDefault(); - user.FishType = type; - await Context.Channel.SendMessageAsync($"Changed **{usar.Username}**'s bf type to {species}."); - } - await Database.SaveChangesAsync(); - } - } - [RequireRolePrecondition(AccessLevel.BotOwner)] - [Command("setbflv")] - public async Task SetBattleFishLevel(int lv, IUser usar = null) - { - using (var Database = new ApplicationDbContextFactory().CreateDbContext()) - { - if (usar == null) - { - var user = Database.Users.FirstOrDefault(x => x.Id == Context.User.Id).BattleFish.FirstOrDefault(); - user.Lvl = lv; - await Context.Channel.SendMessageAsync($"Changed **{Context.User.Username}**'s bf lvl to {lv}."); - } - else - { - var user = Database.Users.FirstOrDefault(x => x.Id == usar.Id).BattleFish.FirstOrDefault(); - user.Lvl = lv; - await Context.Channel.SendMessageAsync($"Changed **{usar.Username}**'s bf lvl to {lv}."); - } - await Database.SaveChangesAsync(); - } - } + } } diff --git a/Kehyeedra3/Migrations/20200531192223_boofboof.Designer.cs b/Kehyeedra3/Migrations/20200531192223_boofboof.Designer.cs new file mode 100644 index 0000000..fc6453b --- /dev/null +++ b/Kehyeedra3/Migrations/20200531192223_boofboof.Designer.cs @@ -0,0 +1,239 @@ +// +using System; +using Kehyeedra3; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +namespace Kehyeedra3.Migrations +{ + [DbContext(typeof(ApplicationDbContext))] + [Migration("20200531192223_boofboof")] + partial class boofboof + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "3.1.2") + .HasAnnotation("Relational:MaxIdentifierLength", 64); + + modelBuilder.Entity("Kehyeedra3.Services.Models.Fishing", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint unsigned"); + + b.Property("Inventory") + .HasColumnType("LONGTEXT"); + + b.Property("LastFish") + .HasColumnType("bigint unsigned"); + + b.Property("Lvl") + .HasColumnType("bigint unsigned"); + + b.Property("Prestige") + .HasColumnType("int"); + + b.Property("RodOwned") + .HasColumnType("tinyint unsigned"); + + b.Property("RodUsed") + .HasColumnType("tinyint unsigned"); + + b.Property("TXp") + .HasColumnType("bigint unsigned"); + + b.Property("Xp") + .HasColumnType("bigint unsigned"); + + b.HasKey("Id"); + + b.ToTable("Fishing"); + }); + + modelBuilder.Entity("Kehyeedra3.Services.Models.ItemOffer", b => + { + b.Property("OfferId") + .ValueGeneratedOnAdd() + .HasColumnType("bigint unsigned"); + + b.Property("Amount") + .HasColumnType("int"); + + b.Property("BuyerId") + .HasColumnType("bigint unsigned"); + + b.Property("IsPurchaseFromStore") + .HasColumnType("tinyint(1)"); + + b.Property("IsSellOffer") + .HasColumnType("tinyint(1)"); + + b.Property("ItemId") + .HasColumnType("bigint unsigned"); + + b.Property("OfferAmount") + .HasColumnType("int"); + + b.Property("StoreFrontId") + .HasColumnType("bigint unsigned"); + + b.Property("StoreId") + .HasColumnType("bigint unsigned"); + + b.HasKey("OfferId"); + + b.HasIndex("StoreFrontId"); + + b.ToTable("ItemOffer"); + }); + + modelBuilder.Entity("Kehyeedra3.Services.Models.Reminder", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint unsigned"); + + b.Property("Created") + .HasColumnType("bigint unsigned"); + + b.Property("Message") + .HasColumnType("longtext CHARACTER SET utf8mb4"); + + b.Property("Send") + .HasColumnType("bigint unsigned"); + + b.Property("UserId") + .HasColumnType("bigint unsigned"); + + b.HasKey("Id"); + + b.ToTable("Reminders"); + }); + + modelBuilder.Entity("Kehyeedra3.Services.Models.StoreFront", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint unsigned"); + + b.Property("StoreItemType") + .HasColumnType("int"); + + b.Property("UserId") + .HasColumnType("bigint unsigned"); + + b.HasKey("Id"); + + b.ToTable("StoreFronts"); + }); + + modelBuilder.Entity("Kehyeedra3.Services.Models.StoreInventory", b => + { + b.Property("InvId") + .ValueGeneratedOnAdd() + .HasColumnType("bigint unsigned"); + + b.Property("Amount") + .HasColumnType("int"); + + b.Property("Item") + .HasColumnType("longtext CHARACTER SET utf8mb4"); + + b.Property("Price") + .HasColumnType("int"); + + b.Property("StoreFrontId") + .HasColumnType("bigint unsigned"); + + b.HasKey("InvId"); + + b.HasIndex("StoreFrontId"); + + b.ToTable("StoreInventory"); + }); + + modelBuilder.Entity("Kehyeedra3.Services.Models.User", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint unsigned"); + + b.Property("Avatar") + .HasColumnType("longtext CHARACTER SET utf8mb4"); + + b.Property("GeneralInventory") + .HasColumnType("LONGTEXT"); + + b.Property("LastMine") + .HasColumnType("bigint unsigned"); + + b.Property("Money") + .HasColumnType("bigint"); + + b.Property("Username") + .HasColumnType("longtext CHARACTER SET utf8mb4"); + + b.HasKey("Id"); + + b.ToTable("Users"); + }); + + modelBuilder.Entity("Kehyeedra3.Services.Models.User+BattleFishObject", b => + { + b.Property("FishId") + .ValueGeneratedOnAdd() + .HasColumnType("bigint unsigned"); + + b.Property("FishType") + .HasColumnType("tinyint unsigned"); + + b.Property("Lvl") + .HasColumnType("int"); + + b.Property("Name") + .HasColumnType("longtext CHARACTER SET utf8mb4"); + + b.Property("NextXp") + .HasColumnType("bigint unsigned"); + + b.Property("UserId") + .HasColumnType("bigint unsigned"); + + b.Property("Xp") + .HasColumnType("bigint unsigned"); + + b.HasKey("FishId"); + + b.HasIndex("UserId"); + + b.ToTable("BattleFishObject"); + }); + + modelBuilder.Entity("Kehyeedra3.Services.Models.ItemOffer", b => + { + b.HasOne("Kehyeedra3.Services.Models.StoreFront", null) + .WithMany("Offers") + .HasForeignKey("StoreFrontId"); + }); + + modelBuilder.Entity("Kehyeedra3.Services.Models.StoreInventory", b => + { + b.HasOne("Kehyeedra3.Services.Models.StoreFront", null) + .WithMany("Items") + .HasForeignKey("StoreFrontId"); + }); + + modelBuilder.Entity("Kehyeedra3.Services.Models.User+BattleFishObject", b => + { + b.HasOne("Kehyeedra3.Services.Models.User", null) + .WithMany("BattleFish") + .HasForeignKey("UserId"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Kehyeedra3/Migrations/20200531192223_boofboof.cs b/Kehyeedra3/Migrations/20200531192223_boofboof.cs new file mode 100644 index 0000000..06968d9 --- /dev/null +++ b/Kehyeedra3/Migrations/20200531192223_boofboof.cs @@ -0,0 +1,17 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +namespace Kehyeedra3.Migrations +{ + public partial class boofboof : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + + } + } +} diff --git a/Kehyeedra3/Migrations/20200531193428_oofboof.Designer.cs b/Kehyeedra3/Migrations/20200531193428_oofboof.Designer.cs new file mode 100644 index 0000000..2c802c0 --- /dev/null +++ b/Kehyeedra3/Migrations/20200531193428_oofboof.Designer.cs @@ -0,0 +1,230 @@ +// +using System; +using Kehyeedra3; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +namespace Kehyeedra3.Migrations +{ + [DbContext(typeof(ApplicationDbContext))] + [Migration("20200531193428_oofboof")] + partial class oofboof + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "3.1.2") + .HasAnnotation("Relational:MaxIdentifierLength", 64); + + modelBuilder.Entity("Kehyeedra3.Services.Models.Fishing", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint unsigned"); + + b.Property("Inventory") + .HasColumnType("LONGTEXT"); + + b.Property("LastFish") + .HasColumnType("bigint unsigned"); + + b.Property("Lvl") + .HasColumnType("bigint unsigned"); + + b.Property("Prestige") + .HasColumnType("int"); + + b.Property("RodOwned") + .HasColumnType("tinyint unsigned"); + + b.Property("RodUsed") + .HasColumnType("tinyint unsigned"); + + b.Property("TXp") + .HasColumnType("bigint unsigned"); + + b.Property("Xp") + .HasColumnType("bigint unsigned"); + + b.HasKey("Id"); + + b.ToTable("Fishing"); + }); + + modelBuilder.Entity("Kehyeedra3.Services.Models.ItemOffer", b => + { + b.Property("OfferId") + .ValueGeneratedOnAdd() + .HasColumnType("bigint unsigned"); + + b.Property("Amount") + .HasColumnType("int"); + + b.Property("BuyerId") + .HasColumnType("bigint unsigned"); + + b.Property("IsPurchaseFromStore") + .HasColumnType("tinyint(1)"); + + b.Property("IsSellOffer") + .HasColumnType("tinyint(1)"); + + b.Property("ItemId") + .HasColumnType("bigint unsigned"); + + b.Property("OfferAmount") + .HasColumnType("int"); + + b.Property("StoreFrontId") + .HasColumnType("bigint unsigned"); + + b.Property("StoreId") + .HasColumnType("bigint unsigned"); + + b.HasKey("OfferId"); + + b.HasIndex("StoreFrontId"); + + b.ToTable("ItemOffer"); + }); + + modelBuilder.Entity("Kehyeedra3.Services.Models.Reminder", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint unsigned"); + + b.Property("Created") + .HasColumnType("bigint unsigned"); + + b.Property("Message") + .HasColumnType("longtext CHARACTER SET utf8mb4"); + + b.Property("Send") + .HasColumnType("bigint unsigned"); + + b.Property("UserId") + .HasColumnType("bigint unsigned"); + + b.HasKey("Id"); + + b.ToTable("Reminders"); + }); + + modelBuilder.Entity("Kehyeedra3.Services.Models.StoreFront", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint unsigned"); + + b.Property("StoreItemType") + .HasColumnType("int"); + + b.Property("UserId") + .HasColumnType("bigint unsigned"); + + b.HasKey("Id"); + + b.ToTable("StoreFronts"); + }); + + modelBuilder.Entity("Kehyeedra3.Services.Models.StoreInventory", b => + { + b.Property("InvId") + .ValueGeneratedOnAdd() + .HasColumnType("bigint unsigned"); + + b.Property("Amount") + .HasColumnType("int"); + + b.Property("Item") + .HasColumnType("longtext CHARACTER SET utf8mb4"); + + b.Property("Price") + .HasColumnType("int"); + + b.Property("StoreFrontId") + .HasColumnType("bigint unsigned"); + + b.HasKey("InvId"); + + b.HasIndex("StoreFrontId"); + + b.ToTable("StoreInventory"); + }); + + modelBuilder.Entity("Kehyeedra3.Services.Models.User", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint unsigned"); + + b.Property("Avatar") + .HasColumnType("longtext CHARACTER SET utf8mb4"); + + b.Property("GeneralInventory") + .HasColumnType("LONGTEXT"); + + b.Property("LastMine") + .HasColumnType("bigint unsigned"); + + b.Property("Money") + .HasColumnType("bigint"); + + b.Property("Username") + .HasColumnType("longtext CHARACTER SET utf8mb4"); + + b.HasKey("Id"); + + b.ToTable("Users"); + }); + + modelBuilder.Entity("Kehyeedra3.Services.Models.User+BattleFishObject", b => + { + b.Property("FishId") + .ValueGeneratedOnAdd() + .HasColumnType("bigint unsigned"); + + b.Property("FishType") + .HasColumnType("tinyint unsigned"); + + b.Property("Lvl") + .HasColumnType("int"); + + b.Property("Name") + .HasColumnType("longtext CHARACTER SET utf8mb4"); + + b.Property("NextXp") + .HasColumnType("bigint unsigned"); + + b.Property("UserId") + .HasColumnType("bigint unsigned"); + + b.Property("Xp") + .HasColumnType("bigint unsigned"); + + b.HasKey("FishId"); + + b.ToTable("Battlefish"); + }); + + modelBuilder.Entity("Kehyeedra3.Services.Models.ItemOffer", b => + { + b.HasOne("Kehyeedra3.Services.Models.StoreFront", null) + .WithMany("Offers") + .HasForeignKey("StoreFrontId"); + }); + + modelBuilder.Entity("Kehyeedra3.Services.Models.StoreInventory", b => + { + b.HasOne("Kehyeedra3.Services.Models.StoreFront", null) + .WithMany("Items") + .HasForeignKey("StoreFrontId"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Kehyeedra3/Migrations/20200531193428_oofboof.cs b/Kehyeedra3/Migrations/20200531193428_oofboof.cs new file mode 100644 index 0000000..8ada119 --- /dev/null +++ b/Kehyeedra3/Migrations/20200531193428_oofboof.cs @@ -0,0 +1,75 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +namespace Kehyeedra3.Migrations +{ + public partial class oofboof : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropForeignKey( + name: "FK_BattleFishObject_Users_UserId", + table: "BattleFishObject"); + + migrationBuilder.DropPrimaryKey( + name: "PK_BattleFishObject", + table: "BattleFishObject"); + + migrationBuilder.DropIndex( + name: "IX_BattleFishObject_UserId", + table: "BattleFishObject"); + + migrationBuilder.RenameTable( + name: "BattleFishObject", + newName: "Battlefish"); + + migrationBuilder.AlterColumn( + name: "UserId", + table: "Battlefish", + nullable: false, + oldClrType: typeof(ulong), + oldType: "bigint unsigned", + oldNullable: true); + + migrationBuilder.AddPrimaryKey( + name: "PK_Battlefish", + table: "Battlefish", + column: "FishId"); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropPrimaryKey( + name: "PK_Battlefish", + table: "Battlefish"); + + migrationBuilder.RenameTable( + name: "Battlefish", + newName: "BattleFishObject"); + + migrationBuilder.AlterColumn( + name: "UserId", + table: "BattleFishObject", + type: "bigint unsigned", + nullable: true, + oldClrType: typeof(ulong)); + + migrationBuilder.AddPrimaryKey( + name: "PK_BattleFishObject", + table: "BattleFishObject", + column: "FishId"); + + migrationBuilder.CreateIndex( + name: "IX_BattleFishObject_UserId", + table: "BattleFishObject", + column: "UserId"); + + migrationBuilder.AddForeignKey( + name: "FK_BattleFishObject_Users_UserId", + table: "BattleFishObject", + column: "UserId", + principalTable: "Users", + principalColumn: "Id", + onDelete: ReferentialAction.Restrict); + } + } +} diff --git a/Kehyeedra3/Migrations/20200531204543_oofoof.Designer.cs b/Kehyeedra3/Migrations/20200531204543_oofoof.Designer.cs new file mode 100644 index 0000000..9fba401 --- /dev/null +++ b/Kehyeedra3/Migrations/20200531204543_oofoof.Designer.cs @@ -0,0 +1,233 @@ +// +using System; +using Kehyeedra3; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; + +namespace Kehyeedra3.Migrations +{ + [DbContext(typeof(ApplicationDbContext))] + [Migration("20200531204543_oofoof")] + partial class oofoof + { + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "3.1.2") + .HasAnnotation("Relational:MaxIdentifierLength", 64); + + modelBuilder.Entity("Kehyeedra3.Services.Models.Fishing", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint unsigned"); + + b.Property("Inventory") + .HasColumnType("LONGTEXT"); + + b.Property("LastFish") + .HasColumnType("bigint unsigned"); + + b.Property("Lvl") + .HasColumnType("bigint unsigned"); + + b.Property("Prestige") + .HasColumnType("int"); + + b.Property("RodOwned") + .HasColumnType("tinyint unsigned"); + + b.Property("RodUsed") + .HasColumnType("tinyint unsigned"); + + b.Property("TXp") + .HasColumnType("bigint unsigned"); + + b.Property("Xp") + .HasColumnType("bigint unsigned"); + + b.HasKey("Id"); + + b.ToTable("Fishing"); + }); + + modelBuilder.Entity("Kehyeedra3.Services.Models.ItemOffer", b => + { + b.Property("OfferId") + .ValueGeneratedOnAdd() + .HasColumnType("bigint unsigned"); + + b.Property("Amount") + .HasColumnType("int"); + + b.Property("BuyerId") + .HasColumnType("bigint unsigned"); + + b.Property("IsPurchaseFromStore") + .HasColumnType("tinyint(1)"); + + b.Property("IsSellOffer") + .HasColumnType("tinyint(1)"); + + b.Property("ItemId") + .HasColumnType("bigint unsigned"); + + b.Property("OfferAmount") + .HasColumnType("int"); + + b.Property("StoreFrontId") + .HasColumnType("bigint unsigned"); + + b.Property("StoreId") + .HasColumnType("bigint unsigned"); + + b.HasKey("OfferId"); + + b.HasIndex("StoreFrontId"); + + b.ToTable("ItemOffer"); + }); + + modelBuilder.Entity("Kehyeedra3.Services.Models.Reminder", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint unsigned"); + + b.Property("Created") + .HasColumnType("bigint unsigned"); + + b.Property("Message") + .HasColumnType("longtext CHARACTER SET utf8mb4"); + + b.Property("Send") + .HasColumnType("bigint unsigned"); + + b.Property("UserId") + .HasColumnType("bigint unsigned"); + + b.HasKey("Id"); + + b.ToTable("Reminders"); + }); + + modelBuilder.Entity("Kehyeedra3.Services.Models.StoreFront", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint unsigned"); + + b.Property("StoreItemType") + .HasColumnType("int"); + + b.Property("UserId") + .HasColumnType("bigint unsigned"); + + b.HasKey("Id"); + + b.ToTable("StoreFronts"); + }); + + modelBuilder.Entity("Kehyeedra3.Services.Models.StoreInventory", b => + { + b.Property("InvId") + .ValueGeneratedOnAdd() + .HasColumnType("bigint unsigned"); + + b.Property("Amount") + .HasColumnType("int"); + + b.Property("Item") + .HasColumnType("longtext CHARACTER SET utf8mb4"); + + b.Property("Price") + .HasColumnType("int"); + + b.Property("StoreFrontId") + .HasColumnType("bigint unsigned"); + + b.HasKey("InvId"); + + b.HasIndex("StoreFrontId"); + + b.ToTable("StoreInventory"); + }); + + modelBuilder.Entity("Kehyeedra3.Services.Models.User", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint unsigned"); + + b.Property("Avatar") + .HasColumnType("longtext CHARACTER SET utf8mb4"); + + b.Property("CurrentBattlefish") + .HasColumnType("int"); + + b.Property("GeneralInventory") + .HasColumnType("LONGTEXT"); + + b.Property("LastMine") + .HasColumnType("bigint unsigned"); + + b.Property("Money") + .HasColumnType("bigint"); + + b.Property("Username") + .HasColumnType("longtext CHARACTER SET utf8mb4"); + + b.HasKey("Id"); + + b.ToTable("Users"); + }); + + modelBuilder.Entity("Kehyeedra3.Services.Models.User+BattleFishObject", b => + { + b.Property("FishId") + .ValueGeneratedOnAdd() + .HasColumnType("bigint unsigned"); + + b.Property("FishType") + .HasColumnType("int"); + + b.Property("Lvl") + .HasColumnType("int"); + + b.Property("Name") + .HasColumnType("longtext CHARACTER SET utf8mb4"); + + b.Property("NextXp") + .HasColumnType("bigint unsigned"); + + b.Property("UserId") + .HasColumnType("bigint unsigned"); + + b.Property("Xp") + .HasColumnType("bigint unsigned"); + + b.HasKey("FishId"); + + b.ToTable("Battlefish"); + }); + + modelBuilder.Entity("Kehyeedra3.Services.Models.ItemOffer", b => + { + b.HasOne("Kehyeedra3.Services.Models.StoreFront", null) + .WithMany("Offers") + .HasForeignKey("StoreFrontId"); + }); + + modelBuilder.Entity("Kehyeedra3.Services.Models.StoreInventory", b => + { + b.HasOne("Kehyeedra3.Services.Models.StoreFront", null) + .WithMany("Items") + .HasForeignKey("StoreFrontId"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/Kehyeedra3/Migrations/20200531204543_oofoof.cs b/Kehyeedra3/Migrations/20200531204543_oofoof.cs new file mode 100644 index 0000000..745ff41 --- /dev/null +++ b/Kehyeedra3/Migrations/20200531204543_oofoof.cs @@ -0,0 +1,37 @@ +using Microsoft.EntityFrameworkCore.Migrations; + +namespace Kehyeedra3.Migrations +{ + public partial class oofoof : Migration + { + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.AddColumn( + name: "CurrentBattlefish", + table: "Users", + nullable: false, + defaultValue: 0); + + migrationBuilder.AlterColumn( + name: "FishType", + table: "Battlefish", + nullable: false, + oldClrType: typeof(byte), + oldType: "tinyint unsigned"); + } + + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropColumn( + name: "CurrentBattlefish", + table: "Users"); + + migrationBuilder.AlterColumn( + name: "FishType", + table: "Battlefish", + type: "tinyint unsigned", + nullable: false, + oldClrType: typeof(int)); + } + } +} diff --git a/Kehyeedra3/Migrations/ApplicationDbContextModelSnapshot.cs b/Kehyeedra3/Migrations/ApplicationDbContextModelSnapshot.cs index fb639bb..34d209c 100644 --- a/Kehyeedra3/Migrations/ApplicationDbContextModelSnapshot.cs +++ b/Kehyeedra3/Migrations/ApplicationDbContextModelSnapshot.cs @@ -163,6 +163,9 @@ namespace Kehyeedra3.Migrations b.Property("Avatar") .HasColumnType("longtext CHARACTER SET utf8mb4"); + b.Property("CurrentBattlefish") + .HasColumnType("int"); + b.Property("GeneralInventory") .HasColumnType("LONGTEXT"); @@ -186,8 +189,8 @@ namespace Kehyeedra3.Migrations .ValueGeneratedOnAdd() .HasColumnType("bigint unsigned"); - b.Property("FishType") - .HasColumnType("tinyint unsigned"); + b.Property("FishType") + .HasColumnType("int"); b.Property("Lvl") .HasColumnType("int"); @@ -198,7 +201,7 @@ namespace Kehyeedra3.Migrations b.Property("NextXp") .HasColumnType("bigint unsigned"); - b.Property("UserId") + b.Property("UserId") .HasColumnType("bigint unsigned"); b.Property("Xp") @@ -206,9 +209,7 @@ namespace Kehyeedra3.Migrations b.HasKey("FishId"); - b.HasIndex("UserId"); - - b.ToTable("BattleFishObject"); + b.ToTable("Battlefish"); }); modelBuilder.Entity("Kehyeedra3.Services.Models.ItemOffer", b => @@ -224,13 +225,6 @@ namespace Kehyeedra3.Migrations .WithMany("Items") .HasForeignKey("StoreFrontId"); }); - - modelBuilder.Entity("Kehyeedra3.Services.Models.User+BattleFishObject", b => - { - b.HasOne("Kehyeedra3.Services.Models.User", null) - .WithMany("BattleFish") - .HasForeignKey("UserId"); - }); #pragma warning restore 612, 618 } } diff --git a/Kehyeedra3/Services/Models/User.cs b/Kehyeedra3/Services/Models/User.cs index c0011a0..ee210e1 100644 --- a/Kehyeedra3/Services/Models/User.cs +++ b/Kehyeedra3/Services/Models/User.cs @@ -15,7 +15,9 @@ namespace Kehyeedra3.Services.Models public ulong LastMine { get; set; } = 0; [Column(TypeName = "LONGTEXT")] public string GeneralInventory { get; set; } = "{}"; - public ICollection BattleFish { get; set; } + [Column(TypeName = "TINYINT")] + public BattleFish CurrentBattlefish { get; set; } = 0; + public bool GrantMoney(User bank, long amount) @@ -30,18 +32,6 @@ namespace Kehyeedra3.Services.Models return false; } - //public void SetGenInv(List newInv) - //{ - // GeneralInventory = JsonConvert.SerializeObject(newInv); - //} - //public List GetGenInv() - //{ - // if (string.IsNullOrEmpty(GeneralInventory)) - // { - // return new List(); - // } - // return JsonConvert.DeserializeObject>(GeneralInventory); - //} public Dictionary GetGenInve() { @@ -68,6 +58,12 @@ namespace Kehyeedra3.Services.Models Name = "Lan's Love", Price = 100 }, + new Item() + { + Id = Items.Lettuce, + Name = "Lettuce", + Price = 50 + } }; } public class Item @@ -76,20 +72,33 @@ namespace Kehyeedra3.Services.Models public string Name { get; set; } public int Price { get; set; } } + public class BattleFishObject { [Key] public ulong FishId { get; set; } - public byte FishType { get; set; } = 0; + [Required] + public ulong UserId { get; set; } + [Column(TypeName = "TINYINT")] + public BattleFish FishType { get; set; } = 0; public ulong Xp { get; set; } = 0; public ulong NextXp { get; set; } = 50; public int Lvl { get; set; } = 0; public string Name { get; set; } = "Unnamed"; } } + public enum BattleFish + { + None = 0, + Herring = 1, + Birgus = 2, + Abama = 3, + Pistashrimp = 4 + } public enum Items { DirtyBoot = 0, + Lettuce = 1 } public class ItemSlot { diff --git a/Kehyeedra3/Services/ReminderService.cs b/Kehyeedra3/Services/ReminderService.cs index 0ba8812..cd1a7b8 100644 --- a/Kehyeedra3/Services/ReminderService.cs +++ b/Kehyeedra3/Services/ReminderService.cs @@ -11,73 +11,82 @@ namespace Kehyeedra3.Services { private static async Task SendReminderAsync(Reminder reminder) { - var dmchannel = await Bot._bot.GetUser(reminder.UserId).GetOrCreateDMChannelAsync(); - if (dmchannel != null) - { - ulong m = (reminder.Send - reminder.Created) / 60; - ulong h = 0; - ulong d = 0; - while (m > 59) - { - h += 1; - m -= 60; - } - while (h > 23) + try { + var dmchannel = await Bot._bot.GetUser(reminder.UserId).GetOrCreateDMChannelAsync(); + if (dmchannel != null) { - d += 1; - h -= 24; - } - string remin = ""; - if (d > 0) - { - remin += $" {d} day"; - if (d > 1) + ulong m = (reminder.Send - reminder.Created) / 60; + ulong h = 0; + ulong d = 0; + while (m > 59) { - remin += $"s"; + h += 1; + m -= 60; } - } - if (h > 0) - { - remin += $" {h} hour"; - if (h > 1) + while (h > 23) { - remin += $"s"; + d += 1; + h -= 24; } - } - if (m > 0) - { - remin += $" {m} minute"; - if (m > 1) + string remin = ""; + if (d > 0) + { + remin += $" {d} day"; + if (d > 1) + { + remin += $"s"; + } + } + if (h > 0) + { + remin += $" {h} hour"; + if (h > 1) + { + remin += $"s"; + } + } + if (m > 0) { - remin += $"s"; + remin += $" {m} minute"; + if (m > 1) + { + remin += $"s"; + } } + await dmchannel.SendMessageAsync($"**Reminder from{remin} ago:**\n\n''{reminder.Message}''"); } - await dmchannel.SendMessageAsync($"**Reminder from{remin} ago:**\n\n''{reminder.Message}''"); } + catch { await (await Bot._bot.GetUser(242040333309837327).GetOrCreateDMChannelAsync()).SendMessageAsync($"Time of error ^\n" + + $"A fucky wucky has occurred, uwu\nFix wemindew sewwis dimwiwt" + + $"\nThis was the reminder: {reminder.Id} {reminder.UserId} {reminder.Send.FromYeedraStamp()}"); } } + public async Task Tick() { while (true) { - using (var Database = new ApplicationDbContextFactory().CreateDbContext()) - { - var reminders = Database.Reminders.ToList(); - if(Database.Reminders.Any() && Bot._bot != null && Bot._bot.ConnectionState == Discord.ConnectionState.Connected) + if(Bot.IsReady) + { + using (var Database = new ApplicationDbContextFactory().CreateDbContext()) { - bool hasChanged = false; - foreach (var x in reminders) + var reminders = Database.Reminders.ToList(); + if (Database.Reminders.Any() && Bot._bot != null && Bot._bot.ConnectionState == Discord.ConnectionState.Connected) { - if (x.Send <= DateTime.UtcNow.ToYeedraStamp()) + bool hasChanged = false; + foreach (var x in reminders) { - await SendReminderAsync(x).ConfigureAwait(false); - Database.Reminders.Remove(x); - hasChanged = true; + if (x.Send <= DateTime.UtcNow.ToYeedraStamp()) + { + await SendReminderAsync(x).ConfigureAwait(false); + Database.Reminders.Remove(x); + hasChanged = true; + } } - } - if (hasChanged) - { - await Database.SaveChangesAsync().ConfigureAwait(false); + if (hasChanged) + { + await Database.SaveChangesAsync().ConfigureAwait(false); + } } } }