Class ConversationBuilder

java.lang.Object
games.stendhal.server.entity.npc.ConversationBuilder

public class ConversationBuilder extends Object
A low level builder for npc interaction. This is designed to be used with ConditionBuilder.
An example conversation with a response, conditions and a state change:
 
 conversation(actor(npc)
     .respondsTo(ConversationPhrases.GREETING_MESSAGES)
     .inState(ConversationStates.IDLE)
     .saying("I hope you didn't lose your goblet! Do you need another?")
     .when(greetingMatchesName(npc.getName())
         .and(questInState(QUEST_SLOT, "start"))
         .unless(playerCarriesItem("empty goblet")
             .or(playerCarriesItem("goblet"))))
     .changingStateTo(ConversationStates.QUESTION_1));
 
 
See Also:
  • Method Details

    • actor

      public static ConversationBuilder actor(SpeakerNPC npc)
      Creates a ConversationBuilder for the specified npc.
      Parameters:
      npc - SpeakerNPC for which the conversation is created
      Returns:
      ConversationBuilder for the specified npc
    • inState

      public ConversationBuilder inState(ConversationStates state)
      Specifies an initial state of the NPC for which the conversation is used. Every conversation must have at least one specified initial state.
      If there are no initial states set earlier, this is also used as the end state, unless a state change is specified with #changingStateTo().
      Parameters:
      state - initial state
      Returns:
      the builder itself
    • inStates

      public ConversationBuilder inStates(ConversationStates[] states)
      Specifies multiple initial states of the NPC for which the conversation is used. Every conversation must have at least one specified initial state.
      Parameters:
      states -
      Returns:
      the builder itself
    • respondsTo

      public ConversationBuilder respondsTo(String trigger)
      Add a trigger word to which the NPC responds to.
      Parameters:
      trigger - trigger word
      Returns:
      the builder itself
    • respondsTo

      public ConversationBuilder respondsTo(Collection<String> triggers)
      Add multiple trigger words to which the NPC responds to.
      Parameters:
      triggers - trigger words
      Returns:
      the builder itself
    • saying

      public ConversationBuilder saying(String reply)
      Specify a verbal reply for the npc.
      Parameters:
      reply -
      Returns:
      the builder itself
    • when

      public ConversationBuilder when(ConditionBuilder condition)
      Specify conditions for the conversation. Use the ConditionBuilder factory methods in the ChatConditions. This method can be called at most once.
      Parameters:
      condition - A condition builder for the conditions of the conversation
      Returns:
      the builder itself
    • doing

      public ConversationBuilder doing(ChatAction... actions)
      Specify additional actions for the conversation. For readability, use the static factory methods of the actions.
      Parameters:
      actions -
      Returns:
      the builder itself
    • changingStateTo

      public ConversationBuilder changingStateTo(ConversationStates endState)
      Specify the final state of the npc after the conversation.
      Parameters:
      endState -
      Returns:
      the builder itself
      See Also:
    • build

      public void build()
      Generates the conversation state transitions for the npc FSM. This is public mainly for the higher level builders. Most conversations made directly with ConversationBuilder should use conversation(ConversationBuilder) instead.
    • conversation

      public static void conversation(ConversationBuilder builder)
      Generates the conversation for the npc. This is a convenience wrapper around build().
      Parameters:
      builder -