public async Task Battle(IUser user) { try { //if (Context.User.Id == user.Id) // await ReplyAsync("you can't battle your self"); EmbedBuilder builder = new EmbedBuilder { Color = Color.DarkTeal, Timestamp = DateTimeOffset.Now, Title = $"a battle betwean {Context.User.Username} and {user.Username}" }; Random rand = new Random(); BattleUser user1 = new BattleUser(Context.User.Id); BattleUser user2 = new BattleUser(user.Id); BattleInfo Info = new BattleInfo(); while (user1.Healt > 0.0 && user2.Healt > 0.0) { int turn = rand.Next(2); if (turn == 0) { int damage = rand.Next(int.Parse(user1.Damage[0]), int.Parse(user1.Damage[1])); double dealdamage = double.Parse(damage.ToString()) * user1.DamageMultiplier; user2.Healt -= dealdamage; Info.AddDamage(dealdamage); } else if (turn == 1) { int damage = rand.Next(int.Parse(user2.Damage[0]), int.Parse(user2.Damage[1])); double dealdamage = double.Parse(damage.ToString()) * user2.DamageMultiplier; user1.Healt -= dealdamage; Info.AddDamage(dealdamage); } Info.Addturn(); } if (user1.Healt > 0.0) { builder.AddField("Victory", $"{Context.User.Username} has won this match"); //user1.AddWin(); //user2.AddLoss(); } else { builder.AddField("Victory", $"{user.Username} has won this match"); //user1.AddLoss(); //user2.AddWin(); } builder.AddField("Battle info", $"Total damage dealt: {Info.TotalDamage}\nTotal turns taken: {Info.Totalturs}"); CommandUsed.TotalDamageAdd(Info.TotalDamage); await ReplyAsync("", false, builder.Build()); } catch (Exception ex) { Console.WriteLine(ex.ToString()); } }
private async Task HandleCommandAsync(SocketMessage arg) { string userpath = levelpath + arg.Author.Id + ".xml"; var msg = arg as SocketUserMessage; if (msg == null) { return; } if (msg.Author.Id == _client.CurrentUser.Id || msg.Author.IsBot) { return; } int pos = 0; LevelUser user = new LevelUser(); if (!File.Exists(userpath)) { Console.WriteLine(user.AddNewUserRank(arg.Author.Id.ToString())); } Ranking.CheckUser(userpath, arg.Author.Id.ToString(), mineinv, baginv, craftlist); UserInfo info = new UserInfo(arg.Author.Id); info.AddMessage(); if (msg.HasStringPrefix("%", ref pos) || msg.HasMentionPrefix(_client.CurrentUser, ref pos)) { var context = new SocketCommandContext(_client, msg); GuildChannel guild = new GuildChannel(context.Guild.Id); if (!guild.On || guild.Channels.Contains(arg.Channel.Id) == false || msg.Content == "%disable") { var result = await _commands.ExecuteAsync(context, pos, _services); if (!result.IsSuccess) { Utils.CustomErrors(msg, result, context); } else if (result.IsSuccess) { info.AddCommand(); Console.ForegroundColor = ConsoleColor.Cyan; Console.WriteLine($"{DateTime.Now,-19} [{msg.Channel.Name}] [{msg.Author.Id}] Used {msg.ToString()}"); Console.ForegroundColor = ConsoleColor.White; CommandUsed.CommandAdd(); } } else { var message = await context.Channel.GetMessageAsync(msg.Id); await message.DeleteAsync(); CommandUsed.ClearAdd(1); //await msg.Channel.SendMessageAsync("commands can't be used in this channel"); } } if (arg.Author.IsBot && arg.Author.Id != 372615866652557312) { return; } else { try { CommandUsed.GainedMessagesAdd(); Random rand = new Random(); user.Load(arg.Author.Id); int xp = rand.Next(1, 5); CommandUsed.TotalXpAdd(xp); user.GainXpUser(arg, xp); if (File.Exists($"./userimg.png")) { File.Delete($"./userimg.png"); } } catch (Exception ex) { Console.WriteLine($"User:{arg.Author.Id}" + ex.ToString()); } } }
public async Task Battle(IUser user) { try { //if (Context.User.Id == user.Id) // await ReplyAsync("you can't battle your self"); EmbedBuilder builder = new EmbedBuilder { Color = Color.DarkTeal, Title = $"a battle betwean {Context.User.Username} and {user.Username}" }; Random rand = new Random(); BattleUser[] users = { new BattleUser(Context.User.Id), new BattleUser(user.Id) }; UserInfo[] usersinfo = { new UserInfo(Context.User.Id), new UserInfo(user.Id) }; BattleInfo Info = new BattleInfo(); while (users[0].Healt > 0.0 && users[1].Healt > 0.0) { int turn = rand.Next(2); if (turn == 0) { int damage = rand.Next(4, 7); double dealdamage = (double)damage * users[0].DamageMultiplier; users[1].Healt -= dealdamage; Info.AddDamage(dealdamage); } else if (turn == 1) { int damage = rand.Next(4, 7); double dealdamage = (double)damage * users[1].DamageMultiplier; users[0].Healt -= dealdamage; Info.AddDamage(dealdamage); } Info.Addturn(); } if (users[0].Healt > 0.0) { builder.AddField("Victory", $"{Context.User.Username} has won this match with {users[0].Healt} health left"); if (Context.User.Id != user.Id) { usersinfo[0].AddWin(); usersinfo[1].AddLost(); } } else { builder.AddField("Victory", $"{user.Username} has won this match with {users[1].Healt} health left"); if (Context.User.Id != user.Id) { usersinfo[0].AddLost(); usersinfo[1].AddWin(); } } builder.AddField("Battle info", $"Total damage dealt: {Info.TotalDamage}\nTotal turns taken: {Info.Totalturs}"); CommandUsed.TotalDamageAdd(Info.TotalDamage); await ReplyAsync("", false, builder.Build()); } catch (Exception ex) { Console.WriteLine(ex.ToString()); } }