Conversation API - Is this multi-player conversation flowchart possible?

Discussion in 'Plugin Development' started by Father Of Time, Apr 29, 2012.

Thread Status:
Not open for further replies.
  1. Offline

    Father Of Time

    Good evening/morning all,

    I couldn't think of an easy way to explain my question, so I figured it would be much easier to convey my question with a picture (a picture is worth a thousand words afterall, right?).

    [​IMG]

    I am hoping to figure out a way to get multiple people as part of the same conversation with the console. The console will start by asking the player one a series of questions to obtain the information it needs, and once complete move on to player to. The last prompt the player 1 will be sent is "please wait for other players to decide". So basically the server will get what it needs from one player, move on to the next get what it needs, move on to the next and so on.

    Does anyone think this is possible? I was making decent progress but sadly I have work in the morning and I'm already up way later than I want to be, so I figured I would see what guidance I can get from the bukkit community over the night so that I have some additional material to work with tomorrow when I get home from work.

    Thank you all in advance for your assistance and participation with this topic, have a wonderful day!

    Tags for people of interest:
    deltahat
    Bone008
     
  2. Offline

    Prgr

    Bump, look at decompiling the Questioner that was associated with Towny awhile back, It has a good API to work with and I think it's worth the look.
     
  3. Offline

    kumpelblase2

    I'm pretty sure it's possible. You can send a ValidatingPromt to the first player and when he entered a message send him a MessagePromt to wait for the others. Do this for all players. When you got a response from everyone you can e.g. send everyone the answers of the others. I've worked a lot with the conversations and can probably assist as well if you need any help regarding the conversations.


    EDIT: FYI, the order of prompts is actually something like a flow chart.
     
  4. Offline

    AmoebaMan

    This is all just to conduct a chat conversation between 4 people? It seems like there should be an easier way...
     
  5. Offline

    ItsHarry

    I must be a noob but I don't get it o-o
     
  6. Offline

    kumpelblase2

    I made a quick code example:

    Your main, or at least part of it:
    Code:java
    1. public class <MainClass>
    2. {
    3. private static <MainClass> instance;
    4. public Map<String, String> answers = new HashMap<String, String> //Key: Player name, Value: answer of player
    5. public List<String> players; // Players that should be asked
    6. private ConversationFactory convfactory; // We store it so we don't don't need create a new one every time
    7.  
    8. //...
    9.  
    10. public static <MainClass> getInstance() // Just so we can get the main class everywhere.
    11. {
    12. return instance;
    13. }
    14.  
    15. public void addAnswer(String player, String answer) // add an answer of a player to the total answers
    16. {
    17. this.answers.put(player, answer);
    18. }
    19.  
    20. public List<String> getParticipatingPlayers() // Get the players that should be asked
    21. {
    22. return this.players;
    23. }
    24.  
    25. public void start() // Starting function
    26. {
    27. if(this.players.size() == 0) // If no players should be asked
    28. {
    29. this.onEnd(); //We could just leave this out but I leave it in.
    30. return;
    31. }
    32.  
    33. this.createConversation(Bukkit.getPlayer(this.players.get(this.players.size() - 1)), new QuestionPromt()); // Creating the conversation with the first player
    34. }
    35.  
    36. public void createConversation(Player player, Prompt prompt)
    37. {
    38. if(this.convfactory == null) // If we didn't created the conversation factory yet, create one
    39. this.convfactory = new ConversationFactory(this);
    40.  
    41. player.beginConversation(this.convfactory.withFirstPromt(prompt).buildConversation(player)); // start the conversation
    42. }
    43.  
    44. public void onEnd() // When ever player made their response we call this function. You can do it different (with events for example) but this is the easiest way.
    45. {
    46. //Do whatever here.
    47. }
    48. }
    49.  


    and the prompt the we're going to send:
    Code:java
    1. public QuestionPrompt extends ValidatingPrompt // We create our own prompt
    2. {
    3. @Override
    4. public String getPromptText(ConversationContext context) // This will return the text that gets displayed to the player, in this case our question
    5. {
    6. return "<YOUR QUESTION HERE>";
    7. }
    8.  
    9. @Override
    10. protected boolean isInputValid(ConversationContext context, String input) // We check the input. We don't check anything currently but we could check for specific words for example.
    11. {
    12. return true; // Return true, if the input is valid otherwise false
    13. }
    14.  
    15. @Override
    16. protected Prompt acceptValidatedInput(ConversationContext context, String input) // handle the input
    17. {
    18. <MainClass> main = <MainClass>.getInstance();
    19. String playername = ((Player)context.getForWhom()).getName();
    20. main.addAnswer(playername, input); // Add the validated answer to our list/map
    21. main.getParticipatingPlayers().remove(playername); // remove the player from out list
    22. context.getForWhom().sendRawMessage("Thanks for your answer, please wait until the other participants entered their input."); // We send a message to tell him that his answer got accepted.
    23.  
    24. if(main.getParticipatingPlayers().size() == 0) // If there are no other players left to ask, we finish
    25. {
    26. main.onEnd();
    27. return END_OF_CONVERSATION;
    28. }
    29.  
    30. main.createConversation(Bukkit.getPlayer(main.getParticipatingPlayers().get(main.getParticipatingPlayers().size() - 1)), new QuestionPrompt()); // We create a conversation with the next player
    31.  
    32. return END_OF_CONVERSATION; // We end the conversation with the current player
    33. }
    34. }
    35.  


    I wrote this outside of my IDE so there might be some mistakes. I hope that this helps you/answers your question. If you still have a question regarding conversations or my code, just tell me and I'm gonna try my best to answer it!

    EDIT: I hate it when the indentation gets fucked up -.-'

    Father Of Time: any progress?

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 25, 2016
    Father Of Time likes this.
  7. Offline

    Father Of Time

    Unfortunately I am still at work, I don't get out for about another 45 minutes. I was going to send you a PM when I got home to see if you wouldn't mine meeting with me for a short while (via TeamSpeak) and discuss this project in greater detail; and hopefully share some of your knowledge with the Conversation API.

    I've been wanting to speak with you for unrelated reasons for some time, but I've been putting it off due to time constraints; but this seems like a good opportunity to kill two birds with one stone. ;) Let me know if you have interest in meeting, I will PM you the TeamSpeak DNS.

    Take care Kumpelblase2, and thank you for showing an interest in our project. :D
     
  8. Offline

    deltahat

    This is doable. Player begins the first conversation, collecting the relevant details. When all details are collected, the conversation ends with a MessagePrompt implemetation. The MessagePrompt's getPromptText() implementation tells the user to wait for feedback. The getNextPrompt() implementation starts a conversation with the next user and then returns Prompt.END_OF_CONVERSATION.

    The second, third, and nth conversations play out just like the first - gather details, tell the user to wait, trigger the next conversation, and then end the current conversation.

    Finally, once all information is collected from all players, send a standard console message to everybody involved with the results.

    Is this clear?
     
    Father Of Time likes this.
  9. Offline

    Father Of Time

    Thank you greatly for your insight deltahat. This most definitely makes sense, although conceptually understanding is a great deal easier than the physical implementation.

    After my experiments last evening I figured it would be something like this, not one continual conversation with multiple participants, but rather a bunch of very short conversations with a single player done in a series to simulate a group conversation environment; however this is completely acceptable and awesome to me because the end result will be fairly seamless if done right.

    I have my work cut out for me, but I think this was the final piece to my puzzle, meaning my project can be done with 100% certainty; it's only a matter of the labor.

    Thank you again for your assistance, have a wonderful evening!
     
  10. Offline

    deltahat

    Good luck!
     
    Father Of Time likes this.
  11. Offline

    Father Of Time



    Extremely nice example kumpelblase2, especially if it's just an off of the top of your head example and not a snippet from another project! Most of the difficulty here will be familiarizing myself with the Conversation API, getting used to its "flow". I'm interested in reading your "multi-participant" aspects a little more closely as that is really the main issue.

    As I stated before I would be interested in speaking with you regarding this project in greater detail; if you are interested send me a PM.

    Oh and p.s. I hate when it destroys formatting myself, I find that if you cut and paste the code into notepad first to remove any special characters it helps alleviate that problem.


    It's not a conversation between four people, it's a conversation that the console is having with four people at once, a back and forth of the console delivering information to the four players and the four players responding with input the cosole can act upon.

    This could easily be done with chat events and commands, but it would be messier, more work, would require the use of /commands instead of natural spoken language, and would be flooded by normal game chat (which is blocked during a Conversation).

    Simply put, this is just a simplier cleaner method of exchanging mass continual information between the console and four players.

    I hope this help clear things up (sadly it likely won't :p).

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: May 25, 2016
  12. Offline

    ItsHarry

    You're right, I still don't get it :p
    I'll just leave this thread to the pros :)
     
  13. Offline

    AmoebaMan

    Father Of Time Harry might give up, but I don't. I'd like to know exactly what this "Conversation" is.
     
  14. Offline

    kumpelblase2

  15. Offline

    AmoebaMan

Thread Status:
Not open for further replies.

Share This Page