|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object wyvern.lib.Kernel
Has the most commonly used game engine functions in one convenient location. Reduces the number of kernel classes that game classes have to import.
The Kernel is an example of the Facade pattern, and delegates most of its calls to other kernel objects. You can call these objects directly in many cases, if you like.
Nested Class Summary |
Nested classes inherited from class wyvern.common.net.RPCConstants |
RPCConstants.ImageAlign, RPCConstants.ImageFlags, RPCConstants.ImageFormat, RPCConstants.OutputView, RPCConstants.TextStyle |
Field Summary | |
static java.lang.String |
DATE_FORMAT
The format string that the Kernel uses for formatting dates used in properties such as "last-login". |
static int |
ONE_DAY
Number of milliseconds in one day (24 hours) |
static int |
ONE_HOUR
Number of milliseconds in one hour. |
static int |
ONE_MINUTE
Number of milliseconds in one minute. |
static int |
ONE_MONTH
Approx. number of milliseconds in one month (30 days). |
static int |
ONE_SECOND
Number of milliseconds in one minute. |
static int |
ONE_WEEK
Number of milliseconds in one week (7 days) |
static int |
ONE_YEAR
Approx. number of milliseconds in one year (365 days). |
Constructor Summary | |
Kernel()
|
Method Summary | |
static boolean |
adjacentTo(GameObject o1,
GameObject o2)
Returns true if two objects are adjacent to one another. |
static boolean |
adjacentTo(GameObject obj,
Point p)
Returns true if the specified Point is adjacent to the specified GameObject. |
static boolean |
canPK(GameObject agent,
GameObject target)
Implements rules for Player Killing. |
static void |
config(java.lang.Class sourceClass,
java.lang.String sourceMethod,
java.lang.String msg)
Logs a CONFIG message. |
static void |
config(java.lang.String sourceClass,
java.lang.String sourceMethod,
java.lang.String msg)
Logs a CONFIG message. |
static EventQueue |
createEventQueue(Commandable owner)
Creates an EventQueue to associated with a Commandable object. |
static void |
entering(java.lang.Class sourceClass,
java.lang.String sourceMethod)
Logs a method entry. |
static void |
entering(java.lang.Class sourceClass,
java.lang.String sourceMethod,
java.lang.Object[] params)
Logs a method entry. |
static void |
entering(java.lang.String sourceClass,
java.lang.String sourceMethod)
Logs a method entry. |
static void |
entering(java.lang.String sourceClass,
java.lang.String sourceMethod,
java.lang.Object[] params)
Logs a method entry. |
static void |
exiting(java.lang.Class sourceClass,
java.lang.String sourceMethod)
Logs a method return. |
static void |
exiting(java.lang.Class sourceClass,
java.lang.String sourceMethod,
java.lang.Object result)
Logs a method return. |
static void |
exiting(java.lang.String sourceClass,
java.lang.String sourceMethod)
Logs a method return. |
static void |
exiting(java.lang.String sourceClass,
java.lang.String sourceMethod,
java.lang.Object result)
Logs a method return. |
static java.lang.String |
extractWizNameFromClass(java.lang.String path)
Given a java classname, such as "wyvern.wiz.foobar.whatever.Thing", extracts the wizard name from the classname, if present. |
static java.lang.String |
extractWizNameFromPath(java.lang.String path)
Given a relative path, e.g. |
static void |
fine(java.lang.Class sourceClass,
java.lang.String sourceMethod,
java.lang.String msg)
Logs a FINE message. |
static void |
fine(java.lang.String sourceClass,
java.lang.String sourceMethod,
java.lang.String msg)
Logs a FINE message. |
static void |
finer(java.lang.Class sourceClass,
java.lang.String sourceMethod,
java.lang.String msg)
Logs a FINER message. |
static void |
finer(java.lang.String sourceClass,
java.lang.String sourceMethod,
java.lang.String msg)
Logs a FINER message. |
static void |
finest(java.lang.Class sourceClass,
java.lang.String sourceMethod,
java.lang.String msg)
Logs a FINEST message. |
static void |
finest(java.lang.String sourceClass,
java.lang.String sourceMethod,
java.lang.String msg)
Logs a FINEST message. |
static java.lang.String |
formatDate(java.util.Date date)
Formats the specified Date in the format we use for date properties. |
static java.lang.String |
getDate()
Returns the current date and time, formatted as a String suitable for writing into a property value. |
static java.util.logging.Logger |
getLog(java.lang.String path)
Gets a Logger for a file under admin/logs. |
static java.lang.String |
getLogLevel(java.lang.String name)
Returns the java.util.logging.Level for a Logger specified by name. |
static Predicate |
getNameMatchPredicate(java.lang.String name)
Takes an object description and returns a predicate suitable for finding it. |
static java.lang.String |
getTime()
Returns the current time, formatted as hours and minutes. |
static java.util.logging.Logger |
getWizLogger(java.lang.String wizname)
Returns a Logger that writes to a specified wizard logfile. |
static java.util.logging.Logger |
getWizLogger(java.lang.String wizname,
java.lang.String path)
Returns a Logger for the specified file in a wiz directory. |
static void |
info(java.lang.Class sourceClass,
java.lang.String sourceMethod,
java.lang.String msg)
Logs an INFO message. |
static void |
info(java.lang.String sourceClass,
java.lang.String sourceMethod,
java.lang.String msg)
Logs an INFO message. |
static GameObject |
instantiate(Archetype arch)
Instantiates an archetype by instantiating the class, then copying all the properties from the archetype to the new object. |
GameObject |
instantiate(Archetype arch,
boolean moveProps)
Instantiates an archetype by instantiating the class, then setting the new object's parent pointer to point to the passed archetype. |
static GameObject |
instantiate(java.lang.String archname)
A high-level utility for that loads an archetype, instantiates its class, and initializes the resulting object from the archetype definition. |
static GameObject |
instantiatePyGameObject(java.lang.String filename)
Instantiates a python-based GameObject implementation. |
static java.lang.Object |
instantiatePython(java.lang.String path,
java.lang.Class type)
Instantiates a Python object by loading it from a python file. |
static boolean |
isInstance(GameObject obj,
java.lang.String type)
Returns true if the passed object derives from a specific archetype. |
static boolean |
isInstance(PropertyList list,
java.lang.String type)
Returns true if the passed object derives from a specific archetype. |
static void |
killTimer(Timer timer)
Kills a timer. |
static Archetype |
loadArchetype(java.lang.String name)
Finds or loads the specified archetype, given its name. |
static void |
log(java.lang.String log,
java.lang.String msg)
Logs a message to the specified logfile under admin/logs. |
static void |
logError(java.lang.String msg)
Logs an error to the system logfile. |
static void |
logError(java.lang.String msg,
java.lang.Throwable t)
Logs an error message, with a stack trace included after the message. |
static void |
logEvent(java.lang.String msg)
Writes an event message to the system event log. |
static boolean |
onKernelThread()
Returns true if we're running on the "Kernel thread", meaning we have the map-exclusive. |
static java.util.Date |
parseDate(java.lang.String date)
Parses a date string in the format returned by Kernel.getDate(). |
static Point |
pointAdjacentTo(GameObject o1,
GameObject o2)
Fast check to see whether one object is adjacent to another. |
static void |
println(java.lang.String msg)
Alias for System.out.println, for debugging convenience. |
static void |
publish(java.lang.String subject)
Publishes a message with no Body or attachments. |
static void |
publish(java.lang.String subject,
java.util.Map attachments)
Publishes a message with attachments, but no Body. |
static void |
publish(java.lang.String subject,
java.lang.Object body)
Publishes a message with a body, but no attachments. |
static void |
publish(java.lang.String subject,
java.lang.Object body,
java.util.Map attachments)
Publishes a message with attachments, but no Body. |
static void |
setLogLevel(java.lang.String name,
java.util.logging.Level level)
Sets the log level for a given Logger, specified by its name. |
static void |
setLogLevel(java.lang.String name,
java.lang.String level)
Sets the log level for a given Logger, specified by its name. |
static Timer |
setRepeatingTimer(long delay,
long period,
Timed callback)
Registers a repeating timer to start after the specified delay. |
static Timer |
setRepeatingTimer(long period,
Timed callback)
Registers a repeating timer. |
static Timer |
setTimer(long delay,
Timed callback)
Registers a one-shot timer. |
static void |
severe(java.lang.Class sourceClass,
java.lang.String sourceMethod,
java.lang.String msg)
Logs a SEVERE message. |
static void |
severe(java.lang.String sourceClass,
java.lang.String sourceMethod,
java.lang.String msg)
Logs a SEVERE message. |
static void |
subscribe(Subscriber subscriber,
java.lang.String subject)
Registers a Subscriber for a particular subject. |
static void |
throwing(java.lang.Class sourceClass,
java.lang.String sourceMethod,
java.lang.Throwable t)
Logs throwing an exception. |
static void |
throwing(java.util.logging.Level level,
java.lang.String sourceClass,
java.lang.String sourceMethod,
java.lang.String msg,
java.lang.Throwable t)
Logs throwing an exception to all registered Handlers for the source class that are enabled for the passed log level. |
static void |
throwing(java.lang.String sourceClass,
java.lang.String sourceMethod,
java.lang.Throwable t)
Logs throwing an exception. |
static void |
unsubscribe(Subscriber subscriber,
java.lang.String subject)
De-registers a Subscriber for a particular subject. |
static void |
warning(java.lang.Class sourceClass,
java.lang.String sourceMethod,
java.lang.String msg)
Logs a WARNING message. |
static void |
warning(java.lang.String sourceClass,
java.lang.String sourceMethod,
java.lang.String msg)
Logs a WARNING message. |
static void |
writeWizLog(java.lang.String wizname,
java.lang.String path,
java.lang.String msg)
Logs a message into a specific logfile in a wiz directory. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final java.lang.String DATE_FORMAT
public static final int ONE_SECOND
public static final int ONE_MINUTE
public static final int ONE_HOUR
public static final int ONE_DAY
public static final int ONE_WEEK
public static final int ONE_MONTH
public static final int ONE_YEAR
Constructor Detail |
public Kernel()
Method Detail |
public static boolean canPK(GameObject agent, GameObject target)
agent
- player doing the attacktarget
- target getting attacked
public static EventQueue createEventQueue(Commandable owner)
public static Archetype loadArchetype(java.lang.String name) throws java.lang.Exception
name
- the local path to the archetype file (e.g. terrain/dirt1)
java.lang.Exception
ArchetypeManager.loadArchetype(java.lang.String)
public static GameObject instantiate(java.lang.String archname) throws java.lang.Exception
archname
- the archetype to load (e.g. "spells/medium_fireball")
java.lang.Exception
ArchetypeManager.instantiate(java.lang.String)
public static GameObject instantiate(Archetype arch) throws java.lang.Exception
arch
- the archetype to instantiate
java.lang.Exception
ArchetypeManager.instantiate(wyvern.lib.Archetype)
public GameObject instantiate(Archetype arch, boolean moveProps) throws java.lang.Exception
arch
- the archetype to instantiate
java.lang.Exception
public static GameObject instantiatePyGameObject(java.lang.String filename) throws java.lang.Exception
filename
- the absolute or relative path to a python file,
e.g. "wiz/rhialto/python/foo.py" or
"/games/wyvern/wiz/rhialto/python/foo.py". The method assumes
that if the path starts with "/", it's an absolute path.
java.lang.Exception
ArchetypeManager.instantiatePyGameObject(java.lang.String)
public static java.lang.Object instantiatePython(java.lang.String path, java.lang.Class type) throws java.lang.Exception
This method will automatically detect whether there is a jythonc-compiled version of the python class in the same directory. It will instantiate whichever one has been modified more recently. Note, however, that the game can only load a compiled version once per session, so if you make a change and recompile it, your compiled version won't be used until the next game reset.
You can get the path to the python file that was used for loading a particular python object by calling one of the getPythonFilePath() methods. Additionally, if type parameter to instantiatePython() is PropertyList.class, or a subclass of PropertyList (including GameObject and its sub-interfaces and implementation classes), then the returned object will be tagged with a "@python" PList property holding the relative path of the python file.
path
- the absolute or relative path to a python file,
e.g. "wiz/rhialto/python/foo.py" or
"/games/wyvern/wiz/rhialto/python/foo.py". The method assumes
that if the path starts with "/", it's an absolute path.type
- an instance of the java class which the python
class inherits from. You need to pass this if you're going
to cast the returned object into a Java class or interface.
Required because of some complexities in the Jython software.
You can cast the return value to an instance of this class.
If you pass null, you'll be stuck with treating it as an Object.
an
- exception if jython couldn't parse it, or
it's not an instance of the passed type.
java.lang.Exception
public static boolean isInstance(GameObject obj, java.lang.String type)
Note: GameObjects implement the PropertyList interface, so calling this method is the same as calling ArchetypeManager.isInstance(PropertyList, String). This version is just a convenience wrapper that calls that version.
ArchetypeManager.isInstance(wyvern.lib.GameObject, java.lang.String)
public static boolean isInstance(PropertyList list, java.lang.String type)
list
- the property list to check (a GameObject or Archetype)type
- the path to the archetype, e.g.
"objects/treasure/coins" or "wiz/foobar/misc/quest_item".
ArchetypeManager.isInstance(wyvern.lib.PropertyList, java.lang.String)
public static Timer setTimer(long delay, Timed callback)
delay
- the timer delay, in milliseconds.callback
- a Timed object to call when the time elapses
Timers.setTimer(long, wyvern.lib.Timed)
public static Timer setRepeatingTimer(long period, Timed callback)
This method will throw an IllegalArgumentException if any of the following conditions is true:
period
- the timer interval, in milliseconds.callback
- a Timed object to call when the time elapses
Timers.setRepeatingTimer(wyvern.lib.Timed, long)
public static Timer setRepeatingTimer(long delay, long period, Timed callback)
* This method will throw an IllegalArgumentException if any of the following conditions is true:
delay
- how long to wait before the first timer is deliveredperiod
- the timer interval, in milliseconds.callback
- a Timed object to call when the time elapses
Timers.setRepeatingTimer(wyvern.lib.Timed, long, long)
public static void killTimer(Timer timer)
timer
- the Timer returned by setTimer.Timers.killTimer(wyvern.lib.Timer)
public static Predicate getNameMatchPredicate(java.lang.String name)
name
- an object description, which may or may not have
an item number at the end.
ItemDesc.getNameMatchPredicate(java.lang.String)
public static final Point pointAdjacentTo(GameObject o1, GameObject o2)
o1
- first objecto2
- second object
public static final boolean adjacentTo(GameObject o1, GameObject o2)
o1
- the first objecto2
- the second object
public static final boolean adjacentTo(GameObject obj, Point p)
obj
- the game objectp
- the point to compare
public static void println(java.lang.String msg)
public static void logError(java.lang.String msg)
msg
- a the message to writepublic static void logError(java.lang.String msg, java.lang.Throwable t)
Equivalent to Logging.getSytemLogger().throwing(msg, t)
msg
- the message to logt
- the exception to printpublic static void logEvent(java.lang.String msg)
msg
- a message to logpublic static void log(java.lang.String log, java.lang.String msg)
log
- the name of the logfile - it will have ".log" appended
and go into the log directory. Don't create new logs unless
you have specific approval for it.msg
- the message to log - it automatically has a timestamp
put in front of it.public static void writeWizLog(java.lang.String wizname, java.lang.String path, java.lang.String msg)
wizname
- the wizard's namepath
- the path to the logfile under their wiz directory,
such as "logs/quest.log"msg
- the message to writepublic static java.util.logging.Logger getLog(java.lang.String path)
path
- the path, relative to Wyvern.getLogDir()
public static java.util.logging.Logger getWizLogger(java.lang.String wizname)
wizname
- the wizard's name
public static java.util.logging.Logger getWizLogger(java.lang.String wizname, java.lang.String path)
wizname
- the wizard namepath
- the relative path under the wiz dir, including
the log filename. E.g. "logs/quest.log"public static void config(java.lang.String sourceClass, java.lang.String sourceMethod, java.lang.String msg)
sourceClass
- the class doing the loggingsourceMethod
- the method where it's thrownmsg
- the message to logpublic static void config(java.lang.Class sourceClass, java.lang.String sourceMethod, java.lang.String msg)
sourceClass
- the class doing the loggingsourceMethod
- the method where it's thrownmsg
- the message to logpublic static void fine(java.lang.String sourceClass, java.lang.String sourceMethod, java.lang.String msg)
sourceClass
- the class doing the loggingsourceMethod
- the method where it's thrownmsg
- the message to logpublic static void fine(java.lang.Class sourceClass, java.lang.String sourceMethod, java.lang.String msg)
sourceClass
- the class doing the loggingsourceMethod
- the method where it's thrownmsg
- the message to logpublic static void finer(java.lang.String sourceClass, java.lang.String sourceMethod, java.lang.String msg)
sourceClass
- the class doing the loggingsourceMethod
- the method where it's thrownmsg
- the message to logpublic static void finer(java.lang.Class sourceClass, java.lang.String sourceMethod, java.lang.String msg)
sourceClass
- the class doing the loggingsourceMethod
- the method where it's thrownmsg
- the message to logpublic static void finest(java.lang.String sourceClass, java.lang.String sourceMethod, java.lang.String msg)
sourceClass
- the class doing the loggingsourceMethod
- the method where it's thrownmsg
- the message to logpublic static void finest(java.lang.Class sourceClass, java.lang.String sourceMethod, java.lang.String msg)
sourceClass
- the class doing the loggingsourceMethod
- the method where it's thrownmsg
- the message to logpublic static void info(java.lang.String sourceClass, java.lang.String sourceMethod, java.lang.String msg)
sourceClass
- the class doing the loggingsourceMethod
- the method where it's thrownmsg
- the log message to writepublic static void info(java.lang.Class sourceClass, java.lang.String sourceMethod, java.lang.String msg)
sourceClass
- the class doing the loggingsourceMethod
- the method where it's thrownmsg
- the log message to writepublic static void severe(java.lang.String sourceClass, java.lang.String sourceMethod, java.lang.String msg)
sourceClass
- the class doing the loggingsourceMethod
- the method where it's thrownmsg
- the message to logpublic static void severe(java.lang.Class sourceClass, java.lang.String sourceMethod, java.lang.String msg)
sourceClass
- the class doing the loggingsourceMethod
- the method where it's thrownmsg
- the message to logpublic static void throwing(java.util.logging.Level level, java.lang.String sourceClass, java.lang.String sourceMethod, java.lang.String msg, java.lang.Throwable t)
level
- the level at which we care about the exceptionsourceClass
- the class you're logging fromsourceMethod
- the method you're logging frommsg
- the log message to printt
- the exception being thrown - the stack trace may
or may not be logged, depending on the logger configuration
for sourceClasspublic static void throwing(java.lang.String sourceClass, java.lang.String sourceMethod, java.lang.Throwable t)
sourceClass
- the class you're logging fromsourceMethod
- the method you're logging fromt
- the exception to logpublic static void throwing(java.lang.Class sourceClass, java.lang.String sourceMethod, java.lang.Throwable t)
sourceClass
- the class you're logging fromsourceMethod
- the method you're logging fromt
- the exception to logpublic static void warning(java.lang.String sourceClass, java.lang.String sourceMethod, java.lang.String msg)
sourceClass
- the class you're logging fromsourceMethod
- the method you're logging frompublic static void warning(java.lang.Class sourceClass, java.lang.String sourceMethod, java.lang.String msg)
sourceClass
- the class you're logging fromsourceMethod
- the method you're logging frompublic static void entering(java.lang.String sourceClass, java.lang.String sourceMethod)
sourceClass
- name of the class that issued the logging requestsourceMethod
- name of the method being enteredpublic static void entering(java.lang.Class sourceClass, java.lang.String sourceMethod)
Convenient use: "Log.entering(getClass(), "myMethod");"
sourceClass
- name of the class that issued the logging requestsourceMethod
- name of the method being enteredpublic static void entering(java.lang.String sourceClass, java.lang.String sourceMethod, java.lang.Object[] params)
sourceClass
- name of the class that issued the logging requestsourceMethod
- name of the method being enteredparams
- array of parameters to the method being enteredpublic static void entering(java.lang.Class sourceClass, java.lang.String sourceMethod, java.lang.Object[] params)
sourceClass
- name of the class that issued the logging requestsourceMethod
- name of the method being enteredparams
- array of parameters to the method being enteredpublic static void exiting(java.lang.String sourceClass, java.lang.String sourceMethod)
sourceClass
- name of the class that issued the logging requestsourceMethod
- name of the method being exitedpublic static void exiting(java.lang.Class sourceClass, java.lang.String sourceMethod)
sourceClass
- name of the class that issued the logging requestsourceMethod
- name of the method being exitedpublic static void exiting(java.lang.String sourceClass, java.lang.String sourceMethod, java.lang.Object result)
sourceClass
- name of the class that issued the logging requestsourceMethod
- name of the method being exitedresult
- Object that's being returned from the methodpublic static void exiting(java.lang.Class sourceClass, java.lang.String sourceMethod, java.lang.Object result)
sourceClass
- name of the class that issued the logging requestsourceMethod
- name of the method being exitedresult
- Object that's being returned from the methodpublic static void setLogLevel(java.lang.String name, java.util.logging.Level level)
name
- an identifier for a Logger - almost always a
fully-qualified class name or a package name, such as
"wyvern.kernel.maps.MapLoader", or "wyvern.wiz.legolas.jungle".
If you specify a package name, the new logging level is set
for every class in that package.level
- the new log levelpublic static void setLogLevel(java.lang.String name, java.lang.String level)
name
- an identifier for a Logger - almost always a
fully-qualified class name or a package name, such as
"wyvern.kernel.maps.MapLoader", or "wyvern.wiz.legolas.jungle".
If you specify a package name, the new logging level is set
for every class in that package.level
- the new log level: "severe", "warning", "info",
"config", "fine", "finer", "finest", "all", or "off"
java.lang.IllegalArgumentException
- if the passed level isn't
one of the predefined java.util.logger.Level objects.public static java.lang.String getLogLevel(java.lang.String name)
name
- the logger - usually a fully-qualified class name,
or a package name.
public static java.lang.String getDate()
public static java.lang.String formatDate(java.util.Date date)
date
- the date to format
public static java.util.Date parseDate(java.lang.String date)
date
- a date string created by Kernel.getDate()
public static java.lang.String getTime()
public static java.lang.String extractWizNameFromPath(java.lang.String path)
path
- a path in any format (relative or absolute),
as long as it uses forward-slashes as the path component
separator.
public static java.lang.String extractWizNameFromClass(java.lang.String path)
path
- a java class
public static void subscribe(Subscriber subscriber, java.lang.String subject)
unsubscribe
.
Invokes wyvern.kernel.kernel.PubSub.subscribe().
subject
- the subject to unregister for. Can
be a single subject ( "foo.bar.whatever") or a set
of subjects ("foo.bar."). If it ends with ".", it's
considered to be a subject space for all subjects
that start with that string.subscriber
- the Subscriber to receive notifications
when messages are published to subject
public static void unsubscribe(Subscriber subscriber, java.lang.String subject)
subject
- the subject to unregister for. Can
be a single subject ( "foo.bar.whatever") or a set
of subjects ("foo.bar."). If it ends with ".", it's
considered to be a subject space for all subjects
that start with that string.subscriber
- the Subscriber to receive notifications
when messages are published to subject
public static void publish(java.lang.String subject)
public static void publish(java.lang.String subject, java.lang.Object body)
Invokes wyvern.kernel.kernel.PubSub.publishBody(). If you have trouble invoking this method from Jython, try using the PubSub versions instead, which have non-overloaded names to make it easier for Jython.
subject
- the subject for the message.body
- the body of the messagepublic static void publish(java.lang.String subject, java.util.Map attachments)
subject
- the subject for the message.attachments
- a java.util.Map (usually a HashMap)
containing the attachments objects.public static void publish(java.lang.String subject, java.lang.Object body, java.util.Map attachments)
subject
- the subject for the message.body
- the body of the messageattachments
- a java.util.Map (usually a HashMap)
containing the attachments objects.public static boolean onKernelThread()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |