Marauroa Core API: Difference between revisions
Jump to navigation
Jump to search
Content deleted Content added
No edit summary |
imported>StephenIerodiaconou No edit summary |
||
| Line 1: | Line 1: | ||
Marauroa |
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: |
The main entities you should know about are: |
||
* Attributes |
* Attributes |
||
| Line 9: | Line 9: | ||
* RPClass |
* RPClass |
||
If you plan to use Java only |
If you plan to use Java only you also should know about: |
||
* IRPZone interface |
* IRPZone interface |
||
* IRPRuleProcessor interface |
* IRPRuleProcessor interface |
||
Or if you prefer Python for developing the rules: |
Or if you would prefer to use Python for developing the game rules read about: |
||
* ~PythonZone |
* ~PythonZone |
||
* PythonRP |
* PythonRP |
||
!! Attributes |
|||
Attributes are a list of pairs name, value that store information in Arianne. |
|||
The methods exposed by Attributes class are: |
|||
Sets the value of an attribute |
|||
* void put(String name, String value) |
|||
* void put(String name, int value) |
|||
Add quantity to the value of an attribute that MUST exists |
|||
* void add(String name, int quantity) |
|||
=== Attributes === |
|||
Returns the value of an attribute |
|||
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 |
|||
* String get(String name) |
|||
* int get(String name) |
|||
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. |
|||
Removes an entry of the list of attributes |
|||
There are two special entries in attributes: |
|||
* void remove(String name) |
|||
* ''type'': defines the name of the RPClass that the object belongs to. |
|||
* ''id'': defines a unique identifier |
|||
The methods exposed by the Attributes class to the game developer are shown below. These are the functions you should use to modify your attributes. |
|||
Returns True if an attribute exists |
|||
* boolean has(String name) |
|||
Setting the value of an attribute: |
|||
Each attribute has its type that is define in a RPClass. An attributes is an instance of a RPClass. |
|||
* ''void put(String name, String value)'' |
|||
There are two special entries at attributes: |
|||
* ''void put(String name, int value)'' |
|||
* type that define the name of the RPClass the object belong to. |
|||
* id that define an unique |
|||
Add a quantity to the value element of an attribute that MUST already exist: |
|||
_Example_: %%% |
|||
* ''void add(String name, int quantity)'' |
|||
<verbatim> |
|||
Returns the value of an attribute: |
|||
* ''String get(String name)'' |
|||
* ''int get(String name)'' |
|||
Removes an attribute entry from the list of attributes: |
|||
* ''void remove(String name)'' |
|||
Returns True if an attribute exists: |
|||
* ''boolean has(String name)'' |
|||
'''Example''': <br> |
|||
<pre> |
|||
Attributes test=new Attributes(); |
Attributes test=new Attributes(); |
||
test.put("name","Test attribute"); |
test.put("name","Test attribute"); |
||
| Line 53: | Line 57: | ||
test.remove("name"); |
test.remove("name"); |
||
</ |
</pre> |
||
=== RPClass === |
|||
This class is a key concept |
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). |
||
RPClass has five different parts: |
|||
Type Data definition: |
|||
* String a string of up to 2^32 bytes |
|||
* Short String a string of 255 bytes |
|||
* Integer a 32 bits integer |
|||
* Short a 16 bits integer |
|||
* Byte a 8 bits integer |
|||
* Flag a binary flag. |
|||
RPClass is made up of five different parts: |
|||
Visibility Data definition: |
|||
* Visible if the attribute can be seen by clients. |
|||
* Hidden if the attribute is not visible by clients. |
|||
A data type definition: |
|||
Creation of the RPClass: |
|||
* |
* ''String'': a string of up to 2^32 bytes |
||
* |
* ''Short String'': a string of 255 bytes |
||
* ''Integer'': a 32 bits integer |
|||
* void isA(String parent) |
|||
* ''Short'': a 16 bits integer |
|||
* void isA(RPClass parent) |
|||
* ''Byte'': a 8 bits integer |
|||
These methods adds attributes to the RPClass and set the parent of this class. Of course a class can have no parent. |
|||
* ''Flag'': a binary flag. |
|||
The Visibility of the data: |
|||
Query: |
|||
* ''Visible'': if the attribute can be seen by clients. |
|||
* String getName() |
|||
* ''Hidden'': if the attribute is not visible to clients. |
|||
* byte getType(String name) |
|||
* byte getVisibility(String name) |
|||
* boolean hasAttribute(String name) |
|||
* boolean subclassOf(String parentclass) |
|||
Once the class is filled with data, you can querey using these methods 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. |
|||
Creation methods of the RPClass: (These are part of each RPClass instance, see example below for usage) |
|||
Class wide query: |
|||
* |
* ''void add(String name, byte type)'' |
||
* |
* ''void add(String name, byte type, byte visibility)'' |
||
* ''void isA(String parent)'' |
|||
You can query the system classes using these methods, it is not a good idea to modify them once you are running. The class definitions are send to client on connect, if you change class definitions on the middle of a game it is prone that you will crash your clients. |
|||
* ''void isA(RPClass parent)'' |
|||
These methods add attributes to the RPClass and set their type and visibility. You can also set the parent of this class. Of course a class can have no parent. |
|||
When writting a class definition you can skip id and type attributes as they are automatically determined by RPClass. |
|||
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> |
|||
_Example_: %%% |
|||
'''Query''': |
|||
<verbatim> |
|||
* ''String getName()'' |
|||
* ''byte getType(String name)'' |
|||
* ''byte getVisibility(String name)'' |
|||
* ''boolean hasAttribute(String name)'' |
|||
* ''boolean subclassOf(String parentclass)'' |
|||
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''': |
|||
* ''boolean hasRPClass(String name)'' |
|||
* ''RPClass getRPClass(String name)'' |
|||
When writting a class definition you can skip the ''id'' and ''type'' attributes as they are automatically determined by RPClass. |
|||
'''Example''':<br> |
|||
<pre> |
|||
RPClass objclass=new RPClass("position"); |
RPClass objclass=new RPClass("position"); |
||
objclass.add("x",RPClass.BYTE); |
objclass.add("x",RPClass.BYTE); |
||
| Line 107: | Line 115: | ||
objclass.add("!hdir",RPClass.STRING,RPClass.HIDDEN); |
objclass.add("!hdir",RPClass.STRING,RPClass.HIDDEN); |
||
objclass.add("?kill",RPClass.FLAG); |
objclass.add("?kill",RPClass.FLAG); |
||
</ |
</pre> |
||
== DONE TO HERE == |
|||
Each time you create a new RPClass and as long as you give it a name ( ie: player, position, ... ) it will be added to the system list of classes. |
Each time you create a new RPClass and as long as you give it a name ( ie: player, position, ... ) it will be added to the system list of classes. |
||