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)
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=&quot;age&quot; and value=21
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:
&lt;source lang=&quot;java&quot;&gt;
<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)
&lt;/source&gt;
</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:
&lt;source lang=&quot;java&quot;&gt;
<source lang="java">
public void add(String name, int quantity)
public void add(String name, int quantity)
&lt;/source&gt;
</source>


Returns the value of an attribute:
Returns the value of an attribute:
&lt;source lang=&quot;java&quot;&gt;
<source lang="java">
public String get(String name)
public String get(String name)
public int get(String name)
public int get(String name)
&lt;/source&gt;
</source>


Removes an attribute entry from the list of attributes:
Removes an attribute entry from the list of attributes:
&lt;source lang=&quot;java&quot;&gt;
<source lang="java">
public void remove(String name)
public void remove(String name)
&lt;/source&gt;
</source>


Returns True if an attribute exists:
Returns True if an attribute exists:
&lt;source lang=&quot;java&quot;&gt;
<source lang="java">
public boolean has(String name)
public boolean has(String name)
&lt;/source&gt;
</source>


'''Example''': &lt;br&gt;
'''Example''': <br>
&lt;source lang=&quot;java&quot;&gt;
<source lang="java">
Attributes test=new Attributes();
Attributes test=new Attributes();
test.put(&quot;name&quot;,&quot;Test attribute&quot;);
test.put("name","Test attribute");
test.put(&quot;hp&quot;,100);
test.put("hp",100);


if(test.has(&quot;hp&quot;)) {
if(test.has("hp")) {
test.add(&quot;hp&quot;,10);
test.add("hp",10);
}
}


test.remove(&quot;name&quot;);
test.remove("name");
&lt;/source&gt;
</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)
&lt;source lang=&quot;java&quot;&gt;
<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)
&lt;/source&gt;
</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''':
&lt;source lang=&quot;java&quot;&gt;
<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)
&lt;/source&gt;
</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''':
&lt;source lang=&quot;java&quot;&gt;
<source lang="java">
boolean hasRPClass(String name)
boolean hasRPClass(String name)
RPClass getRPClass(String name)
RPClass getRPClass(String name)
&lt;/source&gt;
</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''':&lt;br&gt;
'''Example''':<br>
&lt;source lang=&quot;java&quot;&gt;
<source lang="java">


// a general entity with a position
// a general entity with a position
RPClass objclass = new RPClass(&quot;entity&quot;);
RPClass objclass = new RPClass("entity");
objclass.add(&quot;x&quot;, RPClass.BYTE);
objclass.add("x", RPClass.BYTE);
objclass.add(&quot;y&quot;, RPClass.BYTE);
objclass.add("y", RPClass.BYTE);


// an entity specialized in players
// an entity specialized in players
objclass = RPClass(&quot;player&quot;);
objclass = RPClass("player");
objclass.isA(&quot;entity&quot;);
objclass.isA("entity");
objclass.add(&quot;name&quot;, RPClass.SHORT_STRING);
objclass.add("name", RPClass.SHORT_STRING);
objclass.add(&quot;direction&quot;, RPClass.SHORT_STRING);
objclass.add("direction", RPClass.SHORT_STRING);
objclass.add(&quot;score&quot;, RPClass.INT);
objclass.add("score", RPClass.INT);
objclass.add(&quot;super&quot;, RPClass.BYTE);
objclass.add("super", RPClass.BYTE);
objclass.add(&quot;!vdir&quot;, RPClass.STRING,RPClass.HIDDEN);
objclass.add("!vdir", RPClass.STRING,RPClass.HIDDEN);
objclass.add(&quot;!hdir&quot;, RPClass.STRING,RPClass.HIDDEN);
objclass.add("!hdir", RPClass.STRING,RPClass.HIDDEN);
objclass.add(&quot;?kill&quot;, RPClass.FLAG);
objclass.add("?kill", RPClass.FLAG);
&lt;/source&gt;
</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:
&lt;source lang=&quot;java&quot;&gt;
<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()
&lt;/source&gt;
</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.


&lt;source lang=&quot;java&quot;&gt;
<source lang="java">
public RPObject.ID getID()
public RPObject.ID getID()
&lt;/source&gt;
</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:
&lt;source lang=&quot;java&quot;&gt;
<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()
&lt;/source&gt;
</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.


&lt;source lang=&quot;java&quot;&gt;
<source lang="java">
public Iterator iterator()
public Iterator iterator()
&lt;/source&gt;
</source>


It is used to visit all the objects of the slot.
It is used to visit all the objects of the slot.


&lt;source lang=&quot;java&quot;&gt;
<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(&quot;player&quot;);
RPObject object = new RPObject("player");
object.put(&quot;name&quot;, &quot;example&quot;);
object.put("name", "example");
object.put(&quot;score&quot;, 0);
object.put("score", 0);


// create a slot called backpack
// create a slot called backpack
RPSlot slot = new RPSlot(&quot;backpack&quot;);
RPSlot slot = new RPSlot("backpack");
object.addSlot(slot);
object.addSlot(slot);


// create an object of RPClass &quot;coin&quot; and put it into the slot
// create an object of RPClass "coin" and put it into the slot
RPObject coin = new RPObject(&quot;coin&quot;);
RPObject coin = new RPObject("coin");
slot.add(coin);
slot.add(coin);
&lt;/source&gt;
</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.


&lt;source lang=&quot;java&quot;&gt;
<source lang="java">
public void onInit() throws Exception
public void onInit() throws Exception
public void onFinish() throws Exception
public void onFinish() throws Exception
&lt;/source&gt;
</source>


Some helper methods to add zones and iterate them.
Some helper methods to add zones and iterate them.


&lt;source lang=&quot;java&quot;&gt;
<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&lt;IRPZone&gt; iterator()
public Iterator<IRPZone> iterator()
public int size()
public int size()
&lt;/source&gt;
</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.


&lt;source lang=&quot;java&quot;&gt;
<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
&lt;/source&gt;
</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.


&lt;source lang=&quot;java&quot;&gt;
<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
&lt;/source&gt;
</source>


==IRPZone==
==IRPZone==
Line 262: Line 254:


The methods are:
The methods are:
&lt;source lang=&quot;java&quot;&gt;
<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);
&lt;/source&gt;
</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.&lt;br&gt;
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:
&lt;source lang=&quot;java&quot;&gt;
<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;
&lt;/source&gt;
</source>


[[Category:Marauroa]]
[[Category:Marauroa]]