|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
A list of properties that a game object can inherit from.
Archetypes are the game's persistence mechanism: they are stored on disk as XML files. An archetype file represents one "game object instance", and has a GameObject implementation class to instantiate, plus optional extra properties and their values.
Nearly every GameObject originates as an Archetype in an XML archetype file on the server. An Archetype needs to specify a GameObject class or subclass to instantiate, along with an optional list of properties to add to the game object after instantiating it.
Archetypes can inherit from other archetypes. For instance, there is a "wand" archetype that specifies a GameObject class (wyvern.lib.classes.magic.Wand), a default weight, a default description, and a default appearance. The standard wand archetype is actually not strictly necessary, because the default properties could have been specified in the Wand class. However, sub-archetypes of wand have more specific properties, such as the spell to cast, the number of charges, the value of the wand, the maximum charges the wand can hold, and so on.
Archetypes are stored in an XML format on disk. Most archetypes are created in the Map Editor (or will be, although it's not supported as of 8/26/2000), but they can also be hand-edited in any text editor, which makes them very convenient to use.
One disadvantage of archetypes is that you can't put code in them. If, for example, you wanted to create a wand that casts a different spell every time you zap it, you'd have to write a class - either a Wand subclass, or perhaps a RandomSpell class that you could attach to the wand as its spell. So there's a limit to how much extensibility you get using Archetypes, and to do really interesting things you have to write in Jython or Java.
Let's say you're writing a quest that requires the player to obtain a length of rope from anywhere else in the game. You want them to find any object that is of type "rope".
There isn't a GameObject subclass called Rope (or if there
is, let's pretend that there isn't). However, it's easy to
create a rope-like object by making an archetype file like so:
The Archetype above has chosen to use
DynamicObject as
its GameObject implementation class, a fairly generic class.
The Archetype then adds properties to make the object look
like a rope, weigh as much as a rope, have a short description
that says "rope", and have the proper material for a rope.
At this point, most people would say it's pretty much a rope.
However, how does your quest code know that this is a rope?
What property, or set of properties, does it check? Java has
an instanceof
operator to tell you if an object
is of a certain class. No such operation exists for archetypes,
nor could it, really. They're just bundles of properties with
a generic parent class. Your code could check the description
to see if it matches "rope", but someone could easily have
created a "robe" archetype and mistyped it, thereby allowing
your players to solve your quest using a robe. Not good.
Or you could check the appearance, but someone may have used
a different picture called "string", and then you'd fail to
recognize what might be a valid rope.
In a nutshell, you can't do effective strong typing using Archetypes - you can make guesses or use heuristics, but if you really want strong typing, you need to make a real GameObject subclass in Jython or Java. This is the reason that things like Coins have their own class - there are times when you need to be absolutely sure that an object is of the correct type, and in these cases, only a class will do.
If, as is more common, you just have the name/path of the archetype, such as "terrain/water" (a system archetype) or "wiz/foobar/sword_of_coolness" (a wizard-defined archetype), you can call the instantiate() method of wyvern.lib.Kernel.
There are still other ways to create archetypes, but most of them are for rather obscure purposes, and you shouldn't worry about them too much if you stumble across them.
The short answer is: you don't. Jython is a perfectly acceptable way to define your game objects. Archetypes are slightly more efficient, but Jython classes are far more flexible. Archetypes were designed for people who want to build game areas without doing any programming, and it's easy to create and manipulate them in the map editor, or in a text editor, with little or no programming experience. You can certainly use Jython for everything if you prefer.
Field Summary |
Fields inherited from interface wyvern.lib.PropertyList |
PROPERTY_PACKAGE |
Method Summary | |
java.lang.String |
getName()
Returns the name of the archetype file, e.g. |
java.lang.String |
getPythonPath()
Returns the "path" attribute of the Archetype |
GameObject |
instantiate()
Creates an instance of this archetype. |
boolean |
isPythonArch()
Returns true if this is a Jython archetype. |
java.lang.Class |
loadClass()
Loads an Archetype's class. |
java.lang.String |
provideName()
Returns a name for the archetype suitable for writing it to a map file. |
void |
setName(java.lang.String name)
Sets the name of the archetype file. |
java.lang.String |
toString()
Returns the archetype formatted as a property list, for debugging. |
java.lang.String |
toString(boolean inherit)
Returns a string representation of this archetype. |
Method Detail |
public GameObject instantiate() throws java.lang.Exception
java.lang.Exception
public java.lang.Class loadClass() throws java.lang.Exception
java.lang.Exception
public java.lang.String toString()
public java.lang.String toString(boolean inherit)
toString
in interface PropertyList
inherit
- true to include inherited properties, false
to include only ones in the local list.
public java.lang.String getName()
public void setName(java.lang.String name)
name
- the local or relative path to the archetype filepublic java.lang.String provideName()
a) if name returned by getName() returns non-null, then:
public boolean isPythonArch()
public java.lang.String getPythonPath()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |