Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 
 

170 righe
3.4 KiB

  1. const getTargetPos = (physics, obj, m, pushback) => {
  2. pushback = 0; // TEMPORARY FIX, PLEASE REVERT
  3. let targetPos = {
  4. x: m.x,
  5. y: m.y
  6. };
  7. let dx = m.x - obj.x;
  8. let dy = m.y - obj.y;
  9. while ((dx === 0) && (dy === 0)) {
  10. dx = ~~(Math.random() * 2) - 1;
  11. dy = ~~(Math.random() * 2) - 1;
  12. }
  13. dx = ~~(dx / Math.abs(dx));
  14. dy = ~~(dy / Math.abs(dy));
  15. for (let l = 0; l < pushback; l++) {
  16. if (physics.isTileBlocking(targetPos.x + dx, targetPos.y + dy)) {
  17. if (physics.isTileBlocking(targetPos.x + dx, targetPos.y)) {
  18. if (physics.isTileBlocking(targetPos.x, targetPos.y + dy))
  19. break;
  20. else {
  21. dx = 0;
  22. targetPos.y += dy;
  23. }
  24. } else {
  25. dy = 0;
  26. targetPos.x += dx;
  27. }
  28. } else {
  29. targetPos.x += dx;
  30. targetPos.y += dy;
  31. }
  32. }
  33. return targetPos;
  34. };
  35. module.exports = {
  36. type: 'fireblast',
  37. targetGround: true,
  38. targetPlayerPos: true,
  39. radius: 2,
  40. pushback: 4,
  41. damage: 1,
  42. cast: function (action) {
  43. let obj = this.obj;
  44. let { x, y, instance: { physics, syncer } } = obj;
  45. let radius = this.radius;
  46. const particleEvent = {
  47. source: this,
  48. particleConfig: extend({}, this.particles)
  49. };
  50. obj.fireEvent('beforeSpawnParticles', particleEvent);
  51. for (let i = x - radius; i <= x + radius; i++) {
  52. for (let j = y - radius; j <= y + radius; j++) {
  53. if (!physics.hasLos(~~x, ~~y, ~~i, ~~j))
  54. continue;
  55. let effect = {
  56. x: i,
  57. y: j,
  58. components: [{
  59. type: 'particles',
  60. ttl: 10,
  61. blueprint: particleEvent.particleConfig
  62. }]
  63. };
  64. if ((i !== x) || (j !== y))
  65. syncer.queue('onGetObject', effect, -1);
  66. let mobs = physics.getCell(i, j);
  67. let mLen = mobs.length;
  68. for (let k = 0; k < mLen; k++) {
  69. let m = mobs[k];
  70. //Maybe we killed something?
  71. if (!m) {
  72. mLen--;
  73. continue;
  74. } else if (!m.aggro || !m.effects)
  75. continue;
  76. else if (!obj.aggro.canAttack(m))
  77. continue;
  78. const targetPos = getTargetPos(physics, obj, m, this.pushback);
  79. let distance = Math.max(Math.abs(m.x - targetPos.x), Math.abs(m.y - targetPos.y));
  80. let ttl = distance * 125;
  81. m.clearQueue();
  82. let damage = this.getDamage(m);
  83. m.stats.takeDamage(damage, 1, obj);
  84. if (m.destroyed)
  85. continue;
  86. const eventMsg = {
  87. success: true,
  88. targetPos
  89. };
  90. m.fireEvent('beforePositionChange', eventMsg);
  91. if (!eventMsg.success)
  92. continue;
  93. const targetEffect = m.effects.addEffect({
  94. type: 'stunned',
  95. silent: true
  96. });
  97. //If targetEffect is undefined, it means that the target has become resistant
  98. if (!targetEffect)
  99. continue;
  100. this.sendAnimation({
  101. id: m.id,
  102. components: [{
  103. type: 'moveAnimation',
  104. targetX: targetPos.x,
  105. targetY: targetPos.y,
  106. ttl: ttl
  107. }]
  108. });
  109. this.queueCallback(this.endEffect.bind(this, m, targetPos, targetEffect), ttl, null, m);
  110. }
  111. }
  112. }
  113. this.sendBump({
  114. x: x,
  115. y: y - 1
  116. });
  117. return true;
  118. },
  119. endEffect: function (target, targetPos, targetEffect) {
  120. target.effects.removeEffect(targetEffect.id);
  121. target.instance.physics.removeObject(target, target.x, target.y);
  122. target.x = targetPos.x;
  123. target.y = targetPos.y;
  124. let syncer = target.syncer;
  125. syncer.o.x = targetPos.x;
  126. syncer.o.y = targetPos.y;
  127. target.instance.physics.addObject(target, target.x, target.y);
  128. const moveEvent = {
  129. newPos: targetPos,
  130. source: this
  131. };
  132. target.fireEvent('afterPositionChange', moveEvent);
  133. }
  134. };