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)
 
(49 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://stendhal.game-host.org/hudson/job/marauroa_HEAD/javadoc/ JavaDoc API Documentation] is available, too.
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 209: Line 211:
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 216: 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 onFinish() throws Exception
public void onInit() 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 IRPZone getRPZone(IRPZone.ID zoneid)
public void addRPZone(IRPZone zone)
public IRPZone getRPZone(RPObject.ID objectid)
public IRPZone getRPZone(IRPZone.ID zoneid)
public Iterator<IRPZone> iterator()
public IRPZone getRPZone(RPObject.ID objectid)
public int size()
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 void add(RPObject object) throws NoRPZoneException, RPObjectInvalidException
public RPObject get(RPObject.ID id) throws NoRPZoneException, RPObjectInvalidException
public void add(RPObject object) throws NoRPZoneException, RPObjectInvalidException
public boolean has(RPObject.ID id) throws NoRPZoneException, RPObjectInvalidException
public RPObject get(RPObject.ID id) throws NoRPZoneException, RPObjectInvalidException
public RPObject remove(RPObject.ID id) throws NoRPZoneException, RPObjectNotFoundException
public boolean has(RPObject.ID id) throws NoRPZoneException, RPObjectInvalidException
public void modify(RPObject object) throws NoRPZoneException
public RPObject remove(RPObject.ID id) throws NoRPZoneException, RPObjectNotFoundException
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(String oldzone, String newzone, 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
</source>

==IRPZone==
IRPZone is the interface that handles the world content and the perceptions. In most cases you should use the implementation MarauroaRPZone and extend it.


=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:
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 252: 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 266: 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 271: 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);
</pre>
</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 282: Line 300:
* buildMapObjectsList
* buildMapObjectsList


==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.<br>
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:
Line 321: Line 338:


[[Category:Marauroa]]
[[Category:Marauroa]]
{{#breadcrumbs: [[Marauroa]] | [[Navigation for Marauroa Users|Using]] | [[Marauroa Core API|Core API]]}}