Class Transition
java.lang.Object
games.stendhal.server.entity.npc.fsm.Transition
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 Summary
ConstructorDescriptionTransition(ConversationStates currentState, Collection<Expression> triggers, PreTransitionCondition condition, boolean secondary, ConversationStates nextState, String reply, PostTransitionAction action)
Creates a new transition.Transition(ConversationStates currentState, Collection<Expression> triggers, PreTransitionCondition condition, boolean secondary, ConversationStates nextState, String reply, PostTransitionAction action, String label)
Creates a new transition.Transition(Transition tr)
Create transition and copy values from existing transition -
Method Summary
Modifier and TypeMethodDescriptionboolean
checkLabel(String aLabel)
Checks for labels equalitygetReply()
getState()
boolean
isConditionFulfilled(Player player, Sentence sentence, SpeakerNPC npc)
Checks whether this transition's condition is fulfilled.boolean
check if label is empty stringboolean
boolean
matches(ConversationStates state, Expression trigger)
Checks whether this transition is possible now.boolean
matches(ConversationStates currentState, Sentence sentence)
Checks whether this transition is possible now.boolean
matchesNormalized(ConversationStates state, Expression trigger)
Checks whether this transition is possible now by using matching of the normalized expression.boolean
matchesNormalized(ConversationStates state, Sentence sentence)
Checks whether this transition is possible now by using matching of the normalized expression.boolean
matchesNormalizedWithCondition(ConversationStates state, Expression trigger, PreTransitionCondition condition)
Checks for normalized match with the given state/trigger/condition combination.boolean
matchesSimilar(ConversationStates state, Sentence sentence)
Checks whether this transition is possible now by checking the similarity of the normalized expression.boolean
matchesWild(Sentence sentence)
Checks whether this is a "wildcard" transition (see class comment of SpeakerNPC) which can be fired by the given text.boolean
matchesWildNormalized(Sentence sentence)
Checks whether this is a "wildcard" transition (see class comment of SpeakerNPC) and the normalized text matches the trigger.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.boolean
matchesWithCondition(ConversationStates state, Expression trigger, PreTransitionCondition condition)
Checks for match with the given state/trigger/condition combination.void
Sets the output for this transition.toString()
Return a string representation of this Transition.
-
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 statetriggers
- input triggerscondition
- additional preconditionsecondary
- flag to mark secondary transitions to be taken into account after preferred transitionsnextState
- state after the transitionreply
- outputaction
- additional action after the conditionlabel
- 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 statetriggers
- input triggerscondition
- additional preconditionsecondary
- flag to mark secondary transitions to be taken into account after preferred transitionsnextState
- state after the transitionreply
- outputaction
- additional action after the condition
-
Transition
Create transition and copy values from existing transition- Parameters:
tr
- - source transition, must not be null
-
-
Method Details
-
matchesWild
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
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
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
Checks whether this transition is possible now.- Parameters:
currentState
- old statesentence
- trigger- Returns:
- true if the Transition matches, false otherwise
-
matches
Checks whether this transition is possible now.- Parameters:
state
- old statetrigger
- trigger- Returns:
- true if the Transition matches, false otherwise
-
matchesNormalized
Checks whether this transition is possible now by using matching of the normalized expression.- Parameters:
state
- old statesentence
- trigger- Returns:
- true if the Transition matches, false otherwise
-
matchesNormalized
Checks whether this transition is possible now by using matching of the normalized expression.- Parameters:
state
- old statetrigger
- trigger- Returns:
- true if the Transition matches, false otherwise
-
matchesSimilar
Checks whether this transition is possible now by checking the similarity of the normalized expression.- Parameters:
state
- old statesentence
- 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
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
Checks whether this transition's condition is fulfilled.- Parameters:
player
- Playersentence
- the sentence the player saidnpc
- SpeakerNPC- Returns:
- true iff there is no condition or if there is one which is fulfilled
-
getAction
- Returns:
- Action to execute after transition or null if there is none
-
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
- Returns:
- state after transition
-
getReply
- Returns:
- output or null if there is none
-
setReply
Sets the output for this transition.- Parameters:
reply
- output
-
getState
- Returns:
- the source state
-
getTriggers
- Returns:
- input
-
toString
Return a string representation of this Transition.
-