public async Task Initiative([Remainder] string skill = null) { var b = GetBattle(Context.Channel.Id); if (!b.Active) { await ReplyAsync("There is no encounter happening on this channel. Start one with `!Encounter Start`"); return; } Character c = GetCharacter(); skill = skill?.ToLower() ?? ""; if (c == null) { await ReplyAsync("You have no active character!"); return; } string[] Bonuses = new string[0]; if (BonusRegex.IsMatch(skill)) { Bonuses = BonusRegex.Matches(skill).Select(x => x.Value).ToArray(); foreach (var bo in Bonuses) { skill = skill.Replace(bo, ""); } skill = skill.Trim(); } var embed = new EmbedBuilder() .WithTitle(c.Name + " Rolled initiative!") .WithThumbnailUrl(c.ImageUrl); var values = await SheetService.GetValues(c); if (skill.NullorEmpty()) { var bonus = ((int)values["perception"]["bonus"] - (int)values["perception"]["penalty"]); try { var results = Roller.Roll("1d20 + " + bonus + (Bonuses.Length > 0 ? string.Join(" ", Bonuses) : "")); embed.WithDescription("Perception: " + results.ParseResult() + " = `" + results.Value + "`"); if (b.Participants.Any(x => x.Name.ToLower() == c.Name.ToLower())) { var i = b.Participants.FindIndex(x => x.Name.ToLower() == c.Name.ToLower()); b.Participants[i] = new Participant( ) { Initiative = (int)results.Value, Name = c.Name, Player = c.Owner }; b.Participants = b.Participants.OrderBy(x => x.Initiative).Reverse().ToList(); UpdateBattle(b); } else { b.Participants.Add(new Participant() { Initiative = (int)results.Value, Name = c.Name, Player = c.Owner }); b.Participants = b.Participants.OrderBy(x => x.Initiative).Reverse().ToList(); UpdateBattle(b); } } catch { await ReplyAsync("Something went wrong when rolling the dice, make sure you only added a bonus/penalty using +X or -X where x is an integer (No fractions or decimals)."); return; } } else { var sheet = await SheetService.GetFullSheet(c); var snk = from sk in sheet["skills"].Children() where ((string)sk["name"]).ToLower().StartsWith(skill.ToLower()) || (sk["lore"] != null && ((string)sk["lore"]).ToLower().StartsWith(skill.ToLower())) orderby sk["name"] select sk; if (snk.Count() == 0) { await ReplyAsync("You have no skill whose name starts with that."); return; } var s = snk.FirstOrDefault(); string name = (string)s["lore"] ?? (string)s["name"]; var bonus = (int)values[name.ToLower()]["bonus"] - (int)values[name.ToLower()]["penalty"]; try { var results = Roller.Roll("1d20 + " + bonus + (Bonuses.Length > 0 ? string.Join(" ", Bonuses) : "")); embed.WithDescription(name.Uppercase() + ": " + results.ParseResult() + " = `" + results.Value + "`"); if (b.Participants.Any(x => x.Name.ToLower() == c.Name.ToLower())) { var i = b.Participants.FindIndex(x => x.Name.ToLower() == c.Name.ToLower()); b.Participants[i] = new Participant() { Initiative = (int)results.Value, Name = c.Name, Player = c.Owner }; b.Participants = b.Participants.OrderBy(x => x.Initiative).Reverse().ToList(); UpdateBattle(b); } else { b.Participants.Add(new Participant() { Initiative = (int)results.Value, Name = c.Name, Player = c.Owner }); b.Participants = b.Participants.OrderBy(x => x.Initiative).Reverse().ToList(); UpdateBattle(b); } } catch { await ReplyAsync("Something went wrong when rolling the dice, make sure you only added a bonus/penalty using +X or -X where x is an integer (No fractions or decimals)."); return; } } Random randonGen = new Random(); Color randomColor = new Color(randonGen.Next(255), randonGen.Next(255), randonGen.Next(255)); embed.WithColor(randomColor); if (c.Color != null) { embed.WithColor(new Color(c.Color[0], c.Color[1], c.Color[2])); } await ReplyAsync(" ", embed.Build()); }
public async Task ability(Saves saves, params string[] args) { Character c; if (args.Length >= 1 && args.Contains("-c")) { c = GetCompanion(); if (c == null) { await ReplyAsync("You have no active companion."); return; } } else { c = GetCharacter(); if (c == null) { await ReplyAsync("You have no active character."); return; } } for (int i = 0; i < args.Length; i++) { if (!int.TryParse(args[i], out int a) && args[i].ToLower() != "-c" && args[i].ToLower() != "-f") { args[i] = " "; } } string arguments = string.Join(" ", args).Replace("-c", ""); var sheet = await SheetService.GetFullSheet(c); var values = await SheetService.GetValues(c); if (values == null || sheet == null) { var err = new EmbedBuilder() .WithTitle("Click here") .WithUrl("https://character.pf2.tools/?" + c.RemoteId) .WithDescription("Seems like we cannot fetch " + c.Name + "'s values. This is due to the fact values are only updated when you open the sheet in pf2.tools. To fix this, click the link above to generate those values."); await ReplyAsync("", err.Build()); return; } JToken bonus = null; string message = ""; switch ((int)saves) { case 1: bonus = ((int)values["strength"]["values"]).GetModifier(); message = c.Name + " makes a strength check!"; break; case 2: bonus = ((int)values["dexterity"]["values"]).GetModifier(); message = c.Name + " makes a dexterity check!"; break; case 3: bonus = ((int)values["constitution"]["values"]).GetModifier(); message = c.Name + " makes a constitution check!"; break; case 4: bonus = ((int)values["intelligence"]["values"]).GetModifier(); message = c.Name + " makes a intelligence check!"; break; case 5: bonus = ((int)values["wisdom"]["values"]).GetModifier(); message = c.Name + " makes a wisdom check!"; break; case 6: bonus = ((int)values["charisma"]["values"]).GetModifier(); message = c.Name + " makes a charisma check!"; break; } var result = Roller.Roll("d20 + " + bonus + arguments); var embed = new EmbedBuilder() .WithTitle(message) .WithThumbnailUrl(c.ImageUrl) .WithDescription(result.ParseResult() + "\nTotal = `" + result.Value + "`") .WithFooter((c.ValuesLastUpdated.Outdated() ? "⚠️ Couldn't retrieve updated values. Roll might not be accurate" : DateTime.Now.ToString())); Random randonGen = new Random(); Color randomColor = new Color(randonGen.Next(255), randonGen.Next(255), randonGen.Next(255)); embed.WithColor(randomColor); if (c.Color != null) { embed.WithColor(new Color(c.Color[0], c.Color[1], c.Color[2])); } await ReplyAsync(" ", embed.Build()); }
public async Task SkillCheck([Remainder] string Skill) { Character c; Skill = Skill.ToLower(); bool familiar = false; if (Skill.Contains("-c")) { c = GetCompanion(); if (c == null) { await ReplyAsync("You have no active companion."); return; } Skill = Skill.Replace("-c", "").Trim(); } else { c = GetCharacter(); if (c == null) { await ReplyAsync("You have no active character."); return; } } if (Skill.Contains("-f")) { familiar = true; Skill = Skill.Replace("-f", "".Trim()); } string[] Bonuses = new string[0]; if (BonusRegex.IsMatch(Skill)) { Bonuses = BonusRegex.Matches(Skill).Select(x => x.Value).ToArray(); foreach (var b in Bonuses) { Skill = Skill.Replace(b, ""); } Skill = Skill.Trim(); } var sheet = await SheetService.GetFullSheet(c); var values = await SheetService.GetValues(c); ; if (values == null || sheet == null) { var embed = new EmbedBuilder() .WithTitle("Click here") .WithUrl("https://character.pf2.tools/?" + c.RemoteId) .WithDescription("Seems like we cannot fetch " + c.Name + "'s values. This is due to the fact values are only updated when you open the sheet in pf2.tools. To fix this, click the link above to generate those values."); await ReplyAsync("", embed.Build()); return; } if (Skill == "perception" || Skill == "per" || Skill == "perc") { var embed = new EmbedBuilder(); JToken bonus; string message = ""; if (familiar) { if (c.Familiar.NullorEmpty()) { await ReplyAsync("You have no named familiars."); return; } bonus = (int)values["famperception " + c.Familiar]["bonus"] - (int)values["famperception " + c.Familiar]["penalty"];; message = c.Name + "'s familiar makes a Perception check!"; embed.WithThumbnailUrl(c.FamImg); } else { bonus = values["perception"]["bonus"] ?? 0; message = c.Name + " makes a Perception check!"; embed.WithThumbnailUrl(c.ImageUrl); } var result = Roller.Roll("d20 + " + bonus + (Bonuses.Length > 0?string.Join(" ", Bonuses):"")); embed.WithTitle(message) .WithDescription(result.ParseResult() + "\nTotal = `" + result.Value + "`") .WithFooter((c.ValuesLastUpdated.Outdated() ? "⚠️ Couldn't retrieve updated values. Roll might not be accurate" : DateTime.Now.ToString()));; Random randonGen = new Random(); Color randomColor = new Color(randonGen.Next(255), randonGen.Next(255), randonGen.Next(255)); embed.WithColor(randomColor); if (c.Color != null) { embed.WithColor(new Color(c.Color[0], c.Color[1], c.Color[2])); } await ReplyAsync("", embed.Build()); return; } else { var embed = new EmbedBuilder(); JToken bonus; string message = ""; if (familiar) { if (c.Familiar.NullorEmpty()) { await ReplyAsync("You have no named familiars."); return; } switch (Skill.ToLower()) { case "acrobatics": bonus = (int)values["famacrobatics " + c.Familiar]["bonus"] - (int)values["famacrobatics " + c.Familiar]["penalty"]; message = c.Name + "'s familiar makes an Acrobatics check!"; break; case "stealth": bonus = (int)values["famstealth " + c.Familiar]["bonus"] - (int)values["famstealth " + c.Familiar]["penalty"]; message = c.Name + "'s familiar makes a Stealth check!"; break; default: bonus = (int)values["famother " + c.Familiar]["bonus"] - (int)values["famother " + c.Familiar]["penalty"]; message = c.Name + "'s familiar makes a skill check!"; break; } embed.WithThumbnailUrl(c.FamImg); } else { var skill = from sk in sheet["skills"].Children() where ((string)sk["name"]).ToLower().StartsWith(Skill.ToLower()) || (sk["lore"] != null && ((string)sk["lore"]).ToLower().StartsWith(Skill.ToLower())) orderby sk["name"] select sk; if (skill.Count() == 0) { await ReplyAsync("You have no skill whose name starts with that."); return; } var s = skill.FirstOrDefault(); string name = (string)s["lore"] ?? (string)s["name"]; message = c.Name + " makes " + (name.StartsWithVowel() ? "an " : "a ") + name.Uppercase() + " check!"; bonus = values[name.ToLower()]["bonus"] ?? 0; embed.WithThumbnailUrl(c.ImageUrl); } var result = Roller.Roll("d20 + " + bonus + (Bonuses.Length > 0 ? string.Join(" ", Bonuses) : "")); embed.WithTitle(message) .WithDescription(result.ParseResult() + "\nTotal = `" + result.Value + "`") .WithFooter((c.ValuesLastUpdated.Outdated()? "⚠️ Couldn't retrieve updated values. Roll might not be accurate" : DateTime.Now.ToString())); Random randonGen = new Random(); Color randomColor = new Color(randonGen.Next(255), randonGen.Next(255), randonGen.Next(255)); embed.WithColor(randomColor); if (c.Color != null) { embed.WithColor(new Color(c.Color[0], c.Color[1], c.Color[2])); } await ReplyAsync(" ", embed.Build()); } }
public async Task Save(Saves Throw, params string[] args) { Character c; if (args.Length >= 1 && args.Contains("-c")) { c = GetCompanion(); if (c == null) { await ReplyAsync("You have no active companion."); return; } } else { c = GetCharacter(); if (c == null) { await ReplyAsync("You have no active character."); return; } } for (int i = 0; i < args.Length; i++) { if (!int.TryParse(args[i], out int a) && args[i].ToLower() != "-c" && args[i].ToLower() != "-f") { args[i] = " "; } } string arguments = string.Join(" ", args).Replace("-c", ""); var sheet = await SheetService.GetFullSheet(c); var values = await SheetService.GetValues(c); if (values == null || sheet == null) { var err = new EmbedBuilder() .WithTitle("Click here") .WithUrl("https://character.pf2.tools/?" + c.RemoteId) .WithDescription("Seems like we cannot fetch " + c.Name + "'s values. This is due to the fact values are only updated when you open the sheet in pf2.tools. To fix this, click the link above to generate those values."); await ReplyAsync("", err.Build()); return; } var embed = new EmbedBuilder(); int bonus = 0; string message = ""; if (args.Contains("-f")) { if (c.Familiar.NullorEmpty()) { await ReplyAsync("You have no named familiars."); return; } switch ((int)Throw) { case 1: bonus = (int)values["famfort " + c.Familiar]["bonus"] + (int)values["famfort " + c.Familiar]["penalty"]; message = c.Name + "'s familiar makes a fortitude check!"; break; case 2: bonus = (int)values["famref " + c.Familiar]["bonus"] + (int)values["famref " + c.Familiar]["penalty"]; message = c.Name + "'s familiar makes a reflex check!"; break; case 3: bonus = (int)values["famwill " + c.Familiar]["bonus"] + (int)values["famwill " + c.Familiar]["penalty"]; message = c.Name + "'s familiar makes a will check!"; break; } arguments = arguments.Replace("-f", ""); embed.WithThumbnailUrl(c.FamImg); } else { switch ((int)Throw) { case 1: bonus = (int)values["fortitude"]["bonus"] + (int)values["fortitude"]["penalty"]; message = c.Name + " makes a fortitude check!"; break; case 2: bonus = (int)values["reflex"]["bonus"] + (int)values["reflex"]["penalty"]; message = c.Name + " makes a reflex check!"; break; case 3: bonus = (int)values["will"]["bonus"] + (int)values["will"]["penalty"]; message = c.Name + " makes a will check!"; break; } embed.WithThumbnailUrl(c.ImageUrl); } var result = Roller.Roll("d20 + " + bonus + arguments); embed.WithTitle(message) .WithDescription(result.ParseResult() + "\nTotal = `" + result.Value + "`") .WithFooter((c.ValuesLastUpdated.Outdated() ? "⚠️ Couldn't retrieve updated values. Roll might not be accurate" : DateTime.Now.ToString())); Random randonGen = new Random(); Color randomColor = new Color(randonGen.Next(255), randonGen.Next(255), randonGen.Next(255)); embed.WithColor(randomColor); if (c.Color != null) { embed.WithColor(new Color(c.Color[0], c.Color[1], c.Color[2])); } await ReplyAsync(" ", embed.Build()); }