Marauroa Core API: Difference between revisions
Content deleted Content added
imported>Hendrik Brummermann No edit summary |
imported>Hendrik Brummermann No edit summary |
||
Line 3:
Marauroa exposes a very simplified and reduced API so you can easily develop your own games. A nightly build [http://stendhal.game-host.org/hudson/job/marauroa_HEAD/javadoc/ JavaDoc API Documentation] is available, too.▼
▲Marauroa exposes a very simplified and reduced API so you can easily develop your own games.
== Content ==
The main entities you should know about are:
* Attributes
Line 25 ⟶ 24:
The Python API can be found at [[PyArianneAPIDefinition]] and an example of its use at [[PyArianneAPIExample]]. You can read more about using Python for developing in our game tutorial [[HowToWriteGamesUsingArianne]].
== Attributes ==
Attributes are pairs of data stored in a list. Each attribute comprises of a ''name'' and ''value'' element. Attributes are the standard way of storing data in Arianne. An example of an attribute is your age, e.g. name="age" and value=21
Each attribute also has a type associated with it that is defined in a ''RPClass''. An attributes is an instance of a ''RPClass'' (see next section of this document to read more on RPClass.
There are two special entries in attributes:
* ''type'': defines the name of the RPClass that the object belongs to.
Line 36:
Setting the value of an attribute:
<source lang="java">
* ''void put(String name, String value)''▼
</source>
Add a quantity to the value element of an attribute that MUST already exist:
<source lang="java">
</source>
Returns the value of an attribute:
<source lang="java">
* ''String get(String name)''▼
</source>
Removes an attribute entry from the list of attributes:
<source lang="java">
Returns True if an attribute exists:
<source lang="java">
</source>
'''Example''': <br>
<source lang="java">
Attributes test=new Attributes();
test.put("name","Test attribute");
test.put("hp",100);
if(test.has("hp")) {
test.add("hp",10);▼
▲ test.add("hp",10);
}
test.remove("name");
</
== RPClass ==
This class is a key concept of Arianne. An RPClass is much like a Java Class but for Arianne RPObjects: it defines the type (
RPClass is made up of five different parts:
Line 82 ⟶ 90:
* ''Visible'': if the attribute can be seen by clients.
* ''Hidden'': if the attribute is not visible to clients.
* ''Private'': if the attribute is only visible to the client the object is associated with (the player object controlled by this client)
Creation methods of the RPClass: (These are part of each RPClass instance, see example below for usage)
<source lang="java">
public void isA(RPClass parent)
</source>
These methods add attributes to the RPClass and set their type and visibility. You can also set the parent of this class. Of course, however, a class can have no parent (be parentless).
Line 93 ⟶ 104:
Once the class has been filled, you can query the data using these methods. These methods alow you to get the class name of the class, the the type of an attribute, determine if an attribute exists and to know if that RPClass is a subclass of another.<br>
'''Query''':
<source lang="java">
public boolean subclassOf(String parentclass)
</source>
You can query the system classes using these methods. Note that it is '''not''' a good idea to modify them once you are running. The class definitions are send to the client on connect hence if you change the class definitions in the middle of a game you will crash your clients!<br>
'''Class wide query''':
<source lang="java">
* ''boolean hasRPClass(String name)''
* ''RPClass getRPClass(String name)''
</source>
Line 108 ⟶ 123:
'''Example''':<br>
<source lang="java">
RPClass objclass=new RPClass("position");▼
// a general entity with a position
objclass.add("x",RPClass.BYTE);▼
RPClass objclass
▲ objclass.add("x",RPClass.BYTE);
// an entity specialized in players
objclass.add("name",RPClass.SHORT_STRING);▼
objclass.add("dir",RPClass.SHORT_STRING);▼
objclass.add("score",RPClass.INT);▼
objclass.add("!vdir",RPClass.STRING,RPClass.HIDDEN);▼
objclass.add("!hdir",RPClass.STRING,RPClass.HIDDEN);▼
objclass.add("?kill",RPClass.FLAG);
</source>
Each time you create a new RPClass, as long as you give it a name ( ie: player, position, ... ), it will be added to the system list of classes.
Notice in the example that the HIDDEN attribute must be specified if you want the RPClass to have this property otherwise by default an attribute is visible.
▲ objclass.isA("position");
▲ objclass.add("name",RPClass.SHORT_STRING);
▲ objclass.add("dir",RPClass.SHORT_STRING);
▲ objclass.add("score",RPClass.INT);
▲ objclass.add("super",RPClass.BYTE);
▲ objclass.add("!vdir",RPClass.STRING,RPClass.HIDDEN);
▲ objclass.add("!hdir",RPClass.STRING,RPClass.HIDDEN);
▲ objclass.add("?kill",RPClass.FLAG);
▲Each time you create a new RPClass, as long as you give it a name ( ie: player, position, ... ), it will be added to the system list of classes.<br>
▲Notice in the example that the HIDDEN attribute must be specified if you want the RPClass to have this property otherwise by default an attribute is visible.<br>
Note: You can choose not to use RPClasses in your application BUT the performance penalty will be big on bandwidth and CPU usage.
== RPAction ==
RPAction is an object used to represent actions that a player wants to do.
It is up to you to create these when you design your game as they are specific to each game ( you should also define a RPClass for these ).
== RPObject and RPSlot ==
RPObjects are the containters of data in Arianne. An RPObject is an (''isa'' function) Attributes element with a list of RPSlots attached. <br>
RPSlots are slots on objects that items can be placed on/in, such as backpacks, pockets, boxes, ...<br>
| |||