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.
 
 
 

130 lines
2.3 KiB

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