/*METHODS*/ public async Task AnswerTurn(CancellationToken ct) { try { await User.SendMessageAsync("Please answer the following questions as accurately as you can."); finishedTurn = false; Client.MessageReceived += CheckForResponse; foreach (PlayerFibbagePrompt prompt in prompts) { responded = false; response = ""; await User.SendMessageAsync(prompt.AnswererQuestion); while (!responded) { await Task.Delay(500); ct.ThrowIfCancellationRequested(); } prompt.Truth = response; } await User.SendMessageAsync("That's all! Please return to the game channel."); finishedTurn = true; } catch (OperationCanceledException) { await User.SendMessageAsync("Time is up! Please return to the game channel."); } catch (Exception err) { await ResponseChannel.SendMessageAsync($"IN TURN {User.Id}\n{err.ToString()}"); } }
/*METHODS*/ public async Task takeTurn(List <Prompt> prompts, CancellationToken ct, int playerID) { try { await User.SendMessageAsync("Please answer the following 2 prompts as best as you can."); finishedTurn = false; //connect message being recieved to response checking Client.MessageReceived += CheckForResponse; foreach (Prompt prompt in prompts) { responded = false; response = ""; if (prompt.PlayerA == playerID) { //send the prompt await User.SendMessageAsync(prompt.Question); //wait for response (see method CheckForResponse) while (!responded) { await Task.Delay(1); ct.ThrowIfCancellationRequested(); } prompt.AnswerA = response; } else if (prompt.PlayerB == playerID) { //send the prompt await User.SendMessageAsync(prompt.Question); //wait for response (see method CheckForResponse) while (!responded) { await Task.Delay(1); ct.ThrowIfCancellationRequested(); } prompt.AnswerB = response; } } await User.SendMessageAsync("That's all! Please return to the game channel."); finishedTurn = true; await Task.CompletedTask; } catch (OperationCanceledException) { await User.SendMessageAsync("Time is up! Please return to the game channel."); await Task.CompletedTask; } catch (Exception err) { await ResponseChannel.SendMessageAsync(err.ToString()); } }
/// <summary> /// Fills the player's Lies with answers for the current round /// </summary> /// <param name="prompts">The round's prompts</param> /// <param name="roundUsername">The round's subject's username. For giving the player the correct username</param> /// <param name="ct">To cancel the process when time runs up</param> /// <returns></returns> public async Task LieTurn(PlayerFibbagePrompt[] prompts, string roundUsername, CancellationToken ct) { try { responses = new string[prompts.Length]; await User.SendMessageAsync("Please answer the following prompts with answers that may fool your other players into believing they are true"); finishedTurn = false; Client.MessageReceived += CheckForResponse; for (int i = 0; i < prompts.Length; i++) { responded = false; response = ""; await User.SendMessageAsync(prompts[i].GetLiarQuestion(roundUsername)); while (!responded) { await Task.Delay(500); ct.ThrowIfCancellationRequested(); } if (response == prompts[i].Truth) { await User.SendMessageAsync("You entered the truth! Please answer again, with something different this time."); i--; continue; } responses[i] = response; await User.SendMessageAsync("That's all! Please return to the game channel."); finishedTurn = true; } } catch (OperationCanceledException) { await User.SendMessageAsync("Time is up! Please return to the game channel."); } catch (Exception err) { await ResponseChannel.SendMessageAsync($"IN TURN {User.Id}\n{err.ToString()}"); } }
public async Task lastTurn(List <Prompt> prompts, CancellationToken ct, int playerID) { try { await User.SendMessageAsync("Please answer the following prompts as best as you can. Your answer will be used for both prompts."); //set responded off and clear response responded = false; response = ""; var text = ""; //connect message being recieved to response checking Client.MessageReceived += CheckForResponse; foreach (Prompt prompt in prompts) { if (prompt.PlayerA == playerID) { if (!responded) { text += prompt.Question + "\n"; //send the prompt //await User.SendMessageAsync(prompt.Question); } /* * //wait for response (see method CheckForResponse) * while (!responded) * { * await Task.Delay(1); * ct.ThrowIfCancellationRequested(); * } * prompt.AnswerA = response; * responded = true; */ } else if (prompt.PlayerB == playerID) { if (!responded) { text += prompt.Question + "\n"; //send the prompt //await User.SendMessageAsync(prompt.Question); } /* * //wait for response (see method CheckForResponse) * while (!responded) * { * await Task.Delay(1); * ct.ThrowIfCancellationRequested(); * } * prompt.AnswerB = response; * responded = true; */ } } //send the prompts await User.SendMessageAsync(text); while (!responded) { await Task.Delay(50); ct.ThrowIfCancellationRequested(); } foreach (Prompt prompt in prompts) { if (prompt.PlayerA == playerID) { prompt.AnswerA = response; } if (prompt.PlayerB == playerID) { prompt.AnswerB = response; } } await User.SendMessageAsync("That's all! Please return to the game channel."); finishedTurn = true; await Task.CompletedTask; } catch (OperationCanceledException) { await User.SendMessageAsync("Time is up! Please return to the game channel."); await Task.CompletedTask; } catch (Exception err) { await ResponseChannel.SendMessageAsync(err.ToString()); } }
/// <summary> /// Gets what the person answers once all lies have been submitted /// </summary> /// <param name="prompt">The prompt (to present and format in DMs)</param> /// <param name="subjectID">The ID of the round's player, so they can't score for their own round</param> /// <param name="promptIndex">The prompt's index, so it can be properly formatted</param> /// <param name="playerIndex">The player's index according to the player list</param> /// <param name="ct">For cancelling when time runs out</param> /// <returns></returns> public async Task GetAnswer(EmbedBuilder prompt, ulong subjectID, int promptIndex, int playerIndex, CancellationToken ct) { try { finishedTurn = false; if (subjectID == User.Id) { if (promptIndex == 0) { await User.SendMessageAsync("This is your round! Kick back, and wait for the others to answer."); } finishedTurn = true; } else { var sr = new StringReader(prompt.Description); string newDesc = ""; string line = ""; int counter = 0; //remove the player's answer from the list while (true) { counter++; line = sr.ReadLine(); //okay we're done if (line == null || line == "Answer via the DMs!") { break; } if (line == Lies[promptIndex]) { continue; } newDesc += $"{counter}) {line}\n"; } newDesc += "Answer by typing the number for the answer you want to pick!"; prompt.Description = newDesc; Client.MessageReceived += CheckForResponse; await User.SendMessageAsync("", false, prompt); while (true) { responded = false; response = ""; answer = 0; while (!responded) { await Task.Delay(500); ct.ThrowIfCancellationRequested(); } if (!Int32.TryParse(response, out answer) || answer < 1 || answer > 9) { await User.SendMessageAsync("Send a numeral between 1-9"); } else if (answer == playerIndex + 1) { await User.SendMessageAsync("That number is reserved for your answer! Please try another number."); } else { break; } } await User.SendMessageAsync("That's all! Please return to the game channel."); } } catch (OperationCanceledException) { await User.SendMessageAsync("Time is up! Please return to the game channel."); } catch (Exception err) { await ResponseChannel.SendMessageAsync($"IN TURN {User.Id}\n{err.ToString()}"); } }