Class Engine
java.lang.Object
games.stendhal.server.entity.npc.fsm.Engine
a finite state machine.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
add(ConversationStates state, String triggerString, ChatCondition condition, boolean secondary, ConversationStates nextState, String reply, ChatAction action)
Adds a new transition to FSM.void
add(ConversationStates state, String triggerString, ChatCondition condition, boolean secondary, ConversationStates nextState, String reply, ChatAction action, String label)
Adds a new transition to FSM.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.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.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.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.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.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.Gets the current state.Returns a copy of the transition table.boolean
remove matches transitionvoid
setCurrentState(ConversationStates currentState)
Sets the current State without doing a normal transition.boolean
Do one transition of the finite state machine.boolean
Do one transition of the finite state machine.boolean
Do one transition of the finite state machine with debugging output and reset of the previous response.
-
Constructor Details
-
Engine
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 statetriggerString
- input triggercondition
- 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
-
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 statetriggerString
- input triggercondition
- 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
- 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 FSMtriggerStrings
- a list of inputs for this transition, must not be nullcondition
- null or condition that has to return true for this transition to be consideredsecondary
- flag to mark secondary transitions to be taken into account after preferred transitionsnextState
- the new state of the FSMreply
- 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 FSMtriggerStrings
- a list of inputs for this transition, must not be nullcondition
- null or condition that has to return true for this transition to be consideredsecondary
- flag to mark secondary transitions to be taken into account after preferred transitionsnextState
- the new state of the FSMreply
- 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 FSMtriggerString
- input for this transition, must not be nullmatcher
-condition
- null or condition that has to return true for this transition to be consideredsecondary
- flag to mark secondary transitions to be taken into account after preferred transitionsnextState
- the new state of the FSMreply
- 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 FSMtriggerStrings
- a list of inputs for this transition, must not be nullmatcher
- Expression matchercondition
- null or condition that has to return true for this transition to be consideredsecondary
- flag to mark secondary transitions to be taken into account after preferred transitionsnextState
- the new state of the FSMreply
- 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 nullstate
- the starting state of the FSMcondition
- null or condition that has to return true for this transition to be consideredsecondary
- flag to mark secondary transitions to be taken into account after preferred transitionsnextState
- the new state of the FSMreply
- 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 nullstate
- the starting state of the FSMcondition
- null or condition that has to return true for this transition to be consideredsecondary
- flag to mark secondary transitions to be taken into account after preferred transitionsnextState
- the new state of the FSMreply
- a simple sentence reply (may be null for no reply)action
- a special action to be taken (may be null)
-
remove
remove matches transition- Parameters:
label
- the label of transitions to remove- Returns:
- true, if at least one transition was removed
-
getCurrentState
Gets the current state.- Returns:
- current state
-
setCurrentState
Sets the current State without doing a normal transition.- Parameters:
currentState
- new state
-
step
Do one transition of the finite state machine.- Parameters:
player
- Playertext
- input- Returns:
- true if a transition was made, false otherwise
-
step
Do one transition of the finite state machine.- Parameters:
player
- Playersentence
- input- Returns:
- true if a transition was made, false otherwise
-
stepTest
Do one transition of the finite state machine with debugging output and reset of the previous response.- Parameters:
player
- Playertext
- input- Returns:
- true if a transition was made, false otherwise
-
getTransitions
Returns a copy of the transition table.- Returns:
- list of transitions
-