Marauroa Core API: Difference between revisions
Content deleted Content added
imported>Hendrik Brummermann No edit summary |
imported>Blacklads Undo revision 11663 by Ufizavipupu (Talk) |
||
| (82 intermediate revisions by 3 users not shown) | |||
Line 3:
Marauroa exposes a very simplified and reduced API so you can easily develop your own games. A nightly build [http://
== Content ==
[[Image:Classdiagram_marauroa.common.game_rp_stubs.png|thumb|Class Diagram of RP* classes]]
The main entities you should know about are:
* Attributes
Line 22 ⟶ 24:
* PythonWorld
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]]. Please note that Python support is dormant.
== Attributes ==
Line 156 ⟶ 158:
== RPObject and RPSlot ==
RPObjects are the containters of data in Arianne. An RPObject is an
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:
<source lang="java">
public boolean hasSlot(String name)
</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.
<source lang="java">
</source>
This is a helper method to get the unique ID of the object.
RPSlot
<source lang="java">
public RPObject remove(RPObject.ID id)
These methods modify objects in the RPSlot.▼
</source>
▲These methods modify objects in the RPSlot. The clear() method removes all the objects in the slot.
* Iterator iterator()▼
<source lang="java">
</source>
It is used to visit all the objects of the slot.
<source lang="java">
RPObject object
object.put("
▲ coin.put("type","coin");
slot.add(coin);▼
object.addSlot(slot);
// create an object of RPClass "coin" and put it into the slot
RPObject coin = new RPObject("coin");
▲ slot.add(coin);
</source>
Now for the complex part. Where it all becomes a little nuts!: IRPZone and IRPRuleProcessor interfaces
==RPWorld==
This class is just a container of zones.
Line 203 ⟶ 218:
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
</source>
Some helper methods to add zones and iterate them.
<source lang="java">
public
public IRPZone getRPZone(
public
public
public int size()
</source>
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
public
public
public
</source>
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(
▲ public void changeZone(
</source>
==IRPZone==▼
IRPZone is the
▲=IRPZone=
▲IRPZone is the class that handles the world content and the perceptions. It would be wise to forget about it, or extend MarauroaRPZone instead as it's a complex and error prone class. <br>
The methods are:
<source lang="java">
/** This method is called when the zone is created to populate it */
public void onInit() throws Exception;
/** This method is called when the server finish to save the content of the zone */
public void onFinish() throws Exception;
Line 239 ⟶ 263:
/** This method adds an object to the Zone */
public void add(RPObject object) throws RPObjectInvalidException;
/** This method tag an object of the Zone as modified */
public void modify(RPObject object) throws RPObjectInvalidException;
/** This method removed an object of the Zone and return it.*/
public RPObject remove(RPObject.ID id) throws RPObjectNotFoundException;
/** This method returns an object of the Zone */
public RPObject get(RPObject.ID id) throws RPObjectNotFoundException;
/** This method returns true if the object exists in the Zone */
public boolean has(RPObject.ID id);
Line 253 ⟶ 281:
/** Iterates over the elements of the zone */
public Iterator iterator();
/** Returns the number of elements of the zone */
public long size();
Line 258 ⟶ 287:
/** This method return the perception of a zone for a player */
public Perception getPerception(RPObject.ID id, byte type);
/** This method is called to take zone to the next turn */
public void nextTurn();
/** Method to create the map to send to player's client */
public java.util.List buildMapObjectsList(RPObject.ID id);
</
In most of the cases all you will wish to modify are:
Line 269 ⟶ 300:
* buildMapObjectsList
==IRPRuleProcessor==▼
This class
▲=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.<br>
The API is as follows:
<source lang="java">
/** Set the context where the actions are executed.
* @param zone The zone where actions happens. */
public void setContext(IRPZone zone);
/** 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 actionList the list of actions that the player wants to execute. */
public void approvedActions(RPObject.ID id, RPActionList actionList);
/** Execute an action in the name of a player.
* @param id the id of the object owner of the actions.
Line 287 ⟶ 319:
* refer to Actions Explained for more info. */
public RPAction.Status execute(RPObject.ID id, RPAction action);
/** Notify it when a new turn happens */
public void nextTurn();
/** Callback method called when a new player enters in the game
* @param object the new player that enters in the game. */
public boolean onInit(RPObject object) throws RPObjectInvalidException;
/** Callback method called when a new player exits the game
* @param id the new player id that exits the game.
* @return true to update the player on database. */
public boolean onExit(RPObject.ID id) throws RPObjectNotFoundException;
/** Callback method called when a new player time out
* @param id the new player id that timeouts. */
public boolean onTimeout(RPObject.ID id) throws RPObjectNotFoundException;
</
[[Category:Marauroa]]
{{#breadcrumbs: [[Marauroa]] | [[Navigation for Marauroa Users|Using]] | [[Marauroa Core API|Core API]]}}
| |||