com.planet_ink.coffee_mud.Behaviors
Class Scriptable

java.lang.Object
  extended by com.planet_ink.coffee_mud.Behaviors.StdBehavior
      extended by com.planet_ink.coffee_mud.Behaviors.Scriptable
All Implemented Interfaces:
Behavior, CMCommon, ScriptingEngine, CMObject, Contingent, Modifiable, MsgListener, Tickable, java.lang.Cloneable, java.lang.Comparable<CMObject>

public class Scriptable
extends StdBehavior
implements ScriptingEngine


Nested Class Summary
 
Nested classes/interfaces inherited from interface com.planet_ink.coffee_mud.Common.interfaces.ScriptingEngine
ScriptingEngine.ScriptableResponse
 
Field Summary
protected  ScriptingEngine engine
           
 
Fields inherited from class com.planet_ink.coffee_mud.Behaviors.StdBehavior
CODES, isSavableBehavior, parms
 
Fields inherited from interface com.planet_ink.coffee_mud.Common.interfaces.ScriptingEngine
CONNECTOR_AND, CONNECTOR_ANDNOT, CONNECTOR_MAP, CONNECTOR_NOT, CONNECTOR_OR, CONNECTOR_ORNOT, CONNECTORS, DATETIME_ARGS, funcs, GSTATADD_CLAN, GSTATADD_CLANROLE, GSTATADD_DEITY, GSTATADD_STINK, GSTATCODES_ADDITIONAL, methods, progs, SIGN_EQGT, SIGN_EQLT, SIGN_EQUL, SIGN_GRAT, SIGN_GTEQ, SIGN_LEST, SIGN_LTEQ, SIGN_NTEQ, SIGNS, SPECIAL_9SHOPHASPRICE, SPECIAL_NUM_OBJECTS, SPECIAL_RANDANYONE, SPECIAL_RANDPC
 
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
 
Fields inherited from interface com.planet_ink.coffee_mud.Behaviors.interfaces.Behavior
CAN_AREAS, CAN_EXITS, CAN_ITEMS, CAN_MOBS, CAN_ROOMS, FLAG_LEGALBEHAVIOR, FLAG_MOBILITY, FLAG_POTENTIALLYAGGRESSIVE, FLAG_POTENTIALLYAUTODEATHING, FLAG_TROUBLEMAKING
 
Constructor Summary
Scriptable()
           
 
Method Summary
 java.lang.String accountForYourself()
          Returns a string describing what this behavior does.
protected  int canImproveCode()
           
 CMObject copyOf()
          Similar to Cloneable.clone(), but does its best to make sure that any internal objects to this class are also copyOfed.
 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).
protected  ScriptingEngine engine()
           
 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.
 void executeMsg(Environmental affecting, CMMsg msg)
          The general message event handler for the object.
 java.util.List<java.lang.String> externalFiles()
          Returns a string list of any external files which may be required to make this ability work.
 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 getParms()
          Returns the raw parameter string for this behavior.
 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.
 int getTickStatus()
          A coded status for this object during the period where its tick method is being called.
 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.
 java.lang.String ID()
          The CoffeeMud Java Class ID shared by all instances of this 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.
 boolean okMessage(Environmental host, CMMsg msg)
          The general message event previewer for the object.
 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)
          Called after a behavior is added to an Environmental object.
 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 setParms(java.lang.String newParms)
          Sets the raw parameter string for this behavior.
 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.
 boolean tick(Tickable ticking, int tickID)
          this is the method which is called periodically by the threading engine.
 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 class com.planet_ink.coffee_mud.Behaviors.StdBehavior
amDestroyed, canActAtAll, canFreelyBehaveNormal, canImprove, canImprove, compareTo, destroy, flags, getBehaversMOB, getBehaversRoom, getCodeNum, getSaveStatIndex, getStat, getStatCodes, grantsAggressivenessTo, initializeClass, isSavable, isStat, L, name, newInstance, parmsFormat, sameAs, setSavable, setStat, startBehavior
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.planet_ink.coffee_mud.Common.interfaces.ScriptingEngine
isSavable, setSavable
 
Methods inherited from interface com.planet_ink.coffee_mud.core.interfaces.Tickable
name
 
Methods inherited from interface com.planet_ink.coffee_mud.core.interfaces.CMObject
initializeClass, newInstance
 
Methods inherited from interface java.lang.Comparable
compareTo
 

Field Detail

engine

protected ScriptingEngine engine
Constructor Detail

Scriptable

public Scriptable()
Method Detail

ID

public java.lang.String ID()
Description copied from interface: CMObject
The CoffeeMud Java Class ID shared by all instances of this object. Unlike the Java Class name, this method does not include package information. However, it must return a String value unique to its class category in the ClassLoader. Class categories include Libraries, Common, Areas, Abilities, Behaviors, CharClasses, Commands, Exits Locales, MOBS, Races, WebMacros, Basic Items, Armor, Weapons, ClanItems, Tech. The name is typically identical to the class name.

Specified by:
ID in interface CMObject
Overrides:
ID in class StdBehavior
Returns:
the name of this class

canImproveCode

