From ca1710158669bbc27cb56ee8fb64916978fd9d61 Mon Sep 17 00:00:00 2001 From: appelemac Date: Sat, 2 Apr 2016 23:17:42 +0200 Subject: [PATCH] moved PokemonMoves to their own json --- NadekoBot/Classes/DBHandler.cs | 1 - NadekoBot/Classes/JSONModels/Configuration.cs | 6 + NadekoBot/Classes/JSONModels/PokeMove.cs | 19 ++ NadekoBot/Classes/_DataModels/PokeTypes.cs | 2 +- NadekoBot/Classes/_DataModels/pokemoves.cs | 15 - NadekoBot/Modules/Pokemon/PokemonModule.cs | 10 +- .../PokemonTypes/IPokeTypeExtensions.cs | 11 +- .../Modules/Pokemon/PokemonTypes/PokeType.cs | 4 +- NadekoBot/NadekoBot.cs | 1 + NadekoBot/NadekoBot.csproj | 2 +- NadekoBot/bin/Debug/data/moves.json | 294 ++++++++++++++++++ 11 files changed, 335 insertions(+), 30 deletions(-) create mode 100644 NadekoBot/Classes/JSONModels/PokeMove.cs delete mode 100644 NadekoBot/Classes/_DataModels/pokemoves.cs create mode 100644 NadekoBot/bin/Debug/data/moves.json diff --git a/NadekoBot/Classes/DBHandler.cs b/NadekoBot/Classes/DBHandler.cs index c6488a27..a3063b38 100644 --- a/NadekoBot/Classes/DBHandler.cs +++ b/NadekoBot/Classes/DBHandler.cs @@ -26,7 +26,6 @@ namespace NadekoBot.Classes conn.CreateTable(); conn.CreateTable(); conn.CreateTable(); - conn.CreateTable(); conn.CreateTable(); conn.CreateTable(); conn.CreateTable(); diff --git a/NadekoBot/Classes/JSONModels/Configuration.cs b/NadekoBot/Classes/JSONModels/Configuration.cs index 1bfcd92d..4727fa54 100644 --- a/NadekoBot/Classes/JSONModels/Configuration.cs +++ b/NadekoBot/Classes/JSONModels/Configuration.cs @@ -14,6 +14,9 @@ namespace NadekoBot.Classes.JSONModels [JsonIgnore] public List Quotes { get; set; } = new List(); + [JsonIgnore] + public List PokemonMoves { get; set; } = new List(); + public List RotatingStatuses { get; set; } = new List(); public CommandPrefixesModel CommandPrefixes { get; set; } = new CommandPrefixesModel(); public HashSet ServerBlacklist { get; set; } = new HashSet(); @@ -25,6 +28,7 @@ namespace NadekoBot.Classes.JSONModels 143515953525817344 }; + public string[] _8BallResponses { get; set; } = { "Most definitely yes", @@ -78,6 +82,7 @@ namespace NadekoBot.Classes.JSONModels public string CurrencySign { get; set; } = "🌸"; public string CurrencyName { get; set; } = "NadekoFlower"; + } public class CommandPrefixesModel @@ -127,4 +132,5 @@ namespace NadekoBot.Classes.JSONModels public override string ToString() => $"{Text}\n\t*-{Author}*"; } + } diff --git a/NadekoBot/Classes/JSONModels/PokeMove.cs b/NadekoBot/Classes/JSONModels/PokeMove.cs new file mode 100644 index 00000000..419009ea --- /dev/null +++ b/NadekoBot/Classes/JSONModels/PokeMove.cs @@ -0,0 +1,19 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace NadekoBot.Classes.JSONModels +{ + public class PokeMove + { + public PokeMove(string n, string t) + { + name = n; + type = t; + } + public string name { get; set; } = ""; + public string type { get; set; } = ""; + } +} diff --git a/NadekoBot/Classes/_DataModels/PokeTypes.cs b/NadekoBot/Classes/_DataModels/PokeTypes.cs index d4cceac2..0410eb7f 100644 --- a/NadekoBot/Classes/_DataModels/PokeTypes.cs +++ b/NadekoBot/Classes/_DataModels/PokeTypes.cs @@ -9,6 +9,6 @@ namespace NadekoBot.Classes._DataModels class UserPokeTypes : IDataModel { public long UserId { get; set; } - public int type { get; set; } + public string type { get; set; } } } diff --git a/NadekoBot/Classes/_DataModels/pokemoves.cs b/NadekoBot/Classes/_DataModels/pokemoves.cs deleted file mode 100644 index bacbed68..00000000 --- a/NadekoBot/Classes/_DataModels/pokemoves.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace NadekoBot.Classes._DataModels -{ - class PokeMoves : IDataModel - { - public string move { get; set; } - public int type { get; set; } - public long UserId { get; internal set; } - } -} diff --git a/NadekoBot/Modules/Pokemon/PokemonModule.cs b/NadekoBot/Modules/Pokemon/PokemonModule.cs index 8ddf25e9..b52ee0f4 100644 --- a/NadekoBot/Modules/Pokemon/PokemonModule.cs +++ b/NadekoBot/Modules/Pokemon/PokemonModule.cs @@ -37,10 +37,10 @@ namespace NadekoBot.Modules.Pokemon { var db = DbHandler.Instance.GetAllRows(); - Dictionary setTypes = db.ToDictionary(x => x.UserId, y => y.type); + Dictionary setTypes = db.ToDictionary(x => x.UserId, y => y.type); if (setTypes.ContainsKey((long)id)) { - return PokemonTypesMain.IntToPokeType(setTypes[(long)id]); + return PokemonTypesMain.stringToPokeType(setTypes[(long)id])?? new PokemonTypes.NormalType(); } int remainder = Math.Abs((int)(id % 18)); @@ -116,7 +116,7 @@ namespace NadekoBot.Modules.Pokemon var enabledMoves = userType.GetMoves(); if (!enabledMoves.Contains(move.ToLowerInvariant())) { - await e.Channel.SendMessage($"{e.User.Mention} was not able to use **{move}**, use {Prefix}listmoves to see moves you can use"); + await e.Channel.SendMessage($"{e.User.Mention} was not able to use **{move}**, use `{Prefix}ml` to see moves you can use"); return; } @@ -177,7 +177,7 @@ namespace NadekoBot.Modules.Pokemon .Do(async e => { var userType = GetPokeType(e.User.Id); - List movesList = userType.GetMoves(); + var movesList = userType.GetMoves(); var str = $"**Moves for `{userType.Name}` type.**"; foreach (string m in movesList) { @@ -298,7 +298,7 @@ namespace NadekoBot.Modules.Pokemon DbHandler.Instance.InsertData(new UserPokeTypes { UserId = (long)e.User.Id, - type = targetType.Num + type = targetType.Name }); //Now for the response diff --git a/NadekoBot/Modules/Pokemon/PokemonTypes/IPokeTypeExtensions.cs b/NadekoBot/Modules/Pokemon/PokemonTypes/IPokeTypeExtensions.cs index 1b81790e..d06b8227 100644 --- a/NadekoBot/Modules/Pokemon/PokemonTypes/IPokeTypeExtensions.cs +++ b/NadekoBot/Modules/Pokemon/PokemonTypes/IPokeTypeExtensions.cs @@ -1,5 +1,6 @@ using NadekoBot.Classes; using NadekoBot.Classes._DataModels; +using NadekoBot.Classes.JSONModels; using System.Collections.Generic; namespace NadekoBot.Modules.Pokemon.PokeTypes.Extensions @@ -8,15 +9,15 @@ namespace NadekoBot.Modules.Pokemon.PokeTypes.Extensions { public static List GetMoves(this PokeType poketype) { - var db = DbHandler.Instance.GetAllRows(); + var moveSet = NadekoBot.Config.PokemonMoves; List moves = new List(); - foreach (PokeMoves p in db) + foreach (PokeMove p in moveSet) { - if (p.type == poketype.Num) + if (p.type == poketype.Name) { - if (!moves.Contains(p.move)) + if (!moves.Contains(p.name)) { - moves.Add(p.move); + moves.Add(p.name); } } } diff --git a/NadekoBot/Modules/Pokemon/PokemonTypes/PokeType.cs b/NadekoBot/Modules/Pokemon/PokemonTypes/PokeType.cs index efde0905..36db3a9c 100644 --- a/NadekoBot/Modules/Pokemon/PokemonTypes/PokeType.cs +++ b/NadekoBot/Modules/Pokemon/PokemonTypes/PokeType.cs @@ -18,12 +18,12 @@ namespace NadekoBot.Modules.Pokemon.PokeTypes foreach (PokeType t in TypeList) { - if (t.Name == newType) + if (t.Name == newType.ToUpperInvariant()) { return t; } } - return null; + return new NormalType(); } //These classes can use all methods (except getMoves) diff --git a/NadekoBot/NadekoBot.cs b/NadekoBot/NadekoBot.cs index 6442839f..f6e1fa31 100644 --- a/NadekoBot/NadekoBot.cs +++ b/NadekoBot/NadekoBot.cs @@ -66,6 +66,7 @@ namespace NadekoBot { Config = JsonConvert.DeserializeObject(File.ReadAllText("data/config.json")); Config.Quotes = JsonConvert.DeserializeObject>(File.ReadAllText("data/quotes.json")); + Config.PokemonMoves = JsonConvert.DeserializeObject>(File.ReadAllText("data/moves.json")); } catch { diff --git a/NadekoBot/NadekoBot.csproj b/NadekoBot/NadekoBot.csproj index c43cd975..d444273c 100644 --- a/NadekoBot/NadekoBot.csproj +++ b/NadekoBot/NadekoBot.csproj @@ -131,6 +131,7 @@ + @@ -150,7 +151,6 @@ - diff --git a/NadekoBot/bin/Debug/data/moves.json b/NadekoBot/bin/Debug/data/moves.json new file mode 100644 index 00000000..5814f5cd --- /dev/null +++ b/NadekoBot/bin/Debug/data/moves.json @@ -0,0 +1,294 @@ +[ + { + "name": "sonic boom", + "type": "NORMAL" + }, + { + "name": "quick attack", + "type": "NORMAL" + }, + { + "name": "doubleslap", + "type": "NORMAL" + }, + { + "name": "headbutt", + "type": "NORMAL" + }, + { + "name": "incinerate", + "type": "FIRE" + }, + { + "name": "ember", + "type": "FIRE" + }, + { + "name": "fire punch", + "type": "FIRE" + }, + { + "name": "fiery dance", + "type": "FIRE" + }, + { + "name": "bubblebeam", + "type": "WATER" + }, + { + "name": "dive", + "type": "WATER" + }, + { + "name": "whirlpool", + "type": "WATER" + }, + { + "name": "aqua tail", + "type": "WATER" + }, + { + "name": "nuzzle", + "type": "ELECTRIC" + }, + { + "name": "thunderbolt", + "type": "ELECTRIC" + }, + { + "name": "thundershock", + "type": "ELECTRIC" + }, + { + "name": "discharge", + "type": "ELECTRIC" + }, + { + "name": "absorb", + "type": "GRASS" + }, + { + "name": "mega drain", + "type": "GRASS" + }, + { + "name": "vine whip", + "type": "GRASS" + }, + { + "name": "razor leaf", + "type": "GRASS" + }, + { + "name": "ice ball", + "type": "ICE" + }, + { + "name": "powder snow", + "type": "ICE" + }, + { + "name": "avalanche", + "type": "ICE" + }, + { + "name": "icy wind", + "type": "ICE" + }, + { + "name": "low kick", + "type": "FIGHTING" + }, + { + "name": "force palm", + "type": "FIGHTING" + }, + { + "name": "mach punch", + "type": "FIGHTING" + }, + { + "name": "double kick", + "type": "FIGHTING" + }, + { + "name": "acid", + "type": "POISON" + }, + { + "name": "smog", + "type": "POISON" + }, + { + "name": "sludge", + "type": "POISON" + }, + { + "name": "poison jab", + "type": "POISON" + }, + { + "name": "mud-slap", + "type": "GROUND" + }, + { + "name": "boomerang", + "type": "GROUND" + }, + { + "name": "bulldoze", + "type": "GROUND" + }, + { + "name": "dig", + "type": "GROUND" + }, + { + "name": "peck", + "type": "FLY" + }, + { + "name": "pluck", + "type": "FLY" + }, + { + "name": "gust", + "type": "FLY" + }, + { + "name": "aerial ace", + "type": "FLY" + }, + { + "name": "confusion", + "type": "PSYCHIC" + }, + { + "name": "psybeam", + "type": "PSYCHIC" + }, + { + "name": "psywave", + "type": "PSYCHIC" + }, + { + "name": "heart stamp", + "type": "PSYCHIC" + }, + { + "name": "bug bite", + "type": "BUG" + }, + { + "name": "infestation", + "type": "BUG" + }, + { + "name": "x-scissor", + "type": "BUG" + }, + { + "name": "twineedle", + "type": "BUG" + }, + { + "name": "rock throw", + "type": "ROCK" + }, + { + "name": "rollout", + "type": "ROCK" + }, + { + "name": "rock tomb", + "type": "ROCK" + }, + { + "name": "rock blast", + "type": "ROCK" + }, + { + "name": "astonish", + "type": "GHOST" + }, + { + "name": "night shade", + "type": "GHOST" + }, + { + "name": "lick", + "type": "GHOST" + }, + { + "name": "ominous wind", + "type": "GHOST" + }, + { + "name": "hex", + "type": "GHOST" + }, + { + "name": "dragon tail", + "type": "DRAGON" + }, + { + "name": "dragon rage", + "type": "DRAGON" + }, + { + "name": "dragonbreath", + "type": "DRAGON" + }, + { + "name": "twister", + "type": "DRAGON" + }, + { + "name": "pursuit", + "type": "DARK" + }, + { + "name": "assurance", + "type": "DARK" + }, + { + "name": "bite", + "type": "DARK" + }, + { + "name": "faint attack", + "type": "DARK" + }, + { + "name": "bullet punch", + "type": "STEEL" + }, + { + "name": "metal burst", + "type": "STEEL" + }, + { + "name": "gear grind", + "type": "STEEL" + }, + { + "name": "magnet bomb", + "type": "STEEL" + }, + { + "name": "fairy wind", + "type": "FAIRY" + }, + { + "name": "draining kiss", + "type": "FAIRY" + }, + { + "name": "dazzling gleam", + "type": "FAIRY" + }, + { + "name": "play rough", + "type": "FAIRY" + } + ] \ No newline at end of file