Marauroa Core API: Difference between revisions
Jump to navigation
Jump to search
Content deleted Content added
imported>Hendrik Brummermann |
imported>Blacklads Undo revision 11663 by Ufizavipupu (Talk) |
||
| (62 intermediate revisions by 3 users not shown) | |||
| Line 3: | Line 3: | ||
Marauroa exposes a very simplified and reduced API so you can easily develop your own games. A nightly build [http:// |
Marauroa exposes a very simplified and reduced API so you can easily develop your own games. A nightly build [http://stendhalgame.org/hudson/job/marauroa_HEAD/javadoc/ JavaDoc API Documentation] is available, too. |
||
== Content == |
== Content == |
||
[[Image:Classdiagram_marauroa.common.game_rp_stubs.png|thumb|Class Diagram of RP* classes]] |
|||
The main entities you should know about are: |
The main entities you should know about are: |
||
* Attributes |
* Attributes |
||
| Line 156: | Line 158: | ||
== RPObject and RPSlot == |
== RPObject and RPSlot == |
||
RPObjects are the containters of data in Arianne. An RPObject is an |
RPObjects are the containters of data in Arianne. An RPObject is an Attributes element with a list of RPSlots attached. |
||
RPSlots are slots on objects that items can be placed on/in, such as backpacks, pockets, boxes, ...<br> |
|||
RPSlots are slots owned by an RPObject into which other RPObjects can be placed (like items in a backpack) |
|||
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) |
|||
* ''RPSlot getSlot(String name)'' |
|||
public RPSlot getSlot(String name) |
|||
public void removeSlot(String name) |
|||
public boolean hasSlot(String name) |
|||
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() |
|||
</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 |
RPSlot has a simple API: |
||
<source lang="java"> |
|||
* void add(RPObject object) |
|||
public void add(RPObject object) |
|||
public RPObject get(RPObject.ID id) |
|||
public boolean has(RPObject.ID id) |
|||
public RPObject remove(RPObject.ID id) |
|||
public void clear() |
|||
| ⚫ | |||
</source> |
|||
The clear() method removes all the objects in the slot. |
|||
| ⚫ | |||
| ⚫ | |||
<source lang="java"> |
|||
| ⚫ | |||
</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"> |
|||
<pre> |
|||
// create an object of RPClass player and set some attribute values |
|||
object |
RPObject object = new RPObject("player"); |
||
object.put(" |
object.put("name", "example"); |
||
| ⚫ | |||
// create a slot called backpack |
|||
RPSlot slot = new RPSlot("backpack"); |
|||
| ⚫ | |||
| ⚫ | |||
object.addSlot(slot); |
object.addSlot(slot); |
||
</pre> |
|||
// create an object of RPClass "coin" and put it into the slot |
|||
RPObject coin = new RPObject("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 |
||
=RPWorld= |
==RPWorld== |
||
This class is just a container of zones. |
This class is just a container of zones. |
||
| Line 203: | 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 |
public void onInit() 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 |
public void addRPZone(IRPZone zone) |
||
public IRPZone getRPZone( |
public IRPZone getRPZone(IRPZone.ID zoneid) |
||
public |
public IRPZone getRPZone(RPObject.ID objectid) |
||
public |
public Iterator<IRPZone> iterator() |
||
public int size() |
|||
</source> |
|||
Methods to add,get,test existence, remove and modify objects. |
Methods to add, get, test existence, remove and modify objects. modify() is as you know for delta^2 algorithm. |
||
Modify is as you know for delta^2 algorithm. |
|||
<source lang="java"> |
|||
| ⚫ | |||
public |
public void add(RPObject object) throws NoRPZoneException, RPObjectInvalidException |
||
public |
public RPObject get(RPObject.ID id) throws NoRPZoneException, RPObjectInvalidException |
||
public |
public boolean has(RPObject.ID id) throws NoRPZoneException, RPObjectInvalidException |
||
public |
public RPObject remove(RPObject.ID id) throws NoRPZoneException, RPObjectNotFoundException |
||
| ⚫ | |||
</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( |
public void changeZone(IRPZone.ID oldzoneid, IRPZone.ID newzoneid, RPObject object) throws NoRPZoneException |
||
| ⚫ | |||
</source> |
|||
| ⚫ | |||
| ⚫ | |||
| ⚫ | |||
| ⚫ | |||
The methods are: |
The methods are: |
||
<source lang="java"> |
|||
<pre> |
|||
/** 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; |
||
/** This method is called when the server finish to save the content of the zone */ |
/** This method is called when the server finish to save the content of the zone */ |
||
public void onFinish() throws Exception; |
public void onFinish() throws Exception; |
||
| Line 239: | Line 263: | ||
/** This method adds an object to the Zone */ |
/** This method adds an object to the Zone */ |
||
public void add(RPObject object) throws RPObjectInvalidException; |
public void add(RPObject object) throws RPObjectInvalidException; |
||
/** This method tag an object of the Zone as modified */ |
/** This method tag an object of the Zone as modified */ |
||
public void modify(RPObject object) throws RPObjectInvalidException; |
public void modify(RPObject object) throws RPObjectInvalidException; |
||
/** This method removed an object of the Zone and return it.*/ |
/** This method removed an object of the Zone and return it.*/ |
||
public RPObject remove(RPObject.ID id) throws RPObjectNotFoundException; |
public RPObject remove(RPObject.ID id) throws RPObjectNotFoundException; |
||
/** This method returns an object of the Zone */ |
/** This method returns an object of the Zone */ |
||
public RPObject get(RPObject.ID id) throws RPObjectNotFoundException; |
public RPObject get(RPObject.ID id) throws RPObjectNotFoundException; |
||
/** This method returns true if the object exists in the Zone */ |
/** This method returns true if the object exists in the Zone */ |
||
public boolean has(RPObject.ID id); |
public boolean has(RPObject.ID id); |
||
| Line 253: | Line 281: | ||
/** Iterates over the elements of the zone */ |
/** Iterates over the elements of the zone */ |
||
public Iterator iterator(); |
public Iterator iterator(); |
||
/** Returns the number of elements of the zone */ |
/** Returns the number of elements of the zone */ |
||
public long size(); |
public long size(); |
||
| Line 258: | Line 287: | ||
/** This method return the perception of a zone for a player */ |
/** This method return the perception of a zone for a player */ |
||
public Perception getPerception(RPObject.ID id, byte type); |
public Perception getPerception(RPObject.ID id, byte type); |
||
/** This method is called to take zone to the next turn */ |
/** This method is called to take zone to the next turn */ |
||
public void nextTurn(); |
public void nextTurn(); |
||
/** 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 269: | Line 300: | ||
* buildMapObjectsList |
* buildMapObjectsList |
||
| ⚫ | |||
| ⚫ | |||
| ⚫ | |||
| ⚫ | |||
The API is as follows: |
The API is as follows: |
||
<source lang="java"> |
|||
<pre> |
|||
/** 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. */ |
||
public void setContext(IRPZone zone); |
public void setContext(IRPZone zone); |
||
/** Pass the whole list of actions so that it can approve or deny the actions in it. |
/** Pass the whole list of actions so that it can approve or deny the actions in it. |
||
* @param id the id of the object owner of the actions. |
* @param id the id of the object owner of the actions. |
||
* @param actionList the list of actions that the player wants to execute. */ |
* @param actionList the list of actions that the player wants to execute. */ |
||
public void approvedActions(RPObject.ID id, RPActionList actionList); |
public void approvedActions(RPObject.ID id, RPActionList actionList); |
||
/** Execute an action in the name of a player. |
/** Execute an action in the name of a player. |
||
* @param id the id of the object owner of the actions. |
* @param id the id of the object owner of the actions. |
||
| Line 287: | Line 319: | ||
* refer to Actions Explained for more info. */ |
* refer to Actions Explained for more info. */ |
||
public RPAction.Status execute(RPObject.ID id, RPAction action); |
public RPAction.Status execute(RPObject.ID id, RPAction action); |
||
/** Notify it when a new turn happens */ |
/** Notify it when a new turn happens */ |
||
public void nextTurn(); |
public void nextTurn(); |
||
/** Callback method called when a new player enters in the game |
/** Callback method called when a new player enters in the game |
||
* @param object the new player that enters in the game. */ |
* @param object the new player that enters in the game. */ |
||
public boolean onInit(RPObject object) throws RPObjectInvalidException; |
public boolean onInit(RPObject object) throws RPObjectInvalidException; |
||
/** Callback method called when a new player exits the game |
/** Callback method called when a new player exits the game |
||
* @param id the new player id that exits the game. |
* @param id the new player id that exits the game. |
||
* @return true to update the player on database. */ |
* @return true to update the player on database. */ |
||
public boolean onExit(RPObject.ID id) throws RPObjectNotFoundException; |
public boolean onExit(RPObject.ID id) throws RPObjectNotFoundException; |
||
/** Callback method called when a new player time out |
/** Callback method called when a new player time out |
||
* @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]] |
||
{{#breadcrumbs: [[Marauroa]] | [[Navigation for Marauroa Users|Using]] | [[Marauroa Core API|Core API]]}} |
|||