您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 

129 行
2.2 KiB

  1. /* eslint-disable max-lines-per-function */
  2. define([
  3. 'js/rendering/renderer',
  4. 'js/system/events',
  5. 'js/system/client'
  6. ], function (
  7. renderer,
  8. events,
  9. client
  10. ) {
  11. let round = Math.round.bind(Math);
  12. let maxPathLength = 50;
  13. return {
  14. type: 'pather',
  15. path: [],
  16. pathColor: '0x48edff',
  17. pathAlpha: 0.2,
  18. pathPos: {
  19. x: 0,
  20. y: 0
  21. },
  22. lastX: 0,
  23. lastY: 0,
  24. init: function () {
  25. events.on('teleportToPosition', this.resetPath.bind(this));
  26. events.on('onDeath', this.resetPath.bind(this));
  27. events.on('onClearQueue', this.resetPath.bind(this));
  28. this.pathPos.x = round(this.obj.x);
  29. this.pathPos.y = round(this.obj.y);
  30. },
  31. clearPath: function () {
  32. this.path.forEach(function (p) {
  33. renderer.destroyObject({
  34. layerName: 'effects',
  35. sprite: p.sprite
  36. });
  37. });
  38. this.path = [];
  39. },
  40. resetPath: function () {
  41. this.clearPath();
  42. this.pathPos.x = round(this.obj.x);
  43. this.pathPos.y = round(this.obj.y);
  44. },
  45. add: function (x, y) {
  46. if (this.path.length >= maxPathLength || this.obj.moveAnimation)
  47. return;
  48. this.pathPos.x = x;
  49. this.pathPos.y = y;
  50. this.path.push({
  51. x: x,
  52. y: y,
  53. sprite: renderer.buildRectangle({
  54. layerName: 'effects',
  55. color: this.pathColor,
  56. alpha: this.pathAlpha,
  57. x: (x * scale) + scaleMult,
  58. y: (y * scale) + scaleMult,
  59. w: scale - (scaleMult * 2),
  60. h: scale - (scaleMult * 2)
  61. })
  62. });
  63. client.request({
  64. cpn: 'player',
  65. method: 'move',
  66. data: {
  67. x: x,
  68. y: y,
  69. priority: !this.path.length
  70. }
  71. });
  72. },
  73. update: function () {
  74. if (this.obj.moveAnimation)
  75. this.clearPath();
  76. let x = this.obj.x;
  77. let y = this.obj.y;
  78. if (this.path.length === 0) {
  79. this.pathPos.x = round(x);
  80. this.pathPos.y = round(y);
  81. }
  82. if ((x === this.lastX) && (y === this.lastY))
  83. return;
  84. this.lastX = x;
  85. this.lastY = y;
  86. for (let i = 0; i < this.path.length; i++) {
  87. let p = this.path[i];
  88. if ((p.x === x) && (p.y === y)) {
  89. for (let j = 0; j <= i; j++) {
  90. renderer.destroyObject({
  91. layerName: 'effects',
  92. sprite: this.path[j].sprite
  93. });
  94. }
  95. this.path.splice(0, i + 1);
  96. return;
  97. }
  98. }
  99. },
  100. destroy: function () {
  101. this.unhookEvents();
  102. }
  103. };
  104. });