org.starhope.appius.game.npc.plebeian
Class PlebeianScriptRunner

java.lang.Object
  extended by org.starhope.appius.game.npc.plebeian.PlebeianScriptRunner
All Implemented Interfaces:
ScriptRunner

public final class PlebeianScriptRunner
extends Object
implements ScriptRunner

WRITEME: Document this type.

Author:
brpocock@star-hope.org

Nested Class Summary
private  class PlebeianScriptRunner.GoToCoordRunner
          WRITEME: Document this type.
private  class PlebeianScriptRunner.GoToNamedTargetRunner
          WRITEME: Document this type.
private  class PlebeianScriptRunner.GoToRoomRunner
          WRITEME: Document this type.
private  class PlebeianScriptRunner.GrantToActorRunner
          WRITEME: Document this type.
private  class PlebeianScriptRunner.If_Runner
          WRITEME: Document this type.
private  class PlebeianScriptRunner.PaySomeoneRunner
          WRITEME: Document this type.
(package private)  class PlebeianScriptRunner.PopAction
          WRITEME: Document this type.
 class PlebeianScriptRunner.Random_Runner
          Run something randomly from a set of possible outcomes
private  class PlebeianScriptRunner.SayCasuallyRunner
          WRITEME: Document this type.
private  class PlebeianScriptRunner.SimultaneousExecutionRunner
          WRITEME: Document this type.
private  class PlebeianScriptRunner.StateChangeRunner
          WRITEME: Document this type.
private  class PlebeianScriptRunner.TestActorEquippedItem
          WRITEME: Document this type.
private  class PlebeianScriptRunner.TestActorHasCurrency
          WRITEME: Document this type.
private  class PlebeianScriptRunner.TestActorHasItem
          WRITEME: Document this type.
private static class PlebeianScriptRunner.TestAND
          WRITEME: Document this type.
private  class PlebeianScriptRunner.TestIndirectContains
          WRITEME: Document this type.
private static class PlebeianScriptRunner.TestOR
          WRITEME: Document this type.
private static class PlebeianScriptRunner.TestXOR
          WRITEME: Document this type.
 
Field Summary
 Deque<Action> actions
          currently-being-handled action (potentially recursive; eww.)
 Map<String,Queue<PlebeianExpression>> expressions
          state machine stuff
 AtomicInteger ignoreNextStepsCounter
          counter of how deeply we're ignoring the next step counter
private  long lastScriptTime
          last time something happened
 String logicalState
          WRITEME
 Deque<Runnable> toDo
          Steps to be executed
private  ScriptPuppet victim
          the NPC to which this script is running
(package private) static String WS_PUNC
          whitespace and whitespace-equivalent punctuation characters to be ignored in tokenizing
 
Constructor Summary
private PlebeianScriptRunner(AtomicInteger ignoreCounter, String initialState, Map<String,Queue<PlebeianExpression>> initialExpressions, Deque<Action> initialActions, Deque<Runnable> initialToDoItems, ScriptPuppet puppet)
          WRITEME: Document this constructor brpocock@star-hope.org
  PlebeianScriptRunner(ScriptPuppet master)
          WRITEME: Document this constructor brpocock@star-hope.org
 
Method Summary
private  PlebeianScriptConditional addCondition(PlebeianScriptConditional prior, PlebeianTestConjunction conj, PlebeianScriptConditional latter)
          WRITEME: Document this method brpocock@star-hope.org
private  void addExpressionToState(PlebeianExpression expression)
          add an expression to a state, handling autovivification if it's the first expression for that state
private  void addSteps(Queue<Runnable> steps, List<Runnable> newSteps)
          Add one or more steps to the given queue, running the steps together if more than one are specified.
 void dispatch(Action a)
          WRITEME: Document this method brpocock@star-hope.org
 void doNextToDoItem()
          Do the next script step in queue.
protected  AbstractUser getActorByRole(PlebeianActor rôle)
          Get an actor in an active action.
 long getLastScriptTime()
          WRITEME: Document this method brpocock@star-hope.org
 ScriptPuppet getPuppet()
          WRITEME: Document this method brpocock@star-hope.org
 String getWsPunc()
           
