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.
 
 
 

124 lines
2.3 KiB

  1. let cpnArcanePatch = {
  2. type: 'arcanePatch',
  3. contents: [],
  4. init: function (blueprint) {
  5. for (let p in blueprint)
  6. this[p] = blueprint[p];
  7. },
  8. collisionEnter: function (o) {
  9. if ((!o.aggro) || (!o.player))
  10. return;
  11. let isPlayer = !!this.caster.player;
  12. let isTargetPlayer = !!o.player;
  13. if ((this.caster.aggro.canAttack(o)) || (isPlayer !== isTargetPlayer))
  14. return;
  15. this.contents.push(o);
  16. },
  17. collisionExit: function (o) {
  18. let contents = this.contents;
  19. let cLen = contents.length;
  20. for (let i = 0; i < cLen; i++) {
  21. if (contents[i] === o) {
  22. contents.splice(i, 1);
  23. return;
  24. }
  25. }
  26. },
  27. update: function () {
  28. let stats = this.caster.stats;
  29. let contents = this.contents;
  30. let cLen = contents.length;
  31. for (let i = 0; i < cLen; i++) {
  32. let c = contents[i];
  33. let amount = this.spell.getDamage(c, true);
  34. c.stats.getHp(amount, this.caster);
  35. }
  36. }
  37. };
  38. module.exports = {
  39. type: 'arcaneBarrier',
  40. cdMax: 20,
  41. manaCost: 0,
  42. range: 9,
  43. duration: 70,
  44. targetGround: true,
  45. cast: function (action) {
  46. let obj = this.obj;
  47. let target = action.target;
  48. let radius = this.radius;
  49. let x = target.x;
  50. let y = target.y;
  51. let objects = this.obj.instance.objects;
  52. let patches = [];
  53. let physics = this.obj.instance.physics;
  54. for (let i = x - radius; i <= x + radius; i++) {
  55. let dx = Math.abs(x - i);
  56. for (let j = y - radius; j <= y + radius; j++) {
  57. let distance = dx + Math.abs(j - y);
  58. if (distance > radius + 1)
  59. continue;
  60. if (!physics.hasLos(x, y, i, j))
  61. continue;
  62. let patch = objects.buildObjects([{
  63. x: i,
  64. y: j,
  65. properties: {
  66. cpnArcanePatch: cpnArcanePatch,
  67. cpnParticles: {
  68. simplify: function () {
  69. return {
  70. type: 'particles',
  71. blueprint: this.blueprint
  72. };
  73. },
  74. blueprint: this.particles
  75. }
  76. },
  77. extraProperties: {
  78. arcanePatch: {
  79. caster: this.obj,
  80. spell: this
  81. }
  82. }
  83. }]);
  84. patches.push(patch);
  85. }
  86. }
  87. this.sendBump(target);
  88. this.queueCallback(null, this.duration * 350, this.endEffect.bind(this, patches), null, true);
  89. return true;
  90. },
  91. endEffect: function (patches) {
  92. let pLen = patches.length;
  93. for (let i = 0; i < pLen; i++)
  94. patches[i].destroyed = true;
  95. }
  96. };