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.
 
 
 

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