PokeGame work, initialisation of database unstable, need to do with sql-request
This commit is contained in:
parent
12dc9af8e6
commit
21b2f1252a
@ -1,17 +1,17 @@
|
|||||||
using Discord;
|
|
||||||
using Discord.Commands;
|
using Discord.Commands;
|
||||||
using NadekoBot.Attributes;
|
using NadekoBot.Attributes;
|
||||||
using NadekoBot.Extensions;
|
using NadekoBot.Extensions;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
|
||||||
using System.Threading.Tasks;
|
|
||||||
using NadekoBot.Services;
|
using NadekoBot.Services;
|
||||||
using Discord.WebSocket;
|
|
||||||
using NadekoBot.Services.Database.Models;
|
using NadekoBot.Services.Database.Models;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using Discord;
|
||||||
|
using NLog;
|
||||||
|
using System;
|
||||||
|
using Newtonsoft.Json;
|
||||||
|
using System.IO;
|
||||||
using System.Collections.Concurrent;
|
using System.Collections.Concurrent;
|
||||||
using System.Linq;
|
|
||||||
|
|
||||||
|
|
||||||
namespace NadekoBot.Modules.Pokemon
|
namespace NadekoBot.Modules.Pokemon
|
||||||
{
|
{
|
||||||
@ -23,30 +23,27 @@ namespace NadekoBot.Modules.Pokemon
|
|||||||
public static string CurrencyPluralName { get; set; }
|
public static string CurrencyPluralName { get; set; }
|
||||||
public static string CurrencySign { get; set; }
|
public static string CurrencySign { get; set; }
|
||||||
|
|
||||||
public Gambling(ILocalization loc, CommandService cmds, ShardedDiscordClient client) : base(loc, cmds, client)
|
private static List<PokemonType> PokemonTypes = new List<PokemonType>();
|
||||||
{
|
private static ConcurrentDictionary<ulong, PokeStats> Stats = new ConcurrentDictionary<ulong, PokeStats>();
|
||||||
using (var uow = DbHandler.UnitOfWork())
|
|
||||||
{
|
|
||||||
var conf = uow.BotConfig.GetOrCreate();
|
|
||||||
|
|
||||||
CurrencyName = conf.CurrencyName;
|
public const string PokemonTypesFile = "data/pokemon_types.json";
|
||||||
CurrencySign = conf.CurrencySign;
|
|
||||||
CurrencyPluralName = conf.CurrencyPluralName;
|
private Logger _pokelog { get; }
|
||||||
|
|
||||||
|
public PokemonModule(ILocalization loc, CommandService cmds, ShardedDiscordClient client) : base(loc, cmds, client)
|
||||||
|
{
|
||||||
|
_pokelog = LogManager.GetCurrentClassLogger();
|
||||||
|
if (File.Exists(PokemonTypesFile))
|
||||||
|
{
|
||||||
|
PokemonTypes = JsonConvert.DeserializeObject<List<PokemonType>>(File.ReadAllText(PokemonTypesFile));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_pokelog.Warn(PokemonTypesFile + " is missing. Pokemon types not loaded.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
class PokemonModule : DiscordModule
|
|
||||||
{
|
|
||||||
public override string Prefix { get; } = NadekoBot.Config.CommandPrefixes.Pokemon;
|
|
||||||
|
|
||||||
private ConcurrentDictionary<ulong, PokeStats> Stats = new ConcurrentDictionary<ulong, PokeStats>();
|
|
||||||
|
|
||||||
public PokemonModule()
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private int GetDamage(PokemonType usertype, PokemonType targetType)
|
private int GetDamage(PokemonType usertype, PokemonType targetType)
|
||||||
{
|
{
|
||||||
var rng = new Random();
|
var rng = new Random();
|
||||||
@ -63,20 +60,25 @@ namespace NadekoBot.Modules.Pokemon
|
|||||||
return damage;
|
return damage;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private PokemonType GetPokeType(ulong id)
|
private PokemonType GetPokeType(ulong id)
|
||||||
{
|
{
|
||||||
|
|
||||||
var db = DbHandler.Instance.GetAllRows<UserPokeTypes>();
|
Dictionary<long, string> setTypes;
|
||||||
Dictionary<long, string> setTypes = db.ToDictionary(x => x.UserId, y => y.type);
|
using (var uow = DbHandler.UnitOfWork())
|
||||||
|
{
|
||||||
|
setTypes = uow.PokeGame.GetAll().ToDictionary(x => x.UserId, y => y.type);
|
||||||
|
}
|
||||||
|
|
||||||
if (setTypes.ContainsKey((long)id))
|
if (setTypes.ContainsKey((long)id))
|
||||||
{
|
{
|
||||||
return stringToPokemonType(setTypes[(long)id]);
|
return stringToPokemonType(setTypes[(long)id]);
|
||||||
}
|
}
|
||||||
int count = NadekoBot.Config.PokemonTypes.Count;
|
int count = PokemonTypes.Count;
|
||||||
|
|
||||||
int remainder = Math.Abs((int)(id % (ulong)count));
|
int remainder = Math.Abs((int)(id % (ulong)count));
|
||||||
|
|
||||||
return NadekoBot.Config.PokemonTypes[remainder];
|
return PokemonTypes[remainder];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -84,7 +86,7 @@ namespace NadekoBot.Modules.Pokemon
|
|||||||
private PokemonType stringToPokemonType(string v)
|
private PokemonType stringToPokemonType(string v)
|
||||||
{
|
{
|
||||||
var str = v.ToUpperInvariant();
|
var str = v.ToUpperInvariant();
|
||||||
var list = NadekoBot.Config.PokemonTypes;
|
var list = PokemonTypes;
|
||||||
foreach (PokemonType p in list)
|
foreach (PokemonType p in list)
|
||||||
{
|
{
|
||||||
if (str == p.Name)
|
if (str == p.Name)
|
||||||
@ -95,266 +97,279 @@ namespace NadekoBot.Modules.Pokemon
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Install(ModuleManager manager)
|
|
||||||
|
[NadekoCommand, Usage, Description, Aliases]
|
||||||
|
[RequireContext(ContextType.Guild)]
|
||||||
|
public async Task Attack(IUserMessage umsg, string move, IGuildUser targetUser = null)
|
||||||
{
|
{
|
||||||
manager.CreateCommands("", cgb =>
|
var channel = (ITextChannel)umsg.Channel;
|
||||||
|
IGuildUser user = (IGuildUser)umsg.Author;
|
||||||
|
|
||||||
|
if (string.IsNullOrWhiteSpace(move)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (targetUser == null)
|
||||||
{
|
{
|
||||||
cgb.AddCheck(PermissionChecker.Instance);
|
await channel.SendMessageAsync("No such person.").ConfigureAwait(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else if (targetUser == user)
|
||||||
|
{
|
||||||
|
await channel.SendMessageAsync("You can't attack yourself.").ConfigureAwait(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
commands.ForEach(cmd => cmd.Init(cgb));
|
|
||||||
|
|
||||||
cgb.CreateCommand(Prefix + "attack")
|
// Checking stats first, then move
|
||||||
.Description($"Attacks a target with the given move. Use `{Prefix}movelist` to see a list of moves your type can use. | `{Prefix}attack \"vine whip\" @someguy`")
|
//Set up the userstats
|
||||||
.Parameter("move", ParameterType.Required)
|
PokeStats userStats;
|
||||||
.Parameter("target", ParameterType.Unparsed)
|
userStats = Stats.GetOrAdd(user.Id, new PokeStats());
|
||||||
.Do(async e =>
|
|
||||||
{
|
|
||||||
var move = e.GetArg("move");
|
|
||||||
var targetStr = e.GetArg("target")?.Trim();
|
|
||||||
if (string.IsNullOrWhiteSpace(targetStr))
|
|
||||||
return;
|
|
||||||
var target = e.Server.FindUsers(targetStr).FirstOrDefault();
|
|
||||||
if (target == null)
|
|
||||||
{
|
|
||||||
await e.Channel.SendMessage("No such person.").ConfigureAwait(false);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
else if (target == e.User)
|
|
||||||
{
|
|
||||||
await e.Channel.SendMessage("You can't attack yourself.").ConfigureAwait(false);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// Checking stats first, then move
|
|
||||||
//Set up the userstats
|
|
||||||
PokeStats userStats;
|
|
||||||
userStats = Stats.GetOrAdd(e.User.Id, new PokeStats());
|
|
||||||
|
|
||||||
//Check if able to move
|
//Check if able to move
|
||||||
//User not able if HP < 0, has made more than 4 attacks
|
//User not able if HP < 0, has made more than 4 attacks
|
||||||
if (userStats.Hp < 0)
|
if (userStats.Hp < 0)
|
||||||
{
|
{
|
||||||
await e.Channel.SendMessage($"{e.User.Mention} has fainted and was not able to move!").ConfigureAwait(false);
|
await channel.SendMessageAsync($"{user.Mention} has fainted and was not able to move!").ConfigureAwait(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (userStats.MovesMade >= 5)
|
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!").ConfigureAwait(false);
|
await channel.SendMessageAsync($"{user.Mention} has used too many moves in a row and was not able to move!").ConfigureAwait(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (userStats.LastAttacked.Contains(target.Id))
|
if (userStats.LastAttacked.Contains(targetUser.Id))
|
||||||
{
|
{
|
||||||
await e.Channel.SendMessage($"{e.User.Mention} can't attack again without retaliation!").ConfigureAwait(false);
|
await channel.SendMessageAsync($"{user.Mention} can't attack again without retaliation!").ConfigureAwait(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
//get target stats
|
//get target stats
|
||||||
PokeStats targetStats;
|
PokeStats targetStats;
|
||||||
targetStats = Stats.GetOrAdd(target.Id, new PokeStats());
|
targetStats = Stats.GetOrAdd(targetUser.Id, new PokeStats());
|
||||||
|
|
||||||
//If target's HP is below 0, no use attacking
|
//If target's HP is below 0, no use attacking
|
||||||
if (targetStats.Hp <= 0)
|
if (targetStats.Hp <= 0)
|
||||||
{
|
{
|
||||||
await e.Channel.SendMessage($"{target.Mention} has already fainted!").ConfigureAwait(false);
|
await channel.SendMessageAsync($"{targetUser.Mention} has already fainted!").ConfigureAwait(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
//Check whether move can be used
|
//Check whether move can be used
|
||||||
PokemonType userType = GetPokeType(e.User.Id);
|
PokemonType userType = GetPokeType(user.Id);
|
||||||
|
|
||||||
var enabledMoves = userType.Moves;
|
var enabledMoves = userType.Moves;
|
||||||
if (!enabledMoves.Contains(move.ToLowerInvariant()))
|
if (!enabledMoves.Contains(move.ToLowerInvariant()))
|
||||||
{
|
{
|
||||||
await e.Channel.SendMessage($"{e.User.Mention} was not able to use **{move}**, use `{Prefix}ml` to see moves you can use").ConfigureAwait(false);
|
await channel.SendMessageAsync($"{user.Mention} is not able to use **{move}**. Type {NadekoBot.ModulePrefixes[typeof(PokemonModule).Name]}ml to see moves").ConfigureAwait(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
//get target type
|
//get target type
|
||||||
PokemonType targetType = GetPokeType(target.Id);
|
PokemonType targetType = GetPokeType(targetUser.Id);
|
||||||
//generate damage
|
//generate damage
|
||||||
int damage = GetDamage(userType, targetType);
|
int damage = GetDamage(userType, targetType);
|
||||||
//apply damage to target
|
//apply damage to target
|
||||||
targetStats.Hp -= damage;
|
targetStats.Hp -= damage;
|
||||||
|
|
||||||
var response = $"{e.User.Mention} used **{move}**{userType.Icon} on {target.Mention}{targetType.Icon} for **{damage}** damage";
|
var response = $"{user.Mention} used **{move}**{userType.Icon} on {targetUser.Mention}{targetType.Icon} for **{damage}** damage";
|
||||||
|
|
||||||
//Damage type
|
//Damage type
|
||||||
if (damage < 40)
|
if (damage < 40)
|
||||||
{
|
{
|
||||||
response += "\nIt's not effective..";
|
response += "\nIt's not effective..";
|
||||||
}
|
}
|
||||||
else if (damage > 60)
|
else if (damage > 60)
|
||||||
{
|
{
|
||||||
response += "\nIt's super effective!";
|
response += "\nIt's super effective!";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
response += "\nIt's somewhat effective";
|
response += "\nIt's somewhat effective";
|
||||||
}
|
}
|
||||||
|
|
||||||
//check fainted
|
//check fainted
|
||||||
|
|
||||||
if (targetStats.Hp <= 0)
|
if (targetStats.Hp <= 0)
|
||||||
{
|
{
|
||||||
response += $"\n**{target.Name}** has fainted!";
|
response += $"\n**{targetUser.Username}** has fainted!";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
response += $"\n**{target.Name}** has {targetStats.Hp} HP remaining";
|
response += $"\n**{targetUser.Username}** has {targetStats.Hp} HP remaining";
|
||||||
}
|
}
|
||||||
|
|
||||||
//update other stats
|
//update other stats
|
||||||
userStats.LastAttacked.Add(target.Id);
|
userStats.LastAttacked.Add(targetUser.Id);
|
||||||
userStats.MovesMade++;
|
userStats.MovesMade++;
|
||||||
targetStats.MovesMade = 0;
|
targetStats.MovesMade = 0;
|
||||||
if (targetStats.LastAttacked.Contains(e.User.Id))
|
if (targetStats.LastAttacked.Contains(user.Id))
|
||||||
{
|
{
|
||||||
targetStats.LastAttacked.Remove(e.User.Id);
|
targetStats.LastAttacked.Remove(user.Id);
|
||||||
}
|
}
|
||||||
|
|
||||||
//update dictionary
|
//update dictionary
|
||||||
//This can stay the same right?
|
//This can stay the same right?
|
||||||
Stats[e.User.Id] = userStats;
|
Stats[user.Id] = userStats;
|
||||||
Stats[target.Id] = targetStats;
|
Stats[targetUser.Id] = targetStats;
|
||||||
|
|
||||||
await e.Channel.SendMessage(response).ConfigureAwait(false);
|
await channel.SendMessageAsync(response).ConfigureAwait(false);
|
||||||
});
|
|
||||||
|
|
||||||
cgb.CreateCommand(Prefix + "movelist")
|
|
||||||
.Alias(Prefix + "ml")
|
|
||||||
.Description($"Lists the moves you are able to use | `{Prefix}ml`")
|
|
||||||
.Do(async e =>
|
|
||||||
{
|
|
||||||
var userType = GetPokeType(e.User.Id);
|
|
||||||
var movesList = userType.Moves;
|
|
||||||
var str = $"**Moves for `{userType.Name}` type.**";
|
|
||||||
foreach (string m in movesList)
|
|
||||||
{
|
|
||||||
str += $"\n{userType.Icon}{m}";
|
|
||||||
}
|
|
||||||
await e.Channel.SendMessage(str).ConfigureAwait(false);
|
|
||||||
});
|
|
||||||
|
|
||||||
cgb.CreateCommand(Prefix + "heal")
|
|
||||||
.Description($"Heals someone. Revives those who fainted. Costs a {NadekoBot.Config.CurrencyName} | `{Prefix}heal @someone`")
|
|
||||||
.Parameter("target", ParameterType.Unparsed)
|
|
||||||
.Do(async e =>
|
|
||||||
{
|
|
||||||
var targetStr = e.GetArg("target")?.Trim();
|
|
||||||
if (string.IsNullOrWhiteSpace(targetStr))
|
|
||||||
return;
|
|
||||||
var usr = e.Server.FindUsers(targetStr).FirstOrDefault();
|
|
||||||
if (usr == null)
|
|
||||||
{
|
|
||||||
await e.Channel.SendMessage("No such person.").ConfigureAwait(false);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (Stats.ContainsKey(usr.Id))
|
|
||||||
{
|
|
||||||
|
|
||||||
var targetStats = Stats[usr.Id];
|
|
||||||
int HP = targetStats.Hp;
|
|
||||||
if (targetStats.Hp == targetStats.MaxHp)
|
|
||||||
{
|
|
||||||
await e.Channel.SendMessage($"{usr.Name} already has full HP!").ConfigureAwait(false);
|
|
||||||
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 {NadekoBot.Config.CurrencyName}s! \nYou still need {amount - pts} {NadekoBot.Config.CurrencySign} to be able to do this!").ConfigureAwait(false);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
var target = (usr.Id == e.User.Id) ? "yourself" : usr.Name;
|
|
||||||
await FlowersHandler.RemoveFlowers(e.User, $"Poke-Heal {target}", amount).ConfigureAwait(false);
|
|
||||||
//healing
|
|
||||||
targetStats.Hp = targetStats.MaxHp;
|
|
||||||
if (HP < 0)
|
|
||||||
{
|
|
||||||
//Could heal only for half HP?
|
|
||||||
Stats[usr.Id].Hp = (targetStats.MaxHp / 2);
|
|
||||||
await e.Channel.SendMessage($"{e.User.Name} revived {usr.Name} with one {NadekoBot.Config.CurrencySign}").ConfigureAwait(false);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
var vowelFirst = new[] { 'a', 'e', 'i', 'o', 'u' }.Contains(NadekoBot.Config.CurrencyName[0]);
|
|
||||||
await e.Channel.SendMessage($"{e.User.Name} healed {usr.Name} for {targetStats.MaxHp - HP} HP with {(vowelFirst ? "an" : "a")} {NadekoBot.Config.CurrencySign}").ConfigureAwait(false);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
await e.Channel.SendMessage($"{usr.Name} already has full HP!").ConfigureAwait(false);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
cgb.CreateCommand(Prefix + "type")
|
|
||||||
.Description($"Get the poketype of the target. | `{Prefix}type @someone`")
|
|
||||||
.Parameter("target", ParameterType.Unparsed)
|
|
||||||
.Do(async e =>
|
|
||||||
{
|
|
||||||
var usrStr = e.GetArg("target")?.Trim();
|
|
||||||
if (string.IsNullOrWhiteSpace(usrStr))
|
|
||||||
return;
|
|
||||||
var usr = e.Server.FindUsers(usrStr).FirstOrDefault();
|
|
||||||
if (usr == null)
|
|
||||||
{
|
|
||||||
await e.Channel.SendMessage("No such person.").ConfigureAwait(false);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
var pType = GetPokeType(usr.Id);
|
|
||||||
await e.Channel.SendMessage($"Type of {usr.Name} is **{pType.Name.ToLowerInvariant()}**{pType.Icon}").ConfigureAwait(false);
|
|
||||||
|
|
||||||
});
|
|
||||||
|
|
||||||
cgb.CreateCommand(Prefix + "settype")
|
|
||||||
.Description($"Set your poketype. Costs a {NadekoBot.Config.CurrencyName}. | `{Prefix}settype fire`")
|
|
||||||
.Parameter("targetType", ParameterType.Unparsed)
|
|
||||||
.Do(async e =>
|
|
||||||
{
|
|
||||||
var targetTypeStr = e.GetArg("targetType")?.ToUpperInvariant();
|
|
||||||
if (string.IsNullOrWhiteSpace(targetTypeStr))
|
|
||||||
return;
|
|
||||||
var targetType = stringToPokemonType(targetTypeStr);
|
|
||||||
if (targetType == null)
|
|
||||||
{
|
|
||||||
await e.Channel.SendMessage("Invalid type specified. Type must be one of:\n" + string.Join(", ", NadekoBot.Config.PokemonTypes.Select(t => t.Name.ToUpperInvariant()))).ConfigureAwait(false);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (targetType == GetPokeType(e.User.Id))
|
|
||||||
{
|
|
||||||
await e.Channel.SendMessage($"Your type is already {targetType.Name.ToLowerInvariant()}{targetType.Icon}").ConfigureAwait(false);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
//Payment~
|
|
||||||
var amount = 1;
|
|
||||||
var pts = DbHandler.Instance.GetStateByUserId((long)e.User.Id)?.Value ?? 0;
|
|
||||||
if (pts < amount)
|
|
||||||
{
|
|
||||||
await e.Channel.SendMessage($"{e.User.Mention} you don't have enough {NadekoBot.Config.CurrencyName}s! \nYou still need {amount - pts} {NadekoBot.Config.CurrencySign} to be able to do this!").ConfigureAwait(false);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
await FlowersHandler.RemoveFlowers(e.User, $"set usertype to {targetTypeStr}", amount).ConfigureAwait(false);
|
|
||||||
//Actually changing the type here
|
|
||||||
var preTypes = DbHandler.Instance.GetAllRows<UserPokeTypes>();
|
|
||||||
Dictionary<long, int> Dict = preTypes.ToDictionary(x => x.UserId, y => y.Id.Value);
|
|
||||||
if (Dict.ContainsKey((long)e.User.Id))
|
|
||||||
{
|
|
||||||
//delete previous type
|
|
||||||
DbHandler.Instance.Delete<UserPokeTypes>(Dict[(long)e.User.Id]);
|
|
||||||
}
|
|
||||||
|
|
||||||
DbHandler.Instance.Connection.Insert(new UserPokeTypes
|
|
||||||
{
|
|
||||||
UserId = (long)e.User.Id,
|
|
||||||
type = targetType.Name
|
|
||||||
}, typeof(UserPokeTypes));
|
|
||||||
|
|
||||||
//Now for the response
|
|
||||||
|
|
||||||
await e.Channel.SendMessage($"Set type of {e.User.Mention} to {targetTypeStr}{targetType.Icon} for a {NadekoBot.Config.CurrencySign}").ConfigureAwait(false);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
[NadekoCommand, Usage, Description, Aliases]
|
||||||
|
[RequireContext(ContextType.Guild)]
|
||||||
|
public async Task Movelist(IUserMessage umsg)
|
||||||
|
{
|
||||||
|
var channel = (ITextChannel)umsg.Channel;
|
||||||
|
IGuildUser user = (IGuildUser)umsg.Author;
|
||||||
|
|
||||||
|
var userType = GetPokeType(user.Id);
|
||||||
|
var movesList = userType.Moves;
|
||||||
|
var str = $"**Moves for `{userType.Name}` type.**";
|
||||||
|
foreach (string m in movesList)
|
||||||
|
{
|
||||||
|
str += $"\n{userType.Icon}{m}";
|
||||||
|
}
|
||||||
|
await channel.SendMessageAsync(str).ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
[NadekoCommand, Usage, Description, Aliases]
|
||||||
|
[RequireContext(ContextType.Guild)]
|
||||||
|
public async Task Heal(IUserMessage umsg, IGuildUser targetUser = null)
|
||||||
|
{
|
||||||
|
var channel = (ITextChannel)umsg.Channel;
|
||||||
|
IGuildUser user = (IGuildUser)umsg.Author;
|
||||||
|
|
||||||
|
if (targetUser == null) {
|
||||||
|
await channel.SendMessageAsync("No such person.").ConfigureAwait(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (Stats.ContainsKey(targetUser.Id))
|
||||||
|
{
|
||||||
|
var targetStats = Stats[targetUser.Id];
|
||||||
|
if (targetStats.Hp == targetStats.MaxHp)
|
||||||
|
{
|
||||||
|
await channel.SendMessageAsync($"{targetUser.Username} already has full HP!").ConfigureAwait(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
//Payment~
|
||||||
|
var amount = 1;
|
||||||
|
|
||||||
|
var target = (targetUser.Id == user.Id) ? "yourself" : targetUser.Username;
|
||||||
|
if (amount > 0)
|
||||||
|
{
|
||||||
|
if (!await CurrencyHandler.RemoveCurrencyAsync(user, $"Poke-Heal {target}", amount, true).ConfigureAwait(false))
|
||||||
|
{
|
||||||
|
try { await channel.SendMessageAsync($"{user.Mention} You don't have enough {CurrencyName}s.").ConfigureAwait(false); } catch { }
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//healing
|
||||||
|
targetStats.Hp = targetStats.MaxHp;
|
||||||
|
if (targetStats.Hp < 0)
|
||||||
|
{
|
||||||
|
//Could heal only for half HP?
|
||||||
|
Stats[targetUser.Id].Hp = (targetStats.MaxHp / 2);
|
||||||
|
if (target == "yourself")
|
||||||
|
{
|
||||||
|
await channel.SendMessageAsync($"You revived yourself with one {CurrencySign}").ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
await channel.SendMessageAsync($"{user.Username} revived {targetUser.Username} with one {CurrencySign}").ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
await channel.SendMessageAsync($"{user.Username} healed {targetUser.Username} with one {CurrencySign}").ConfigureAwait(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
await channel.SendMessageAsync($"{targetUser.Username} already has full HP!").ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
[NadekoCommand, Usage, Description, Aliases]
|
||||||
|
[RequireContext(ContextType.Guild)]
|
||||||
|
public async Task Type(IUserMessage umsg, IGuildUser targetUser = null)
|
||||||
|
{
|
||||||
|
var channel = (ITextChannel)umsg.Channel;
|
||||||
|
IGuildUser user = (IGuildUser)umsg.Author;
|
||||||
|
|
||||||
|
if (targetUser == null)
|
||||||
|
{
|
||||||
|
await channel.SendMessageAsync("No such person.").ConfigureAwait(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var pType = GetPokeType(targetUser.Id);
|
||||||
|
await channel.SendMessageAsync($"Type of {targetUser.Username} is **{pType.Name.ToLowerInvariant()}**{pType.Icon}").ConfigureAwait(false);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
[NadekoCommand, Usage, Description, Aliases]
|
||||||
|
[RequireContext(ContextType.Guild)]
|
||||||
|
public async Task Settype(IUserMessage umsg, [Remainder] string typeTargeted = null)
|
||||||
|
{
|
||||||
|
var channel = (ITextChannel)umsg.Channel;
|
||||||
|
IGuildUser user = (IGuildUser)umsg.Author;
|
||||||
|
|
||||||
|
if (string.IsNullOrWhiteSpace(typeTargeted))
|
||||||
|
return;
|
||||||
|
var targetType = stringToPokemonType(typeTargeted);
|
||||||
|
if (targetType == null)
|
||||||
|
{
|
||||||
|
await channel.SendMessageAsync("Invalid type specified. Type must be one of:\n" + string.Join(", ", PokemonTypes.Select(t => t.Name.ToUpperInvariant()))).ConfigureAwait(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (targetType == GetPokeType(user.Id))
|
||||||
|
{
|
||||||
|
await channel.SendMessageAsync($"Your type is already {targetType.Name.ToLowerInvariant()}{targetType.Icon}").ConfigureAwait(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
//Payment~
|
||||||
|
var amount = 1;
|
||||||
|
if (amount > 0)
|
||||||
|
{
|
||||||
|
if (!await CurrencyHandler.RemoveCurrencyAsync(user, $"{user.Username} change type to {typeTargeted}", amount, true).ConfigureAwait(false))
|
||||||
|
{
|
||||||
|
try { await channel.SendMessageAsync($"{user.Mention} You don't have enough {CurrencyName}s.").ConfigureAwait(false); } catch { }
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//Actually changing the type here
|
||||||
|
Dictionary<long, string> setTypes;
|
||||||
|
|
||||||
|
using (var uow = DbHandler.UnitOfWork())
|
||||||
|
{
|
||||||
|
setTypes = uow.PokeGame.GetAll().ToDictionary(x => x.UserId, y => y.type);
|
||||||
|
var pt = new UserPokeTypes
|
||||||
|
{
|
||||||
|
UserId = (long)user.Id,
|
||||||
|
type = targetType.Name,
|
||||||
|
};
|
||||||
|
if (!setTypes.ContainsKey((long)user.Id))
|
||||||
|
{
|
||||||
|
//create user in db
|
||||||
|
uow.PokeGame.Add(pt);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
//update user in db
|
||||||
|
uow.PokeGame.Update(pt);
|
||||||
|
}
|
||||||
|
await uow.CompleteAsync();
|
||||||
|
}
|
||||||
|
|
||||||
|
//Now for the response
|
||||||
|
await channel.SendMessageAsync($"Set type of {user.Mention} to {typeTargeted}{targetType.Icon} for a {CurrencySign}").ConfigureAwait(false);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
33
src/NadekoBot/Modules/Pokemon/PokemonType.cs
Normal file
33
src/NadekoBot/Modules/Pokemon/PokemonType.cs
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Text;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
|
namespace NadekoBot.Modules.Pokemon
|
||||||
|
{
|
||||||
|
public class PokemonType
|
||||||
|
{
|
||||||
|
public PokemonType(string n, string i, string[] m, List<PokemonMultiplier> multi)
|
||||||
|
{
|
||||||
|
Name = n;
|
||||||
|
Icon = i;
|
||||||
|
Moves = m;
|
||||||
|
Multipliers = multi;
|
||||||
|
}
|
||||||
|
public string Name { get; set; }
|
||||||
|
public List<PokemonMultiplier> Multipliers { get; set; }
|
||||||
|
public string Icon { get; set; }
|
||||||
|
public string[] Moves { get; set; }
|
||||||
|
}
|
||||||
|
public class PokemonMultiplier
|
||||||
|
{
|
||||||
|
public PokemonMultiplier(string t, double m)
|
||||||
|
{
|
||||||
|
Type = t;
|
||||||
|
Multiplication = m;
|
||||||
|
}
|
||||||
|
public string Type { get; set; }
|
||||||
|
public double Multiplication { get; set; }
|
||||||
|
}
|
||||||
|
}
|
@ -21,6 +21,7 @@ namespace NadekoBot.Services.Database
|
|||||||
ICurrencyRepository Currency { get; }
|
ICurrencyRepository Currency { get; }
|
||||||
ICurrencyTransactionsRepository CurrencyTransactions { get; }
|
ICurrencyTransactionsRepository CurrencyTransactions { get; }
|
||||||
IMusicPlaylistRepository MusicPlaylists { get; }
|
IMusicPlaylistRepository MusicPlaylists { get; }
|
||||||
|
IPokeGameRepository PokeGame { get; }
|
||||||
|
|
||||||
int Complete();
|
int Complete();
|
||||||
Task<int> CompleteAsync();
|
Task<int> CompleteAsync();
|
||||||
|
@ -7,7 +7,7 @@ using System.Threading.Tasks;
|
|||||||
|
|
||||||
namespace NadekoBot.Services.Database.Models
|
namespace NadekoBot.Services.Database.Models
|
||||||
{
|
{
|
||||||
class UserPokeTypes : DbEntity
|
public class UserPokeTypes : DbEntity
|
||||||
{
|
{
|
||||||
public long UserId { get; set; }
|
public long UserId { get; set; }
|
||||||
public string type { get; set; }
|
public string type { get; set; }
|
||||||
|
@ -22,6 +22,7 @@ namespace NadekoBot.Services.Database
|
|||||||
public DbSet<MusicPlaylist> MusicPlaylists { get; set; }
|
public DbSet<MusicPlaylist> MusicPlaylists { get; set; }
|
||||||
public DbSet<CustomReaction> CustomReactions { get; set; }
|
public DbSet<CustomReaction> CustomReactions { get; set; }
|
||||||
public DbSet<CurrencyTransaction> CurrencyTransactions { get; set; }
|
public DbSet<CurrencyTransaction> CurrencyTransactions { get; set; }
|
||||||
|
public DbSet<UserPokeTypes> PokeGame { get; set; }
|
||||||
|
|
||||||
//logging
|
//logging
|
||||||
public DbSet<LogSetting> LogSettings { get; set; }
|
public DbSet<LogSetting> LogSettings { get; set; }
|
||||||
@ -69,7 +70,8 @@ namespace NadekoBot.Services.Database
|
|||||||
new ModulePrefix() { ModuleName = "Permissions", Prefix = ";" },
|
new ModulePrefix() { ModuleName = "Permissions", Prefix = ";" },
|
||||||
new ModulePrefix() { ModuleName = "Pokemon", Prefix = ">" },
|
new ModulePrefix() { ModuleName = "Pokemon", Prefix = ">" },
|
||||||
new ModulePrefix() { ModuleName = "Utility", Prefix = "." },
|
new ModulePrefix() { ModuleName = "Utility", Prefix = "." },
|
||||||
new ModulePrefix() { ModuleName = "CustomReactions", Prefix = "." }
|
new ModulePrefix() { ModuleName = "CustomReactions", Prefix = "." },
|
||||||
|
new ModulePrefix() { ModuleName = "PokeGame", Prefix = ">" }
|
||||||
});
|
});
|
||||||
bc.RaceAnimals.AddRange(new HashSet<RaceAnimal>
|
bc.RaceAnimals.AddRange(new HashSet<RaceAnimal>
|
||||||
{
|
{
|
||||||
@ -218,6 +220,16 @@ namespace NadekoBot.Services.Database
|
|||||||
.OnDelete(Microsoft.EntityFrameworkCore.Metadata.DeleteBehavior.Cascade);
|
.OnDelete(Microsoft.EntityFrameworkCore.Metadata.DeleteBehavior.Cascade);
|
||||||
|
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
#region PokeGame
|
||||||
|
var pokeGameEntity = modelBuilder.Entity<UserPokeTypes>();
|
||||||
|
|
||||||
|
pokeGameEntity
|
||||||
|
.HasIndex(pt => pt.UserId)
|
||||||
|
.IsUnique();
|
||||||
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,10 @@
|
|||||||
|
using NadekoBot.Services.Database.Models;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
|
namespace NadekoBot.Services.Database.Repositories
|
||||||
|
{
|
||||||
|
public interface IPokeGameRepository : IRepository<UserPokeTypes>
|
||||||
|
{
|
||||||
|
//List<UserPokeTypes> GetAllPokeTypes();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,23 @@
|
|||||||
|
using NadekoBot.Services.Database.Models;
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Linq;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
|
||||||
|
namespace NadekoBot.Services.Database.Repositories.Impl
|
||||||
|
{
|
||||||
|
public class PokeGameRepository : Repository<UserPokeTypes>, IPokeGameRepository
|
||||||
|
{
|
||||||
|
public PokeGameRepository(DbContext context) : base(context)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
//List<UserPokeTypes> GetAllPokeTypes()
|
||||||
|
//{
|
||||||
|
// var toReturn = _set.Include(pt => pt.UserId).ToList();
|
||||||
|
// toReturn.ForEach(pt => pt.).ToList();
|
||||||
|
// return toReturn;
|
||||||
|
//}
|
||||||
|
}
|
||||||
|
}
|
@ -48,6 +48,9 @@ namespace NadekoBot.Services.Database
|
|||||||
private ICustomReactionRepository _customReactions;
|
private ICustomReactionRepository _customReactions;
|
||||||
public ICustomReactionRepository CustomReactions => _customReactions ?? (_customReactions = new CustomReactionsRepository(_context));
|
public ICustomReactionRepository CustomReactions => _customReactions ?? (_customReactions = new CustomReactionsRepository(_context));
|
||||||
|
|
||||||
|
private IPokeGameRepository _pokegame;
|
||||||
|
public IPokeGameRepository PokeGame => _pokegame ?? (_pokegame = new PokeGameRepository(_context));
|
||||||
|
|
||||||
public UnitOfWork(NadekoContext context)
|
public UnitOfWork(NadekoContext context)
|
||||||
{
|
{
|
||||||
_context = context;
|
_context = context;
|
||||||
|
Loading…
Reference in New Issue
Block a user