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.
 
 
 

137 lines
2.5 KiB

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