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.
 
 
 

141 lines
2.8 KiB

  1. module.exports = {
  2. type: 'fireblast',
  3. targetGround: true,
  4. radius: 2,
  5. pushback: 4,
  6. cast: function (action) {
  7. let obj = this.obj;
  8. let radius = this.radius;
  9. let x = obj.x;
  10. let y = obj.y;
  11. let physics = obj.instance.physics;
  12. let syncer = obj.instance.syncer;
  13. for (let i = x - radius; i <= x + radius; i++) {
  14. for (let j = y - radius; j <= y + radius; j++) {
  15. if (!physics.hasLos(~~x, ~~y, ~~i, ~~j))
  16. continue;
  17. let effect = {
  18. x: i,
  19. y: j,
  20. components: [{
  21. type: 'particles',
  22. ttl: 10,
  23. blueprint: this.particles
  24. }]
  25. };
  26. if ((i !== x) || (j !== y))
  27. syncer.queue('onGetObject', effect, -1);
  28. let mobs = physics.getCell(i, j);
  29. let mLen = mobs.length;
  30. for (let k = 0; k < mLen; k++) {
  31. let m = mobs[k];
  32. //Maybe we killed something?
  33. if (!m) {
  34. mLen--;
  35. continue;
  36. }
  37. if ((!m.aggro) || (!m.effects))
  38. continue;
  39. if (!this.obj.aggro.canAttack(m))
  40. continue;
  41. let targetEffect = m.effects.addEffect({
  42. type: 'stunned',
  43. noMsg: true
  44. });
  45. let targetPos = {
  46. x: m.x,
  47. y: m.y
  48. };
  49. //Find out where the mob should end up
  50. let dx = m.x - obj.x;
  51. let dy = m.y - obj.y;
  52. while ((dx === 0) && (dy === 0)) {
  53. dx = ~~(Math.random() * 2) - 1;
  54. dy = ~~(Math.random() * 2) - 1;
  55. }
  56. dx = ~~(dx / Math.abs(dx));
  57. dy = ~~(dy / Math.abs(dy));
  58. for (let l = 0; l < this.pushback; l++) {
  59. if (physics.isTileBlocking(targetPos.x + dx, targetPos.y + dy)) {
  60. if (physics.isTileBlocking(targetPos.x + dx, targetPos.y)) {
  61. if (physics.isTileBlocking(targetPos.x, targetPos.y + dy))
  62. break;
  63. else {
  64. dx = 0;
  65. targetPos.y += dy;
  66. }
  67. } else {
  68. dy = 0;
  69. targetPos.x += dx;
  70. }
  71. } else {
  72. targetPos.x += dx;
  73. targetPos.y += dy;
  74. }
  75. }
  76. let distance = Math.max(Math.abs(m.x - targetPos.x), Math.abs(m.y - targetPos.y));
  77. let ttl = distance * 125;
  78. m.clearQueue();
  79. this.sendAnimation({
  80. id: m.id,
  81. components: [{
  82. type: 'moveAnimation',
  83. targetX: targetPos.x,
  84. targetY: targetPos.y,
  85. ttl: ttl
  86. }]
  87. });
  88. let damage = this.getDamage(m);
  89. m.stats.takeDamage(damage, 1, obj);
  90. physics.removeObject(m, m.x, m.y);
  91. this.queueCallback(this.endEffect.bind(this, m, targetPos, targetEffect), ttl);
  92. }
  93. }
  94. }
  95. this.sendBump({
  96. x: x,
  97. y: y - 1
  98. });
  99. return true;
  100. },
  101. endEffect: function (target, targetPos, targetEffect) {
  102. target.effects.removeEffect(targetEffect, true);
  103. target.x = targetPos.x;
  104. target.y = targetPos.y;
  105. let syncer = target.syncer;
  106. syncer.o.x = targetPos.x;
  107. syncer.o.y = targetPos.y;
  108. target.instance.physics.addObject(target, target.x, target.y);
  109. }
  110. };