com.planet_ink.coffee_mud.Common.interfaces
Interface ScriptingEngine

All Superinterfaces:
java.lang.Cloneable, CMCommon, CMObject, java.lang.Comparable<CMObject>, MsgListener, Tickable
All Known Implementing Classes:
DefaultScriptingEngine, Scriptable, ScriptableEverymob

public interface ScriptingEngine
extends CMCommon, Tickable, MsgListener

The interface for the main CoffeeMud scripting engine, which implements a scripting engine descended from the old mud codebases of the 90's usually called MOBPROG. Its main features include easy to understand event-oriented triggers, making all mud commands implicit scripting commands. It also includes methods for embedding javascript.

See Also:
Scriptable

Nested Class Summary
static class ScriptingEngine.ScriptableResponse
          An object that holds the information about an event until it is time to execute its associated script.
 
Field Summary
static int CONNECTOR_AND
          index and equate for logical connector AND
static int CONNECTOR_ANDNOT
          index and equate for logical connector ANDNOT
static int[][] CONNECTOR_MAP
          A table to describe what happens when connectors are found sequentially (and and not or not and and, etc)
static int CONNECTOR_NOT
          index and equate for logical connector NOT
static int CONNECTOR_OR
          index and equate for logical connector OR
static int CONNECTOR_ORNOT
          index and equate for logical connector ORNOT
static java.lang.String[] CONNECTORS
          a list of logical connectors (and, or, etc)
static java.lang.String[] DATETIME_ARGS
          a list of the different parts of a time clock
static java.lang.String[] funcs
          String list of all valid mobprog functions for logical expressions or string functions
static int GSTATADD_CLAN
          index and equate for stat code for mob: clan
static int GSTATADD_CLANROLE
          index and equate for stat code for mob: clan role
static int GSTATADD_DEITY
          index and equate for stat code for mob: deity
static int GSTATADD_STINK
          index and equate for stat code for mob: hygeine
static java.lang.String[] GSTATCODES_ADDITIONAL
          a list of some some extra stat codes for mobs
static java.lang.String[] methods
          String list of all valid mobprog commands
static java.lang.String[] progs
          String list of all valid trigger keywords
static int SIGN_EQGT
          Index and equate for =>
static int SIGN_EQLT
          Index and equate for =<
static int SIGN_EQUL
          Index and equate for ==
static int SIGN_GRAT
          Index and equate for >
static int SIGN_GTEQ
          Index and equate for >=
static int SIGN_LEST
          Index and equate for <
static int SIGN_LTEQ
          Index and equate for <=
static int SIGN_NTEQ
          Index and equate for !=
static java.lang.String[] SIGNS
          List of evaluation signs ==, !=, >, etc.
static int SPECIAL_9SHOPHASPRICE
          The index into the local variables array for a random items shop price from shophas
static int SPECIAL_NUM_OBJECTS
          The number of local variables associated with an execution of a script
static int SPECIAL_RANDANYONE
          The index into the local variables array for a random pc or mob
static int SPECIAL_RANDPC
          The index into the local variables array for a random pc
 
Fields inherited from interface com.planet_ink.coffee_mud.core.interfaces.Tickable
STATUS_AFFECT, STATUS_ALIVE, STATUS_BEHAVIOR, STATUS_CLASS, STATUS_DEAD, STATUS_END, STATUS_FIGHT, STATUS_MISC, STATUS_MISC2, STATUS_MISC3, STATUS_MISC4, STATUS_MISC5, STATUS_MISC6, STATUS_MISC7, STATUS_NOT, STATUS_OTHER, STATUS_RACE, STATUS_REBIRTH, STATUS_SCRIPT, STATUS_START, STATUS_WEATHER, TICKID_AREA, TICKID_BEAMWEAPON, TICKID_CLAN, TICKID_CLANITEM, TICKID_DEADBODY_DECAY, TICKID_ELECTRONICS, TICKID_EMAIL, TICKID_EXIT_BEHAVIOR, TICKID_EXIT_REOPEN, TICKID_ITEM_BEHAVIOR, TICKID_ITEM_BOUNCEBACK, TICKID_LIGHT_FLICKERS, TICKID_LIVEAUCTION, TICKID_LONGERMASK, TICKID_MISCELLANEOUS, TICKID_MOB, TICKID_PROPERTY_SPECIAL, TICKID_QUEST, TICKID_READYTOSTOP, TICKID_ROOM_BEHAVIOR, TICKID_ROOM_ITEM_REJUV, TICKID_SOLITARYMASK, TICKID_SPECIALCOMBAT, TICKID_SPECIALMANEUVER, TICKID_SPELL_AFFECT, TICKID_SUPPORT, TICKID_TIMEAUCTION, TICKID_TRAP_DESTRUCTION, TICKID_TRAP_RESET
 
