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.
 
 
 

196 lines
4.7 KiB

  1. define([
  2. 'world/atlas',
  3. 'config/classes',
  4. 'config/roles'
  5. ], function(
  6. atlas,
  7. classes,
  8. roles
  9. ) {
  10. return {
  11. type: 'player',
  12. seen: [],
  13. cdSave: 1000,
  14. cdSaveMax: 1000,
  15. update: function() {
  16. if (this.cdSave > 0)
  17. this.cdSave--;
  18. else {
  19. this.cdSave = this.cdSaveMax;
  20. this.obj.auth.doSave();
  21. }
  22. },
  23. spawn: function(character) {
  24. var obj = this.obj;
  25. extend(true, obj, {
  26. sheetName: classes.getSpritesheet(character.class),
  27. layerName: 'mobs',
  28. cell: character.cell,
  29. previewSpritesheet: character.previewSpritesheet,
  30. name: character.name,
  31. class: character.class,
  32. zoneName: character.zoneName || 'tutorial-cove',
  33. x: character.x,
  34. y: character.y,
  35. account: character.account,
  36. instanceId: character.instanceId
  37. });
  38. character.components = character.components || [];
  39. roles.onBeforePlayerEnterGame(obj, character);
  40. var blueprintStats = character.components.find(c => c.type == 'stats') || {};
  41. extend(true, blueprintStats, classes.stats[obj.class]);
  42. blueprintStats.values.hpMax = 10 + ((blueprintStats.values.level || 1) * 40);
  43. if (!blueprintStats.values.hp)
  44. blueprintStats.values.hp = blueprintStats.values.hpMax;
  45. var stats = obj.addComponent('stats');
  46. for (var s in blueprintStats.values) {
  47. stats.values[s] = blueprintStats.values[s];
  48. }
  49. for (var s in blueprintStats.stats) {
  50. stats.stats[s] = blueprintStats.stats[s];
  51. }
  52. stats.vitScale = blueprintStats.vitScale;
  53. stats.stats.logins++;
  54. //obj.addComponent('spellbook', { spells: extend(true, [], classes.spells[obj.class]) });
  55. obj.addComponent('spellbook');
  56. obj.addComponent('dialogue');
  57. obj.addComponent('trade', character.components.find(c => c.type == 'trade'));
  58. obj.addComponent('reputation', character.components.find(c => c.type == 'reputation'));
  59. obj.addComponent('social');
  60. obj.addComponent('aggro', {
  61. faction: 1
  62. });
  63. obj.addComponent('gatherer');
  64. obj.addComponent('stash', {
  65. items: character.stash
  66. });
  67. obj.addComponent('effects', blueprintEffects);
  68. obj.addComponent('equipment', character.components.find(c => c.type == 'equipment'));
  69. obj.addComponent('inventory', character.components.find(c => c.type == 'inventory'));
  70. obj.addComponent('quests', character.components.find(c => c.type == 'quests'));
  71. var prophecies = character.components.find(c => c.type == 'prophecies');
  72. if (prophecies)
  73. obj.addComponent('prophecies', prophecies);
  74. var blueprintEffects = character.components.find(c => c.type == 'effects') || {};
  75. if (blueprintEffects.effects) {
  76. //Calculate ttl of effects
  77. var time = +new Date;
  78. blueprintEffects.effects.filter(function(e) {
  79. var remaining = e.expire - time;
  80. if (remaining < 0)
  81. return false;
  82. else {
  83. e.ttl = Math.max(~~(remaining / 350), 1);
  84. delete e.expire;
  85. return true;
  86. }
  87. });
  88. }
  89. obj.xp = stats.values.xp;
  90. obj.level = stats.values.level;
  91. atlas.addObject(obj, true);
  92. io.sockets.emit('events', {
  93. onGetMessages: [{
  94. messages: [{
  95. class: 'q3',
  96. message: obj.name + ' has come online'
  97. }]
  98. }],
  99. onGetConnectedPlayer: [cons.getCharacterList()]
  100. });
  101. },
  102. broadcastSelf: function() {
  103. var obj = this.obj;
  104. var self = {
  105. id: obj.id,
  106. zone: obj.zone,
  107. name: obj.name,
  108. level: obj.level,
  109. class: obj.class
  110. };
  111. io.sockets.emit('events', {
  112. onGetConnectedPlayer: [self]
  113. });
  114. },
  115. hasSeen: function(id) {
  116. return (this.seen.indexOf(id) > -1);
  117. },
  118. see: function(id) {
  119. this.seen.push(id);
  120. },
  121. unsee: function(id) {
  122. this.seen.spliceWhere(s => s == id);
  123. },
  124. die: function(source, permadeath) {
  125. this.obj.clearQueue();
  126. var physics = this.obj.instance.physics;
  127. physics.removeObject(this.obj, this.obj.x, this.obj.y);
  128. if (!permadeath) {
  129. this.obj.x = this.obj.spawn.x;
  130. this.obj.y = this.obj.spawn.y;
  131. var syncer = this.obj.syncer;
  132. syncer.o.x = this.obj.x;
  133. syncer.o.y = this.obj.y;
  134. physics.addObject(this.obj, this.obj.x, this.obj.y);
  135. this.obj.stats.die(source);
  136. }
  137. else
  138. this.obj.stats.dead = true;
  139. this.obj.aggro.die();
  140. this.obj.spellbook.die();
  141. this.obj.effects.die();
  142. this.obj.aggro.move();
  143. },
  144. move: function(msg) {
  145. atlas.queueAction(this.obj, {
  146. action: 'move',
  147. data: msg.data
  148. });
  149. },
  150. moveList: function(msg) {
  151. atlas.queueAction(this.obj, {
  152. action: 'move',
  153. list: true,
  154. data: msg.data
  155. });
  156. },
  157. queueAction: function(msg) {
  158. atlas.queueAction(this.obj, msg.data);
  159. },
  160. performAction: function(msg) {
  161. if (msg.callback)
  162. msg.data.data.callbackId = atlas.registerCallback(msg.callback);
  163. atlas.performAction(this.obj, msg.data);
  164. }
  165. };
  166. });