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.
 
 
 

129 lines
2.5 KiB

  1. module.exports = {
  2. type: 'charge',
  3. cdMax: 20,
  4. manaCost: 10,
  5. range: 9,
  6. damage: 5,
  7. speed: 70,
  8. stunDuration: 15,
  9. needLos: true,
  10. cast: function (action) {
  11. let obj = this.obj;
  12. let target = action.target;
  13. let x = obj.x;
  14. let y = obj.y;
  15. let dx = target.x - x;
  16. let dy = target.y - y;
  17. //We need to stop just short of the target
  18. let offsetX = 0;
  19. if (dx !== 0)
  20. offsetX = dx / Math.abs(dx);
  21. let offsetY = 0;
  22. if (dy !== 0)
  23. offsetY = dy / Math.abs(dy);
  24. let targetPos = {
  25. x: target.x,
  26. y: target.y
  27. };
  28. let physics = obj.instance.physics;
  29. //Check where we should land
  30. if (!this.isTileValid(physics, x, y, targetPos.x - offsetX, targetPos.y - offsetY)) {
  31. if (!this.isTileValid(physics, x, y, targetPos.x - offsetX, targetPos.y))
  32. targetPos.y -= offsetY;
  33. else
  34. targetPos.x -= offsetX;
  35. } else {
  36. targetPos.x -= offsetX;
  37. targetPos.y -= offsetY;
  38. }
  39. let distance = Math.sqrt(Math.pow(dx, 2) + Math.pow(dy, 2));
  40. let ttl = distance * this.speed;
  41. let targetEffect = target.effects.addEffect({
  42. type: 'stunned'
  43. });
  44. if (targetEffect) {
  45. this.obj.instance.syncer.queue('onGetDamage', {
  46. id: target.id,
  47. event: true,
  48. text: 'stunned'
  49. }, -1);
  50. }
  51. let selfEffect = this.obj.effects.addEffect({
  52. type: 'stunned',
  53. noMsg: true
  54. });
  55. this.sendAnimation({
  56. id: this.obj.id,
  57. components: [{
  58. type: 'moveAnimation',
  59. idTarget: target.id,
  60. targetX: targetPos.x,
  61. targetY: targetPos.y,
  62. ttl: ttl
  63. }]
  64. });
  65. if (this.animation) {
  66. this.obj.instance.syncer.queue('onGetObject', {
  67. id: this.obj.id,
  68. components: [{
  69. type: 'animation',
  70. template: this.animation
  71. }]
  72. }, -1);
  73. }
  74. physics.removeObject(obj, obj.x, obj.y);
  75. this.queueCallback(this.reachDestination.bind(this, target, targetPos, targetEffect, selfEffect), ttl - 50);
  76. return true;
  77. },
  78. reachDestination: function (target, targetPos, targetEffect, selfEffect) {
  79. if (this.obj.destroyed)
  80. return;
  81. let obj = this.obj;
  82. obj.x = targetPos.x;
  83. obj.y = targetPos.y;
  84. let syncer = obj.syncer;
  85. syncer.o.x = targetPos.x;
  86. syncer.o.y = targetPos.y;
  87. obj.instance.physics.addObject(obj, obj.x, obj.y);
  88. obj.effects.removeEffect(selfEffect, true);
  89. this.obj.aggro.move();
  90. if (targetEffect)
  91. targetEffect.ttl = this.stunDuration;
  92. let damage = this.getDamage(target);
  93. target.stats.takeDamage(damage, this.threatMult, obj);
  94. },
  95. isTileValid: function (physics, fromX, fromY, toX, toY) {
  96. if (physics.isTileBlocking(toX, toY))
  97. return false;
  98. return physics.hasLos(fromX, fromY, toX, toY);
  99. }
  100. };