public async Task Vote(CommandContext e, int playerNum) { if (phase % 2 == 0) { SVObject.UserObject PlayerVoting = RPClass.SVData.Players.FirstOrDefault(x => x.ID == e.Message.Author.Id); if (PlayerVoting != null && RPClass.SVData.Players.Exists(x => x.ID == e.Message.Author.Id && x.Status == 0) && !UsedAbility.Contains(PlayerVoting)) { SVObject.UserObject PlayerVoted = RPClass.SVData.Players.First(x => x.PlayerNum == playerNum); if (PlayerVoted != PlayerVoting && PlayerVoted.Status == 0) { await e.RespondAsync("You have voted for " + PlayerVoted.Username + "."); Votes.Add(new SVObject.VoteObject(PlayerVoted, 1)); UsedAbility.Add(PlayerVoting); } else if (PlayerVoted == PlayerVoting) { await e.RespondAsync("You cannot vote for yourself."); } else if (PlayerVoted.Status == 1) { await e.RespondAsync(PlayerVoted.Username + " has already been killed. You cannot vote for a dead player."); } } } else { await e.RespondAsync("You can only vote in the day."); } }
public static async void ProcessTurn(CommandContext e, int dayModifier) { DiscordChannel Channel = RPClass.GameChannel; processing = true; while (RPClass.SVData != null) { if (RPClass.SVData.Timer.AddMinutes(dayModifier) < DateTime.Now || phase == 0) { phase += 1; if (phase % 2 == 0) { if (Deaths.Any()) { SVObject.UserObject Death = Deaths.FirstOrDefault(x => !Protected.Contains(x)); string roleType = Death.Role == 1 ? "Villain" : Death.Role == 2 ? "Medic" : Death.Role == 3 ? "Spy" : Death.Role == 4 ? "Joker" : Death.Role == 5 ? "Hero" : "ERROR, Please report this to Jcryer."; if (Death != null) { await Channel.SendMessageAsync(string.Format("__**Secret Villain™**__\n\n*It is now the day phase!* {0} *was killed by the Villain(s).* {1} *was a(n):* {2}", "**" + Death.Username + "**", "**" + Death.Username + "**", "**" + roleType + "**")); } else { await Channel.SendMessageAsync(string.Format("__**Secret Villain™**__\n\n*It is now the day phase! The Villains attempted to kill* {0}, *however was protected by a* **Medic**.", "**" + Death.Username + "**")); } } else { await Channel.SendMessageAsync("__**Secret Villain™**__\n\n*It is now the day phase! Nobody was killed by the Villains this round.*"); } foreach (SVObject.UserObject PlayerData in RPClass.SVData.Players) { if (Deaths.Contains(PlayerData) && !Protected.Contains(PlayerData)) { PlayerData.Status = 1; } } if (RPClass.SVData.Players.Count(x => x.Role == 1 && x.Status == 0) >= RPClass.SVData.Players.Count(x => (x.Role == 2 || x.Role == 3 || x.Role == 5) && x.Status == 0)) { await Channel.SendMessageAsync("__**Secret Villain™**__\n\n*The Villains turn on the helpless Heroes, and assassinate them all.* \n __**The Villains have won!**__"); await RPClass.SVData.DisplayData(e, true); await EndGame(e); } else if (RPClass.SVData.Players.Count(x => x.Role == 1 && x.Status == 0) == 0) { await Channel.SendMessageAsync("__**Secret Villain™**__\n\n*The Heroes turn on the final remaining Villain, killing them with anger and hatred.* __**The Heroes have won!**__"); await RPClass.SVData.DisplayData(e, true); await EndGame(e); } await Channel.SendMessageAsync("\n*Please, vote on who you think the Villains are using the command* **!sv vote PLAYERNUM.** \n*To get the player numbers, please use the command* **!sv info.**"); Deaths.Clear(); UsedAbility.Clear(); Protected.Clear(); Votes.Clear(); } else { string MedicText = ""; string SpyText = ""; if (RPClass.SVData.Players.Any(x => x.Role == 2 && x.Status == 0)) { MedicText = "\n# Medic, PM me who you wish to protect using the command !sv protect PLAYERNUM."; } if (RPClass.SVData.Players.Any(x => x.Role == 3 && x.Status == 0)) { SpyText = "\n+ Spy, PM me who you wish to find out about using the command !sv find PLAYERNUM."; } if (Votes.Any()) { List <SVObject.VoteObject> TalliedVotes = new List <SVObject.VoteObject>(); foreach (SVObject.UserObject UniqueVotes in Votes.Select(x => x.user).Distinct()) { TalliedVotes.Add(new SVObject.VoteObject(UniqueVotes, Votes.Count(x => x.user == UniqueVotes))); } int VoteNum = TalliedVotes.Where(x => x.voteNum != 0).Max(x => x.voteNum); if (TalliedVotes.FindAll(x => x.voteNum == VoteNum).Count == 1) { SVObject.UserObject HighestVote = TalliedVotes.First(x => x.voteNum == VoteNum).user; string roleType = HighestVote.Role == 1 ? "Villain" : HighestVote.Role == 2 ? "Medic" : HighestVote.Role == 3 ? "Spy" : HighestVote.Role == 4 ? "Joker" : HighestVote.Role == 5 ? "Hero" : "ERROR, Please report this to Jcryer."; await Channel.SendMessageAsync(string.Format("__**Secret Villain™**__\n\n*It is now the night phase!* {0} *was the majority vote with* {1} *vote(s), and was killed.*\n{2} *was a(n)* {3 }.", "**" + HighestVote.Username + "**", "**" + VoteNum + "**", "**" + HighestVote.Username + "**", "**" + roleType + "**")); Deaths.Add(TalliedVotes.First(x => x.voteNum == VoteNum).user); } else { await Channel.SendMessageAsync("__**Secret Villain™**__\n\n*It is now the night phase! There was a tie with the votes, and as such nobody will die this phase.*"); } } else { if (phase == 1) { await Channel.SendMessageAsync("__**Secret Villain™**__\n\n*Welcome to Round One of this Secret Villain™ game! It is now the night phase.*"); } else { await Channel.SendMessageAsync("__**Secret Villain™**__\n\n*It is now the night phase! There was no majority vote, and therefore nobody was killed.*"); } } await Channel.SendMessageAsync(string.Format("```diff\n- Villains, PM me your next kill using the command !sv kill PLAYERNUM. {0} {1}``` \n *To get the player numbers, please use the command* **!sv info.**", MedicText, SpyText)); foreach (SVObject.UserObject PlayerData in RPClass.SVData.Players) { if (Deaths.Contains(PlayerData)) { PlayerData.Status = 1; } } if (RPClass.SVData.Players.Count(x => x.Role == 1 && x.Status == 0) >= RPClass.SVData.Players.Count(x => (x.Role == 2 || x.Role == 3 || x.Role == 5) && x.Status == 0)) { await Channel.SendMessageAsync("__**Secret Villain™**__\n\n*The Villains turn on the helpless Heroes, and assassinate them all.* \n__**The Villains have won!**__"); await RPClass.SVData.DisplayData(e, true); await EndGame(e); } else if (RPClass.SVData.Players.Count(x => x.Role == 1 && x.Status == 0) == 0) { await Channel.SendMessageAsync("__**Secret Villain™**__\n\n*The Heroes turn on the final remaining Villain, killing them with anger and hatred.* \n__**The shinobi have won!**__"); await RPClass.SVData.DisplayData(e, true); await EndGame(e); } else if (Deaths.Contains(RPClass.SVData.Players.Find(x => x.Role == 4 && x.Status == 1))) { await Channel.SendMessageAsync("__**Secret Villain™**__\n\n__**The Joker has won**__, *as he was killed by the shinobi.*"); } Deaths.Clear(); UsedAbility.Clear(); Protected.Clear(); Votes.Clear(); } RPClass.SVData.Timer = DateTime.Now; } await Task.Delay(60000); } }
public static async Task PMTasks(CommandContext e, int role, int playerNum) { if (phase % 2 != 0) { if (role == 1) { if (RPClass.SVData.Players.Exists(x => x.ID == e.Message.Author.Id && x.Role == 1)) { SVObject.UserObject PlayerKilling = RPClass.SVData.Players.First(x => x.ID == e.Message.Author.Id); if (!UsedAbility.Contains(PlayerKilling)) { SVObject.UserObject PlayerKilled = RPClass.SVData.Players.FirstOrDefault(x => x.PlayerNum == playerNum); if (PlayerKilled != null) { if (PlayerKilled != PlayerKilling) { UsedAbility.Add(PlayerKilling); await e.RespondAsync("Player " + PlayerKilled.Username + " will be assassinated."); foreach (SVObject.UserObject a in RPClass.SVData.Players.FindAll(x => x.Role == 1 && x.ID != e.Message.Author.Id)) { DiscordMember user = await e.Guild.GetMemberAsync(a.ID); await user.SendMessageAsync(a.Username + " just voted to kill " + PlayerKilled.Username + "."); } if (!Protected.Contains(PlayerKilled)) { Deaths.Add(PlayerKilled); } } else { await e.RespondAsync("You cannot kill yourself."); } } else { await e.RespondAsync("Invalid player number."); } } } } else if (role == 2) { if (RPClass.SVData.Players.Exists(x => x.ID == e.Message.Author.Id && x.Role == 2)) { SVObject.UserObject PlayerSearching = RPClass.SVData.Players.First(x => x.ID == e.Message.Author.Id); if (!UsedAbility.Contains(PlayerSearching)) { SVObject.UserObject PlayerSearched = RPClass.SVData.Players.FirstOrDefault(x => x.PlayerNum == playerNum); if (PlayerSearched != null) { if (PlayerSearched != PlayerSearching) { await e.RespondAsync("Player " + PlayerSearched.Username + " protected."); if (!Protected.Contains(PlayerSearched)) { Protected.Add(PlayerSearched); } UsedAbility.Add(PlayerSearching); } else { await e.RespondAsync("You cannot protect yourself."); } } else { await e.RespondAsync("Invalid player number."); } } } } else if (role == 3) { if (RPClass.SVData.Players.Exists(x => x.ID == e.Message.Author.Id && x.Role == 3)) { SVObject.UserObject PlayerSearching = RPClass.SVData.Players.First(x => x.ID == e.Message.Author.Id); if (!UsedAbility.Contains(PlayerSearching)) { SVObject.UserObject PlayerSearched = RPClass.SVData.Players.FirstOrDefault(x => x.PlayerNum == playerNum); if (PlayerSearched != null) { if (PlayerSearched != PlayerSearching) { string roleType = PlayerSearched.Role == 1 ? "Villain" : PlayerSearched.Role == 2 ? "Medic" : PlayerSearched.Role == 3 ? "Spy" : PlayerSearched.Role == 4 ? "Joker" : PlayerSearched.Role == 5 ? "Hero" : "ERROR, Please report this to Jcryer."; await e.RespondAsync("Player " + PlayerSearched.Username + "'s role is: " + roleType + "."); UsedAbility.Add(PlayerSearching); } else { await e.RespondAsync("You can not find information about yourself!"); } } else { await e.RespondAsync("Invalid player number."); } } } } } else { await e.RespondAsync("It is currently the day phase, you may only use abilities in the night phase."); } }
public VoteObject(SVObject.UserObject user, int voteNum) { this.user = user; this.voteNum = voteNum; }