Method Summary
 java.lang.String defaultQuestName()
          If this script is associated with a particular quest, this method is called to return that quest name.
 void dequeResponses()
          Forces any queued event responses to be immediately executed.
 boolean endQuest(PhysicalAgent hostObj, MOB mob, java.lang.String quest)
          Calling this method forces this script to look for a trigger dealing with the end of a quest (QUEST_TIME_PROG -1).
 boolean eval(PhysicalAgent scripted, MOB source, Environmental target, MOB monster, Item primaryItem, Item secondaryItem, java.lang.String msg, java.lang.Object[] tmp, java.lang.String[][] eval, int startEval)
          Evaluates a scripting function.
 java.lang.String execute(PhysicalAgent scripted, MOB source, Environmental target, MOB monster, Item primaryItem, Item secondaryItem, DVector script, java.lang.String msg, java.lang.Object[] tmp)
          Executes a script in response to an event The scripts are formatted as a 2 dimensional DVector with the first row being the trigger information.
 java.util.List<java.lang.String> externalFiles()
          If the script is a load command, this will return the list of loaded script files referenced by the load command
 java.lang.String functify(PhysicalAgent scripted, MOB source, Environmental target, MOB monster, Item primaryItem, Item secondaryItem, java.lang.String msg, java.lang.Object[] tmp, java.lang.String evaluable)
          Evaluates one of the boolean functions as a string variable expression, which gives different and informative results.
 java.lang.String getLocalVarXML()
          If the variable scope of this script is local, this will return all the variables and values defined as an xml document for easy storage.
 MOB getMakeMOB(Tickable ticking)
          Creates a mob from the Tickable object sent, possibly saving it locally to this object for use later.
 java.lang.String getScript()
          Returns the script or load command(s).
 java.lang.String getScriptResourceKey()
          Returns the hey used to cache the script or load commands in here.
 java.lang.String getVar(java.lang.String context, java.lang.String variable)
          Returns the value of one of the internal variables, determined by the scope of the script, the context of the variable, and the name of the variable.
 java.lang.String getVarScope()
          Returns the scope of any variables defined within the script.
 boolean isSavable()
          Returns whether this script is a temporary attributed of the scripted object, or a permanent on that should be saved with the object.
 boolean isVar(java.lang.String context, java.lang.String variable)
          Returns whether an internal variables, determined by the scope of the script, the context of the variable, and the name of the variable, is defined.
 java.lang.String[] parseEval(java.lang.String evaluable)
          Receives a string for evaluation by the eval function, and stores it as the first element in the given 2 dimensional string array.
 void registerDefaultQuest(java.lang.String questName)
          If this script is associated with a particular quest, this method is called to register that quest name.
 void setLocalVarXML(java.lang.String xml)
          If the variable scope of this script is local, this will set all the variables and values defined from a passed in xml document.
 void setSavable(boolean truefalse)
          Sets whether this script is a temporary attributed of the scripted object, or a permanent on that should be saved with the object.
 void setScript(java.lang.String newParms)
          Sets the script or load command(s).
 void setVar(java.lang.String context, java.lang.String variable, java.lang.String value)
          Sets the value of one of the internal variables, determined by the scope of the script, the context of the variable, and the name of the variable.
 void setVarScope(java.lang.String scope)
          Sets the scope of any variables defined within the script.
 java.lang.String varify(MOB source, Environmental target, PhysicalAgent scripted, MOB monster, Item primaryItem, Item secondaryItem, java.lang.String msg, java.lang.Object[] tmp, java.lang.String varifyable)
          Uses this scripting engines variable parsing system to replace any script variables $XXXX with their script determined values.
 
Methods inherited from interface com.planet_ink.coffee_mud.core.interfaces.Tickable
getTickStatus, name, tick
 
