diff --git a/NadekoBot/Classes/JSONModels/Configuration.cs b/NadekoBot/Classes/JSONModels/Configuration.cs index dcd8920f..0de62d26 100644 --- a/NadekoBot/Classes/JSONModels/Configuration.cs +++ b/NadekoBot/Classes/JSONModels/Configuration.cs @@ -89,6 +89,7 @@ namespace NadekoBot.Classes.JSONModels { public string Gambling { get; set; } = "$"; public string Permissions { get; set; } = ";"; public string Programming { get; set; } = "%"; + public string Pokemon { get; set; } = "poke"; } public static class ConfigHandler { diff --git a/NadekoBot/Modules/Pokegame/Pokegame.cs b/NadekoBot/Modules/Pokegame/Pokegame.cs deleted file mode 100644 index 8bda3a9e..00000000 --- a/NadekoBot/Modules/Pokegame/Pokegame.cs +++ /dev/null @@ -1,419 +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; - -namespace NadekoBot.Modules.pokegame -{ - class Pokegame : DiscordModule - { - public override string Prefix { get; } = "poke"; - public readonly int BASEHEALTH = 500; - private Dictionary stats = new Dictionary(); - - 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.Required) - .Do(async e => - { - var move = e.GetArg("move"); - var target = e.Server.FindUsers(e.GetArg("target")).FirstOrDefault(); - if (target == null) - { - await e.Channel.SendMessage("No such person."); - return; - } - // Checking stats first, then move - //Set up the userstats - Pokestats userstats; - if (stats.ContainsKey(e.User.Id)) - { - userstats = stats[e.User.Id]; - } - else - { - //not really necessary now - userstats = defaultStats(); - stats.Add(e.User.Id, userstats); - } - //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; - if (stats.ContainsKey(target.Id)) - { - targetstats = stats[target.Id]; - } - else - { - targetstats = defaultStats(); - stats.Add(target.Id, targetstats); - } - //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 - pokegame.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 - pokegame.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 - 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); - var 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 pokegame.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; - } - - - } -} diff --git a/NadekoBot/Modules/Pokegame/pokestats.cs b/NadekoBot/Modules/Pokegame/pokestats.cs deleted file mode 100644 index 08c5da82..00000000 --- a/NadekoBot/Modules/Pokegame/pokestats.cs +++ /dev/null @@ -1,18 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace NadekoBot.Modules.pokegame -{ - 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(); - } -} diff --git a/NadekoBot/Modules/Pokegame/PokemonTypes.cs b/NadekoBot/Modules/PokemonModule.cs similarity index 61% rename from NadekoBot/Modules/Pokegame/PokemonTypes.cs rename to NadekoBot/Modules/PokemonModule.cs index b3304cce..616fce14 100644 --- a/NadekoBot/Modules/Pokegame/PokemonTypes.cs +++ b/NadekoBot/Modules/PokemonModule.cs @@ -1,15 +1,436 @@ -using NadekoBot.Classes; -using NadekoBot.Classes._DataModels; -using System; +using System; using System.Collections.Generic; using System.Linq; -using System.Reflection; 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 { @@ -24,7 +445,7 @@ namespace NadekoBot.Modules.pokegame } public static PokeType stringToPokeType(string newType) { - + foreach (PokeType t in typeList) { if (t.getName() == newType) @@ -58,7 +479,7 @@ namespace NadekoBot.Modules.pokegame public static PokeType intToPokeType(int id) { - foreach(PokeType t in typeList) + foreach (PokeType t in typeList) { if (t.getNum() == id) { @@ -68,7 +489,7 @@ namespace NadekoBot.Modules.pokegame return null; } - class Type_NORMAL : PokeType + class Type_NORMAL : PokeType { static readonly string name = "NORMAL"; public static int type_num = 0; @@ -123,7 +544,7 @@ namespace NadekoBot.Modules.pokegame return type_num; } } - class Type_FIRE : PokeType + class Type_FIRE : PokeType { static readonly string name = "FIRE"; public static int type_num = 1; @@ -183,7 +604,7 @@ namespace NadekoBot.Modules.pokegame return type_num; } } - class Type_WATER : PokeType + class Type_WATER : PokeType { static readonly string name = "WATER"; public static int type_num = 2; @@ -1057,16 +1478,4 @@ namespace NadekoBot.Modules.pokegame } } -namespace PokeTypeExtensions -{ - public static class PokeTypeExtension - { - - - static int numberToType(this NadekoBot.Modules.pokegame.PokemonTypes.PokeType t) - { - return t.getNum(); - } - } -} \ No newline at end of file diff --git a/NadekoBot/NadekoBot.csproj b/NadekoBot/NadekoBot.csproj index d45aefac..8da82223 100644 --- a/NadekoBot/NadekoBot.csproj +++ b/NadekoBot/NadekoBot.csproj @@ -186,9 +186,7 @@ - - - +