Marauroa Core API: Difference between revisions

Jump to navigation Jump to search
Content deleted Content added
imported>Hendrik Brummermann
No edit summary
imported>Hendrik Brummermann
No edit summary
Line 3: 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.
{{Likely Outdated}}
Marauroa exposes a very simplified and reduced API so you can easily develop your own games.


= Content =
== Content ==
The main entities you should know about are:
The main entities you should know about are:
* Attributes
* Attributes
Line 25: Line 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]].
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 ==
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
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.
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:
There are two special entries in attributes:
* ''type'': defines the name of the RPClass that the object belongs to.
* ''type'': defines the name of the RPClass that the object belongs to.
Line 36: Line 36:


Setting the value of an attribute:
Setting the value of an attribute:
<source lang="java">
* ''void put(String name, String value)''
* ''void put(String name, int value)''
public void put(String name, String value)
public void put(String name, int value)
</source>


Add a quantity to the value element of an attribute that MUST already exist:
Add a quantity to the value element of an attribute that MUST already exist:
<source lang="java">
* ''void add(String name, int quantity)''
public void add(String name, int quantity)
</source>


Returns the value of an attribute:
Returns the value of an attribute:
<source lang="java">
* ''String get(String name)''
* ''int get(String name)''
public String get(String name)
public int get(String name)
</source>


Removes an attribute entry from the list of attributes:
Removes an attribute entry from the list of attributes:
<source lang="java">
* ''void remove(String name)''
public void remove(String name)


Returns True if an attribute exists:
Returns True if an attribute exists:
<source lang="java">
* ''boolean has(String name)''
public boolean has(String name)
</source>


'''Example''': <br>
'''Example''': <br>
<source lang="java">
<pre>
Attributes test=new Attributes();
Attributes test=new Attributes();
test.put("name","Test attribute");
test.put("name","Test attribute");
test.put("hp",100);
test.put("hp",100);


if(test.has("hp"))
if(test.has("hp")) {
test.add("hp",10);
{
test.add("hp",10);
}
}


test.remove("name");
test.remove("name");
</pre>
</source>


= RPClass =
== 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 ( string, int, boolean, ... ) and the visibility ( hidden attribute or visible attribute ) of the attributes that make up an object (an object is a collection of attributes, e.g. for a human, age, height etc).
This class is a key concept of Arianne. An RPClass is much like a Java Class but for Arianne RPObjects: it defines the type (string, int, boolean, ...) and the visibility (hidden, private or visible) of the attributes that make up an object (an object is a collection of attributes, for example for a human, age, height etc).


RPClass is made up of five different parts:
RPClass is made up of five different parts:
Line 82: Line 90:
* ''Visible'': if the attribute can be seen by clients.
* ''Visible'': if the attribute can be seen by clients.
* ''Hidden'': if the attribute is not visible to 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)
Creation methods of the RPClass: (These are part of each RPClass instance, see example below for usage)
<source lang="java">
* ''void add(String name, byte type)''
* ''void add(String name, byte type, byte visibility)''
public void add(String name, byte type)
* ''void isA(String parent)''
public void add(String name, byte type, byte visibility)
* ''void isA(RPClass parent)''
public void isA(String parent)
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).
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: Line 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>
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''':
'''Query''':
<source lang="java">
* ''String getName()''
* ''byte getType(String name)''
public String getName()
* ''byte getVisibility(String name)''
public byte getType(String name)
* ''boolean hasAttribute(String name)''
public byte getVisibility(String name)
* ''boolean subclassOf(String parentclass)''
public boolean hasAttribute(String name)
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>
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''':
'''Class wide query''':
<source lang="java">
* ''boolean hasRPClass(String name)''
* ''boolean hasRPClass(String name)''
* ''RPClass getRPClass(String name)''
* ''RPClass getRPClass(String name)''
</source>




Line 108: Line 123:


'''Example''':<br>
'''Example''':<br>
<source lang="java">
<pre>

RPClass objclass=new RPClass("position");
// a general entity with a position
objclass.add("x",RPClass.BYTE);
objclass.add("y",RPClass.BYTE);
RPClass objclass = new RPClass("entity");
objclass.add("x",RPClass.BYTE);
objclass.add("y",RPClass.BYTE);

// an entity specialized in players
objclass = RPClass("player");
objclass.isA("entity");
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);
</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=RPClass("player");
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);
</pre>


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.
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 ==
RPAction is an object used to represent actions that a player wants to do.
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 ).
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 =
== 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>
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>
RPSlots are slots on objects that items can be placed on/in, such as backpacks, pockets, boxes, ...<br>