Methods inherited from interface com.planet_ink.coffee_mud.core.interfaces.CMObject
copyOf, ID, initializeClass, newInstance
 
Methods inherited from interface java.lang.Comparable
compareTo
 
Methods inherited from interface com.planet_ink.coffee_mud.core.interfaces.MsgListener
executeMsg, okMessage
 

Field Detail

SPECIAL_NUM_OBJECTS

static final int SPECIAL_NUM_OBJECTS
The number of local variables associated with an execution of a script

See Also:
Constant Field Values

SPECIAL_RANDPC

static final int SPECIAL_RANDPC
The index into the local variables array for a random pc

See Also:
Constant Field Values

SPECIAL_RANDANYONE

static final int SPECIAL_RANDANYONE
The index into the local variables array for a random pc or mob

See Also:
Constant Field Values

SPECIAL_9SHOPHASPRICE

static final int SPECIAL_9SHOPHASPRICE
The index into the local variables array for a random items shop price from shophas

See Also:
Constant Field Values

progs

static final java.lang.String[] progs
String list of all valid trigger keywords


funcs

static final java.lang.String[] funcs
String list of all valid mobprog functions for logical expressions or string functions


methods

static final java.lang.String[] methods
String list of all valid mobprog commands


GSTATCODES_ADDITIONAL

static final java.lang.String[] GSTATCODES_ADDITIONAL
a list of some some extra stat codes for mobs


GSTATADD_DEITY

static final int GSTATADD_DEITY
index and equate for stat code for mob: deity

See Also:
Constant Field Values

GSTATADD_CLAN

static final int GSTATADD_CLAN
index and equate for stat code for mob: clan

See Also:
Constant Field Values

GSTATADD_CLANROLE

static final int GSTATADD_CLANROLE
index and equate for stat code for mob: clan role

See Also:
Constant Field Values

GSTATADD_STINK

static final int GSTATADD_STINK
index and equate for stat code for mob: hygeine

See Also:
Constant Field Values

DATETIME_ARGS

static final java.lang.String[] DATETIME_ARGS
a list of the different parts of a time clock


SIGNS

static final java.lang.String[] SIGNS
List of evaluation signs ==, !=, >, etc.


SIGN_EQUL

static final int SIGN_EQUL
Index and equate for ==

See Also:
Constant Field Values

SIGN_GTEQ

static final int SIGN_GTEQ
Index and equate for >=

See Also:
Constant Field Values

SIGN_GRAT

static final int SIGN_GRAT
Index and equate for >

See Also:
Constant Field Values

SIGN_LEST

static final int SIGN_LEST
Index and equate for <

See Also:
Constant Field Values

SIGN_LTEQ

static final int SIGN_LTEQ
Index and equate for <=

See Also:
Constant Field Values

SIGN_EQGT

static final int SIGN_EQGT
Index and equate for =>

See Also:
Constant Field Values

SIGN_EQLT

static final int SIGN_EQLT
Index and equate for =<

See Also:
Constant Field Values

SIGN_NTEQ

static final int SIGN_NTEQ
Index and equate for !=

See Also:
Constant Field Values

CONNECTORS

static final java.lang.String[] CONNECTORS
a list of logical connectors (and, or, etc)


CONNECTOR_AND

static final int CONNECTOR_AND
index and equate for logical connector AND

See Also:
Constant Field Values

CONNECTOR_OR

static final int CONNECTOR_OR
index and equate for logical connector OR

See Also:
Constant Field Values

CONNECTOR_NOT

static final int CONNECTOR_NOT
index and equate for logical connector NOT

See Also:
Constant Field Values

CONNECTOR_ANDNOT

static final int CONNECTOR_ANDNOT
index and equate for logical connector ANDNOT

See Also:
Constant Field Values

CONNECTOR_ORNOT

static final int CONNECTOR_ORNOT
index and equate for logical connector ORNOT

See Also:
Constant Field Values

CONNECTOR_MAP

static final int[][] CONNECTOR_MAP
A table to describe what happens when connectors are found sequentially (and and not or not and and, etc)

Method Detail

execute

java.lang.String execute(PhysicalAgent scripted,
                         MOB source,
                         Environmental target,
                         MOB monster,
                         Item primaryItem,
                         Item secondaryItem,
                         DVector script,
                         java.lang.String msg,
                         java.lang.Object[] tmp)
