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.
 
 
 

160 lines
2.8 KiB

  1. let cpnSmokePatch = {
  2. type: 'smokePatch',
  3. contents: [],
  4. ttl: 0,
  5. applyDamage: function (o, amount) {
  6. o.stats.takeDamage(amount, 1, this.caster);
  7. },
  8. collisionEnter: function (o) {
  9. if (!o.aggro)
  10. return;
  11. if (!this.caster.aggro.canAttack(o))
  12. return;
  13. this.contents.push(o);
  14. },
  15. collisionExit: function (o) {
  16. let contents = this.contents;
  17. let cLen = contents.length;
  18. for (let i = 0; i < cLen; i++) {
  19. if (contents[i] === o) {
  20. contents.splice(i, 1);
  21. return;
  22. }
  23. }
  24. },
  25. update: function () {
  26. this.ttl--;
  27. if (this.ttl <= 0)
  28. this.obj.destroyed = true;
  29. let contents = this.contents;
  30. for (let i = 0; i < contents.length; i++) {
  31. let c = contents[i];
  32. if (c) {
  33. let damage = this.getDamage(c);
  34. this.applyDamage(c, damage);
  35. }
  36. }
  37. }
  38. };
  39. module.exports = {
  40. type: 'smokeBomb',
  41. cdMax: 20,
  42. manaCost: 0,
  43. damage: 1,
  44. duration: 10,
  45. radius: 1,
  46. targetGround: true,
  47. update: function () {
  48. let selfCast = this.selfCast;
  49. if (!selfCast)
  50. return;
  51. if ((selfCast !== true) && (Math.random() >= selfCast))
  52. return;
  53. if (this.canCast()) {
  54. this.cd = this.cdMax;
  55. this.cast();
  56. }
  57. },
  58. cast: function (action) {
  59. let obj = this.obj;
  60. let radius = this.radius;
  61. let repeat = this.repeat || 1;
  62. for (let r = 0; r < repeat; r++) {
  63. let x = obj.x;
  64. let y = obj.y;
  65. if (this.randomPos) {
  66. let range = this.range;
  67. while ((x === obj.x) && (y === obj.y)) {
  68. x = obj.x + ~~(Math.random() * range * 2) - range;
  69. y = obj.y + ~~(Math.random() * range * 2) - range;
  70. }
  71. }
  72. let objects = this.obj.instance.objects;
  73. let patches = [];
  74. let physics = this.obj.instance.physics;
  75. for (let i = x - radius; i <= x + radius; i++) {
  76. let dx = Math.abs(x - i);
  77. for (let j = y - radius; j <= y + radius; j++) {
  78. let distance = dx + Math.abs(j - y);
  79. if (distance > radius + 1)
  80. continue;
  81. if (!physics.hasLos(x, y, i, j))
  82. continue;
  83. let patch = objects.buildObjects([{
  84. x: i,
  85. y: j,
  86. properties: {
  87. cpnHealPatch: cpnSmokePatch,
  88. cpnParticles: {
  89. simplify: function () {
  90. return {
  91. type: 'particles',
  92. blueprint: this.blueprint
  93. };
  94. },
  95. blueprint: this.particles
  96. },
  97. extraProperties: {
  98. smokePatch: {
  99. caster: obj,
  100. statType: this.statType,
  101. getDamage: this.getDamage.bind(this),
  102. ttl: this.duration
  103. }
  104. }
  105. }
  106. }]);
  107. patches.push(patch);
  108. }
  109. }
  110. if (!this.castEvent) {
  111. this.sendBump({
  112. x: x,
  113. y: y - 1
  114. });
  115. }
  116. this.queueCallback(null, this.duration * 350, this.endEffect.bind(this, patches), null, true);
  117. }
  118. return true;
  119. },
  120. endEffect: function (patches) {
  121. let pLen = patches.length;
  122. for (let i = 0; i < pLen; i++)
  123. patches[i].destroyed = true;
  124. patches = null;
  125. }
  126. };