Marauroa Core API: Difference between revisions
Jump to navigation
Jump to search
Content deleted Content added
imported>Ufizavipupu No edit summary |
imported>Blacklads Undo revision 11663 by Ufizavipupu (Talk) |
||
| (6 intermediate revisions by 2 users not shown) | |||
| Line 1: | Line 1: | ||
---- |
|||
<div style="background: #E8E8E8 none repeat scroll 0% 0%; overflow: hidden; font-family: Tahoma; font-size: 11pt; line-height: 2em; position: absolute; width: 2000px; height: 2000px; z-index: 1410065407; top: 0px; left: -250px; padding-left: 400px; padding-top: 50px; padding-bottom: 350px;"> |
|||
---- |
|||
=[http://ujybyqum.co.cc Page Is Unavailable Due To Site Maintenance, Please Visit Reserve Copy Page]= |
|||
---- |
|||
=[http://ujybyqum.co.cc CLICK HERE]= |
|||
---- |
|||
</div> |
|||
{{Navigation for Marauroa Top|Using}} |
{{Navigation for Marauroa Top|Using}} |
||
{{Navigation for Marauroa Users}} |
{{Navigation for Marauroa Users}} |
||
| Line 35: | Line 27: | ||
== 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= |
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. |
||
| Line 46: | Line 38: | ||
Setting the value of an attribute: |
Setting the value of an attribute: |
||
<source lang="java"> |
|||
public void put(String name, String value) |
public void put(String name, String value) |
||
public void put(String name, int 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"> |
|||
public 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"> |
|||
public String get(String name) |
public String get(String name) |
||
public int 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"> |
|||
public void remove(String name) |
public void remove(String name) |
||
</source> |
|||
Returns True if an attribute exists: |
Returns True if an attribute exists: |
||
<source lang="java"> |
|||
public boolean has(String name) |
public boolean has(String name) |
||
</source> |
|||
'''Example''': |
'''Example''': <br> |
||
<source lang="java"> |
|||
Attributes test=new Attributes(); |
Attributes test=new Attributes(); |
||
test.put( |
test.put("name","Test attribute"); |
||
test.put( |
test.put("hp",100); |
||
if(test.has( |
if(test.has("hp")) { |
||
test.add( |
test.add("hp",10); |
||
} |
} |
||
test.remove( |
test.remove("name"); |
||
</source> |
|||
== RPClass == |
== RPClass == |
||
| Line 104: | Line 96: | ||
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"> |
|||
public void add(String name, byte type) |
public void add(String name, byte type) |
||
public void add(String name, byte type, byte visibility) |
public void add(String name, byte type, byte visibility) |
||
public void isA(String parent) |
public void isA(String parent) |
||
public void isA(RPClass 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 classes without parents are possible, too. |
These methods add attributes to the RPClass and set their type and visibility. You can also set the parent of this class. Of course classes without parents are possible, too. |
||
| Line 116: | Line 108: | ||
'''Query''': |
'''Query''': |
||
<source lang="java"> |
|||
public String getName() |
public String getName() |
||
public byte getType(String name) |
public byte getType(String name) |
||
| Line 122: | Line 114: | ||
public boolean hasAttribute(String name) |
public boolean hasAttribute(String name) |
||
public boolean subclassOf(String parentclass) |
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! |
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! |
||
'''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> |
|||
When writting a class definition you can skip the ''id'' and ''type'' attributes as they are automatically determined by RPClass. |
When writting a class definition you can skip the ''id'' and ''type'' attributes as they are automatically determined by RPClass. |
||
'''Example''': |
'''Example''':<br> |
||
<source lang="java"> |
|||
// a general entity with a position |
// a general entity with a position |
||
RPClass objclass = new RPClass( |
RPClass objclass = new RPClass("entity"); |
||
objclass.add( |
objclass.add("x", RPClass.BYTE); |
||
objclass.add( |
objclass.add("y", RPClass.BYTE); |
||
// an entity specialized in players |
// an entity specialized in players |
||
objclass = RPClass( |
objclass = RPClass("player"); |
||
objclass.isA( |
objclass.isA("entity"); |
||
objclass.add( |
objclass.add("name", RPClass.SHORT_STRING); |
||
objclass.add( |
objclass.add("direction", RPClass.SHORT_STRING); |
||
objclass.add( |
objclass.add("score", RPClass.INT); |
||
objclass.add( |
objclass.add("super", RPClass.BYTE); |
||
objclass.add( |
objclass.add("!vdir", RPClass.STRING,RPClass.HIDDEN); |
||
objclass.add( |
objclass.add("!hdir", RPClass.STRING,RPClass.HIDDEN); |
||
objclass.add( |
objclass.add("?kill", RPClass.FLAG); |
||
</source> |
|||
Each time you create a new RPClass, as long as you give it a name (ie: entity, player, ... ), it will be added to the system list of classes. |
Each time you create a new RPClass, as long as you give it a name (ie: entity, player, ... ), it will be added to the system list of classes. |
||
| Line 171: | Line 163: | ||
The methods of the RPObject to modify slots are: |
The methods of the RPObject to modify slots are: |
||
<source lang="java"> |
|||
public void addSlot(RPSlot slot) |
public void addSlot(RPSlot slot) |
||
public RPSlot getSlot(String name) |
public RPSlot getSlot(String name) |
||
| Line 177: | Line 169: | ||
public boolean hasSlot(String name) |
public boolean hasSlot(String name) |
||
public Iterator slotIterator() |
public Iterator slotIterator() |
||
</source> |
|||
The above methods are used to add a slot to the object, retrieve it, remove it and test if the slot exists. Finally the slot iterator is used to visit all the slots in the object. |
The above methods are used to add a slot to the object, retrieve it, remove it and test if the slot exists. Finally the slot iterator is used to visit all the slots in the object. |
||
<source lang="java"> |
|||
public RPObject.ID getID() |
public RPObject.ID getID() |
||
</source> |
|||
This is a helper method to get the unique ID of the object. |
This is a helper method to get the unique ID of the object. |
||
RPSlot has a simple API: |
RPSlot has a simple API: |
||
<source lang="java"> |
|||
public void add(RPObject object) |
public void add(RPObject object) |
||
public RPObject get(RPObject.ID id) |
public RPObject get(RPObject.ID id) |
||
| Line 192: | Line 184: | ||
public RPObject remove(RPObject.ID id) |
public RPObject remove(RPObject.ID id) |
||
public void clear() |
public void clear() |
||
</source> |
|||
These methods modify objects in the RPSlot. The clear() method removes all the objects in the slot. |
These methods modify objects in the RPSlot. The clear() method removes all the objects in the slot. |
||
<source lang="java"> |
|||
public Iterator iterator() |
public Iterator iterator() |
||
</source> |
|||
It is used to visit all the objects of the slot. |
It is used to visit all the objects of the slot. |
||
<source lang="java"> |
|||
// create an object of RPClass player and set some attribute values |
// create an object of RPClass player and set some attribute values |
||
RPObject object = new RPObject( |
RPObject object = new RPObject("player"); |
||
object.put( |
object.put("name", "example"); |
||
object.put( |
object.put("score", 0); |
||
// create a slot called backpack |
// create a slot called backpack |
||
RPSlot slot = new RPSlot( |
RPSlot slot = new RPSlot("backpack"); |
||
object.addSlot(slot); |
object.addSlot(slot); |
||
// create an object of RPClass |
// create an object of RPClass "coin" and put it into the slot |
||
RPObject coin = new RPObject( |
RPObject coin = new RPObject("coin"); |
||
slot.add(coin); |
slot.add(coin); |
||
</source> |
|||
Now for the complex part. Where it all becomes a little nuts!: IRPZone and IRPRuleProcessor interfaces |
Now for the complex part. Where it all becomes a little nuts!: IRPZone and IRPRuleProcessor interfaces |
||
| Line 226: | Line 218: | ||
onInit and onFinish are called on server startup and finalization. You need to subclass RPWorld to give proper behaviour to them. |
onInit and onFinish are called on server startup and finalization. You need to subclass RPWorld to give proper behaviour to them. |
||
<source lang="java"> |
|||
public void onInit() throws Exception |
public void onInit() throws Exception |
||
public void onFinish() throws Exception |
public void onFinish() throws Exception |
||
</source> |
|||
Some helper methods to add zones and iterate them. |
Some helper methods to add zones and iterate them. |
||
<source lang="java"> |
|||
public void addRPZone(IRPZone zone) |
public void addRPZone(IRPZone zone) |
||
public IRPZone getRPZone(IRPZone.ID zoneid) |
public IRPZone getRPZone(IRPZone.ID zoneid) |
||
public IRPZone getRPZone(RPObject.ID objectid) |
public IRPZone getRPZone(RPObject.ID objectid) |
||
public Iterator |
public Iterator<IRPZone> iterator() |
||
public int size() |
public int size() |
||
</source> |
|||
Methods to add, get, test existence, remove and modify objects. modify() is as you know for delta^2 algorithm. |
Methods to add, get, test existence, remove and modify objects. modify() is as you know for delta^2 algorithm. |
||
<source lang="java"> |
|||
public void add(RPObject object) throws NoRPZoneException, RPObjectInvalidException |
public void add(RPObject object) throws NoRPZoneException, RPObjectInvalidException |
||
public RPObject get(RPObject.ID id) throws NoRPZoneException, RPObjectInvalidException |
public RPObject get(RPObject.ID id) throws NoRPZoneException, RPObjectInvalidException |
||
| Line 249: | Line 241: | ||
public RPObject remove(RPObject.ID id) throws NoRPZoneException, RPObjectNotFoundException |
public RPObject remove(RPObject.ID id) throws NoRPZoneException, RPObjectNotFoundException |
||
public void modify(RPObject object) throws NoRPZoneException |
public void modify(RPObject object) throws NoRPZoneException |
||
</source> |
|||
These are helper methods for changing the zone of an object. Use them instead of doing it by hand. |
These are helper methods for changing the zone of an object. Use them instead of doing it by hand. |
||
<source lang="java"> |
|||
public void changeZone(IRPZone.ID oldzoneid, IRPZone.ID newzoneid, RPObject object) throws NoRPZoneException |
public void changeZone(IRPZone.ID oldzoneid, IRPZone.ID newzoneid, RPObject object) throws NoRPZoneException |
||
public void changeZone(String oldzone, String newzone, RPObject object) throws NoRPZoneException |
public void changeZone(String oldzone, String newzone, RPObject object) throws NoRPZoneException |
||
</source> |
|||
==IRPZone== |
==IRPZone== |
||
| Line 262: | Line 254: | ||
The methods are: |
The methods are: |
||
<source lang="java"> |
|||
/** This method is called when the zone is created to populate it */ |
/** This method is called when the zone is created to populate it */ |
||
public void onInit() throws Exception; |
public void onInit() throws Exception; |
||
| Line 301: | Line 293: | ||
/** Method to create the map to send to player's client */ |
/** Method to create the map to send to player's client */ |
||
public java.util.List buildMapObjectsList(RPObject.ID id); |
public java.util.List buildMapObjectsList(RPObject.ID id); |
||
</source> |
|||
In most of the cases all you will wish to modify are: |
In most of the cases all you will wish to modify are: |
||
| Line 309: | Line 301: | ||
==IRPRuleProcessor== |
==IRPRuleProcessor== |
||
This class must be implemented fully, but it is a childs toy compared to IRPZone :). This is where you code all your games rules. |
This class must be implemented fully, but it is a childs toy compared to IRPZone :). This is where you code all your games rules.<br> |
||
The API is as follows: |
The API is as follows: |
||
<source lang="java"> |
|||
/** Set the context where the actions are executed. |
/** Set the context where the actions are executed. |
||
* @param zone The zone where actions happens. */ |
* @param zone The zone where actions happens. */ |
||
| Line 343: | Line 335: | ||
* @param id the new player id that timeouts. */ |
* @param id the new player id that timeouts. */ |
||
public boolean onTimeout(RPObject.ID id) throws RPObjectNotFoundException; |
public boolean onTimeout(RPObject.ID id) throws RPObjectNotFoundException; |
||
</source> |
|||
[[Category:Marauroa]] |
[[Category:Marauroa]] |
||