diff --git a/NadekoBot/Classes/DBHandler.cs b/NadekoBot/Classes/DBHandler.cs index 51cb91e7..fd54899f 100644 --- a/NadekoBot/Classes/DBHandler.cs +++ b/NadekoBot/Classes/DBHandler.cs @@ -23,7 +23,7 @@ namespace NadekoBot.Classes { conn.CreateTable(); conn.CreateTable(); conn.CreateTable(); - conn.CreateTable(); + conn.CreateTable(); conn.CreateTable(); conn.Execute(Queries.TransactionTriggerQuery); } diff --git a/NadekoBot/Classes/_DataModels/PokeTypes.cs b/NadekoBot/Classes/_DataModels/PokeTypes.cs index 432d918c..3661540a 100644 --- a/NadekoBot/Classes/_DataModels/PokeTypes.cs +++ b/NadekoBot/Classes/_DataModels/PokeTypes.cs @@ -6,7 +6,7 @@ using System.Threading.Tasks; namespace NadekoBot.Classes._DataModels { - class PokeTypes : IDataModel + class userPokeTypes : IDataModel { public long UserId { get; set; } public int type { get; set; } diff --git a/NadekoBot/Modules/Pokemon/PokeStats.cs b/NadekoBot/Modules/Pokemon/PokeStats.cs new file mode 100644 index 00000000..dca9d31f --- /dev/null +++ b/NadekoBot/Modules/Pokemon/PokeStats.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace NadekoBot.Modules.Pokemon +{ + class PokeStats + { + } +} diff --git a/NadekoBot/Modules/Pokemon/PokemonModule.cs b/NadekoBot/Modules/Pokemon/PokemonModule.cs new file mode 100644 index 00000000..8bf71139 --- /dev/null +++ b/NadekoBot/Modules/Pokemon/PokemonModule.cs @@ -0,0 +1,435 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using Discord.Modules; +using Discord.Commands; +using NadekoBot.Commands; +using NadekoBot.Classes; +using NadekoBot.Extensions; +using NadekoBot.Classes._DataModels; +using NadekoBot.Classes.Permissions; +using System.Collections.Concurrent; +using NadekoBot.Modules.Pokemon.PokeTypes; + +namespace NadekoBot.Modules.Pokemon +{ + + class PokemonGame : DiscordModule + { + public override string Prefix { get; } = NadekoBot.Config.CommandPrefixes.Pokemon; + public readonly int BASEHEALTH = 500; + //private Dictionary stats = new Dictionary(); + private ConcurrentDictionary stats = new ConcurrentDictionary(); + + + public PokemonGame() + { + //Something? + } + public override void Install(ModuleManager manager) + { + manager.CreateCommands("", cgb => + { + cgb.AddCheck(Classes.Permissions.PermissionChecker.Instance); + + commands.ForEach(cmd => cmd.Init(cgb)); + + cgb.CreateCommand(Prefix + "attack") + .Description("Attacks a target with the given move") + .Parameter("move", ParameterType.Required) + .Parameter("target", ParameterType.Unparsed) + .Do(async e => + { + var move = e.GetArg("move"); + Discord.User target = null; + if (!string.IsNullOrWhiteSpace(e.GetArg("target"))) + { + + target = e.Server.FindUsers(e.GetArg("target")).FirstOrDefault(); + if (target == null) + { + await e.Channel.SendMessage("No such person."); + return; + } + } else + { + await e.Channel.SendMessage("No such person."); + return; + } + // Checking stats first, then move + //Set up the userstats + Pokestats userstats; + userstats = stats.GetOrAdd(e.User.Id, defaultStats()); + + //Check if able to move + //User not able if HP < 0, has made more than 4 attacks + if (userstats.HP < 0) + { + await e.Channel.SendMessage($"{e.User.Mention} has fainted and was not able to move!"); + return; + } + if (userstats.movesMade >= 5) + { + await e.Channel.SendMessage($"{e.User.Mention} has used too many moves in a row and was not able to move!"); + return; + } + if (userstats.lastAttacked.Contains(target.Id)) + { + await e.Channel.SendMessage($"{e.User.Mention} can't attack again without retaliation!"); + return; + } + //get target stats + Pokestats targetstats; + targetstats = stats.GetOrAdd(target.Id, defaultStats()); + + //If target's HP is below 0, no use attacking + if (targetstats.HP <= 0) + { + await e.Channel.SendMessage($"{target.Mention} has already fainted!"); + return; + } + + //Check whether move can be used + IPokeType usertype = getPokeType(e.User.Id); + + 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"); + return; + } + + //get target type + IPokeType targetType = getPokeType(target.Id); + //generate damage + int damage = getDamage(usertype, targetType); + //apply damage to target + targetstats.HP -= damage; + + var response = $"{e.User.Mention} used **{move}**{usertype.getImage()} on {target.Mention}{targetType.getImage()} for **{damage}** damage"; + + //Damage type + if (damage < 40) + { + response += "\nIt's not effective.."; + } + else if (damage > 60) + { + response += "\nIt's super effective!"; + } + else + { + response += "\nIt's somewhat effective"; + } + + //check fainted + + if (targetstats.HP <= 0) + { + response += $"\n**{target.Name}** has fainted!"; + } + else + { + response += $"\n**{target.Name}** has {targetstats.HP} HP remaining"; + } + + //update other stats + userstats.lastAttacked.Add(target.Id); + userstats.movesMade++; + targetstats.movesMade = 0; + if (targetstats.lastAttacked.Contains(e.User.Id)) + { + targetstats.lastAttacked.Remove(e.User.Id); + } + + //update dictionary + //This can stay the same right? + stats[e.User.Id] = userstats; + stats[target.Id] = targetstats; + + await e.Channel.SendMessage(response); + }); + + cgb.CreateCommand(Prefix + "listmoves") + .Description("Lists the moves you are able to use") + .Do(async e => + { + var userType = getPokeType(e.User.Id); + List movesList = userType.getMoves(); + var str = "**Moves:**"; + foreach (string m in movesList) + { + str += $"\n{userType.getImage()}{m}"; + } + await e.Channel.SendMessage(str); + }); + + cgb.CreateCommand(Prefix + "addmove") + .Description($"Adds move given to database.\n**Usage**: {Prefix}addmove flame fire") + .Parameter("movename", ParameterType.Required) + .Parameter("movetype", ParameterType.Required) + .Do(async e => + { + //Implement NadekoFlowers???? + string newMove = e.GetArg("movename").ToLowerInvariant(); + var newType = PokemonTypesMain.stringToPokeType(e.GetArg("movetype").ToUpperInvariant()); + int typeNum = newType.getNum(); + var db = DbHandler.Instance.GetAllRows().Select(x => x.move); + if (db.Contains(newMove)) + { + await e.Channel.SendMessage($"{newMove} already exists"); + return; + } + await Task.Run(() => + { + DbHandler.Instance.InsertData(new Classes._DataModels.PokeMoves + { + move = newMove, + type = typeNum + }); + }); + await e.Channel.SendMessage($"Added {newType.getImage()}{newMove}"); + }); + + cgb.CreateCommand(Prefix + "heal") + .Description($"Heals someone. Revives those that fainted. Costs a NadekoFlower \n**Usage**:{Prefix}revive @someone") + .Parameter("target", ParameterType.Required) + .Do(async e => + { + var usr = e.Server.FindUsers(e.GetArg("target")).FirstOrDefault(); + if (usr == null) + { + await e.Channel.SendMessage("No such person."); + return; + } + if (stats.ContainsKey(usr.Id)) + { + + var targetStats = stats[usr.Id]; + int HP = targetStats.HP; + if (targetStats.HP == BASEHEALTH) + { + await e.Channel.SendMessage($"{usr.Name} already has full HP!"); + return; + } + //Payment~ + var amount = 1; + var pts = Classes.DbHandler.Instance.GetStateByUserId((long)e.User.Id)?.Value ?? 0; + if (pts < amount) + { + await e.Channel.SendMessage($"{e.User.Mention} you don't have enough NadekoFlowers! \nYou still need {amount - pts} to be able to do this!"); + return; + } + var up = (usr.Id == e.User.Id) ? "yourself" : usr.Name; + await FlowersHandler.RemoveFlowersAsync(e.User, $"heal {up}", amount); + //healing + targetStats.HP = BASEHEALTH; + if (HP < 0) + { + //Could heal only for half HP? + stats[usr.Id].HP = (BASEHEALTH / 2); + await e.Channel.SendMessage($"{e.User.Name} revived {usr.Name} for 🌸"); + return; + } + await e.Channel.SendMessage($"{e.User.Name} healed {usr.Name} for {BASEHEALTH - HP} HP with a 🌸"); + return; + } + else + { + await e.Channel.SendMessage($"{usr.Name} already has full HP!"); + } + }); + + cgb.CreateCommand(Prefix + "type") + .Description($"Get the poketype of the target.\n**Usage**: {Prefix}type @someone") + .Parameter("target", ParameterType.Required) + .Do(async e => + { + var usr = e.Server.FindUsers(e.GetArg("target")).FirstOrDefault(); + if (usr == null) + { + await e.Channel.SendMessage("No such person."); + return; + } + var pType = getPokeType(usr.Id); + await e.Channel.SendMessage($"Type of {usr.Name} is **{pType.getName().ToLowerInvariant()}**{pType.getImage()}"); + + }); + + cgb.CreateCommand(Prefix + "defaultmoves") + .Description($"Sets the moves DB to the default state **OWNER ONLY**") + .AddCheck(SimpleCheckers.OwnerOnly()) + .Do(async e => + { + //clear DB + var db = DbHandler.Instance.GetAllRows(); + foreach (PokeMoves p in db) + { + DbHandler.Instance.Delete(p.Id); + } + + Dictionary defaultmoves = new Dictionary() + { + {"flame",1}, + {"hack",3}, + {"scare",13}, + {"splash",2}, + {"freeze",5}, + {"strike",4}, + {"surge",3}, + {"electrocute",3}, + {"surf",2}, + {"mellow",4}, + {"flamethrower",1}, + {"thundershock",3}, + {"lava",12}, + {"fly",9}, + {"control",10}, + {"sting",11}, + {"poison",7}, + {"confusion",10}, + {"breathe",14}, + {"ultrabash",6}, + {"punch",6}, + {"blind",15}, + {"earthquake",8}, + {"rocksmash",12}, + {"transform",0}, + {"bulldoze",8}, + {"frustate",0}, + {"confide",0}, + {"metronome",0}, + {"dracometeor",14}, + {"outrage",14} + }; + + foreach (KeyValuePair entry in defaultmoves) + { + DbHandler.Instance.InsertData(new Classes._DataModels.PokeMoves + { + move = entry.Key, + type = entry.Value + }); + } + + var str = "Reset moves.\n**Moves:**"; + //could sort, but meh + var dbMoves = DbHandler.Instance.GetAllRows(); + foreach (PokeMoves m in dbMoves) + { + var t = PokemonTypesMain.intToPokeType(m.type); + + str += $"\n{t.getImage()}{m.move}"; + } + + await e.Channel.SendMessage(str); + + }); + + cgb.CreateCommand(Prefix + "settype") + .Description($"Set your poketype. Costs a NadekoFlower.\n**Usage**: {Prefix}settype fire") + .Parameter("targetType", ParameterType.Required) + .Do(async e => + { + var targetTypeString = e.GetArg("targetType"); + var targetType = PokemonTypesMain.stringToPokeType(targetTypeString.ToUpperInvariant()); + if (targetType == null) + { + await e.Channel.SendMessage("Invalid type specified. Type must be one of:\nNORMAL, FIRE, WATER, ELECTRIC, GRASS, ICE, FIGHTING, POISON, GROUND, FLYING, PSYCHIC, BUG, ROCK, GHOST, DRAGON, DARK, STEEL"); + return; + } + if (targetType == getPokeType(e.User.Id)) + { + await e.Channel.SendMessage($"Your type is already {targetType.getName().ToLowerInvariant()}{targetType.getImage()}"); + return; + } + + //Payment~ + var amount = 1; + var pts = Classes.DbHandler.Instance.GetStateByUserId((long)e.User.Id)?.Value ?? 0; + if (pts < amount) + { + await e.Channel.SendMessage($"{e.User.Mention} you don't have enough NadekoFlowers! \nYou still need {amount - pts} to be able to do this!"); + return; + } + await FlowersHandler.RemoveFlowersAsync(e.User, $"set usertype to {targetTypeString}", amount); + //Actually changing the type here + var preTypes = DbHandler.Instance.GetAllRows(); + Dictionary Dict = preTypes.ToDictionary(x => x.UserId, y => y.Id); + if (Dict.ContainsKey((long)e.User.Id)) + { + //delete previous type + DbHandler.Instance.Delete(Dict[(long)e.User.Id]); + } + + DbHandler.Instance.InsertData(new Classes._DataModels.userPokeTypes + { + UserId = (long)e.User.Id, + type = targetType.getNum() + }); + + //Now for the response + + await e.Channel.SendMessage($"Set type of {e.User.Mention} to {targetTypeString}{targetType.getImage()} for a 🌸"); + }); + }); + } + + + + + private int getDamage(IPokeType usertype, IPokeType targetType) + { + Random rng = new Random(); + int damage = rng.Next(40, 60); + double multiplier = 1; + multiplier = usertype.getMagnifier(targetType); + damage = (int)(damage * multiplier); + return damage; + } + + private IPokeType getPokeType(ulong id) + { + + var db = DbHandler.Instance.GetAllRows(); + Dictionary setTypes = db.ToDictionary(x => x.UserId, y => y.type); + if (setTypes.ContainsKey((long)id)) + { + return PokemonTypesMain.intToPokeType(setTypes[(long)id]); + } + + int remainder = (int)id % 16; + + return PokemonTypesMain.intToPokeType(remainder); + + + } + + private Pokestats defaultStats() + { + Pokestats s = new Pokestats(); + s.HP = BASEHEALTH; + return s; + } + + + } + class Pokestats + { + //Health left + public int HP { get; set; } = 500; + //Amount of moves made since last time attacked + public int movesMade { get; set; } = 0; + //Last people attacked + public List lastAttacked { get; set; } = new List(); + } +} + + +//Not sure this is what you wanted? + + + + diff --git a/NadekoBot/Modules/Pokemon/PokemonTypes/BugType.cs b/NadekoBot/Modules/Pokemon/PokemonTypes/BugType.cs new file mode 100644 index 00000000..d7d6014a --- /dev/null +++ b/NadekoBot/Modules/Pokemon/PokemonTypes/BugType.cs @@ -0,0 +1,73 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using NadekoBot.Modules.Pokemon; +using NadekoBot.Classes; +using NadekoBot.Classes._DataModels; using NadekoBot.Modules.Pokemon.PokeTypes; + +namespace NadekoBot.Modules.Pokemon.PokemonTypes +{ + class BugType : IPokeType + { + static readonly string name = "BUG"; + public static int numType = 11; + + public double getMagnifier(IPokeType target) + { + switch (target.getName()) + { + + case "FIRE": return 0.5; + case "GRASS": return 2; + case "FIGHTING": return 0.5; + case "POISON": return 0.5; + case "FLYING": return 0.5; + case "PSYCHIC": return 2; + case "ROCK": return 0.5; + case "DARK": return 2; + case "STEEL": return 0.5; + default: return 1; + } + } + List moves = new List(); + + public List getMoves() + { + updateMoves(); + return moves; + } + + + public string getName() + { + return name; + } + + public void updateMoves() + { + var db = DbHandler.Instance.GetAllRows(); + foreach (PokeMoves p in db) + { + if (p.type == numType) + { + if (!moves.Contains(p.move)) + { + moves.Add(p.move); + } + } + } + } + + public string getImage() + { + return "🐛"; + } + + public int getNum() + { + return numType; + } + } +} diff --git a/NadekoBot/Modules/Pokemon/PokemonTypes/DarkType.cs b/NadekoBot/Modules/Pokemon/PokemonTypes/DarkType.cs new file mode 100644 index 00000000..98ba6a68 --- /dev/null +++ b/NadekoBot/Modules/Pokemon/PokemonTypes/DarkType.cs @@ -0,0 +1,69 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using NadekoBot.Modules.Pokemon; +using NadekoBot.Classes; +using NadekoBot.Classes._DataModels; using NadekoBot.Modules.Pokemon.PokeTypes; + +namespace NadekoBot.Modules.Pokemon.PokemonTypes +{ + class DarkType : IPokeType + { + static readonly string name = "DARK"; + public static int numType = 15; + + public double getMagnifier(IPokeType target) + { + switch (target.getName()) + { + + case "FIGHTING": return 0.5; + case "PSYCHIC": return 2; + case "GHOST": return 2; + case "DARK": return 0.5; + case "STEEL": return 0.5; + default: return 1; + } + } + List moves = new List(); + + public List getMoves() + { + updateMoves(); + return moves; + } + + + public string getName() + { + return name; + } + + public void updateMoves() + { + var db = DbHandler.Instance.GetAllRows(); + foreach (PokeMoves p in db) + { + if (p.type == numType) + { + if (!moves.Contains(p.move)) + { + moves.Add(p.move); + } + } + } + } + + public string getImage() + { + return "🕶"; + } + + public int getNum() + { + return numType; + } + } +} diff --git a/NadekoBot/Modules/Pokemon/PokemonTypes/Dragontype.cs b/NadekoBot/Modules/Pokemon/PokemonTypes/Dragontype.cs new file mode 100644 index 00000000..435675b7 --- /dev/null +++ b/NadekoBot/Modules/Pokemon/PokemonTypes/Dragontype.cs @@ -0,0 +1,66 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using NadekoBot.Modules.Pokemon; +using NadekoBot.Classes; +using NadekoBot.Classes._DataModels; using NadekoBot.Modules.Pokemon.PokeTypes; + +namespace NadekoBot.Modules.Pokemon.PokemonTypes +{ + class DragonType : IPokeType + { + static readonly string name = "DRAGON"; + public static int numType = 14; + + public double getMagnifier(IPokeType target) + { + switch (target.getName()) + { + + case "DRAGON": return 2; + case "STEEL": return 0.5; + default: return 1; + } + } + List moves = new List(); + + public List getMoves() + { + updateMoves(); + return moves; + } + + + public string getName() + { + return name; + } + + public void updateMoves() + { + var db = DbHandler.Instance.GetAllRows(); + foreach (PokeMoves p in db) + { + if (p.type == numType) + { + if (!moves.Contains(p.move)) + { + moves.Add(p.move); + } + } + } + } + + public string getImage() + { + return "🐉"; + } + + public int getNum() + { + return numType; + } + } +} diff --git a/NadekoBot/Modules/Pokemon/PokemonTypes/ElectricType.cs b/NadekoBot/Modules/Pokemon/PokemonTypes/ElectricType.cs new file mode 100644 index 00000000..25aaa15e --- /dev/null +++ b/NadekoBot/Modules/Pokemon/PokemonTypes/ElectricType.cs @@ -0,0 +1,69 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using NadekoBot.Modules.Pokemon; +using NadekoBot.Classes; +using NadekoBot.Classes._DataModels; using NadekoBot.Modules.Pokemon.PokeTypes; + +namespace NadekoBot.Modules.Pokemon.PokemonTypes +{ + class ElectricType : IPokeType + { + static readonly string name = "ELECTRIC"; + public static int numType = 3; + + public double getMagnifier(IPokeType target) + { + switch (target.getName()) + { + + case "WATER": return 2; + case "ELECTRIC": return 0.5; + case "GRASS": return 2; + case "GROUND": return 0; + case "FLYING": return 2; + case "DRAGON": return 0.5; + default: return 1; + } + } + List moves = new List(); + + public List getMoves() + { + updateMoves(); + return moves; + } + + + public string getName() + { + return name; + } + + public void updateMoves() + { + var db = DbHandler.Instance.GetAllRows(); + foreach (PokeMoves p in db) + { + if (p.type == numType) + { + if (!moves.Contains(p.move)) + { + moves.Add(p.move); + } + } + } + } + public string getImage() + { + return "⚡️"; + } + + public int getNum() + { + return numType; + } + } +} diff --git a/NadekoBot/Modules/Pokemon/PokemonTypes/FightingType.cs b/NadekoBot/Modules/Pokemon/PokemonTypes/FightingType.cs new file mode 100644 index 00000000..3f22ec33 --- /dev/null +++ b/NadekoBot/Modules/Pokemon/PokemonTypes/FightingType.cs @@ -0,0 +1,73 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using NadekoBot.Modules.Pokemon; +using NadekoBot.Classes; +using NadekoBot.Classes._DataModels; using NadekoBot.Modules.Pokemon.PokeTypes; + +namespace NadekoBot.Modules.Pokemon.PokemonTypes +{ + class FightingType : IPokeType + { + static readonly string name = "FIGHTING"; + public static int numType = 6; + + public double getMagnifier(IPokeType target) + { + switch (target.getName()) + { + + case "NORMAL": return 2; + case "ICE": return 2; + case "POISON": return 0.5; + case "FLYING": return 0.5; + case "PSYCHIC": return 0.5; + case "BUG": return 0.5; + case "ROCK": return 2; + case "GHOST": return 0; + case "DARK": return 2; + case "STEEL": return 2; + default: return 1; + } + } + List moves = new List(); + + public List getMoves() + { + updateMoves(); + return moves; + } + + + public string getName() + { + return name; + } + + public void updateMoves() + { + var db = DbHandler.Instance.GetAllRows(); + foreach (PokeMoves p in db) + { + if (p.type == numType) + { + if (!moves.Contains(p.move)) + { + moves.Add(p.move); + } + } + } + } + public string getImage() + { + return "✊"; + } + + public int getNum() + { + return numType; + } + } +} diff --git a/NadekoBot/Modules/Pokemon/PokemonTypes/FireType.cs b/NadekoBot/Modules/Pokemon/PokemonTypes/FireType.cs new file mode 100644 index 00000000..bf6f8eb0 --- /dev/null +++ b/NadekoBot/Modules/Pokemon/PokemonTypes/FireType.cs @@ -0,0 +1,74 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using NadekoBot.Modules.Pokemon; +using NadekoBot.Classes; +using NadekoBot.Classes._DataModels; using NadekoBot.Modules.Pokemon.PokeTypes; + + + +namespace NadekoBot.Modules.Pokemon.PokemonTypes +{ + class FireType : IPokeType + { + static readonly string name = "FIRE"; + public static int numType = 1; + + public double getMagnifier(IPokeType target) + { + switch (target.getName()) + { + + case "FIRE": return 0.5; + case "WATER": return 0.5; + case "GRASS": return 2; + case "ICE": return 2; + case "BUG": return 2; + case "ROCK": return 0.5; + case "DRAGON": return 0.5; + case "STEEL": return 2; + default: return 1; + } + } + List moves = new List(); + + public List getMoves() + { + updateMoves(); + return moves; + } + + + public string getName() + { + return name; + } + + public void updateMoves() + { + var db = DbHandler.Instance.GetAllRows(); + foreach (PokeMoves p in db) + { + if (p.type == numType) + { + if (!moves.Contains(p.move)) + { + moves.Add(p.move); + } + } + } + } + + public string getImage() + { + return "🔥"; + } + + public int getNum() + { + return numType; + } + } +} diff --git a/NadekoBot/Modules/Pokemon/PokemonTypes/FlyingType.cs b/NadekoBot/Modules/Pokemon/PokemonTypes/FlyingType.cs new file mode 100644 index 00000000..7d7c1d54 --- /dev/null +++ b/NadekoBot/Modules/Pokemon/PokemonTypes/FlyingType.cs @@ -0,0 +1,70 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using NadekoBot.Modules.Pokemon; +using NadekoBot.Classes; +using NadekoBot.Classes._DataModels; using NadekoBot.Modules.Pokemon.PokeTypes; + +namespace NadekoBot.Modules.Pokemon.PokemonTypes +{ + class FlyingType : IPokeType + { + static readonly string name = "FLYING"; + public static int numType = 9; + + public double getMagnifier(IPokeType target) + { + switch (target.getName()) + { + + case "ELECTRIC": return 0.5; + case "GRASS": return 2; + case "FIGHTING": return 2; + case "BUG": return 2; + case "ROCK": return 0.5; + case "STEEL": return 0.5; + default: return 1; + } + } + List moves = new List(); + + public List getMoves() + { + updateMoves(); + return moves; + } + + + public string getName() + { + return name; + } + + public void updateMoves() + { + var db = DbHandler.Instance.GetAllRows(); + foreach (PokeMoves p in db) + { + if (p.type == numType) + { + if (!moves.Contains(p.move)) + { + moves.Add(p.move); + } + } + } + } + + public string getImage() + { + return "☁"; + } + + public int getNum() + { + return numType; + } + } +} diff --git a/NadekoBot/Modules/Pokemon/PokemonTypes/GhostType.cs b/NadekoBot/Modules/Pokemon/PokemonTypes/GhostType.cs new file mode 100644 index 00000000..8db5b678 --- /dev/null +++ b/NadekoBot/Modules/Pokemon/PokemonTypes/GhostType.cs @@ -0,0 +1,69 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using NadekoBot.Modules.Pokemon; +using NadekoBot.Classes; +using NadekoBot.Classes._DataModels; using NadekoBot.Modules.Pokemon.PokeTypes; + +namespace NadekoBot.Modules.Pokemon.PokemonTypes +{ + class GhostType : IPokeType + { + static readonly string name = "GHOST"; + public static int numType = 13; + + public double getMagnifier(IPokeType target) + { + switch (target.getName()) + { + + case "NORMAL": return 0; + case "PSYCHIC": return 2; + case "GHOST": return 2; + case "DARK": return 0.5; + case "STEEL": return 0.5; + default: return 1; + } + } + List moves = new List(); + + public List getMoves() + { + updateMoves(); + return moves; + } + + + public string getName() + { + return name; + } + + public void updateMoves() + { + var db = DbHandler.Instance.GetAllRows(); + foreach (PokeMoves p in db) + { + if (p.type == numType) + { + if (!moves.Contains(p.move)) + { + moves.Add(p.move); + } + } + } + } + + public string getImage() + { + return "👻"; + } + + public int getNum() + { + return numType; + } + } +} diff --git a/NadekoBot/Modules/Pokemon/PokemonTypes/GrassType.cs b/NadekoBot/Modules/Pokemon/PokemonTypes/GrassType.cs new file mode 100644 index 00000000..cab50981 --- /dev/null +++ b/NadekoBot/Modules/Pokemon/PokemonTypes/GrassType.cs @@ -0,0 +1,71 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using NadekoBot.Modules.Pokemon; +using NadekoBot.Classes; +using NadekoBot.Classes._DataModels; using NadekoBot.Modules.Pokemon.PokeTypes; + +namespace NadekoBot.Modules.Pokemon.PokemonTypes +{ + class GrassType : IPokeType + { + static readonly string name = "GRASS"; + public static int numType = 4; + + public double getMagnifier(IPokeType target) + { + switch (target.getName()) + { + + case "FIRE": return 0.5; + case "WATER": return 0.5; + case "GRASS": return 2; + case "ICE": return 2; + case "BUG": return 2; + case "ROCK": return 0.5; + case "DRAGON": return 0.5; + case "STEEL": return 2; + default: return 1; + } + } + List moves = new List(); + + public List getMoves() + { + updateMoves(); + return moves; + } + + + public string getName() + { + return name; + } + + public void updateMoves() + { + var db = DbHandler.Instance.GetAllRows(); + foreach (PokeMoves p in db) + { + if (p.type == numType) + { + if (!moves.Contains(p.move)) + { + moves.Add(p.move); + } + } + } + } + public string getImage() + { + return "🌿"; + } + + public int getNum() + { + return numType; + } + } +} diff --git a/NadekoBot/Modules/Pokemon/PokemonTypes/GroundType.cs b/NadekoBot/Modules/Pokemon/PokemonTypes/GroundType.cs new file mode 100644 index 00000000..b1eb5ec4 --- /dev/null +++ b/NadekoBot/Modules/Pokemon/PokemonTypes/GroundType.cs @@ -0,0 +1,72 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using NadekoBot.Modules.Pokemon; +using NadekoBot.Classes; +using NadekoBot.Classes._DataModels; using NadekoBot.Modules.Pokemon.PokeTypes; + +namespace NadekoBot.Modules.Pokemon.PokemonTypes +{ + class GroundType : IPokeType + { + static readonly string name = "GROUND"; + public static int numType = 8; + + public double getMagnifier(IPokeType target) + { + switch (target.getName()) + { + + case "FIRE": return 2; + case "ELECTRIC": return 2; + case "GRASS": return 0.5; + case "POISON": return 0.5; + case "FLYING": return 0; + case "BUG": return 0.5; + case "ROCK": return 2; + case "STEEL": return 2; + default: return 1; + } + } + List moves = new List(); + + public List getMoves() + { + updateMoves(); + return moves; + } + + + public string getName() + { + return name; + } + + public void updateMoves() + { + var db = DbHandler.Instance.GetAllRows(); + foreach (PokeMoves p in db) + { + if (p.type == numType) + { + if (!moves.Contains(p.move)) + { + moves.Add(p.move); + } + } + } + } + + public string getImage() + { + return "🗻"; + } + + public int getNum() + { + return numType; + } + } +} diff --git a/NadekoBot/Modules/Pokemon/PokemonTypes/IceType.cs b/NadekoBot/Modules/Pokemon/PokemonTypes/IceType.cs new file mode 100644 index 00000000..36cffe65 --- /dev/null +++ b/NadekoBot/Modules/Pokemon/PokemonTypes/IceType.cs @@ -0,0 +1,71 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using NadekoBot.Modules.Pokemon; +using NadekoBot.Classes; +using NadekoBot.Classes._DataModels; using NadekoBot.Modules.Pokemon.PokeTypes; + +namespace NadekoBot.Modules.Pokemon.PokemonTypes +{ + class IceType : IPokeType + { + static readonly string name = "ICE"; + public static int numType = 5; + + public double getMagnifier(IPokeType target) + { + switch (target.getName()) + { + + case "FIRE": return 0.5; + case "WATER": return 0.5; + case "GRASS": return 2; + case "ICE": return 0.5; + case "GROUND": return 2; + case "FLYING": return 2; + case "DRAGON": return 2; + case "STEEL": return 0.5; + default: return 1; + } + } + List moves = new List(); + + public List getMoves() + { + updateMoves(); + return moves; + } + + + public string getName() + { + return name; + } + + public void updateMoves() + { + var db = DbHandler.Instance.GetAllRows(); + foreach (PokeMoves p in db) + { + if (p.type == numType) + { + if (!moves.Contains(p.move)) + { + moves.Add(p.move); + } + } + } + } + public string getImage() + { + return "❄"; + } + + public int getNum() + { + return numType; + } + } +} diff --git a/NadekoBot/Modules/Pokemon/PokemonTypes/NormalType.cs b/NadekoBot/Modules/Pokemon/PokemonTypes/NormalType.cs new file mode 100644 index 00000000..a6127865 --- /dev/null +++ b/NadekoBot/Modules/Pokemon/PokemonTypes/NormalType.cs @@ -0,0 +1,69 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using NadekoBot.Modules.Pokemon; +using NadekoBot.Classes; +using NadekoBot.Classes._DataModels; +using NadekoBot.Modules.Pokemon.PokeTypes; + + +namespace NadekoBot.Modules.Pokemon.PokemonTypes +{ + class NormalType : IPokeType + { + static readonly string name = "NORMAL"; + public static int type_num = 0; + + public double getMagnifier(IPokeType target) + { + switch (target.getName()) + { + + case "ROCK": return 0.5; + case "GHOST": return 0; + case "STEEL": return 0.5; + default: return 1; + } + } + List moves = new List(); + + public List getMoves() + { + updateMoves(); + return moves; + } + + + public string getName() + { + return name; + } + + public void updateMoves() + { + var db = DbHandler.Instance.GetAllRows(); + foreach (PokeMoves p in db) + { + if (p.type == type_num) + { + if (!moves.Contains(p.move)) + { + moves.Add(p.move); + } + } + } + } + + public string getImage() + { + return "⭕️"; + } + + public int getNum() + { + return type_num; + } + } +} diff --git a/NadekoBot/Modules/Pokemon/PokemonTypes/PoisonType.cs b/NadekoBot/Modules/Pokemon/PokemonTypes/PoisonType.cs new file mode 100644 index 00000000..f0cf19d1 --- /dev/null +++ b/NadekoBot/Modules/Pokemon/PokemonTypes/PoisonType.cs @@ -0,0 +1,70 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using NadekoBot.Modules.Pokemon; +using NadekoBot.Classes; +using NadekoBot.Classes._DataModels; +using NadekoBot.Modules.Pokemon.PokeTypes; + +namespace NadekoBot.Modules.Pokemon.PokemonTypes +{ + class PoisonType : IPokeType + { + static readonly string name = "POISON"; + public static int numType = 7; + + public double getMagnifier(IPokeType target) + { + switch (target.getName()) + { + + case "GRASS": return 2; + case "POISON": return 0.5; + case "GROUND": return 0.5; + case "ROCK": return 0.5; + case "GHOST": return 0.5; + case "STEEL": return 0; + default: return 1; + } + } + List moves = new List(); + + public List getMoves() + { + updateMoves(); + return moves; + } + + + public string getName() + { + return name; + } + + public void updateMoves() + { + var db = DbHandler.Instance.GetAllRows(); + foreach (PokeMoves p in db) + { + if (p.type == numType) + { + if (!moves.Contains(p.move)) + { + moves.Add(p.move); + } + } + } + } + public string getImage() + { + return "☠"; + } + + public int getNum() + { + return numType; + } + } +} diff --git a/NadekoBot/Modules/Pokemon/PokemonTypes/PokeType.cs b/NadekoBot/Modules/Pokemon/PokemonTypes/PokeType.cs new file mode 100644 index 00000000..75e265ea --- /dev/null +++ b/NadekoBot/Modules/Pokemon/PokemonTypes/PokeType.cs @@ -0,0 +1,91 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using NadekoBot.Classes; +using NadekoBot.Classes._DataModels; +using NadekoBot.Modules.Pokemon.PokemonTypes; + +namespace NadekoBot.Modules.Pokemon.PokeTypes +{ + + public interface IPokeType + { + string getImage(); + string getName(); + int getNum(); + List getMoves(); + double getMagnifier(IPokeType target); + void updateMoves(); + } + public class PokemonTypesMain + { + + public static IPokeType stringToPokeType(string newType) + { + + foreach (IPokeType t in typeList) + { + if (t.getName() == newType) + { + return t; + } + } + return null; + } + + //These classes can use all methods (except getMoves) + public static List typeList = new List() + { + new NormalType(), + new FireType(), + new WaterType(), + new ElectricType(), + new GrassType(), + new IceType(), + new FightingType(), + new PoisonType(), + new GroundType(), + new FlyingType(), + new PsychicType(), + new BugType(), + new RockType(), + new GhostType(), + new DragonType(), + new DarkType(), + new SteelType() + }; + + public static IPokeType intToPokeType(int id) + { + foreach (IPokeType t in typeList) + { + if (t.getNum() == id) + { + return t; + } + } + return null; + } + + + + + + + + + + + + + + + + + + + + } +} diff --git a/NadekoBot/Modules/Pokemon/PokemonTypes/PsychicType.cs b/NadekoBot/Modules/Pokemon/PokemonTypes/PsychicType.cs new file mode 100644 index 00000000..1f1603ad --- /dev/null +++ b/NadekoBot/Modules/Pokemon/PokemonTypes/PsychicType.cs @@ -0,0 +1,69 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using NadekoBot.Modules.Pokemon; +using NadekoBot.Classes; +using NadekoBot.Classes._DataModels; using NadekoBot.Modules.Pokemon.PokeTypes; + +namespace NadekoBot.Modules.Pokemon.PokemonTypes +{ + class PsychicType : IPokeType + { + static readonly string name = "PSYCHIC"; + public static int numType = 10; + + public double getMagnifier(IPokeType target) + { + switch (target.getName()) + { + + case "FIGHTING": return 2; + case "POISON": return 2; + case "PSYCHIC": return 0.5; + case "DARK": return 0; + case "STEEL": return 0.5; + default: return 1; + } + } + List moves = new List(); + + public List getMoves() + { + updateMoves(); + return moves; + } + + + public string getName() + { + return name; + } + + public void updateMoves() + { + var db = DbHandler.Instance.GetAllRows(); + foreach (PokeMoves p in db) + { + if (p.type == numType) + { + if (!moves.Contains(p.move)) + { + moves.Add(p.move); + } + } + } + } + + public string getImage() + { + return "💫"; + } + + public int getNum() + { + return numType; + } + } +} diff --git a/NadekoBot/Modules/Pokemon/PokemonTypes/RockType.cs b/NadekoBot/Modules/Pokemon/PokemonTypes/RockType.cs new file mode 100644 index 00000000..4a48b9a7 --- /dev/null +++ b/NadekoBot/Modules/Pokemon/PokemonTypes/RockType.cs @@ -0,0 +1,71 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using NadekoBot.Modules.Pokemon; +using NadekoBot.Classes; +using NadekoBot.Classes._DataModels; using NadekoBot.Modules.Pokemon.PokeTypes; + +namespace NadekoBot.Modules.Pokemon.PokemonTypes +{ + class RockType : IPokeType + { + static readonly string name = "ROCK"; + public static int numType = 12; + + public double getMagnifier(IPokeType target) + { + switch (target.getName()) + { + + case "FIRE": return 2; + case "ICE": return 2; + case "FIGHTING": return 0.5; + case "GROUND": return 0.5; + case "FLYING": return 2; + case "BUG": return 2; + case "STEEL": return 0.5; + default: return 1; + } + } + List moves = new List(); + + public List getMoves() + { + updateMoves(); + return moves; + } + + + public string getName() + { + return name; + } + + public void updateMoves() + { + var db = DbHandler.Instance.GetAllRows(); + foreach (PokeMoves p in db) + { + if (p.type == numType) + { + if (!moves.Contains(p.move)) + { + moves.Add(p.move); + } + } + } + } + + public string getImage() + { + return "💎"; + } + + public int getNum() + { + return numType; + } + } +} diff --git a/NadekoBot/Modules/Pokemon/PokemonTypes/SteelType.cs b/NadekoBot/Modules/Pokemon/PokemonTypes/SteelType.cs new file mode 100644 index 00000000..f34e1ff2 --- /dev/null +++ b/NadekoBot/Modules/Pokemon/PokemonTypes/SteelType.cs @@ -0,0 +1,69 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using NadekoBot.Modules.Pokemon; +using NadekoBot.Classes; +using NadekoBot.Classes._DataModels; using NadekoBot.Modules.Pokemon.PokeTypes; + +namespace NadekoBot.Modules.Pokemon.PokemonTypes +{ + class SteelType : IPokeType + { + static readonly string name = "STEEL"; + public static int numType = -1; + + public double getMagnifier(IPokeType target) + { + switch (target.getName()) + { + + case "FIRE": return 0.5; + case "WATER": return 0.5; + case "ELECTRIC": return 0.5; + case "ICE": return 2; + case "ROCK": return 2; + case "STEEL": return 0.5; + default: return 1; + } + } + List moves = new List(); + + public List getMoves() + { + updateMoves(); + return moves; + } + + + public string getName() + { + return name; + } + + public void updateMoves() + { + var db = DbHandler.Instance.GetAllRows(); + foreach (PokeMoves p in db) + { + if (p.type == numType) + { + if (!moves.Contains(p.move)) + { + moves.Add(p.move); + } + } + } + } + public string getImage() + { + return "🔩"; + } + + public int getNum() + { + return numType; + } + } +} diff --git a/NadekoBot/Modules/Pokemon/PokemonTypes/WaterType.cs b/NadekoBot/Modules/Pokemon/PokemonTypes/WaterType.cs new file mode 100644 index 00000000..9ee96880 --- /dev/null +++ b/NadekoBot/Modules/Pokemon/PokemonTypes/WaterType.cs @@ -0,0 +1,69 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using NadekoBot.Modules.Pokemon; +using NadekoBot.Classes; +using NadekoBot.Classes._DataModels; using NadekoBot.Modules.Pokemon.PokeTypes; using NadekoBot.Modules.Pokemon.PokeTypes; + +namespace NadekoBot.Modules.Pokemon.PokemonTypes +{ + class WaterType : IPokeType + { + static readonly string name = "WATER"; + public static int numType = 2; + + public double getMagnifier(IPokeType target) + { + switch (target.getName()) + { + + case "FIRE": return 2; + case "WATER": return 0.5; + case "GRASS": return 0.5; + case "GROUND": return 2; + case "ROCK": return 2; + case "DRAGON": return 0.5; + default: return 1; + } + } + List moves = new List(); + + public List getMoves() + { + updateMoves(); + return moves; + } + + + public string getName() + { + return name; + } + + public void updateMoves() + { + var db = DbHandler.Instance.GetAllRows(); + foreach (PokeMoves p in db) + { + if (p.type == numType) + { + if (!moves.Contains(p.move)) + { + moves.Add(p.move); + } + } + } + } + public string getImage() + { + return "💦"; + } + + public int getNum() + { + return numType; + } + } +} diff --git a/NadekoBot/Modules/PokemonModule.cs b/NadekoBot/Modules/PokemonModule.cs deleted file mode 100644 index 616fce14..00000000 --- a/NadekoBot/Modules/PokemonModule.cs +++ /dev/null @@ -1,1481 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Discord.Modules; -using Discord.Commands; -using NadekoBot.Commands; -using NadekoBot.Classes; -using NadekoBot.Extensions; -using NadekoBot.Classes._DataModels; -using NadekoBot.Classes.Permissions; -using System.Collections.Concurrent; - - -namespace NadekoBot.Modules.pokegame -{ - using Modules.pokegame.poketypes; - class Pokegame : DiscordModule - { - public override string Prefix { get; } = NadekoBot.Config.CommandPrefixes.Pokemon; - public readonly int BASEHEALTH = 500; - //private Dictionary stats = new Dictionary(); - private ConcurrentDictionary stats = new ConcurrentDictionary(); - public Pokegame() - { - //Something? - } - public override void Install(ModuleManager manager) - { - manager.CreateCommands("", cgb => - { - cgb.AddCheck(Classes.Permissions.PermissionChecker.Instance); - - commands.ForEach(cmd => cmd.Init(cgb)); - - cgb.CreateCommand(Prefix + "attack") - .Description("Attacks a target with the given move") - .Parameter("move", ParameterType.Required) - .Parameter("target", ParameterType.Unparsed) - .Do(async e => - { - var move = e.GetArg("move"); - Discord.User target = null; - if (!string.IsNullOrWhiteSpace(e.GetArg("target"))) - { - - target = e.Server.FindUsers(e.GetArg("target")).FirstOrDefault(); - if (target == null) - { - await e.Channel.SendMessage("No such person."); - return; - } - } else - { - await e.Channel.SendMessage("No such person."); - return; - } - // Checking stats first, then move - //Set up the userstats - Pokestats userstats; - userstats = stats.GetOrAdd(e.User.Id, defaultStats()); - - //Check if able to move - //User not able if HP < 0, has made more than 4 attacks - if (userstats.HP < 0) - { - await e.Channel.SendMessage($"{e.User.Mention} has fainted and was not able to move!"); - return; - } - if (userstats.movesMade >= 5) - { - await e.Channel.SendMessage($"{e.User.Mention} has used too many moves in a row and was not able to move!"); - return; - } - if (userstats.lastAttacked.Contains(target.Id)) - { - await e.Channel.SendMessage($"{e.User.Mention} can't attack again without retaliation!"); - return; - } - //get target stats - Pokestats targetstats; - targetstats = stats.GetOrAdd(target.Id, defaultStats()); - - //If target's HP is below 0, no use attacking - if (targetstats.HP <= 0) - { - await e.Channel.SendMessage($"{target.Mention} has already fainted!"); - return; - } - - //Check whether move can be used - PokemonTypes.PokeType usertype = getPokeType(e.User.Id); - - 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"); - return; - } - - //get target type - PokemonTypes.PokeType targetType = getPokeType(target.Id); - //generate damage - int damage = getDamage(usertype, targetType); - //apply damage to target - targetstats.HP -= damage; - - var response = $"{e.User.Mention} used **{move}** on {target.Mention} for **{damage}** damage"; - - //Damage type - if (damage < 40) - { - response += "\nIt's not effective.."; - } - else if (damage > 60) - { - response += "\nIt's super effective!"; - } - else - { - response += "\nIt's somewhat effective"; - } - - //check fainted - - if (targetstats.HP <= 0) - { - response += $"\n**{target.Name}** has fainted!"; - } - else - { - response += $"\n**{target.Name}** has {targetstats.HP} HP remaining"; - } - - //update other stats - userstats.lastAttacked.Add(target.Id); - userstats.movesMade++; - targetstats.movesMade = 0; - if (targetstats.lastAttacked.Contains(e.User.Id)) - { - targetstats.lastAttacked.Remove(e.User.Id); - } - - //update dictionary - //This can stay the same right? - stats[e.User.Id] = userstats; - stats[target.Id] = targetstats; - - await e.Channel.SendMessage(response); - }); - - cgb.CreateCommand(Prefix + "listmoves") - .Description("Lists the moves you are able to use") - .Do(async e => - { - var userType = getPokeType(e.User.Id); - List movesList = userType.getMoves(); - var str = "**Moves:**"; - foreach (string m in movesList) - { - str += $"\n{userType.getImage()}{m}"; - } - await e.Channel.SendMessage(str); - }); - - cgb.CreateCommand(Prefix + "addmove") - .Description($"Adds move given to database.\n**Usage**: {Prefix}addmove flame fire") - .Parameter("movename", ParameterType.Required) - .Parameter("movetype", ParameterType.Required) - .Do(async e => - { - //Implement NadekoFlowers???? - string newMove = e.GetArg("movename").ToLowerInvariant(); - var newType = PokemonTypes.stringToPokeType(e.GetArg("movetype").ToUpperInvariant()); - int typeNum = newType.getNum(); - var db = DbHandler.Instance.GetAllRows().Select(x => x.move); - if (db.Contains(newMove)) - { - await e.Channel.SendMessage($"{newMove} already exists"); - return; - } - await Task.Run(() => - { - DbHandler.Instance.InsertData(new Classes._DataModels.PokeMoves - { - move = newMove, - type = typeNum - }); - }); - await e.Channel.SendMessage($"Added {newType.getImage()}{newMove}"); - }); - - cgb.CreateCommand(Prefix + "heal") - .Description($"Heals someone. Revives those that fainted. Costs a NadekoFlower \n**Usage**:{Prefix}revive @someone") - .Parameter("target", ParameterType.Required) - .Do(async e => - { - var usr = e.Server.FindUsers(e.GetArg("target")).FirstOrDefault(); - if (usr == null) - { - await e.Channel.SendMessage("No such person."); - return; - } - if (stats.ContainsKey(usr.Id)) - { - - var targetStats = stats[usr.Id]; - int HP = targetStats.HP; - if (targetStats.HP == BASEHEALTH) - { - await e.Channel.SendMessage($"{usr.Name} already has full HP!"); - return; - } - //Payment~ - var amount = 1; - var pts = Classes.DbHandler.Instance.GetStateByUserId((long)e.User.Id)?.Value ?? 0; - if (pts < amount) - { - await e.Channel.SendMessage($"{e.User.Mention} you don't have enough NadekoFlowers! \nYou still need {amount - pts} to be able to do this!"); - return; - } - var up = (usr.Id == e.User.Id) ? "yourself" : usr.Name; - await FlowersHandler.RemoveFlowersAsync(e.User, $"heal {up}", amount); - //healing - targetStats.HP = BASEHEALTH; - if (HP < 0) - { - //Could heal only for half HP? - stats[usr.Id].HP = (BASEHEALTH / 2); - await e.Channel.SendMessage($"{e.User.Name} revived {usr.Name} for 🌸"); - return; - } - await e.Channel.SendMessage($"{e.User.Name} healed {usr.Name} for {BASEHEALTH - HP} HP with a 🌸"); - return; - } - else - { - await e.Channel.SendMessage($"{usr.Name} already has full HP!"); - } - }); - - cgb.CreateCommand(Prefix + "type") - .Description($"Get the poketype of the target.\n**Usage**: {Prefix}type @someone") - .Parameter("target", ParameterType.Required) - .Do(async e => - { - var usr = e.Server.FindUsers(e.GetArg("target")).FirstOrDefault(); - if (usr == null) - { - await e.Channel.SendMessage("No such person."); - return; - } - var pType = getPokeType(usr.Id); - await e.Channel.SendMessage($"Type of {usr.Name} is **{pType.getName().ToLowerInvariant()}**{pType.getImage()}"); - - }); - - cgb.CreateCommand(Prefix + "defaultmoves") - .Description($"Sets the moves DB to the default state **OWNER ONLY**") - .AddCheck(SimpleCheckers.OwnerOnly()) - .Do(async e => - { - //clear DB - var db = DbHandler.Instance.GetAllRows(); - foreach (PokeMoves p in db) - { - DbHandler.Instance.Delete(p.Id); - } - - Dictionary defaultmoves = new Dictionary() - { - {"flame",1}, - {"hack",3}, - {"scare",13}, - {"splash",2}, - {"freeze",5}, - {"strike",4}, - {"surge",3}, - {"electrocute",3}, - {"surf",2}, - {"mellow",4}, - {"flamethrower",1}, - {"thundershock",3}, - {"lava",12}, - {"fly",9}, - {"control",10}, - {"sting",11}, - {"poison",7}, - {"confusion",10}, - {"breathe",14}, - {"ultrabash",6}, - {"punch",6}, - {"blind",15}, - {"earthquake",8}, - {"rocksmash",12}, - {"transform",0}, - {"bulldoze",8}, - {"frustate",0}, - {"confide",0}, - {"metronome",0}, - {"dracometeor",14}, - {"outrage",14} - }; - - foreach (KeyValuePair entry in defaultmoves) - { - DbHandler.Instance.InsertData(new Classes._DataModels.PokeMoves - { - move = entry.Key, - type = entry.Value - }); - } - - var str = "Reset moves.\n**Moves:**"; - //could sort, but meh - var dbMoves = DbHandler.Instance.GetAllRows(); - foreach (PokeMoves m in dbMoves) - { - var t = PokemonTypes.intToPokeType(m.type); - - str += $"\n{t.getImage()}{m.move}"; - } - - await e.Channel.SendMessage(str); - - }); - - cgb.CreateCommand(Prefix + "settype") - .Description($"Set your poketype. Costs a NadekoFlower.\n**Usage**: {Prefix}settype fire") - .Parameter("targetType", ParameterType.Required) - .Do(async e => - { - var targetTypeString = e.GetArg("targetType"); - var targetType = PokemonTypes.stringToPokeType(targetTypeString.ToUpperInvariant()); - if (targetType == null) - { - await e.Channel.SendMessage("Invalid type specified. Type must be one of:\nNORMAL, FIRE, WATER, ELECTRIC, GRASS, ICE, FIGHTING, POISON, GROUND, FLYING, PSYCHIC, BUG, ROCK, GHOST, DRAGON, DARK, STEEL"); - return; - } - if (targetType == getPokeType(e.User.Id)) - { - await e.Channel.SendMessage($"Your type is already {targetType.getName().ToLowerInvariant()}{targetType.getImage()}"); - return; - } - - //Payment~ - var amount = 1; - var pts = Classes.DbHandler.Instance.GetStateByUserId((long)e.User.Id)?.Value ?? 0; - if (pts < amount) - { - await e.Channel.SendMessage($"{e.User.Mention} you don't have enough NadekoFlowers! \nYou still need {amount - pts} to be able to do this!"); - return; - } - await FlowersHandler.RemoveFlowersAsync(e.User, $"set usertype to {targetTypeString}", amount); - //Actually changing the type here - var preTypes = DbHandler.Instance.GetAllRows(); - Dictionary Dict = preTypes.ToDictionary(x => x.UserId, y => y.Id); - if (Dict.ContainsKey((long)e.User.Id)) - { - //delete previous type - DbHandler.Instance.Delete(Dict[(long)e.User.Id]); - } - - DbHandler.Instance.InsertData(new Classes._DataModels.PokeTypes - { - UserId = (long)e.User.Id, - type = targetType.getNum() - }); - - //Now for the response - - await e.Channel.SendMessage($"Set type of {e.User.Mention} to {targetTypeString}{targetType.getImage()} for a 🌸"); - }); - }); - } - - - - - private int getDamage(PokemonTypes.PokeType usertype, PokemonTypes.PokeType targetType) - { - Random rng = new Random(); - int damage = rng.Next(40, 60); - double multiplier = 1; - multiplier = usertype.getMagnifier(targetType); - damage = (int)(damage * multiplier); - return damage; - } - - private PokemonTypes.PokeType getPokeType(ulong id) - { - - var db = DbHandler.Instance.GetAllRows(); - Dictionary setTypes = db.ToDictionary(x => x.UserId, y => y.type); - if (setTypes.ContainsKey((long)id)) - { - return PokemonTypes.intToPokeType(setTypes[(long)id]); - } - - int remainder = (int)id % 16; - - return PokemonTypes.intToPokeType(remainder); - - - } - - private Pokestats defaultStats() - { - Pokestats s = new Pokestats(); - s.HP = BASEHEALTH; - return s; - } - - - } - class Pokestats - { - //Health left - public int HP { get; set; } = 500; - //Amount of moves made since last time attacked - public int movesMade { get; set; } = 0; - //Last people attacked - public List lastAttacked { get; set; } = new List(); - } -} - - -//Not sure this is what you wanted? - - - -namespace NadekoBot.Modules.pokegame.poketypes -{ - public class PokemonTypes - { - public interface PokeType - { - string getImage(); - string getName(); - int getNum(); - List getMoves(); - double getMagnifier(PokeType target); - void updateMoves(); - } - public static PokeType stringToPokeType(string newType) - { - - foreach (PokeType t in typeList) - { - if (t.getName() == newType) - { - return t; - } - } - return null; - } - - public static List typeList = new List() - { - new Type_NORMAL(), - new Type_FIRE(), - new Type_WATER(), - new Type_ELECTRIC(), - new Type_GRASS(), - new Type_ICE(), - new Type_FIGHTING(), - new Type_POISON(), - new Type_GROUND(), - new Type_FLYING(), - new Type_PSYCHIC(), - new Type_BUG(), - new Type_ROCK(), - new Type_GHOST(), - new Type_DRAGON(), - new Type_DARK(), - new Type_STEEL() - }; - - public static PokeType intToPokeType(int id) - { - foreach (PokeType t in typeList) - { - if (t.getNum() == id) - { - return t; - } - } - return null; - } - - class Type_NORMAL : PokeType - { - static readonly string name = "NORMAL"; - public static int type_num = 0; - - public double getMagnifier(PokeType target) - { - switch (target.getName()) - { - - case "ROCK": return 0.5; - case "GHOST": return 0; - case "STEEL": return 0.5; - default: return 1; - } - } - List moves = new List(); - - public List getMoves() - { - updateMoves(); - return moves; - } - - - public string getName() - { - return name; - } - - public void updateMoves() - { - var db = DbHandler.Instance.GetAllRows(); - foreach (PokeMoves p in db) - { - if (p.type == type_num) - { - if (!moves.Contains(p.move)) - { - moves.Add(p.move); - } - } - } - } - - public string getImage() - { - return "⭕️"; - } - - public int getNum() - { - return type_num; - } - } - class Type_FIRE : PokeType - { - static readonly string name = "FIRE"; - public static int type_num = 1; - - public double getMagnifier(PokeType target) - { - switch (target.getName()) - { - - case "FIRE": return 0.5; - case "WATER": return 0.5; - case "GRASS": return 2; - case "ICE": return 2; - case "BUG": return 2; - case "ROCK": return 0.5; - case "DRAGON": return 0.5; - case "STEEL": return 2; - default: return 1; - } - } - List moves = new List(); - - public List getMoves() - { - updateMoves(); - return moves; - } - - - public string getName() - { - return name; - } - - public void updateMoves() - { - var db = DbHandler.Instance.GetAllRows(); - foreach (PokeMoves p in db) - { - if (p.type == type_num) - { - if (!moves.Contains(p.move)) - { - moves.Add(p.move); - } - } - } - } - - public string getImage() - { - return "🔥"; - } - - public int getNum() - { - return type_num; - } - } - class Type_WATER : PokeType - { - static readonly string name = "WATER"; - public static int type_num = 2; - - public double getMagnifier(PokeType target) - { - switch (target.getName()) - { - - case "FIRE": return 2; - case "WATER": return 0.5; - case "GRASS": return 0.5; - case "GROUND": return 2; - case "ROCK": return 2; - case "DRAGON": return 0.5; - default: return 1; - } - } - List moves = new List(); - - public List getMoves() - { - updateMoves(); - return moves; - } - - - public string getName() - { - return name; - } - - public void updateMoves() - { - var db = DbHandler.Instance.GetAllRows(); - foreach (PokeMoves p in db) - { - if (p.type == type_num) - { - if (!moves.Contains(p.move)) - { - moves.Add(p.move); - } - } - } - } - public string getImage() - { - return "💦"; - } - - public int getNum() - { - return type_num; - } - } - class Type_ELECTRIC : PokeType - { - static readonly string name = "ELECTRIC"; - public static int type_num = 3; - - public double getMagnifier(PokeType target) - { - switch (target.getName()) - { - - case "WATER": return 2; - case "ELECTRIC": return 0.5; - case "GRASS": return 2; - case "GROUND": return 0; - case "FLYING": return 2; - case "DRAGON": return 0.5; - default: return 1; - } - } - List moves = new List(); - - public List getMoves() - { - updateMoves(); - return moves; - } - - - public string getName() - { - return name; - } - - public void updateMoves() - { - var db = DbHandler.Instance.GetAllRows(); - foreach (PokeMoves p in db) - { - if (p.type == type_num) - { - if (!moves.Contains(p.move)) - { - moves.Add(p.move); - } - } - } - } - public string getImage() - { - return "⚡️"; - } - - public int getNum() - { - return type_num; - } - } - class Type_GRASS : PokeType - { - static readonly string name = "GRASS"; - public static int type_num = 4; - - public double getMagnifier(PokeType target) - { - switch (target.getName()) - { - - case "FIRE": return 0.5; - case "WATER": return 0.5; - case "GRASS": return 2; - case "ICE": return 2; - case "BUG": return 2; - case "ROCK": return 0.5; - case "DRAGON": return 0.5; - case "STEEL": return 2; - default: return 1; - } - } - List moves = new List(); - - public List getMoves() - { - updateMoves(); - return moves; - } - - - public string getName() - { - return name; - } - - public void updateMoves() - { - var db = DbHandler.Instance.GetAllRows(); - foreach (PokeMoves p in db) - { - if (p.type == type_num) - { - if (!moves.Contains(p.move)) - { - moves.Add(p.move); - } - } - } - } - public string getImage() - { - return "🌿"; - } - - public int getNum() - { - return type_num; - } - } - class Type_ICE : PokeType - { - static readonly string name = "ICE"; - public static int type_num = 5; - - public double getMagnifier(PokeType target) - { - switch (target.getName()) - { - - case "FIRE": return 0.5; - case "WATER": return 0.5; - case "GRASS": return 2; - case "ICE": return 0.5; - case "GROUND": return 2; - case "FLYING": return 2; - case "DRAGON": return 2; - case "STEEL": return 0.5; - default: return 1; - } - } - List moves = new List(); - - public List getMoves() - { - updateMoves(); - return moves; - } - - - public string getName() - { - return name; - } - - public void updateMoves() - { - var db = DbHandler.Instance.GetAllRows(); - foreach (PokeMoves p in db) - { - if (p.type == type_num) - { - if (!moves.Contains(p.move)) - { - moves.Add(p.move); - } - } - } - } - public string getImage() - { - return "❄"; - } - - public int getNum() - { - return type_num; - } - } - class Type_FIGHTING : PokeType - { - static readonly string name = "FIGHTING"; - public static int type_num = 6; - - public double getMagnifier(PokeType target) - { - switch (target.getName()) - { - - case "NORMAL": return 2; - case "ICE": return 2; - case "POISON": return 0.5; - case "FLYING": return 0.5; - case "PSYCHIC": return 0.5; - case "BUG": return 0.5; - case "ROCK": return 2; - case "GHOST": return 0; - case "DARK": return 2; - case "STEEL": return 2; - default: return 1; - } - } - List moves = new List(); - - public List getMoves() - { - updateMoves(); - return moves; - } - - - public string getName() - { - return name; - } - - public void updateMoves() - { - var db = DbHandler.Instance.GetAllRows(); - foreach (PokeMoves p in db) - { - if (p.type == type_num) - { - if (!moves.Contains(p.move)) - { - moves.Add(p.move); - } - } - } - } - public string getImage() - { - return "✊"; - } - - public int getNum() - { - return type_num; - } - } - class Type_POISON : PokeType - { - static readonly string name = "POISON"; - public static int type_num = 7; - - public double getMagnifier(PokeType target) - { - switch (target.getName()) - { - - case "GRASS": return 2; - case "POISON": return 0.5; - case "GROUND": return 0.5; - case "ROCK": return 0.5; - case "GHOST": return 0.5; - case "STEEL": return 0; - default: return 1; - } - } - List moves = new List(); - - public List getMoves() - { - updateMoves(); - return moves; - } - - - public string getName() - { - return name; - } - - public void updateMoves() - { - var db = DbHandler.Instance.GetAllRows(); - foreach (PokeMoves p in db) - { - if (p.type == type_num) - { - if (!moves.Contains(p.move)) - { - moves.Add(p.move); - } - } - } - } - public string getImage() - { - return "☠"; - } - - public int getNum() - { - return type_num; - } - } - class Type_GROUND : PokeType - { - static readonly string name = "GROUND"; - public static int type_num = 8; - - public double getMagnifier(PokeType target) - { - switch (target.getName()) - { - - case "FIRE": return 2; - case "ELECTRIC": return 2; - case "GRASS": return 0.5; - case "POISON": return 0.5; - case "FLYING": return 0; - case "BUG": return 0.5; - case "ROCK": return 2; - case "STEEL": return 2; - default: return 1; - } - } - List moves = new List(); - - public List getMoves() - { - updateMoves(); - return moves; - } - - - public string getName() - { - return name; - } - - public void updateMoves() - { - var db = DbHandler.Instance.GetAllRows(); - foreach (PokeMoves p in db) - { - if (p.type == type_num) - { - if (!moves.Contains(p.move)) - { - moves.Add(p.move); - } - } - } - } - - public string getImage() - { - return "🗻"; - } - - public int getNum() - { - return type_num; - } - } - class Type_FLYING : PokeType - { - static readonly string name = "FLYING"; - public static int type_num = 9; - - public double getMagnifier(PokeType target) - { - switch (target.getName()) - { - - case "ELECTRIC": return 0.5; - case "GRASS": return 2; - case "FIGHTING": return 2; - case "BUG": return 2; - case "ROCK": return 0.5; - case "STEEL": return 0.5; - default: return 1; - } - } - List moves = new List(); - - public List getMoves() - { - updateMoves(); - return moves; - } - - - public string getName() - { - return name; - } - - public void updateMoves() - { - var db = DbHandler.Instance.GetAllRows(); - foreach (PokeMoves p in db) - { - if (p.type == type_num) - { - if (!moves.Contains(p.move)) - { - moves.Add(p.move); - } - } - } - } - - public string getImage() - { - return "☁"; - } - - public int getNum() - { - return type_num; - } - } - class Type_PSYCHIC : PokeType - { - static readonly string name = "PSYCHIC"; - public static int type_num = 10; - - public double getMagnifier(PokeType target) - { - switch (target.getName()) - { - - case "FIGHTING": return 2; - case "POISON": return 2; - case "PSYCHIC": return 0.5; - case "DARK": return 0; - case "STEEL": return 0.5; - default: return 1; - } - } - List moves = new List(); - - public List getMoves() - { - updateMoves(); - return moves; - } - - - public string getName() - { - return name; - } - - public void updateMoves() - { - var db = DbHandler.Instance.GetAllRows(); - foreach (PokeMoves p in db) - { - if (p.type == type_num) - { - if (!moves.Contains(p.move)) - { - moves.Add(p.move); - } - } - } - } - - public string getImage() - { - return "💫"; - } - - public int getNum() - { - return type_num; - } - } - class Type_BUG : PokeType - { - static readonly string name = "BUG"; - public static int type_num = 11; - - public double getMagnifier(PokeType target) - { - switch (target.getName()) - { - - case "FIRE": return 0.5; - case "GRASS": return 2; - case "FIGHTING": return 0.5; - case "POISON": return 0.5; - case "FLYING": return 0.5; - case "PSYCHIC": return 2; - case "ROCK": return 0.5; - case "DARK": return 2; - case "STEEL": return 0.5; - default: return 1; - } - } - List moves = new List(); - - public List getMoves() - { - updateMoves(); - return moves; - } - - - public string getName() - { - return name; - } - - public void updateMoves() - { - var db = DbHandler.Instance.GetAllRows(); - foreach (PokeMoves p in db) - { - if (p.type == type_num) - { - if (!moves.Contains(p.move)) - { - moves.Add(p.move); - } - } - } - } - - public string getImage() - { - return "🐛"; - } - - public int getNum() - { - return type_num; - } - } - class Type_ROCK : PokeType - { - static readonly string name = "ROCK"; - public static int type_num = 12; - - public double getMagnifier(PokeType target) - { - switch (target.getName()) - { - - case "FIRE": return 2; - case "ICE": return 2; - case "FIGHTING": return 0.5; - case "GROUND": return 0.5; - case "FLYING": return 2; - case "BUG": return 2; - case "STEEL": return 0.5; - default: return 1; - } - } - List moves = new List(); - - public List getMoves() - { - updateMoves(); - return moves; - } - - - public string getName() - { - return name; - } - - public void updateMoves() - { - var db = DbHandler.Instance.GetAllRows(); - foreach (PokeMoves p in db) - { - if (p.type == type_num) - { - if (!moves.Contains(p.move)) - { - moves.Add(p.move); - } - } - } - } - - public string getImage() - { - return "💎"; - } - - public int getNum() - { - return type_num; - } - } - class Type_GHOST : PokeType - { - static readonly string name = "GHOST"; - public static int type_num = 13; - - public double getMagnifier(PokeType target) - { - switch (target.getName()) - { - - case "NORMAL": return 0; - case "PSYCHIC": return 2; - case "GHOST": return 2; - case "DARK": return 0.5; - case "STEEL": return 0.5; - default: return 1; - } - } - List moves = new List(); - - public List getMoves() - { - updateMoves(); - return moves; - } - - - public string getName() - { - return name; - } - - public void updateMoves() - { - var db = DbHandler.Instance.GetAllRows(); - foreach (PokeMoves p in db) - { - if (p.type == type_num) - { - if (!moves.Contains(p.move)) - { - moves.Add(p.move); - } - } - } - } - - public string getImage() - { - return "👻"; - } - - public int getNum() - { - return type_num; - } - } - class Type_DRAGON : PokeType - { - static readonly string name = "DRAGON"; - public static int type_num = 14; - - public double getMagnifier(PokeType target) - { - switch (target.getName()) - { - - case "DRAGON": return 2; - case "STEEL": return 0.5; - default: return 1; - } - } - List moves = new List(); - - public List getMoves() - { - updateMoves(); - return moves; - } - - - public string getName() - { - return name; - } - - public void updateMoves() - { - var db = DbHandler.Instance.GetAllRows(); - foreach (PokeMoves p in db) - { - if (p.type == type_num) - { - if (!moves.Contains(p.move)) - { - moves.Add(p.move); - } - } - } - } - - public string getImage() - { - return "🐉"; - } - - public int getNum() - { - return type_num; - } - } - class Type_DARK : PokeType - { - static readonly string name = "DARK"; - public static int type_num = 15; - - public double getMagnifier(PokeType target) - { - switch (target.getName()) - { - - case "FIGHTING": return 0.5; - case "PSYCHIC": return 2; - case "GHOST": return 2; - case "DARK": return 0.5; - case "STEEL": return 0.5; - default: return 1; - } - } - List moves = new List(); - - public List getMoves() - { - updateMoves(); - return moves; - } - - - public string getName() - { - return name; - } - - public void updateMoves() - { - var db = DbHandler.Instance.GetAllRows(); - foreach (PokeMoves p in db) - { - if (p.type == type_num) - { - if (!moves.Contains(p.move)) - { - moves.Add(p.move); - } - } - } - } - - public string getImage() - { - return "🕶"; - } - - public int getNum() - { - return type_num; - } - } - class Type_STEEL : PokeType - { - static readonly string name = "STEEL"; - public static int type_num = -1; - - public double getMagnifier(PokeType target) - { - switch (target.getName()) - { - - case "FIRE": return 0.5; - case "WATER": return 0.5; - case "ELECTRIC": return 0.5; - case "ICE": return 2; - case "ROCK": return 2; - case "STEEL": return 0.5; - default: return 1; - } - } - List moves = new List(); - - public List getMoves() - { - updateMoves(); - return moves; - } - - - public string getName() - { - return name; - } - - public void updateMoves() - { - var db = DbHandler.Instance.GetAllRows(); - foreach (PokeMoves p in db) - { - if (p.type == type_num) - { - if (!moves.Contains(p.move)) - { - moves.Add(p.move); - } - } - } - } - public string getImage() - { - return "🔩"; - } - - public int getNum() - { - return type_num; - } - } - - } -} - - diff --git a/NadekoBot/NadekoBot.cs b/NadekoBot/NadekoBot.cs index 96905743..d3e8df01 100644 --- a/NadekoBot/NadekoBot.cs +++ b/NadekoBot/NadekoBot.cs @@ -6,7 +6,7 @@ using NadekoBot.Classes.JSONModels; using NadekoBot.Commands; using NadekoBot.Modules; using NadekoBot.Modules.Gambling; -using NadekoBot.Modules.pokegame; +using NadekoBot.Modules.Pokemon; using Newtonsoft.Json; using System; using System.Collections.Generic; @@ -166,7 +166,7 @@ namespace NadekoBot modules.Add(new Searches(), "Searches", ModuleFilter.None); modules.Add(new NSFW(), "NSFW", ModuleFilter.None); modules.Add(new ClashOfClans(), "ClashOfClans", ModuleFilter.None); - modules.Add(new Pokegame(), "Pokegame", ModuleFilter.None); + modules.Add(new PokemonGame(), "Pokegame", ModuleFilter.None); if (!string.IsNullOrWhiteSpace(Creds.TrelloAppKey)) modules.Add(new Trello(), "Trello", ModuleFilter.None); diff --git a/NadekoBot/NadekoBot.csproj b/NadekoBot/NadekoBot.csproj index 46d81154..c1e5e3ea 100644 --- a/NadekoBot/NadekoBot.csproj +++ b/NadekoBot/NadekoBot.csproj @@ -188,7 +188,26 @@ - + + + + + + + + + + + + + + + + + + + +