Main
Game Bootstrap
Section titled “Game Bootstrap”- The game starts with the Main class, which is invoked by the preloader.
- Begin resource unpacking.
- Event listeners are registered for successful and failed unpacking events.
- Resources are unpacked and loaded asynchronously in the background.
- Once completed, a notification is dispatched indicating that resource loading is done.
Socket Server Connection Establishment
Section titled “Socket Server Connection Establishment”- Begin connection to socket server.
- This is triggered by calling the
connect()
method on the Network class, which internally invokes a privatejoinRoom()
method. joinRoom()
uses the PlayerIO Multiplayer API to request create and join room (API 27).- API server responds room data and the endpoint for the socket server.
- Client connects to the socket server from the given endpoint and port.
- Client initially send
<policy-file-request/>
and server must reply appropriately, by allowing request from any domain to the server port (with byte 0 appended after the policy file response). - Client sends the initial
"join"
message which includes the data received from API 27. - The socket server replies with a
playerio.joinresult
message:- If the join is valid, send a true boolean value.
- If the join is invalid, send false along with an error message.
- Upon success, a connected event is dispatched, indicating the socket connection is ready for communication.
- This is triggered by calling the
Initial Data Exchange & Player Data Loading
Section titled “Initial Data Exchange & Player Data Loading”- Early socket communication is focused on retrieving the player’s game state and additional data stored in the server.
onGameReady
function from Network class is expected to run.- The
"gr"
message (game ready) should be sent from the socket server:- The message contains 5 values:
- Server time in long data type.
- Binaries data in XML or gzipped XML, which are assets like
buildings.xml
,attire.xml
, etc. The game updates its loaded XML with the one sent from server. - JSON cost table data, possibly the in-game cost for items or upgrades.
- JSON survivor class table, the specific stats of a survivor class (e.g.,
baseAttributes
likehealth
,combatMelee
,movement
). - JSON login player state, allegedly updates from server (like news, sales) and other events that has occured while player is logged out.
- The message contains 5 values:
- The
onNetworkGameDataReceived
from coreMain.as
will be triggered every time the game receives XML files from server. This method updates the game’s currently loaded XML with the newly received XML. - The JSON dumps are parsed and stored in local variables in the
Network
class for later use. - Next is loading
PlayerObjects
,NeighborHistory
, andInventory
from BigDB by making request to API 85. A network error (which force disconnects the player) will be raised if the loaded objects are empty or null.
- The
- When all three objects are loaded successfully,
onPlayerDataLoaded
is called. onPlayerDataLoaded
- Create in-game
Survivor
objects using theAHBuildSrvs
method. This method internally reads the parsed survivor class table from the server, loads local assets and data, and maps them to the corresponding survivor object. - Parses
playerObject
andloginPlayerState
to initializes internal game state. - Initializes core game systems:
GlobalQuestSystem
,QuestSystem
,OfferSystem
, andAllianceSystem
. - Send the game ready signal.
- Create in-game
Game Start
Section titled “Game Start”- The
onNetworkGameReady
method in main listens for the game ready signal and calls theonReady
method next, which:- Closes the loading dialogue and removes network listeners for loading/error/start connection events.
- Opens the “create survivor” dialogue (if necessary).
- After survivor is created, or if player player has already created one before, game start signal will be dispatched and
Game.as
(as well asTutorial.as
if not finished tutorial) will enter the stage. - The most important method is loading the compound with the method
gotoCompound
ofGame.as
.
Past this, everything isn’t really sequential anymore, so we stop here. See also Game and Tutorial.