Class Transition

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

public class Transition extends Object
A transition brings a conversation from one state to another one (or to the same one); while doing so, other actions can take place.
  • Constructor Details

    • Transition

      public Transition(ConversationStates currentState, Collection<Expression> triggers, PreTransitionCondition condition, boolean secondary, ConversationStates nextState, String reply, PostTransitionAction action, String label)
      Creates a new transition.
      Parameters:
      currentState - old state
      triggers - input triggers
      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 - string label to handle transitions in NPC's FSM table
    • Transition

      public Transition(ConversationStates currentState, Collection<Expression> triggers, PreTransitionCondition condition, boolean secondary, ConversationStates nextState, String reply, PostTransitionAction action)
      Creates a new transition.
      Parameters:
      currentState - old state
      triggers - input triggers
      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
    • Transition

      public Transition(Transition tr)
      Create transition and copy values from existing transition
      Parameters:
      tr - - source transition, must not be null
  • Method Details

    • matchesWild

      public boolean matchesWild(Sentence sentence)
      Checks whether this is a "wildcard" transition (see class comment of SpeakerNPC) which can be fired by the given text.
      Parameters:
      sentence - The sentence that the player has said
      Returns:
      true iff this is a wildcard transition and the triggering text has been said
    • matchesWildNormalized

      public boolean matchesWildNormalized(Sentence sentence)
      Checks whether this is a "wildcard" transition (see class comment of SpeakerNPC) and the normalized text matches the trigger.
      Parameters:
      sentence - trigger (parsed user input)
      Returns:
      if the transition matches, false otherwise
    • matchesWildSimilar

      public boolean matchesWildSimilar(Sentence sentence)
      Checks whether this is a "wildcard" transition (see class comment of SpeakerNPC) and the normalized text is similar to the trigger.
      Parameters:
      sentence - trigger (parsed user input)
      Returns:
      if the transition matches, false otherwise
    • matches

      public boolean matches(ConversationStates currentState, Sentence sentence)
      Checks whether this transition is possible now.
      Parameters:
      currentState - old state
      sentence - trigger
      Returns:
      true if the Transition matches, false otherwise
    • matches

      public boolean matches(ConversationStates state, Expression trigger)
      Checks whether this transition is possible now.
      Parameters:
      state - old state
      trigger - trigger
      Returns:
      true if the Transition matches, false otherwise
    • matchesNormalized

      public boolean matchesNormalized(ConversationStates state, Sentence sentence)
      Checks whether this transition is possible now by using matching of the normalized expression.
      Parameters:
      state - old state
      sentence - trigger
      Returns:
      true if the Transition matches, false otherwise
    • matchesNormalized

      public boolean matchesNormalized(ConversationStates state, Expression trigger)
      Checks whether this transition is possible now by using matching of the normalized expression.
      Parameters:
      state - old state
      trigger - trigger
      Returns:
      true if the Transition matches, false otherwise
    • matchesSimilar

      public boolean matchesSimilar(ConversationStates state, Sentence sentence)
      Checks whether this transition is possible now by checking the similarity of the normalized expression.
      Parameters:
      state - old state
      sentence - trigger, parsed user input
      Returns:
      true if the Transition matches, false otherwise
    • matchesWithCondition

      public boolean matchesWithCondition(ConversationStates state, Expression trigger, PreTransitionCondition condition)
      Checks for match with the given state/trigger/condition combination.
      Parameters:
      state -
      trigger -
      condition -
      Returns:
      true if condition has been found
    • matchesNormalizedWithCondition

      public boolean matchesNormalizedWithCondition(ConversationStates state, Expression trigger, PreTransitionCondition condition)
      Checks for normalized match with the given state/trigger/condition combination.
      Parameters:
      state -
      trigger -
      condition -
      Returns:
      true if condition has been found
    • checkLabel

      public boolean checkLabel(String aLabel)
      Checks for labels equality
      Parameters:
      aLabel - label to compare
      Returns:
      check result
    • isEmptyLabel

      public boolean isEmptyLabel()
      check if label is empty string
      Returns:
      - check result
    • isConditionFulfilled

      public boolean isConditionFulfilled(Player player, Sentence sentence, SpeakerNPC npc)
      Checks whether this transition's condition is fulfilled.
      Parameters:
      player - Player
      sentence - the sentence the player said
      npc - SpeakerNPC
      Returns:
      true iff there is no condition or if there is one which is fulfilled
    • getAction

      public PostTransitionAction getAction()
      Returns:
      Action to execute after transition or null if there is none
    • getCondition

      public PreTransitionCondition getCondition()
      Returns:
      condition to check before doing the transition or null if there is non
    • isPreferred

      public boolean isPreferred()
      Returns:
      true if this transition should be preferred over others, which also have a matching condition or no condition at all
    • getNextState

      public ConversationStates getNextState()
      Returns:
      state after transition
    • getReply

      public String getReply()
      Returns:
      output or null if there is none
    • setReply

      public void setReply(String reply)
      Sets the output for this transition.
      Parameters:
      reply - output
    • getState

      public ConversationStates getState()
      Returns:
      the source state
    • getTriggers

      public Collection<Expression> getTriggers()
      Returns:
      input
    • toString

      public String toString()
      Return a string representation of this Transition.
      Overrides:
      toString in class Object