protected  void ignoreNextSteps(boolean whether)
           
 void load(String login)
          WRITEME: Document this method brpocock@star-hope.org
protected  void nextToDoItemSoon()
          Do another step, soon, where “soon” is currently defined as 60ms from now
(package private)  PlebeianExpression parseAlwaysCommand(StringTokenizer tokens)
          parse the contents of a “Always” clause
private  PlebeianScriptConditional parseConditional(StringTokenizer tokens)
          WRITEME: Document this method brpocock@star-hope.org
private  void parseDeclarationCommand(String token, StringTokenizer tokens)
          Parse a top-level declaration command
private  void parseNote(StringTokenizer tokens)
          Ignore everything up to the next “End.” token
(package private)  PlebeianScript parseScript(StringTokenizer tokens)
          WRITEME: Document this method brpocock@star-hope.org
(package private)  PlebeianTestClause parseTestClause(StringTokenizer tokens)
          WRITEME: Document this method brpocock@star-hope.org
private  PlebeianExpression parseWhenCommand(StringTokenizer tokens)
          parse the contents of a “When” clause
(package private)  Action peekAction()
          WRITEME: Document this method brpocock@star-hope.org
 void pushToDo(Runnable runnable)
          WRITEME: Document this method brpocock@star-hope.org
private  void readScriptFile(File script)
          WRITEME: Document this method brpocock@star-hope.org
 void setLastScriptTime(long when)
          WRITEME: Document this method brpocock@star-hope.org
protected  void setLogicalState(String newState)
          WRITEME: Document this method brpocock@star-hope.org
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

WS_PUNC

static final String WS_PUNC
whitespace and whitespace-equivalent punctuation characters to be ignored in tokenizing

See Also:
Constant Field Values

actions

public Deque<Action> actions
currently-being-handled action (potentially recursive; eww.)


expressions

public Map<String,Queue<PlebeianExpression>> expressions
state machine stuff


ignoreNextStepsCounter

public AtomicInteger ignoreNextStepsCounter
counter of how deeply we're ignoring the next step counter


lastScriptTime

private long lastScriptTime
last time something happened


logicalState

public String logicalState
WRITEME


toDo

public Deque<Runnable> toDo
Steps to be executed


victim

private final ScriptPuppet victim
the NPC to which this script is running

Constructor Detail

PlebeianScriptRunner

private PlebeianScriptRunner(AtomicInteger ignoreCounter,
                             String initialState,
                             Map<String,Queue<PlebeianExpression>> initialExpressions,
                             Deque<Action> initialActions,
                             Deque<Runnable> initialToDoItems,
                             ScriptPuppet puppet)
WRITEME: Document this constructor brpocock@star-hope.org

Parameters:
ignoreCounter - WRITEME
initialState - WRITEME
initialExpressions - WRITEME
initialActions - WRITEME
initialToDoItems - WRITEME
puppet - NPC to be puppetted

PlebeianScriptRunner

public PlebeianScriptRunner(ScriptPuppet master)
WRITEME: Document this constructor brpocock@star-hope.org

Parameters:
master - WRITEME
Method Detail

addCondition

private PlebeianScriptConditional addCondition(PlebeianScriptConditional prior,
                                               PlebeianTestConjunction conj,
                                               PlebeianScriptConditional latter)
WRITEME: Document this method brpocock@star-hope.org

Parameters:
prior - the prior clause
conj - the conjunction
latter - the latter clause
Returns:
a clause applying the conjunction appropriately

addExpressionToState

private void addExpressionToState(PlebeianExpression expression)
add an expression to a state, handling autovivification if it's the first expression for that state

Parameters:
expression - the expression to be added

addSteps

private void addSteps(Queue<Runnable> steps,
                      List<Runnable> newSteps)
Add one or more steps to the given queue, running the steps together if more than one are specified.

Parameters:
steps - the queue to have the steps added to it
newSteps - the step(s) to be added

dispatch

public void dispatch(Action a)
WRITEME: Document this method brpocock@star-hope.org

Specified by:
dispatch in interface ScriptRunner
Parameters:
a - the action to be dispatched

doNextToDoItem

public void doNextToDoItem()
Do the next script step in queue.

Specified by:
doNextToDoItem in interface ScriptRunner

getActorByRole

