Marauroa Core API: Difference between revisions
Content deleted Content added
imported>Ufizavipupu No edit summary |
imported>Blacklads Undo revision 11663 by Ufizavipupu (Talk) |
||
Line 1:
{{Navigation for Marauroa Top|Using}}
{{Navigation for Marauroa Users}}
Line 35 ⟶ 27:
== 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=
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 ⟶ 38:
Setting the value of an attribute:
public void put(String name, String value)
public void put(String name, int value)
Add a quantity to the value element of an attribute that MUST already exist:
public void add(String name, int quantity)
Returns the value of an attribute:
public String get(String name)
public int get(String name)
Removes an attribute entry from the list of attributes:
public void remove(String name)
Returns True if an attribute exists:
public boolean has(String name)
'''Example''':
Attributes test=new Attributes();
test.put(
test.put(
if(test.has(
test.add(
}
test.remove(
== RPClass ==
Line 104 ⟶ 96:
Creation methods of the RPClass: (These are part of each RPClass instance, see example below for usage)
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)
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 ⟶ 108:
'''Query''':
public String getName()
public byte getType(String name)
Line 122 ⟶ 114:
public boolean hasAttribute(String name)
public boolean subclassOf(String parentclass)
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''':
boolean hasRPClass(String name)
RPClass getRPClass(String name)
When writting a class definition you can skip the ''id'' and ''type'' attributes as they are automatically determined by RPClass.
'''Example''':
// a general entity with a position
RPClass objclass = new RPClass(
objclass.add(
objclass.add(
// an entity specialized in players
objclass = RPClass(
objclass.isA(
objclass.add(
objclass.add(
objclass.add(
objclass.add(
objclass.add(
objclass.add(
objclass.add(
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 ⟶ 163:
The methods of the RPObject to modify slots are:
public void addSlot(RPSlot slot)
public RPSlot getSlot(String name)
Line 177 ⟶ 169:
public boolean hasSlot(String name)
public Iterator slotIterator()
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.
public RPObject.ID getID()
This is a helper method to get the unique ID of the object.
RPSlot has a simple API:
public void add(RPObject object)
public RPObject get(RPObject.ID id)
Line 192 ⟶ 184:
public RPObject remove(RPObject.ID id)
public void clear()
These methods modify objects in the RPSlot. The clear() method removes all the objects in the slot.
public Iterator iterator()
It is used to visit all the objects of the slot.
// create an object of RPClass player and set some attribute values
RPObject object = new RPObject(
object.put(
object.put(
// create a slot called backpack
RPSlot slot = new RPSlot(
object.addSlot(slot);
// create an object of RPClass
RPObject coin = new RPObject(
slot.add(coin);
Now for the complex part. Where it all becomes a little nuts!: IRPZone and IRPRuleProcessor interfaces
Line 226 ⟶ 218:
onInit and onFinish are called on server startup and finalization. You need to subclass RPWorld to give proper behaviour to them.
public void onInit() throws Exception
public void onFinish() throws Exception
Some helper methods to add zones and iterate them.
public void addRPZone(IRPZone zone)
public IRPZone getRPZone(IRPZone.ID zoneid)
public IRPZone getRPZone(RPObject.ID objectid)
public Iterator
public int size()
Methods to add, get, test existence, remove and modify objects. modify() is as you know for delta^2 algorithm.
public void add(RPObject object) throws NoRPZoneException, RPObjectInvalidException
public RPObject get(RPObject.ID id) throws NoRPZoneException, RPObjectInvalidException
Line 249 ⟶ 241:
public RPObject remove(RPObject.ID id) throws NoRPZoneException, RPObjectNotFoundException
public void modify(RPObject object) throws NoRPZoneException
These are helper methods for changing the zone of an object. Use them instead of doing it by hand.
public void changeZone(IRPZone.ID oldzoneid, IRPZone.ID newzoneid, RPObject object) throws NoRPZoneException
public void changeZone(String oldzone, String newzone, RPObject object) throws NoRPZoneException
==IRPZone==
Line 262 ⟶ 254:
The methods are:
/** This method is called when the zone is created to populate it */
public void onInit() throws Exception;
Line 301 ⟶ 293:
/** 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 309 ⟶ 301:
==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.
The API is as follows:
/** Set the context where the actions are executed.
* @param zone The zone where actions happens. */
Line 343 ⟶ 335:
* @param id the new player id that timeouts. */
public boolean onTimeout(RPObject.ID id) throws RPObjectNotFoundException;
[[Category:Marauroa]]
| |||