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: | ||
| ⚫ | |||
{{Likely Outdated}} |
|||
| ⚫ | |||
= 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"> |
|||
| ⚫ | |||
public void put(String name, String 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"> |
|||
public void add(String name, int quantity) |
|||
</source> |
|||
Returns the value of an attribute: |
Returns the value of an attribute: |
||
<source lang="java"> |
|||
| ⚫ | |||
public String 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"> |
|||
public void remove(String name) |
|||
Returns True if an attribute exists: |
Returns True if an attribute exists: |
||
<source lang="java"> |
|||
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.remove("name"); |
test.remove("name"); |
||
</ |
</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 ( |
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)'' |
|||
public void add(String name, byte type) |
|||
public void add(String name, byte type, byte visibility) |
|||
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()'' |
|||
public String getName() |
|||
public byte getType(String name) |
|||
public byte getVisibility(String name) |
|||
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> |
|||
| ⚫ | |||
// a general entity with a position |
|||
| ⚫ | |||
objclass |
RPClass objclass = new RPClass("entity"); |
||
| ⚫ | |||
| ⚫ | |||
// an entity specialized in players |
|||
| ⚫ | |||
| ⚫ | |||
| ⚫ | |||
| ⚫ | |||
| ⚫ | |||
| ⚫ | |||
| ⚫ | |||
| ⚫ | |||
objclass.add("?kill",RPClass.FLAG); |
|||
</source> |
|||
| ⚫ | |||
| ⚫ | |||
objclass=RPClass("player"); |
|||
| ⚫ | |||
| ⚫ | |||
| ⚫ | |||
| ⚫ | |||
| ⚫ | |||
| ⚫ | |||
| ⚫ | |||
| ⚫ | |||
</pre> |
|||
| ⚫ | |||
| ⚫ | |||
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> |
||