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.
 
 
 

201 lines
3.6 KiB

  1. const particlePatch = {
  2. type: 'particlePatch',
  3. ttl: 0,
  4. update: function () {
  5. this.ttl--;
  6. if (this.ttl <= 0)
  7. this.obj.destroyed = true;
  8. }
  9. };
  10. module.exports = {
  11. type: 'ambush',
  12. cdMax: 40,
  13. manaCost: 10,
  14. range: 9,
  15. damage: 1,
  16. speed: 70,
  17. isAttack: true,
  18. stunDuration: 20,
  19. needLos: true,
  20. tickParticles: {
  21. ttl: 5,
  22. blueprint: { color: {
  23. start: ['a24eff', '7a3ad3'],
  24. end: ['533399', '393268']
  25. },
  26. scale: {
  27. start: {
  28. min: 2,
  29. max: 12
  30. },
  31. end: {
  32. min: 0,
  33. max: 6
  34. }
  35. },
  36. lifetime: {
  37. min: 1,
  38. max: 2
  39. },
  40. alpha: {
  41. start: 0.8,
  42. end: 0
  43. },
  44. spawnType: 'rect',
  45. spawnRect: {
  46. x: -12,
  47. y: -12,
  48. w: 24,
  49. h: 24
  50. },
  51. randomScale: true,
  52. randomColor: true,
  53. frequency: 0.25 }
  54. },
  55. cast: function (action) {
  56. let obj = this.obj;
  57. let target = action.target;
  58. let x = obj.x;
  59. let y = obj.y;
  60. let dx = target.x - x;
  61. let dy = target.y - y;
  62. //This calculation is much like the charge one except we land on the
  63. // furthest side of the target instead of the closest. Hence, we multiply
  64. // the delta by -1
  65. let offsetX = 0;
  66. if (dx !== 0)
  67. offsetX = dx / Math.abs(dx);
  68. let offsetY = 0;
  69. if (dy !== 0)
  70. offsetY = dy / Math.abs(dy);
  71. let targetPos = {
  72. x: target.x,
  73. y: target.y
  74. };
  75. const physics = obj.instance.physics;
  76. const fnTileValid = this.isTileValid.bind(this, physics, x, y);
  77. //Check where we should land
  78. if (!fnTileValid(targetPos.x + offsetX, targetPos.y + offsetY)) {
  79. if (!fnTileValid(targetPos.x + offsetX, targetPos.y)) {
  80. if (!fnTileValid(targetPos.x, targetPos.y + offsetY)) {
  81. targetPos.x -= offsetX;
  82. targetPos.y -= offsetY;
  83. } else
  84. targetPos.y += offsetY;
  85. } else
  86. targetPos.x += offsetX;
  87. } else {
  88. targetPos.x += offsetX;
  89. targetPos.y += offsetY;
  90. }
  91. let targetEffect = target.effects.addEffect({
  92. type: 'stunned',
  93. ttl: this.stunDuration
  94. });
  95. if (targetEffect) {
  96. this.obj.instance.syncer.queue('onGetDamage', {
  97. id: target.id,
  98. event: true,
  99. text: 'stunned'
  100. }, -1);
  101. }
  102. if (this.animation) {
  103. this.obj.instance.syncer.queue('onGetObject', {
  104. id: this.obj.id,
  105. components: [{
  106. type: 'animation',
  107. template: this.animation
  108. }]
  109. }, -1);
  110. }
  111. physics.removeObject(obj, obj.x, obj.y);
  112. physics.addObject(obj, targetPos.x, targetPos.y);
  113. this.reachDestination(target, targetPos);
  114. return true;
  115. },
  116. onCastTick: function (particleFrequency) {
  117. const { obj, tickParticles } = this;
  118. const { x, y, instance: { objects } } = obj;
  119. const particleBlueprint = extend({}, tickParticles.blueprint, {
  120. frequency: particleFrequency
  121. });
  122. objects.buildObjects([{
  123. x,
  124. y,
  125. properties: {
  126. cpnParticlePatch: particlePatch,
  127. cpnParticles: {
  128. simplify: function () {
  129. return {
  130. type: 'particles',
  131. blueprint: particleBlueprint
  132. };
  133. },
  134. blueprint: this.particles
  135. }
  136. },
  137. extraProperties: {
  138. particlePatch: {
  139. ttl: tickParticles.ttl
  140. }
  141. }
  142. }]);
  143. },
  144. reachDestination: function (target, targetPos) {
  145. if (this.obj.destroyed)
  146. return;
  147. let obj = this.obj;
  148. obj.x = targetPos.x;
  149. obj.y = targetPos.y;
  150. let syncer = obj.syncer;
  151. syncer.o.x = targetPos.x;
  152. syncer.o.y = targetPos.y;
  153. this.onCastTick(0.01);
  154. this.obj.aggro.move();
  155. let damage = this.getDamage(target);
  156. target.stats.takeDamage({
  157. damage,
  158. threatMult: this.threatMult,
  159. source: this.obj,
  160. target,
  161. spellName: 'ambush'
  162. });
  163. },
  164. isTileValid: function (physics, fromX, fromY, toX, toY) {
  165. if (physics.isTileBlocking(toX, toY))
  166. return false;
  167. return physics.hasLos(fromX, fromY, toX, toY);
  168. }
  169. };