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.
 
 
 

162 lines
2.9 KiB

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