protected int canImproveCode()
Overrides:
canImproveCode in class StdBehavior

engine

protected ScriptingEngine engine()

accountForYourself

public java.lang.String accountForYourself()
Description copied from interface: Behavior
Returns a string describing what this behavior does. Mostly for thought and behavior reading systems.

Specified by:
accountForYourself in interface Behavior
Overrides:
accountForYourself in class StdBehavior
Returns:
a string describing what this behavior does.

getTickStatus

public int getTickStatus()
Description copied from interface: Tickable
A coded status for this object during the period where its tick method is being called. The statis is defined, at least in part, by constants in this interface STATUS_*. STATUS_NOT should be returned when the objects tick method is not currently in execution. It should never return STATUS_NOT when the objects tick method is in execution.

Specified by:
getTickStatus in interface Tickable
Overrides:
getTickStatus in class StdBehavior
Returns:
the numeric status of this object
See Also:
Tickable.tick(Tickable, int)

registerDefaultQuest

public void registerDefaultQuest(java.lang.String questName)
Description copied from interface: Behavior
Called after a behavior is added to an Environmental object. The point is to register a quest objet, should it be needed or be useful to the quest.

Specified by:
registerDefaultQuest in interface Behavior
Specified by:
registerDefaultQuest in interface ScriptingEngine
Overrides:
registerDefaultQuest in class StdBehavior
Parameters:
questName - the Quest name
See Also:
Quest

getMakeMOB

public MOB getMakeMOB(Tickable ticking)
Description copied from interface: ScriptingEngine
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.

Specified by:
getMakeMOB in interface ScriptingEngine
Parameters:
ticking - the scripted object to make a fake mob out of
Returns:
a mob from a tickable

endQuest

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

Specified by:
endQuest in interface ScriptingEngine
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

copyOf

public CMObject copyOf()
Description copied from interface: CMObject
Similar to Cloneable.clone(), but does its best to make sure that any internal objects to this class are also copyOfed.

Specified by:
copyOf in interface CMObject
Overrides:
copyOf in class StdBehavior
Returns:
a clone of this object

externalFiles

public java.util.List<java.lang.String> externalFiles()
Description copied from interface: Behavior
Returns a string list of any external files which may be required to make this ability work. Usually derived from the parameters. Files returned by this method should not be base distrib files!

Specified by:
externalFiles in interface Behavior
Specified by:
externalFiles in interface ScriptingEngine
Overrides:
externalFiles in class StdBehavior
Returns:
a list of the path/names of files used by this behavior
See Also:
Behavior.setParms(String)

getScriptResourceKey

public java.lang.String getScriptResourceKey()
Description copied from interface: ScriptingEngine
Returns the hey used to cache the script or load commands in here.

Specified by:
getScriptResourceKey in interface ScriptingEngine
Returns:
the key to the script or load command(s)
See Also:
ScriptingEngine.getScript()

getParms

public java.lang.String getParms()
Description copied from interface: Behavior
Returns the raw parameter string for this behavior. Parameters are meant to modify or specify specific behavior of this Behavior.

Specified by:
getParms in interface Behavior
Overrides:
getParms in class StdBehavior
Returns:
the parameter string for this behavior
See Also:
Behavior.setParms(String)

parseEval

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

Specified by:
parseEval in interface ScriptingEngine
Parameters:
evaluable - the eval expression
Returns:
EVAL the 1 dimensional array to hold the compiled eval
Throws:
ScriptParseException - a parse error

setParms

public void setParms(java.lang.String newParms)
Description copied from interface: Behavior
Sets the raw parameter string for this behavior. Parameters are meant to modify or specify specific behavior of this Behavior.

Specified by:
setParms in interface Behavior
Overrides:
setParms in class StdBehavior
Parameters:
newParms - the parameter string for this behavior
See Also:
Behavior.getParms()

getVar

public java.lang.String getVar(java.lang.String context,
                               java.lang.String variable)
Description copied from interface: ScriptingEngine
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.

Specified by:
getVar in interface ScriptingEngine
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:
ScriptingEngine.setVarScope(String), ScriptingEngine.getVarScope(), ScriptingEngine.setVar(String, String, String), ScriptingEngine.isVar(String, String), ScriptingEngine.getLocalVarXML(), ScriptingEngine.setLocalVarXML(String)

isVar

public boolean isVar(java.lang.String context,
                     java.lang.String variable)
Description copied from interface: ScriptingEngine
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.

Specified by:
isVar in interface ScriptingEngine
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:
ScriptingEngine.setVarScope(String), ScriptingEngine.getVarScope(), ScriptingEngine.getVar(String, String), ScriptingEngine.setVar(String, String, String), ScriptingEngine.getLocalVarXML(), ScriptingEngine.setLocalVarXML(String)

setVar

public void setVar(java.lang.String context,
                   java.lang.String variable,
                   java.lang.String value)
Description copied from interface: ScriptingEngine
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.

Specified by:
setVar in interface ScriptingEngine
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:
ScriptingEngine.setVarScope(String), ScriptingEngine.getVarScope(), ScriptingEngine.getVar(String, String), ScriptingEngine.isVar(String, String), ScriptingEngine.getLocalVarXML(), ScriptingEngine.setLocalVarXML(String)

