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.
 
 
 

187 lines
3.4 KiB

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