You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

252 rivejä
6.0 KiB

  1. define([
  2. 'world/atlas',
  3. 'config/spirits',
  4. 'config/roles',
  5. 'config/serverConfig'
  6. ], function (
  7. atlas,
  8. classes,
  9. roles,
  10. serverConfig
  11. ) {
  12. return {
  13. type: 'player',
  14. seen: [],
  15. cdSave: 1000,
  16. cdSaveMax: 1000,
  17. update: function () {
  18. if (this.cdSave > 0)
  19. this.cdSave--;
  20. else {
  21. this.cdSave = this.cdSaveMax;
  22. this.obj.auth.doSave();
  23. }
  24. },
  25. spawn: function (character, cb) {
  26. var obj = this.obj;
  27. if (character.dead)
  28. obj.dead = true;
  29. extend(true, obj, {
  30. layerName: 'mobs',
  31. cell: character.cell,
  32. sheetName: character.sheetName,
  33. skinId: character.skinId,
  34. name: character.name,
  35. class: character.class,
  36. zoneName: character.zoneName || serverConfig.defaultZone,
  37. x: character.x,
  38. y: character.y,
  39. hidden: character.dead,
  40. account: character.account,
  41. instanceId: character.instanceId
  42. });
  43. character.components = character.components || [];
  44. roles.onBeforePlayerEnterGame(obj, character);
  45. var blueprintStats = character.components.find(c => c.type == 'stats') || {};
  46. extend(true, blueprintStats, classes.stats[obj.class]);
  47. blueprintStats.values.hpMax = (blueprintStats.values.level || 1) * 32.7;
  48. if (!blueprintStats.values.hp)
  49. blueprintStats.values.hp = blueprintStats.values.hpMax;
  50. var stats = obj.addComponent('stats');
  51. for (var s in blueprintStats.values) {
  52. stats.values[s] = blueprintStats.values[s];
  53. }
  54. for (var s in blueprintStats.stats) {
  55. stats.stats[s] = blueprintStats.stats[s];
  56. }
  57. var gainStats = classes.stats[character.class].gainStats;
  58. for (var s in gainStats) {
  59. stats.values[s] += (gainStats[s] * stats.values.level);
  60. }
  61. obj.portrait = classes.portraits[character.class];
  62. obj.addComponent('spellbook');
  63. obj.addComponent('dialogue');
  64. obj.addComponent('trade', character.components.find(c => c.type == 'trade'));
  65. obj.addComponent('reputation', character.components.find(c => c.type == 'reputation'));
  66. obj.addComponent('passives', character.components.find(c => c.type == 'passives'));
  67. var social = character.components.find(c => c.type == 'social');
  68. if (social)
  69. delete social.party;
  70. obj.addComponent('social', social);
  71. obj.social.init();
  72. obj.social.party = null;
  73. obj.addComponent('aggro', {
  74. faction: 'players'
  75. });
  76. obj.addComponent('gatherer');
  77. obj.addComponent('stash', {
  78. items: character.stash
  79. });
  80. var blueprintEffects = character.components.find(c => c.type == 'effects') || {};
  81. if (blueprintEffects.effects) {
  82. //Calculate ttl of effects
  83. var time = +new Date;
  84. blueprintEffects.effects = blueprintEffects.effects.filter(function (e) {
  85. var remaining = e.expire - time;
  86. if (remaining < 0)
  87. return false;
  88. else {
  89. e.ttl = Math.max(~~(remaining / 350), 1);
  90. return true;
  91. }
  92. });
  93. }
  94. obj.addComponent('effects', blueprintEffects);
  95. var prophecies = character.components.find(c => c.type == 'prophecies');
  96. if (prophecies)
  97. obj.addComponent('prophecies', prophecies);
  98. obj.addComponent('equipment', character.components.find(c => c.type == 'equipment'));
  99. obj.addComponent('inventory', character.components.find(c => c.type == 'inventory'));
  100. obj.addComponent('quests', character.components.find(c => c.type == 'quests'));
  101. obj.addComponent('events', character.components.find(c => c.type == 'events'));
  102. obj.xp = stats.values.xp;
  103. obj.level = stats.values.level;
  104. stats.stats.logins++;
  105. atlas.addObject(this.obj, true);
  106. io.sockets.emit('events', {
  107. onGetMessages: [{
  108. messages: [{
  109. class: 'color-blueB',
  110. message: this.obj.name + ' has come online'
  111. }]
  112. }],
  113. onGetConnectedPlayer: [cons.getCharacterList()]
  114. });
  115. cb();
  116. },
  117. broadcastSelf: function () {
  118. var obj = this.obj;
  119. var self = {
  120. id: obj.id,
  121. zone: obj.zone,
  122. name: obj.name,
  123. level: obj.level,
  124. class: obj.class
  125. };
  126. io.sockets.emit('events', {
  127. onGetConnectedPlayer: [self]
  128. });
  129. },
  130. hasSeen: function (id) {
  131. return (this.seen.indexOf(id) > -1);
  132. },
  133. see: function (id) {
  134. this.seen.push(id);
  135. },
  136. unsee: function (id) {
  137. this.seen.spliceWhere(s => s == id);
  138. },
  139. die: function (source, permadeath) {
  140. this.obj.clearQueue();
  141. var physics = this.obj.instance.physics;
  142. physics.removeObject(this.obj, this.obj.x, this.obj.y);
  143. this.obj.dead = true;
  144. this.obj.aggro.die();
  145. if (!permadeath) {
  146. var level = this.obj.stats.values.level;
  147. var spawns = this.obj.spawn;
  148. var spawnPos = spawns.filter(s => (((s.maxLevel) && (s.maxLevel >= level)) || (!s.maxLevel)));
  149. if ((spawnPos.length == 0) || (!source.name))
  150. spawnPos = spawns[0];
  151. else if (source.name) {
  152. var sourceSpawnPos = spawnPos.find(s => ((s.source) && (s.source.toLowerCase() == source.name.toLowerCase())));
  153. if (sourceSpawnPos)
  154. spawnPos = sourceSpawnPos;
  155. else
  156. spawnPos = spawnPos[0];
  157. }
  158. this.obj.x = spawnPos.x;
  159. this.obj.y = spawnPos.y;
  160. this.obj.stats.die(source);
  161. process.send({
  162. method: 'object',
  163. serverId: this.obj.serverId,
  164. obj: {
  165. dead: true
  166. }
  167. });
  168. } else {
  169. process.send({
  170. method: 'object',
  171. serverId: this.obj.serverId,
  172. obj: {
  173. dead: true,
  174. permadead: true
  175. }
  176. });
  177. }
  178. this.obj.fireEvent('onAfterDeath', source);
  179. this.obj.spellbook.die();
  180. this.obj.effects.die();
  181. },
  182. respawn: function () {
  183. var syncer = this.obj.syncer;
  184. syncer.o.x = this.obj.x;
  185. syncer.o.y = this.obj.y;
  186. this.obj.aggro.move();
  187. this.obj.instance.physics.addObject(this.obj, this.obj.x, this.obj.y);
  188. },
  189. move: function (msg) {
  190. atlas.queueAction(this.obj, {
  191. action: 'move',
  192. data: msg.data
  193. });
  194. },
  195. moveList: function (msg) {
  196. atlas.queueAction(this.obj, {
  197. action: 'move',
  198. list: true,
  199. data: msg.data
  200. });
  201. },
  202. queueAction: function (msg) {
  203. atlas.queueAction(this.obj, msg.data);
  204. },
  205. performAction: function (msg) {
  206. if (msg.callback)
  207. msg.data.data.callbackId = atlas.registerCallback(msg.callback);
  208. atlas.performAction(this.obj, msg.data);
  209. }
  210. };
  211. });