defaultQuestName

public java.lang.String defaultQuestName()
Description copied from interface: ScriptingEngine
If this script is associated with a particular quest, this method is called to return that quest name.

Specified by:
defaultQuestName in interface ScriptingEngine
Returns:
the quest associated with this script, if any
See Also:
ScriptingEngine.registerDefaultQuest(String)

setVarScope

public void setVarScope(java.lang.String scope)
Description copied from interface: ScriptingEngine
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.

Specified by:
setVarScope in interface ScriptingEngine
Parameters:
scope - the scope of variables
See Also:
ScriptingEngine.getVarScope(), ScriptingEngine.getVar(String, String), ScriptingEngine.getLocalVarXML()

getVarScope

public java.lang.String getVarScope()
Description copied from interface: ScriptingEngine
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.

Specified by:
getVarScope in interface ScriptingEngine
Returns:
the scope of variables
See Also:
ScriptingEngine.setVarScope(String), ScriptingEngine.setVar(String, String, String), ScriptingEngine.setLocalVarXML(String)

getLocalVarXML

public java.lang.String getLocalVarXML()
Description copied from interface: ScriptingEngine
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.

Specified by:
getLocalVarXML in interface ScriptingEngine
Returns:
the local variable values as xml
See Also:
ScriptingEngine.setVarScope(String), ScriptingEngine.setVar(String, String, String), ScriptingEngine.setLocalVarXML(String)

setLocalVarXML

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

Specified by:
setLocalVarXML in interface ScriptingEngine
Parameters:
xml - the local variable values as xml
See Also:
ScriptingEngine.getVarScope(), ScriptingEngine.getVar(String, String), ScriptingEngine.getLocalVarXML()

eval

public 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)
Description copied from interface: ScriptingEngine
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.

Specified by:
eval in interface ScriptingEngine
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.

getScript

public java.lang.String getScript()
Description copied from interface: ScriptingEngine
Returns the script or load command(s).

Specified by:
getScript in interface ScriptingEngine
Returns:
the script or load command(s)
See Also:
ScriptingEngine.setScript(String), ScriptingEngine.externalFiles()

setScript

public void setScript(java.lang.String newParms)
Description copied from interface: ScriptingEngine
Sets the script or load command(s).

Specified by:
setScript in interface ScriptingEngine
Parameters:
newParms - the script or load command(s)
See Also:
ScriptingEngine.getScript(), ScriptingEngine.externalFiles()

execute

public 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)
Description copied from interface: ScriptingEngine
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.

Specified by:
execute in interface ScriptingEngine
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

executeMsg

public void executeMsg(Environmental affecting,
                       CMMsg msg)
Description copied from interface: MsgListener
The general message event handler for the object. Messages passed herein may not necessarily be FOR this object, or from it, but will almost always represent events happening in the same room. The messages have already been through an approval process, so this method is called only to affect the final execution of the meaning of the message. Every game event goes through these methods.

Specified by:
executeMsg in interface MsgListener
Overrides:
executeMsg in class StdBehavior
Parameters:
affecting - either the initiator of the event, or the host of this object
msg - the CMMsg that needs to be executed
See Also:
CMMsg

okMessage

public boolean okMessage(Environmental host,
                         CMMsg msg)
Description copied from interface: MsgListener
The general message event previewer for the object. Messages passed herein are in a pending state, and may be safely modified or rejected without fear that they might be in the middle of being executed. Messages passed herein may not necessarily be FOR or FROM this object, but will almost always represent events which want to happen in the same rom. This method should always always return true UNLESS this message needs to be canceled, in which case it is necessary to tell the mob initiating the event (CMMsg.source()) why it is being cancelled. Every game event goes through these methods.

Specified by:
okMessage in interface MsgListener
Overrides:
okMessage in class StdBehavior
Parameters:
host - either the initiator of the event, or the host of this object
msg - the CMMsg that wants to be executed
Returns:
whether this message is allowed to execute
See Also:
CMMsg, CMMsg.source()

tick

public boolean tick(Tickable ticking,
                    int tickID)
Description copied from interface: Tickable
this is the method which is called periodically by the threading engine. How often it is called depends on the parameters passed to the threadding engine when it is submitted for thread access. Typically the period is once per TIME_TICK period, but that is determined when the object is submitted to the thread engine.

Specified by:
tick in interface Tickable
Overrides:
tick in class StdBehavior
Parameters:
ticking - a reference to this Tickable object
tickID - the TICKID_ constant describing this periodic call, as defined in Tickable
Returns:
true always, unless this object no longer wishes to ever tick again, in which case false
See Also:
Tickable, ServiceEngine, TickableGroup

dequeResponses

public void dequeResponses()
Description copied from interface: ScriptingEngine
Forces any queued event responses to be immediately executed.

Specified by:
dequeResponses in interface ScriptingEngine

varify

public 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)
Description copied from interface: ScriptingEngine
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.

Specified by:
varify in interface ScriptingEngine
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

functify

public 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)
Description copied from interface: ScriptingEngine
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.

Specified by:
functify in interface ScriptingEngine
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