-
Notifications
You must be signed in to change notification settings - Fork 219
(This is a stub) All the entities present in the "world" are identified, how do these work ?
Everything that is not part of the map itself is an entity (player, chest, item, npc, mob). They all extend the two Entity classes (client / server). Even the sprites indicating the damage of a weapon stroke have ids.
Tiles also have ids but they are probably not to be mistaken with entity ids, they are described here.
There does not seem to be a centralized entity table that would lease entity IDs. There is therefore a different format for different type of IDs. To be more convenient, the ID is passed to the constructor of the entity as a string and is parsed into an integer by the constructor.
We'll sort the items depending whether their ID is set on the server or client side:
- The websocket connections have an ID, which is then used for the players. It is assigned in
server/js/ws.js
and takes the following value:'5' + Utils.random(99) + '' + (this._counter++)
. This ID is then used as the ID of the player who's connected. The_counter
counts the incoming connections. - Player: the ID of the connection it depends on: [
'5' + Utils.random(99) + '' + (this._counter++)
] (see above) (cf.this._super(this.connection.id, "player", Types.Entities.WARRIOR, 0, 0, "");
). - MobAreas: their ID is pretty much decided in tools/maps/processmap.js depending on the order in which they appear in the .tmx file.
- Mobs:
- Mobs from a MobArea:
'1' + MobArea.id + '' + MobKind + '' + MobCount
. TheMobArea
ID is explained above, theMobKind
is the constant from shared/js/gametypes.js and the mob count is incremented each time a mob is spawned in the area. - "Stand-alone" mobs:
'7' + kind + count++
, the count being the number of static entities already spawned.
- Mobs from a MobArea:
- DamageInfo:
time+""+Math.abs(value)+""+x+""+y
- Player: See server… (The ID is retrieved from the server using
GameClient.welcome_callback
, which is defined ingame.js
).