Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 
 

197 righe
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. obj.addComponent('events', character.components.find(c => c.type == 'events'));
  72. var prophecies = character.components.find(c => c.type == 'prophecies');
  73. if (prophecies)
  74. obj.addComponent('prophecies', prophecies);
  75. var blueprintEffects = character.components.find(c => c.type == 'effects') || {};
  76. if (blueprintEffects.effects) {
  77. //Calculate ttl of effects
  78. var time = +new Date;
  79. blueprintEffects.effects.filter(function(e) {
  80. var remaining = e.expire - time;
  81. if (remaining < 0)
  82. return false;
  83. else {
  84. e.ttl = Math.max(~~(remaining / 350), 1);
  85. delete e.expire;
  86. return true;
  87. }
  88. });
  89. }
  90. obj.xp = stats.values.xp;
  91. obj.level = stats.values.level;
  92. atlas.addObject(obj, true);
  93. io.sockets.emit('events', {
  94. onGetMessages: [{
  95. messages: [{
  96. class: 'q3',
  97. message: obj.name + ' has come online'
  98. }]
  99. }],
  100. onGetConnectedPlayer: [cons.getCharacterList()]
  101. });
  102. },
  103. broadcastSelf: function() {
  104. var obj = this.obj;
  105. var self = {
  106. id: obj.id,
  107. zone: obj.zone,
  108. name: obj.name,
  109. level: obj.level,
  110. class: obj.class
  111. };
  112. io.sockets.emit('events', {
  113. onGetConnectedPlayer: [self]
  114. });
  115. },
  116. hasSeen: function(id) {
  117. return (this.seen.indexOf(id) > -1);
  118. },
  119. see: function(id) {
  120. this.seen.push(id);
  121. },
  122. unsee: function(id) {
  123. this.seen.spliceWhere(s => s == id);
  124. },
  125. die: function(source, permadeath) {
  126. this.obj.clearQueue();
  127. var physics = this.obj.instance.physics;
  128. physics.removeObject(this.obj, this.obj.x, this.obj.y);
  129. if (!permadeath) {
  130. this.obj.x = this.obj.spawn.x;
  131. this.obj.y = this.obj.spawn.y;
  132. var syncer = this.obj.syncer;
  133. syncer.o.x = this.obj.x;
  134. syncer.o.y = this.obj.y;
  135. physics.addObject(this.obj, this.obj.x, this.obj.y);
  136. this.obj.stats.die(source);
  137. }
  138. else
  139. this.obj.stats.dead = true;
  140. this.obj.aggro.die();
  141. this.obj.spellbook.die();
  142. this.obj.effects.die();
  143. this.obj.aggro.move();
  144. },
  145. move: function(msg) {
  146. atlas.queueAction(this.obj, {
  147. action: 'move',
  148. data: msg.data
  149. });
  150. },
  151. moveList: function(msg) {
  152. atlas.queueAction(this.obj, {
  153. action: 'move',
  154. list: true,
  155. data: msg.data
  156. });
  157. },
  158. queueAction: function(msg) {
  159. atlas.queueAction(this.obj, msg.data);
  160. },
  161. performAction: function(msg) {
  162. if (msg.callback)
  163. msg.data.data.callbackId = atlas.registerCallback(msg.callback);
  164. atlas.performAction(this.obj, msg.data);
  165. }
  166. };
  167. });