Achievements
packets6 packets
Achievements and user variables ("stats"), as achievement.AchievementXtCommManager sends and handles them. The server keeps a number for each user variable (games played, the daily gem bonus, settings, tutorials seen) and awards achievements when one passes a threshold, so setting a variable can earn achievements, and the answer lists them.
Hearing and sending packets
What the game sends is heard on phantom.packets.client, and what the server sends on phantom.packets.server. watch hears a packet after it has gone through; on hears it first and may change or drop it; send sends one to that end. See Packets.
Overview
| Packet | Command | Way | What it is |
|---|---|---|---|
AchievementsRequest | za | game → server | The client asks for a player’s achievements. |
UserVarSet | zs | game → server | The client sets one of the player’s user variables. |
UserVarsRequest | zg | game → server | The client asks for all of the player’s user variables. |
Achievements | za | server → game | The server gives a player’s achievements. |
UserVarChanged | zs | server → game | One of the player’s user variables changed, and any achievements it earned. |
UserVars | zg | server → game | The server gives all of the player’s user variables. |
AchievementsRequest
Asks for a player's achievements (AchievementXtCommManager.requestAchievements):
%xt%o%za%<room>%<userName>%<secondsSinceLastAsked>%
secondsSinceLastAsked is -1 the first time. The client asks at most once every ten seconds per player, and only for players it holds a UserInfo for; otherwise it answers from its cache.
Fields
| Field | Type | |
|---|---|---|
userName | string | The player whose achievements to send, by username. |
secondsSinceLastAsked | number | Seconds since the client last asked for this player, or -1 the first time. |
room | number | The room the message was sent in, as the SmartFox room id; -1 when it names none. |
Example
// Each time the game sends it to the server, after it has gone through.
const stop = phantom.packets.client.watch(packets.AchievementsRequest, (packet) => {
console.log(packet.userName, packet.secondsSinceLastAsked);
});UserVarSet
Sets one of the player's user variables (AchievementXtCommManager.requestSetUserVar):
%xt%o%zs%<room>%<userVarId>%<value>%<on>%
The client never sends it while clientInfo.invisMode is set, nor for an id of 0 or less. For a bit field (BIT_FIELD_USER_VARS: type 3 in zg, the settings 363 type 4), value is the bit's number and on whether to set it or clear it: the settings toggles (ItemWindowToggle) send 363, 0, 1 to turn buddy requests off (bit 0 set), the den tutorial 379, 1, 1 once an item is placed. Only the settings are ever sent with on 0; it is 1 for everything else. The client stores whatever value the server answers with, so the answer, not the request, is the variable's value: for a bit field the whole field with the bit changed.
Fields
| Field | Type | |
|---|---|---|
userVarId | number | The user variable to set, such as 363 for the settings (USER_VAR). Always above 0. |
value | number | The value to set it to; for a bit field, the number of the bit to change. |
on | boolean | For a bit field, set the bit (1) or clear it (0). 1 for every other variable. |
room | number | The room the message was sent in, as the SmartFox room id; -1 when it names none. |
Example
// Each time the game sends it to the server, after it has gone through.
const stop = phantom.packets.client.watch(packets.UserVarSet, (packet) => {
console.log(packet.userVarId, packet.value, packet.on);
});UserVarsRequest
Asks for every user variable the player has (AchievementXtCommManager.requestAllUserVars).
Fields
| Field | Type | |
|---|---|---|
room | number | The room the message was sent in, as the SmartFox room id; -1 when it names none. |
Example
// Each time the game sends it to the server, after it has gone through.
const stop = phantom.packets.client.watch(packets.UserVarsRequest, (packet) => {
console.log('achievement.user-vars-request');
});Achievements
A player's achievements (AchievementXtCommManager.getAchievementsResponse):
%xt%za%<room>%<userName>%<count>%<invId>%<defId>%...%
A count of -1 means the account is archived: the buddy card switches to its archive mode (BuddyCard.achievementListCallback).
Fields
| Field | Type | |
|---|---|---|
userName | string | The player the achievements belong to, by username. |
archived | boolean | The account is archived: the count was -1, and there are no achievements. |
achievements | AchievementEntry[] | The player's achievements, after their count. Empty for an archived account. |
room | number | The room the message was sent in, as the SmartFox room id; -1 when it names none. |
Example
// Each time the server sends it to the game, after it has gone through.
const stop = phantom.packets.server.watch(packets.Achievements, (packet) => {
console.log(packet.userName, packet.archived, packet.achievements);
});UserVarChanged
A user variable changed, with any achievements that earned (AchievementXtCommManager.setUserVarResponse):
%xt%zs%<room>%<userVarId>%<value>%<count>%<invId>%<defId>%...%
The client stores the value, applies the daily gem bonus (214) and the name badge setting (363), and shows the new achievements unless the player is in a minigame.
Fields
| Field | Type | |
|---|---|---|
userVarId | number | The user variable that changed (USER_VAR). |
value | number | Its value now, which the client stores. |
achievements | AchievementEntry[] | Achievements the change earned, after their count; empty when none. |
room | number | The room the message was sent in, as the SmartFox room id; -1 when it names none. |
Example
// Each time the server sends it to the game, after it has gone through.
const stop = phantom.packets.server.watch(packets.UserVarChanged, (packet) => {
console.log(packet.userVarId, packet.value, packet.achievements);
});UserVars
Every user variable the player has (AchievementXtCommManager.getUserVarsResponse): a count, then each variable's id, type and value.
Fields
| Field | Type | |
|---|---|---|
userVars | UserVar[] | Every user variable the player has, after their count. |
room | number | The room the message was sent in, as the SmartFox room id; -1 when it names none. |
Example
// Each time the server sends it to the game, after it has gone through.
const stop = phantom.packets.server.watch(packets.UserVars, (packet) => {
console.log(packet.userVars);
});