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.
 
 
 

125 lines
2.3 KiB

  1. module.exports = {
  2. type: 'warnBlast',
  3. needLos: false,
  4. range: 100,
  5. castingEffect: null,
  6. statType: 'agi',
  7. statMult: 1,
  8. targetGround: true,
  9. needLos: true,
  10. damage: 10,
  11. delay: 10,
  12. radius: 1,
  13. cast: function (action) {
  14. let obj = this.obj;
  15. let physics = obj.instance.physics;
  16. let target = action.target;
  17. let x = target.x;
  18. let y = target.y;
  19. let radius = this.radius;
  20. let xMin = x - radius;
  21. let xMax = x + radius;
  22. let yMin = y - radius;
  23. let yMax = y + radius;
  24. let attackTemplate = this.attackTemplate;
  25. if (attackTemplate)
  26. attackTemplate = attackTemplate.split(' ');
  27. let count = -1;
  28. for (let i = xMin; i <= xMax; i++) {
  29. for (let j = yMin; j <= yMax; j++) {
  30. count++;
  31. if (!physics.hasLos(x, y, i, j))
  32. continue;
  33. else if ((attackTemplate) && (attackTemplate[count] === 'x'))
  34. continue;
  35. if ((attackTemplate) && (~~attackTemplate[count] > 0)) {
  36. this.queueCallback(this.spawnWarning.bind(this, i, j), ~~attackTemplate[count] * 350);
  37. continue;
  38. } else
  39. this.spawnWarning(i, j);
  40. }
  41. }
  42. this.sendBump(target);
  43. return true;
  44. },
  45. spawnWarning: function (x, y) {
  46. let obj = this.obj;
  47. let syncer = obj.instance.syncer;
  48. let effect = {
  49. x: x,
  50. y: y,
  51. components: [{
  52. type: 'particles',
  53. noExplosion: true,
  54. ttl: this.delay * 175 / 16,
  55. blueprint: this.particles
  56. }]
  57. };
  58. syncer.queue('onGetObject', effect, -1);
  59. this.queueCallback(this.onWarningOver.bind(this, x, y), this.delay * 350);
  60. },
  61. onWarningOver: function (x, y) {
  62. let obj = this.obj;
  63. let physics = obj.instance.physics;
  64. let syncer = obj.instance.syncer;
  65. let effect = {
  66. x: x,
  67. y: y,
  68. components: [{
  69. type: 'attackAnimation',
  70. destroyObject: true,
  71. row: [10, 10, 10, 10, 10, 10, 10, 8, 8, 8, 7, 7, 7][~~(Math.random() * 13)],
  72. col: 4,
  73. frameDelay: 4 + ~~(Math.random() * 7)
  74. }]
  75. };
  76. syncer.queue('onGetObject', effect, -1);
  77. let mobs = physics.getCell(x, y);
  78. let mLen = mobs.length;
  79. for (let k = 0; k < mLen; k++) {
  80. let m = mobs[k];
  81. //Maybe we killed something?
  82. if (!m) {
  83. mLen--;
  84. continue;
  85. } else if (!m.aggro)
  86. continue;
  87. else if (!this.obj.aggro.canAttack(m))
  88. continue;
  89. let damage = this.getDamage(m);
  90. m.stats.takeDamage(damage, 1, obj);
  91. }
  92. }
  93. };