Executes a script in response to an event The scripts are formatted as a 2 dimensional DVector with the first row being the trigger information. Each row consists of the String command, and a parsed String[] array as dimension 2.

Parameters:
scripted - the object that is scripted
source - the source of the event
target - the target of the event
monster - a mob representation of the scripted object
primaryItem - an item involved in the event
secondaryItem - a second item involved in the event
script - 2 dimensional DVector, the script to execute
msg - a string message associated with the event
tmp - miscellaneous local variables
Returns:
N/A
See Also:
ScriptingEngine.ScriptableResponse

varify

java.lang.String varify(MOB source,
                        Environmental target,
                        PhysicalAgent scripted,
                        MOB monster,
                        Item primaryItem,
                        Item secondaryItem,
                        java.lang.String msg,
                        java.lang.Object[] tmp,
                        java.lang.String varifyable)
Uses this scripting engines variable parsing system to replace any script variables $XXXX with their script determined values. This is a powerful mechanism for getting at the script functions in order to access stat data about specific objects, do math, etc.

Parameters:
source - the source of the event
target - the target of the event
scripted - the object that is scripted
monster - a mob representation of the scripted object
primaryItem - an item involved in the event
secondaryItem - a second item involved in the event
msg - a string message associated with the event
tmp - miscellaneous local variables
varifyable - the string to parse
Returns:
N/A

dequeResponses

void dequeResponses()
Forces any queued event responses to be immediately executed.


getMakeMOB

MOB getMakeMOB(Tickable ticking)
Creates a mob from the Tickable object sent, possibly saving it locally to this object for use later. If the object is a mob, it returns the mob. Otherwise, it makes a fake one.

Parameters:
ticking - the scripted object to make a fake mob out of
Returns:
a mob from a tickable

parseEval

java.lang.String[] parseEval(java.lang.String evaluable)
                             throws ScriptParseException
Receives a string for evaluation by the eval function, and stores it as the first element in the given 2 dimensional string array.

Parameters:
evaluable - the eval expression
Returns:
EVAL the 1 dimensional array to hold the compiled eval
Throws:
ScriptParseException - a parse error

eval

boolean eval(PhysicalAgent scripted,
             MOB source,
             Environmental target,
             MOB monster,
             Item primaryItem,
             Item secondaryItem,
             java.lang.String msg,
             java.lang.Object[] tmp,
             java.lang.String[][] eval,
             int startEval)
Evaluates a scripting function. Is called by the execute command to resolve IF, WHILE, and similar expressions that utilize the MOBPROG functions. The expressions are passed in as a String array stored in a single string array entry (for replacement) in element 0.

Parameters:
scripted - the object that is scripted
source - the source of the event
target - the target of the event
monster - a mob representation of the scripted object
primaryItem - an item involved in the event
secondaryItem - a second item involved in the event
msg - a string message associated with the event
tmp - miscellaneous local variables
eval - the pre-parsed expression
startEval - while line to start evaluating on.
Returns:
true if the expression is true, false otherwise.

functify

java.lang.String functify(PhysicalAgent scripted,
                          MOB source,
                          Environmental target,
                          MOB monster,
                          Item primaryItem,
                          Item secondaryItem,
                          java.lang.String msg,
                          java.lang.Object[] tmp,
                          java.lang.String evaluable)
Evaluates one of the boolean functions as a string variable expression, which gives different and informative results. See the Green Table in the Scripting Guide.

Parameters:
scripted - the object that is scripted
source - the source of the event
target - the target of the event
monster - a mob representation of the scripted object
primaryItem - an item involved in the event
secondaryItem - a second item involved in the event
msg - a string message associated with the event
tmp - miscellaneous local variables
evaluable - the function expression
Returns:
the results of the function expression

endQuest

boolean endQuest(PhysicalAgent hostObj,
                 MOB mob,
                 java.lang.String quest)
Calling this method forces this script to look for a trigger dealing with the end of a quest (QUEST_TIME_PROG -1).

Parameters:
hostObj - the scripted object
mob - a mob representation of the host object
quest - the name of the quest being ended
Returns:
true if a quest ending trigger was found and run

getScript