protected AbstractUser getActorByRole(PlebeianActor rôle)
Get an actor in an active action.

Parameters:
rôle - the actor's rôle
Returns:
the actor

getLastScriptTime

public long getLastScriptTime()
WRITEME: Document this method brpocock@star-hope.org

Returns:
time at which the last scripted action should have / will complete

getPuppet

public ScriptPuppet getPuppet()
Description copied from interface: ScriptRunner
WRITEME: Document this method brpocock@star-hope.org

Specified by:
getPuppet in interface ScriptRunner
Returns:
the puppet controlled by this script

getWsPunc

public String getWsPunc()
Returns:
whitespace and punctuation ignored in script files

ignoreNextSteps

protected void ignoreNextSteps(boolean whether)
Parameters:
whether - shitty way to start and stop ignoring “do next step” calls

load

public void load(String login)
          throws GameLogicException
WRITEME: Document this method brpocock@star-hope.org

Parameters:
login - the NPC's user name (also used to find their script)
Throws:
GameLogicException - usually on a syntax error or something

nextToDoItemSoon

protected void nextToDoItemSoon()
Do another step, soon, where “soon” is currently defined as 60ms from now


parseAlwaysCommand

PlebeianExpression parseAlwaysCommand(StringTokenizer tokens)
                                throws GameLogicException
parse the contents of a “Always” clause

Parameters:
tokens - tokenizer
Returns:
the expression parsed
Throws:
GameLogicException - usually a syntax error

parseConditional

private PlebeianScriptConditional parseConditional(StringTokenizer tokens)
                                            throws GameLogicException
WRITEME: Document this method brpocock@star-hope.org

Parameters:
tokens - token stream from script parser
Returns:
a conditional expression evaluator
Throws:
GameLogicException - syntax error

parseDeclarationCommand

private void parseDeclarationCommand(String token,
                                     StringTokenizer tokens)
                              throws GameLogicException
Parse a top-level declaration command

Parameters:
token - the command word
tokens - the tokenizer stream containing the remainder of the definition, which will be advanced through ti
Throws:
GameLogicException - on syntax errors

parseNote

private void parseNote(StringTokenizer tokens)
Ignore everything up to the next “End.” token

Parameters:
tokens - the tokenizer emitting tokens, which will be advanced past “End.”

parseScript

PlebeianScript parseScript(StringTokenizer tokens)
                     throws GameLogicException
WRITEME: Document this method brpocock@star-hope.org

Parameters:
tokens - WRITEME
Returns:
WRITEME
Throws:
GameLogicException - on syntax errors

parseTestClause

PlebeianTestClause parseTestClause(StringTokenizer tokens)
                             throws GameLogicException
WRITEME: Document this method brpocock@star-hope.org

Parameters:
tokens - the tokenizer
Returns:
a test clause
Throws:
GameLogicException - if the script can't be parsed

parseWhenCommand

private PlebeianExpression parseWhenCommand(StringTokenizer tokens)
parse the contents of a “When” clause

Parameters:
tokens - tokenizer
Returns:
the expression yielded

peekAction

Action peekAction()
WRITEME: Document this method brpocock@star-hope.org

Returns:
the action at the top of the stack

pushToDo

public void pushToDo(Runnable runnable)
Description copied from interface: ScriptRunner
WRITEME: Document this method brpocock@star-hope.org

Specified by:
pushToDo in interface ScriptRunner
See Also:
ScriptRunner.pushToDo(java.lang.Runnable)

readScriptFile

private void readScriptFile(File script)
                     throws GameLogicException
WRITEME: Document this method brpocock@star-hope.org

Parameters:
script - the script file to be read
Throws:
GameLogicException - usually syntax error

setLastScriptTime

public void setLastScriptTime(long when)
Description copied from interface: ScriptRunner
WRITEME: Document this method brpocock@star-hope.org

Specified by:
setLastScriptTime in interface ScriptRunner
See Also:
ScriptRunner.setLastScriptTime(long)

setLogicalState

protected void setLogicalState(String newState)
WRITEME: Document this method brpocock@star-hope.org

Parameters:
newState - the new state to be in

toString

public String toString()
Overrides:
toString in class Object
See Also:
Object.toString()