-
Notifications
You must be signed in to change notification settings - Fork 71
Game Objects
The avatar is an interface between the worker and the managers in the simulation. It also provides a nice abstraction for what the simulation perceives as a 'user'. The avatar related functionality is grouped inside the avatar folder.
The avatar functionality is separated in several classes:
- avatar wrapper - the central avatar functionality, including the communication with the worker and the simulation properties such as health, score and so on
- avatar view - a personalized view of the worlds for each avatar
- avatar appearance - fields used only by the Raphael JS client
- the avatar manager - a structure that keeps a list of avatars. It is used by the Turn Manager to update the environment
- fog of war
The avatar wrapper represents the application's view of a character, together with an API that communicates to the worker via HTTP GETs.
The main functionality is:
- decide action - fetches an action from the worker and updates the current action to be executed
- clear action
- update effects - apply effects that come from getting a pickup
- add event - attaches an event to the event setting -- not yet used
Deciding an action is done by making a GET request to the Game API and processing the received JSON. If an error occurs during the process, a wait action is emitted.
There is also some functionality not fully used/implemented:
- die - dies and respawns at new location
- damage - take damage
An action is a pair (avatar, location). The action is register onto the WorldMap by being appended to a cell.
The action is processed by calling the apply function.
- if the action is legal it is applied
- if not it is rejected
The exposed interface is:
- apply
- has to return true if application succeeded
- attaches an event to the avatar
- is_legal
- returns if an action is legal from the point of view of the map
- the action gets applied or rejected accordingly
- reject
- attaches a (failed) event to the avatar The general processing of an actions is done by applying the action if it is legal and rejecting it if is not.
Each of the 3 elements of the interface are implemented differently by different types of actions.
The current types of actions as:
- WaitAction
- wait is always legal
- no actions get attached to the avatar
- MoveAction
- is_legal
- the responsibility is passed to world_map
- apply
- adds a move event to the avatar
- change the avatar's world view
- updates the map accordingly
- reject
- the failed event is added to the avatar
- overrides the processing of the action
- the action is chained in the action list of a cell
- see World Map and Turn Manager for details
- is_legal