Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 

181 linhas
3.3 KiB

  1. let cpnSpikePatch = {
  2. type: 'spikePatch',
  3. contents: [],
  4. applyDamage: function (o, amount) {
  5. o.stats.takeDamage(amount, 1, this.caster);
  6. },
  7. collisionEnter: function (o) {
  8. if ((o.mob) || (!o.stats))
  9. return;
  10. this.contents.push(o);
  11. },
  12. collisionExit: function (o) {
  13. let contents = this.contents;
  14. let cLen = contents.length;
  15. for (let i = 0; i < cLen; i++) {
  16. if (contents[i] === o) {
  17. contents.splice(i, 1);
  18. return;
  19. }
  20. }
  21. },
  22. update: function () {
  23. if (this.caster.destroyed)
  24. return;
  25. let contents = this.contents;
  26. let cLen = contents.length;
  27. for (let i = 0; i < cLen; i++) {
  28. let c = contents[i];
  29. let amount = this.getDamage(c);
  30. this.applyDamage(c, amount);
  31. }
  32. }
  33. };
  34. module.exports = {
  35. type: 'trailDash',
  36. intCd: 0,
  37. intCdMax: 0,
  38. casting: false,
  39. range: 10,
  40. distance: 0,
  41. castingEffect: null,
  42. dx: 0,
  43. dy: 0,
  44. targetX: 0,
  45. targetY: 0,
  46. currentX: 0,
  47. currentY: 0,
  48. duration: 6,
  49. update: function () {
  50. if (!this.casting)
  51. return;
  52. if (this.intCd > 0) {
  53. this.intCd--;
  54. return;
  55. }
  56. this.intCd = this.intCdMax;
  57. this.currentX += this.dx;
  58. this.currentY += this.dy;
  59. let x = ~~this.currentX;
  60. let y = ~~this.currentY;
  61. if (this.obj.instance.physics.isTileBlocking(x, y))
  62. this.distance = 7;
  63. else if ((x !== this.obj.x) || (y !== this.obj.y)) {
  64. //if ((x !== this.targetX) || (y !== this.targetY)) {
  65. let particles = this.particles;
  66. let spike = this.obj.instance.objects.buildObjects([{
  67. x: this.obj.x,
  68. y: this.obj.y,
  69. properties: {
  70. cpnHealPatch: cpnSpikePatch,
  71. cpnAttackAnimation: {
  72. simplify: function () {
  73. return {
  74. type: 'attackAnimation',
  75. destroyObject: true,
  76. row: [9, 9, 9, 9, 9, 9, 9, 9][~~(Math.random() * 8)],
  77. col: 4,
  78. frameDelay: 6 + ~~(Math.random() * 7),
  79. loop: -1
  80. };
  81. }
  82. },
  83. cpnParticles: {
  84. simplify: function () {
  85. return {
  86. type: 'particles',
  87. noExplosion: true,
  88. blueprint: particles
  89. };
  90. },
  91. blueprint: particles
  92. }
  93. }
  94. }]);
  95. spike.spikePatch.caster = this.obj;
  96. spike.spikePatch.damage = this.damage;
  97. this.queueCallback(null, this.spikeDuration * consts.tickTime, this.endEffect.bind(this, spike), null, true);
  98. this.obj.x = x;
  99. this.obj.y = y;
  100. let syncer = this.obj.syncer;
  101. syncer.o.x = this.obj.x;
  102. syncer.o.y = this.obj.y;
  103. this.distance++;
  104. } else {
  105. this.intCd = 0;
  106. this.update();
  107. }
  108. if (this.distance > 6) {
  109. this.casting = false;
  110. this.castingEffect.destroyed = true;
  111. return true;
  112. }
  113. return true;
  114. },
  115. endEffect: function (spike) {
  116. spike.destroyed = true;
  117. },
  118. cast: function (action) {
  119. do {
  120. this.targetX = action.target.x + ~~(Math.random() * 6) - 3;
  121. this.targetY = action.target.y + ~~(Math.random() * 6) - 3;
  122. } while (this.obj.instance.physics.isTileBlocking(this.targetX, this.targetY));
  123. this.currentX = this.obj.x;
  124. this.currentY = this.obj.y;
  125. this.dx = this.targetX - this.currentX;
  126. this.dy = this.targetY - this.currentY;
  127. let distance = Math.sqrt(Math.pow(this.dx, 2) + Math.pow(this.dy, 2));
  128. if (distance <= 0)
  129. return false;
  130. this.castingEffect = this.obj.effects.addEffect({
  131. type: 'casting',
  132. silent: true
  133. });
  134. this.casting = true;
  135. this.intCd = 0;
  136. this.distance = 0;
  137. this.dx /= distance;
  138. this.dy /= distance;
  139. return true;
  140. }
  141. };