PyArianneAPIDefinition: Difference between revisions

Content deleted Content added
No edit summary
 
imported>StephenIerodiaconou
No edit summary
 
(29 intermediate revisions by 2 users not shown)
Line 1:
!!! =pyarianne API=
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 a 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.
Line 7 ⟶ 8:
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.
<pre>
Line 16 ⟶ 17:
</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 will never fail.
Line 24 ⟶ 25:
</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.
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 ⟶ 36:
</pre>
 
_* ''availableCharacters()*_'' %%%<br>
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.
Line 42 ⟶ 43:
</pre>
 
_* ''serverInfo()*_ %%%''<br>
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.
Line 49 ⟶ 50:
</pre>
 
_* ''getGameType()*_ %%%''<br>
Returns a string containing the type of game we are playing.
<pre>
Line 56 ⟶ 57:
</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.
If it enters correctly it will return true, otherwise it will return false.
Line 67 ⟶ 68:
</pre>
 
_* ''hasRPMap()*_ %%%''<br>
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.
It is up to your client to process it and build an appropriate representation.
Line 76 ⟶ 77:
</pre>
 
_* ''hasPerception()*_ %%%''<br>
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.
<pre>
Line 86 ⟶ 87:
</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.
They return nothing.
Line 98 ⟶ 99:
</pre>
 
_* ''logout()*_ %%%''<br>
Exits the Arianne enviroment and returns true.
If it returns false it means the logout didn't happened.
Line 106 ⟶ 107:
</pre>
 
_* ''iserror()*_ %%%''<br>
Return true if there is a significant error
 
_* ''errorReason()*_ %%%''<br>
Returns a string containing an explanation of the error.
 
Line 119 ⟶ 120:
* Perception
* 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.
 
It has several methods:
_has* ''has(attribute)_ %%%''<br>
Returns true if the action has the attibute whose name matches attribute.
 
_put* ''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.
 
_get* ''get(attribute)_ %%%''<br>
Returns a string containing the value of the attribute
This method will fail if it is called on a attribute that doesn't exist.
 
_getInt* ''getInt(attribute)_ %%%''<br>
Returns an integer containing the value of the attribute
This method will fail if it is called on a attribute that doesn't exist.
 
_remove* ''remove(attribute)_ %%%''<br>
Removes an attribute from the action or fails if it doesn't exist.
 
* ''clear()''<br>
_clear()_ %%%
Remove all the attributes from the action
 
_equals* ''equals(action)_ %%%''<br>
Return true if the action is equal to this action.
 
* ''toString()''<br>
_toString()_ %%%
Return a string representation of the action
 
* ''size()''<br>
_size()_ %%%
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.
 
It has several methods:
_has* ''has(attribute)_ %%%''<br>
Returns true if the object has the attibute whose name matches attribute.
 
_put* ''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.
 
_get* ''get(attribute)_ %%%''<br>
Returns a string containing the value of the attribute
This method will fail if it is called on a attribute that doesn't exist.
 
_getInt* ''getInt(attribute)_ %%%''<br>
Returns an integer containing the value of the attribute
This method will fail if it is called on a attribute that doesn't exist.
 
_remove* ''remove(attribute)_ %%%''<br>
Removes an attribute from the object or fails if it doesn't exist.
 
* ''clear()''<br>
_clear()_ %%%
Removes all the attributes from the object
 
_equals* ''equals(object)_ %%%''<br>
Returns true if the object is equals to this object.
 
* ''toString()''<br>
_toString()_ %%%
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.
 
_addSlot* ''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.
 
_getSlot* ''getSlot(name)_ %%%''<br>
Returns an RPSlot from the Object whose name is name.
It will fail if there is no such slot.
 
_removeSlot* ''removeSlot(name)_ %%%''<br>
Removes the slot from the object whose name is name.
It will fail if there is no such slot.
 
_hasSlot* ''hasSlot(name)_ %%%''<br>
Returns true if the object has a slot named name.
 
* ''applyAddedDifferences(added)''<br>
_applyAddedDifferences(added)_ %%%
_applyDeletedDifferences* ''applyDeletedDifferences(deleted)_ %%%''<br>
* ''removeAllHidden()''<br>
_removeAllHidden()_ %%%
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.
 
It has several methods:
* ''name''<br>
_name_ %%%
It contains the name of the Slot. It is a string.
 
_add* ''add(object)_ %%%''<br>
This method adds an object to the slot or replaces it if it exists.
 
_get* ''get(id)_ %%%''<br>
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
 
_has* ''has(id)_ %%%''<br>
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-
 
* ''clear()''<br>
_clear()_ %%%
Removes all the objects in the slot.
 
_equals* ''equals(slot)_ %%%''<br>
Return true if the slot is equals to this slot.
 
* ''toString()''<br>
_toString()_ %%%
Return a string representation of the slot
 
* ''size()''<br>
_size()_ %%%
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:
* 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 %%%<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.<br>
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.
 
* ''timestamp''<br>
_timestamp_ %%%
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
 
* ''myRPObjectChanged''<br>
_myRPObjectChanged_ %%%
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.
 
Again, you should never use this structure directly, but instead use ~PerceptionHandler
 
_*==World*_ %%%==
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 :(
 
* ''objects_ <br>
_objects_ %%%
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.
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.
 
_apply* ''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.
 
_*~ ''PerceptionListener*_ %%%''<br>
It is a listener class for handling perceptions.
Each method is called on the given event, you can execute whatever you want inside.
 
_onAdded* ''onAdded(object)_ %%%''<br>
It is called when an object is added to the world.
 
_onBeforeModifiedAdded* ''onBeforeModifiedAdded(object, previous)_ %%%''<br>
It is called when an object is modified by adding slots or attributes.
 
_onBeforeModifiedDeleted* ''onBeforeModifiedDeleted(object, previous)_ %%%''<br>
It is called when an object is modified by removing slots or attributes.
 
_onModifiedAdded* ''onModifiedAdded(object)_ %%%''<br>
It is called when an object has been modified by adding slots or attributes.
 
_onModifiedDeleted* ''onModifiedDeleted(object)_ %%%''<br>
It is called when an object has been modified by removing slots or attributes.
 
_onDeleted* ''onDeleted(object)_ %%%''<br>
It is called when an object is deleted of the world
 
_onMyRPObject* ''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
 
* ''onPerception()''<br>
_onPerception()_ %%%
It is called on each perception.
 
* ''onClear()''<br>
_onClear()_ %%%
It is called each time the whole world is emptied
 
* ''onUnsync()''<br>
_onUnsync()_ %%%
When you get out of sync this method is called
 
* ''onSync()''<br>
_onSync()_ %%%
When you recover sync with server this method is called
 
 
That's all.<br>
There is nothing more to this API, please just go to the [[pyArianneAPIExample]] for more info.