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.
 
 
 

98 lines
1.9 KiB

  1. const coordinateDeltas = [
  2. [[0, -1], [1, -1], [1, 0], [1, 1], [0, 1], [-1, 1], [-1, 0], [-1, -1]],
  3. [[0, -2], [0, -1], [1, -2], [2, -2], [1, -1], [2, -1], [2, 0], [1, 0], [2, 1], [2, 2], [1, 1], [1, 2], [0, 2], [0, 1], [-1, 2], [-2, 2], [-2, 1], [-1, 1], [-2, 0], [-1, 0], [-2, -1], [-2, -2], [-1, -1], [-1, -2]]
  4. ];
  5. const applyDamage = (target, damage, threatMult, source) => {
  6. target.stats.takeDamage({
  7. damage,
  8. threatMult,
  9. source,
  10. target,
  11. spellName: 'whirlwind'
  12. });
  13. };
  14. const dealDamage = (spell, obj, coords) => {
  15. const { delay } = spell;
  16. const physics = obj.instance.physics;
  17. coords.forEach(([x, y], i) => {
  18. const cellDelay = i * delay;
  19. const mobs = physics.getCell(x, y);
  20. let mLen = mobs.length;
  21. for (let k = 0; k < mLen; k++) {
  22. const m = mobs[k];
  23. if (!m) {
  24. mLen--;
  25. continue;
  26. }
  27. if (!m.aggro || !m.effects || !obj.aggro.canAttack(m))
  28. continue;
  29. const damage = spell.getDamage(m);
  30. spell.queueCallback(applyDamage.bind(null, m, damage, 1, obj), cellDelay);
  31. }
  32. });
  33. };
  34. module.exports = {
  35. type: 'whirlwind',
  36. cdMax: 5,
  37. manaCost: 10,
  38. range: 1,
  39. //The delay is sent to the client and is how long (in ms) each tick takes to display
  40. delay: 32,
  41. row: 5,
  42. col: 0,
  43. frames: 3,
  44. spriteSheet: 'attacks',
  45. damage: 1,
  46. isAttack: true,
  47. targetGround: true,
  48. targetPlayerPos: true,
  49. cast: function (action) {
  50. const { frames, row, col, delay, obj, spriteSheet } = this;
  51. const { id, instance, x: playerX, y: playerY } = obj;
  52. const coordinates = coordinateDeltas[this.range - 1].map(([x, y]) => [x + playerX, y + playerY]);
  53. const blueprint = {
  54. caster: id,
  55. components: [{
  56. idSource: id,
  57. type: 'whirlwind',
  58. coordinates,
  59. frames,
  60. row,
  61. col,
  62. delay,
  63. spriteSheet
  64. }]
  65. };
  66. this.sendBump({
  67. x: playerX,
  68. y: playerY - 1
  69. });
  70. obj.fireEvent('beforeSpawnWhirlwind', blueprint);
  71. instance.syncer.queue('onGetObject', blueprint, -1);
  72. dealDamage(this, obj, coordinates);
  73. return true;
  74. }
  75. };