java.lang.String getScript()
Returns the script or load command(s).

Returns:
the script or load command(s)
See Also:
setScript(String), externalFiles()

getScriptResourceKey

java.lang.String getScriptResourceKey()
Returns the hey used to cache the script or load commands in here.

Returns:
the key to the script or load command(s)
See Also:
getScript()

setScript

void setScript(java.lang.String newParms)
Sets the script or load command(s).

Parameters:
newParms - the script or load command(s)
See Also:
getScript(), externalFiles()

externalFiles

java.util.List<java.lang.String> externalFiles()
If the script is a load command, this will return the list of loaded script files referenced by the load command

Returns:
a list of loaded script files.
See Also:
getScript(), setScript(String)

registerDefaultQuest

void registerDefaultQuest(java.lang.String questName)
If this script is associated with a particular quest, this method is called to register that quest name.

Parameters:
questName - the quest associated with this script
See Also:
defaultQuestName()

defaultQuestName

java.lang.String defaultQuestName()
If this script is associated with a particular quest, this method is called to return that quest name.

Returns:
the quest associated with this script, if any
See Also:
registerDefaultQuest(String)

setVarScope

void setVarScope(java.lang.String scope)
Sets the scope of any variables defined within the script. Although the scope is somewhat modified if this script is quest-bound, it is usually honored. Valid scopes include: "" for global, "*" for local, or a shared named scope.

Parameters:
scope - the scope of variables
See Also:
getVarScope(), getVar(String, String), getLocalVarXML()

getVarScope

java.lang.String getVarScope()
Returns the scope of any variables defined within the script. Although the scope is somewhat modified if this script is quest-bound, it is usually honored. Valid scopes include: "" for global, "*" for local, or a shared named scope.

Returns:
the scope of variables
See Also:
setVarScope(String), setVar(String, String, String), setLocalVarXML(String)

getLocalVarXML

java.lang.String getLocalVarXML()
If the variable scope of this script is local, this will return all the variables and values defined as an xml document for easy storage.

Returns:
the local variable values as xml
See Also:
setVarScope(String), setVar(String, String, String), setLocalVarXML(String)

setLocalVarXML

void setLocalVarXML(java.lang.String xml)
If the variable scope of this script is local, this will set all the variables and values defined from a passed in xml document.

Parameters:
xml - the local variable values as xml
See Also:
getVarScope(), getVar(String, String), getLocalVarXML()

isSavable

boolean isSavable()
Returns whether this script is a temporary attributed of the scripted object, or a permanent on that should be saved with the object.

Returns:
whether this script is a saveable attribute of the scripted object
See Also:
setSavable(boolean)

setSavable

void setSavable(boolean truefalse)
Sets whether this script is a temporary attributed of the scripted object, or a permanent on that should be saved with the object.

Parameters:
truefalse - true if this script is a saveable attribute of the scripted object
See Also:
isSavable()

getVar

java.lang.String getVar(java.lang.String context,
                        java.lang.String variable)
Returns the value of one of the internal variables, determined by the scope of the script, the context of the variable, and the name of the variable.

Parameters:
context - the context of the variable, usually a mob or object name
variable - the name of the variable
Returns:
the value of the variable
See Also:
setVarScope(String), getVarScope(), setVar(String, String, String), isVar(String, String), getLocalVarXML(), setLocalVarXML(String)

isVar

boolean isVar(java.lang.String context,
              java.lang.String variable)
Returns whether an internal variables, determined by the scope of the script, the context of the variable, and the name of the variable, is defined.

Parameters:
context - the context of the variable, usually a mob or object name
variable - the name of the variable
Returns:
true if the variable has been set in the past, false otherwise
See Also:
setVarScope(String), getVarScope(), getVar(String, String), setVar(String, String, String), getLocalVarXML(), setLocalVarXML(String)

setVar

void setVar(java.lang.String context,
            java.lang.String variable,
            java.lang.String value)
Sets the value of one of the internal variables, determined by the scope of the script, the context of the variable, and the name of the variable.

Parameters:
context - the context of the variable, usually a mob or object name
variable - the name of the variable
value - the value of the variable
See Also:
setVarScope(String), getVarScope(), getVar(String, String), isVar(String, String), getLocalVarXML(), setLocalVarXML(String)