PyArianneAPIDefinition: Difference between revisions
Jump to navigation
Jump to search
Content deleted Content added
No edit summary |
imported>StephenIerodiaconou No edit summary |
||
| (21 intermediate revisions by 2 users not shown) | |||
| Line 1: | Line 1: | ||
=pyarianne API= |
|||
pyarianne is the API that connects your game to the Arianne system. |
pyarianne is the API that connects your game to the Arianne system. For an example of how to use this API, please just go to the [[pyArianneAPIExample]] page. |
||
It is composed of several functions that provide you with |
It is composed of several functions that provide you with basic, low level access in to the Arianne framework. |
||
It is important that you respect the order of the functions; if not the behaviour of your application will be irratic. |
It is important that you respect the order of the functions; if not the behaviour of your application will be irratic. |
||
| Line 7: | Line 8: | ||
Let's first have a look at the function calls and we will describe the data structures later. |
Let's first have a look at the function calls and we will describe the data structures later. |
||
* ''setIdleMethod(function)'' <br> |
|||
This function sets the callback function that will be called each time the module needs to block for a given period of time. The callback function should return true to make the pyarianne module continue wait for data, and false will make the modile stop waiting. |
This function sets the callback function that will be called each time the module needs to block for a given period of time. The callback function should return true to make the pyarianne module continue wait for data, and false will make the modile stop waiting. |
||
<pre> |
<pre> |
||
| Line 16: | Line 17: | ||
</pre> |
</pre> |
||
* ''connectToArianne(serverName, port)'' <br> |
|||
This function is called to connect to an Arianne server running on the server whose name (DNS) or IP is <serverName> and that can be reached at port <port>. |
This function is called to connect to an Arianne server running on the server whose name (DNS) or IP is <serverName> and that can be reached at port <port>. |
||
This function will never fail. |
This function will never fail. |
||
| Line 24: | Line 25: | ||
</pre> |
</pre> |
||
* ''login(username, password)'' <br> |
|||
This function should be called AFTER connecting to the Arianne server; it tries to login to the server using the given username and password combination. |
This function should be called AFTER connecting to the Arianne server; it tries to login to the server using the given username and password combination. |
||
It will return true if the login is completed successfully or false if there is a problem and it then will set error to true. |
It will return true if the login is completed successfully or false if there is a problem and it then will set error to true. |
||
| Line 35: | Line 36: | ||
</pre> |
</pre> |
||
* ''availableCharacters()'' <br> |
|||
Once you have logged into Arianne, you can get the list of characters available for your account. |
Once you have logged into Arianne, you can get the list of characters available for your account. |
||
It will return a list of name of characters. |
It will return a list of name of characters. |
||
| Line 42: | Line 43: | ||
</pre> |
</pre> |
||
* ''serverInfo()''<br> |
|||
Once you have logged into Arianne, you can get the list of server properties that may be relevant to the client. |
Once you have logged into Arianne, you can get the list of server properties that may be relevant to the client. |
||
It will return a list of properties of the form attribute=value. |
It will return a list of properties of the form attribute=value. |
||
| Line 49: | Line 50: | ||
</pre> |
</pre> |
||
* ''getGameType()''<br> |
|||
Returns a string containing the type of game we are playing. |
Returns a string containing the type of game we are playing. |
||
<pre> |
<pre> |
||
| Line 56: | Line 57: | ||
</pre> |
</pre> |
||
* ''chooseCharacter(character)''<br> |
|||
Once have recieved the list of characters you can choose one of them that you will use to enter the game. |
Once have recieved the list of characters you can choose one of them that you will use to enter the game. |
||
If it enters correctly it will return true, otherwise it will return false. |
If it enters correctly it will return true, otherwise it will return false. |
||
| Line 67: | Line 68: | ||
</pre> |
</pre> |
||
* ''hasRPMap()''<br> |
|||
This function returns true if there is a Map available for this game. |
This function returns true if there is a Map available for this game. |
||
* ''getRPMap()''<br> |
|||
This functions returns a list of objects containing the data of the Map. |
This functions returns a list of objects containing the data of the Map. |
||
It is up to your client to process it and build an appropriate representation. |
It is up to your client to process it and build an appropriate representation. |
||
| Line 76: | Line 77: | ||
</pre> |
</pre> |
||
* ''hasPerception()''<br> |
|||
This function returns true if there is a perception available for your game. |
This function returns true if there is a perception available for your game. |
||
* ''getPerception()''<br> |
|||
This function returns a perception that should have been previously stored by a call to hasPerception, using a polling technique. This function won't block the client. |
This function returns a perception that should have been previously stored by a call to hasPerception, using a polling technique. This function won't block the client. |
||
<pre> |
<pre> |
||
| Line 86: | Line 87: | ||
</pre> |
</pre> |
||
* ''send(action)''<br> |
|||
* ''sendBlocking(action)''<br> |
|||
Both these functions send an Action the server, but the blocking function will block until the server replies with a Action ACK message, which will be around the length of the trip time of the message. |
Both these functions send an Action the server, but the blocking function will block until the server replies with a Action ACK message, which will be around the length of the trip time of the message. |
||
They return nothing. |
They return nothing. |
||
| Line 98: | Line 99: | ||
</pre> |
</pre> |
||
* ''logout()''<br> |
|||
Exits the Arianne enviroment and returns true. |
Exits the Arianne enviroment and returns true. |
||
If it returns false it means the logout didn't happened. |
If it returns false it means the logout didn't happened. |
||
| Line 106: | Line 107: | ||
</pre> |
</pre> |
||
* ''iserror()''<br> |
|||
Return true if there is a significant error |
Return true if there is a significant error |
||
* ''errorReason()''<br> |
|||
Returns a string containing an explanation of the error. |
Returns a string containing an explanation of the error. |
||
| Line 119: | Line 120: | ||
* Perception |
* Perception |
||
* World |
* World |
||
* |
* PerceptionHandler |
||
==RPAction== |
|||
We use RPAction to tell the server to do something with our characters. Depending on the game different actions will be accomplished. |
We use RPAction to tell the server to do something with our characters. Depending on the game different actions will be accomplished. |
||
It has several methods: |
It has several methods: |
||
* ''has(attribute)''<br> |
|||
Returns true if the action has the attibute whose name matches attribute. |
Returns true if the action has the attibute whose name matches attribute. |
||
* ''put(attribute, value)''<br> |
|||
Sets an attribute in the action where attribute's name is attribute and value is value. Value can either be a string or a number. |
Sets an attribute in the action where attribute's name is attribute and value is value. Value can either be a string or a number. |
||
* ''get(attribute)''<br> |
|||
Returns a string containing the value of the attribute |
Returns a string containing the value of the attribute |
||
This method will fail if it is called on a attribute that doesn't exist. |
This method will fail if it is called on a attribute that doesn't exist. |
||
* ''getInt(attribute)''<br> |
|||
Returns an integer containing the value of the attribute |
Returns an integer containing the value of the attribute |
||
This method will fail if it is called on a attribute that doesn't exist. |
This method will fail if it is called on a attribute that doesn't exist. |
||
* ''remove(attribute)''<br> |
|||
Removes an attribute from the action or fails if it doesn't exist. |
Removes an attribute from the action or fails if it doesn't exist. |
||
* ''clear()''<br> |
|||
_clear()_ %%% |
|||
Remove all the attributes from the action |
Remove all the attributes from the action |
||
* ''equals(action)''<br> |
|||
Return true if the action is equal to this action. |
Return true if the action is equal to this action. |
||
* ''toString()''<br> |
|||
_toString()_ %%% |
|||
Return a string representation of the action |
Return a string representation of the action |
||
* ''size()''<br> |
|||
_size()_ %%% |
|||
Returns the number of attributes of the action |
Returns the number of attributes of the action |
||
==RPObject== |
|||
This class represents RPObjects in the world, everything in Arianne is an object, keep that in mind. |
This class represents RPObjects in the world, everything in Arianne is an object, keep that in mind. |
||
It has several methods: |
It has several methods: |
||
* ''has(attribute)''<br> |
|||
Returns true if the object has the attibute whose name matches attribute. |
Returns true if the object has the attibute whose name matches attribute. |
||
* ''put(attribute, value)''<br> |
|||
Sets an attribute in the object where attribute's name is attribute and value is value. Value can either be a string or a number. |
Sets an attribute in the object where attribute's name is attribute and value is value. Value can either be a string or a number. |
||
* ''get(attribute)''<br> |
|||
Returns a string containing the value of the attribute |
Returns a string containing the value of the attribute |
||
This method will fail if it is called on a attribute that doesn't exist. |
This method will fail if it is called on a attribute that doesn't exist. |
||
* ''getInt(attribute)''<br> |
|||
Returns an integer containing the value of the attribute |
Returns an integer containing the value of the attribute |
||
This method will fail if it is called on a attribute that doesn't exist. |
This method will fail if it is called on a attribute that doesn't exist. |
||
* ''remove(attribute)''<br> |
|||
Removes an attribute from the object or fails if it doesn't exist. |
Removes an attribute from the object or fails if it doesn't exist. |
||
* ''clear()''<br> |
|||
_clear()_ %%% |
|||
Removes all the attributes from the object |
Removes all the attributes from the object |
||
* ''equals(object)''<br> |
|||
Returns true if the object is equals to this object. |
Returns true if the object is equals to this object. |
||
* ''toString()''<br> |
|||
_toString()_ %%% |
|||
Returns a string representation of the object |
Returns a string representation of the object |
||
* ''size()''<br> |
|||
_size()_ %%% |
|||
Returns the number of attributes of the object plus all the attributes of the objects that exist in the slots. |
Returns the number of attributes of the object plus all the attributes of the objects that exist in the slots. |
||
* ''addSlot(slot)''<br> |
|||
Add an RPSlot to the object; it will fail if the slot already exists on the object. So if you want to replace a slot, first remove the current slot. |
Add an RPSlot to the object; it will fail if the slot already exists on the object. So if you want to replace a slot, first remove the current slot. |
||
* ''getSlot(name)''<br> |
|||
Returns an RPSlot from the Object whose name is name. |
Returns an RPSlot from the Object whose name is name. |
||
It will fail if there is no such slot. |
It will fail if there is no such slot. |
||
* ''removeSlot(name)''<br> |
|||
Removes the slot from the object whose name is name. |
Removes the slot from the object whose name is name. |
||
It will fail if there is no such slot. |
It will fail if there is no such slot. |
||
* ''hasSlot(name)''<br> |
|||
Returns true if the object has a slot named name. |
Returns true if the object has a slot named name. |
||
* ''applyAddedDifferences(added)''<br> |
|||
_applyAddedDifferences(added)_ %%% |
|||
* ''applyDeletedDifferences(deleted)''<br> |
|||
* ''removeAllHidden()''<br> |
|||
_removeAllHidden()_ %%% |
|||
Don't use these methods directly. See |
Don't use these methods directly. See PerceptionHandler. |
||
==RPSlot== |
|||
Every object can be a slot, they are like extensions of an object that allow it to contains more objects. A pocket, a bag, a chest are examples of objects. |
Every object can be a slot, they are like extensions of an object that allow it to contains more objects. A pocket, a bag, a chest are examples of objects. |
||
It has several methods: |
It has several methods: |
||
* ''name''<br> |
|||
_name_ %%% |
|||
It contains the name of the Slot. It is a string. |
It contains the name of the Slot. It is a string. |
||
* ''add(object)''<br> |
|||
This method adds an object to the slot or replaces it if it exists. |
This method adds an object to the slot or replaces it if it exists. |
||
* ''get(id)''<br> |
|||
Returns the object whose id is id or fails if there is no such object. |
Returns the object whose id is id or fails if there is no such object. |
||
* ''getByPosition(i)''<br> |
|||
_getByPosition(i)_ %%% |
|||
Returns the object whose position on the list of objects is i or fails if there is no such position |
Returns the object whose position on the list of objects is i or fails if there is no such position |
||
* ''has(id)''<br> |
|||
Returns true if there is an object whose id is id. False otherwise |
Returns true if there is an object whose id is id. False otherwise |
||
* ''remove(id)''<br> |
|||
_remove(id)_ %%% |
|||
Removes the object whose id is id or fails if it can't be found- |
Removes the object whose id is id or fails if it can't be found- |
||
* ''clear()''<br> |
|||
_clear()_ %%% |
|||
Removes all the objects in the slot. |
Removes all the objects in the slot. |
||
* ''equals(slot)''<br> |
|||
Return true if the slot is equals to this slot. |
Return true if the slot is equals to this slot. |
||
* ''toString()''<br> |
|||
_toString()_ %%% |
|||
Return a string representation of the slot |
Return a string representation of the slot |
||
* ''size()''<br> |
|||
_size()_ %%% |
|||
Returns the number of objects in the slot. |
Returns the number of objects in the slot. |
||
==Perception== |
|||
A perception is the basic unit of information of the Arianne system. You get one perception each turn and basically there are two different classes of perception: |
A perception is the basic unit of information of the Arianne system. You get one perception each turn and basically there are two different classes of perception: |
||
* SYNC |
* SYNC <br> These are sent to synchronize the client with the server, for example, after login or after a few failures on the connection. |
||
* DELTA |
* DELTA <br> These are sent to the client each turn to tell it the differences with the previous status of the world. |
||
Of course you can and must ignore such lowlevel details when using pyarianne. |
Of course you can and must ignore such lowlevel details when using pyarianne.<br> |
||
It contains: |
It contains: <br> |
||
* ''type''<br> |
|||
_type_ %%% |
|||
It is an enum type that can be either 0 or 1 to indicate SYNC and DELTA perception type. |
It is an enum type that can be either 0 or 1 to indicate SYNC and DELTA perception type. |
||
* ''timestamp''<br> |
|||
_timestamp_ %%% |
|||
It is a constant incremental counter to mark each perception |
It is a constant incremental counter to mark each perception |
||
* ''added''<br> |
|||
_added_ %%% |
|||
* ''modifiedAdded''<br> |
|||
_modifiedAdded_ %%% |
|||
* ''modifiedDeleted''<br> |
|||
_modifiedDeleted_ %%% |
|||
* ''deleted''<br> |
|||
_deleted_ %%% |
|||
These are a list of RPObjects that contain added, modified added, modified deleted and deleted objects respectively |
These are a list of RPObjects that contain added, modified added, modified deleted and deleted objects respectively |
||
* ''myRPObjectChanged''<br> |
|||
_myRPObjectChanged_ %%% |
|||
It is a boolean value that will be true if myRPObject contains a valid value |
It is a boolean value that will be true if myRPObject contains a valid value |
||
* ''myRPObject''<br> |
|||
_myRPObject_ %%% |
|||
It is our RPObject containing all the hidden attributes. |
It is our RPObject containing all the hidden attributes. |
||
Again, you should never use this structure directly, but instead use |
Again, you should never use this structure directly, but instead use PerceptionHandler |
||
==World== |
|||
This is a container for objects that must be use by |
This is a container for objects that must be use by PerceptionHandler. |
||
For a unknown reason if this structure is written in Python it is not understood by SWIG and objects are freed :( |
For a unknown reason if this structure is written in Python it is not understood by SWIG and objects are freed :( |
||
* ''objects_ <br> |
|||
_objects_ %%% |
|||
It is a dict of integer<-->RPObject |
It is a dict of integer<-->RPObject |
||
==PerceptionHandler== |
|||
This is the class that cares about perception handling, and this is the only thing you should ever use to handle a perception. |
This is the class that cares about perception handling, and this is the only thing you should ever use to handle a perception. |
||
The class is very simple, it has a constructor a method to handle the perception and modify the world. |
The class is very simple, it has a constructor a method to handle the perception and modify the world. |
||
* ''PerceptionHandler(listener)''<br> |
|||
It is passed an instance of a subclass of ~PerceptionListener that handles everything related to the perception on a detailed way. You can choose to implement your own, or use the default one. |
It is passed an instance of a subclass of ~PerceptionListener that handles everything related to the perception on a detailed way. You can choose to implement your own, or use the default one. |
||
* ''apply(perception, world)''<br> |
|||
Just call this method with the perception you get from getPerception and the world where objects are stored, and voila... perception gets applied. |
Just call this method with the perception you get from getPerception and the world where objects are stored, and voila... perception gets applied. |
||
* ''PerceptionListener''<br> |
|||
It is a listener class for handling perceptions. |
It is a listener class for handling perceptions. |
||
Each method is called on the given event, you can execute whatever you want inside. |
Each method is called on the given event, you can execute whatever you want inside. |
||
* ''onAdded(object)''<br> |
|||
It is called when an object is added to the world. |
It is called when an object is added to the world. |
||
* ''onBeforeModifiedAdded(object, previous)''<br> |
|||
It is called when an object is modified by adding slots or attributes. |
It is called when an object is modified by adding slots or attributes. |
||
* ''onBeforeModifiedDeleted(object, previous)''<br> |
|||
It is called when an object is modified by removing slots or attributes. |
It is called when an object is modified by removing slots or attributes. |
||
* ''onModifiedAdded(object)''<br> |
|||
It is called when an object has been modified by adding slots or attributes. |
It is called when an object has been modified by adding slots or attributes. |
||
* ''onModifiedDeleted(object)''<br> |
|||
It is called when an object has been modified by removing slots or attributes. |
It is called when an object has been modified by removing slots or attributes. |
||
* ''onDeleted(object)''<br> |
|||
It is called when an object is deleted of the world |
It is called when an object is deleted of the world |
||
* ''onMyRPObject(changed, object)''<br> |
|||
It is called on each perception, if changed is true, object contains the resulting new object for our character, else it will contains None |
It is called on each perception, if changed is true, object contains the resulting new object for our character, else it will contains None |
||
* ''onPerception()''<br> |
|||
_onPerception()_ %%% |
|||
It is called on each perception. |
It is called on each perception. |
||
* ''onClear()''<br> |
|||
_onClear()_ %%% |
|||
It is called each time the whole world is emptied |
It is called each time the whole world is emptied |
||
* ''onUnsync()''<br> |
|||
_onUnsync()_ %%% |
|||
When you get out of sync this method is called |
When you get out of sync this method is called |
||
* ''onSync()''<br> |
|||
_onSync()_ %%% |
|||
When you recover sync with server this method is called |
When you recover sync with server this method is called |
||
That's all. |
That's all.<br> |
||
There is nothing more to this API, please just go to the [pyArianneAPIExample] for more info. |
There is nothing more to this API, please just go to the [[pyArianneAPIExample]] for more info. |
||