Class Engine

java.lang.Object
games.stendhal.server.entity.npc.fsm.Engine

public class Engine extends Object
a finite state machine.
  • Constructor Details

    • Engine

      public Engine(SpeakerNPC speakerNPC)
      Creates a new FSM.
      Parameters:
      speakerNPC - the speaker NPC for which this FSM is created must not be null
  • Method Details

    • add

      public void add(ConversationStates state, String triggerString, ChatCondition condition, boolean secondary, ConversationStates nextState, String reply, ChatAction action)
      Adds a new transition to FSM.
      Parameters:
      state - old state
      triggerString - input trigger
      condition - additional precondition
      secondary - flag to mark secondary transitions to be taken into account after preferred transitions
      nextState - state after the transition
      reply - output
      action - additional action after the condition
    • add

      public void add(ConversationStates state, String triggerString, ChatCondition condition, boolean secondary, ConversationStates nextState, String reply, ChatAction action, String label)
      Adds a new transition to FSM.
      Parameters:
      state - old state
      triggerString - input trigger
      condition - additional precondition
      secondary - flag to mark secondary transitions to be taken into account after preferred transitions
      nextState - state after the transition
      reply - output
      action - additional action after the condition
      label - a label to find this transition at a later time
    • add

      public void add(ConversationStates state, Collection<String> triggerStrings, ChatCondition condition, boolean secondary, ConversationStates nextState, String reply, ChatAction action)
      Adds a new set of transitions to the FSM.
      Parameters:
      state - the starting state of the FSM
      triggerStrings - a list of inputs for this transition, must not be null
      condition - null or condition that has to return true for this transition to be considered
      secondary - flag to mark secondary transitions to be taken into account after preferred transitions
      nextState - the new state of the FSM
      reply - a simple sentence reply (may be null for no reply)
      action - a special action to be taken (may be null)
    • add

      public void add(ConversationStates state, Collection<String> triggerStrings, ChatCondition condition, boolean secondary, ConversationStates nextState, String reply, ChatAction action, String label)
      Adds a new set of transitions to the FSM.
      Parameters:
      state - the starting state of the FSM
      triggerStrings - a list of inputs for this transition, must not be null
      condition - null or condition that has to return true for this transition to be considered
      secondary - flag to mark secondary transitions to be taken into account after preferred transitions
      nextState - the new state of the FSM
      reply - a simple sentence reply (may be null for no reply)
      action - a special action to be taken (may be null)
      label - a label to find this transition at a later time
    • addMatching

      public void addMatching(ConversationStates state, String triggerString, ExpressionMatcher matcher, ChatCondition condition, boolean secondary, ConversationStates nextState, String reply, ChatAction action)
      Adds a new transition with explicit ExpressionMatcher to FSM.
      Parameters:
      state - the starting state of the FSM
      triggerString - input for this transition, must not be null
      matcher -
      condition - null or condition that has to return true for this transition to be considered
      secondary - flag to mark secondary transitions to be taken into account after preferred transitions
      nextState - the new state of the FSM
      reply - a simple sentence reply (may be null for no reply)
      action - a special action to be taken (may be null)
    • addMatching

      public void addMatching(ConversationStates state, Collection<String> triggerStrings, ExpressionMatcher matcher, ChatCondition condition, boolean secondary, ConversationStates nextState, String reply, ChatAction action)
      Adds a new set of transitions to the FSM.
      Parameters:
      state - the starting state of the FSM
      triggerStrings - a list of inputs for this transition, must not be null
      matcher - Expression matcher
      condition - null or condition that has to return true for this transition to be considered
      secondary - flag to mark secondary transitions to be taken into account after preferred transitions
      nextState - the new state of the FSM
      reply - a simple sentence reply (may be null for no reply)
      action - a special action to be taken (may be null)
    • add

      public void add(Collection<Expression> triggerExpressions, ConversationStates state, ChatCondition condition, boolean secondary, ConversationStates nextState, String reply, ChatAction action, String label)
      Adds a new set of transitions to the FSM.
      Parameters:
      triggerExpressions - a list of trigger expressions for this transition, must not be null
      state - the starting state of the FSM
      condition - null or condition that has to return true for this transition to be considered
      secondary - flag to mark secondary transitions to be taken into account after preferred transitions
      nextState - the new state of the FSM
      reply - a simple sentence reply (may be null for no reply)
      action - a special action to be taken (may be null)
      label - a label to find this transition at a later time
    • add

      public void add(Collection<Expression> triggerExpressions, ConversationStates state, ChatCondition condition, boolean secondary, ConversationStates nextState, String reply, ChatAction action)
      Adds a new set of transitions to the FSM.
      Parameters:
      triggerExpressions - a list of trigger expressions for this transition, must not be null
      state - the starting state of the FSM
      condition - null or condition that has to return true for this transition to be considered
      secondary - flag to mark secondary transitions to be taken into account after preferred transitions
      nextState - the new state of the FSM
      reply - a simple sentence reply (may be null for no reply)
      action - a special action to be taken (may be null)
    • remove

      public boolean remove(String label)
      remove matches transition
      Parameters:
      label - the label of transitions to remove
      Returns:
      true, if at least one transition was removed
    • getCurrentState

      public ConversationStates getCurrentState()
      Gets the current state.
      Returns:
      current state
    • setCurrentState

      public void setCurrentState(ConversationStates currentState)
      Sets the current State without doing a normal transition.
      Parameters:
      currentState - new state
    • step

      public boolean step(Player player, String text)
      Do one transition of the finite state machine.
      Parameters:
      player - Player
      text - input
      Returns:
      true if a transition was made, false otherwise
    • step

      public boolean step(Player player, Sentence sentence)
      Do one transition of the finite state machine.
      Parameters:
      player - Player
      sentence - input
      Returns:
      true if a transition was made, false otherwise
    • stepTest

      public boolean stepTest(Player player, String text)
      Do one transition of the finite state machine with debugging output and reset of the previous response.
      Parameters:
      player - Player
      text - input
      Returns:
      true if a transition was made, false otherwise
    • getTransitions

      public List<Transition> getTransitions()
      Returns a copy of the transition table.
      Returns:
      list of transitions