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.
 
 
 

200 lines
3.3 KiB

  1. let cpnSmokePatch = {
  2. type: 'smokePatch',
  3. contents: [],
  4. ttl: 0,
  5. applyDamage: function (target, damage) {
  6. target.stats.takeDamage({
  7. damage,
  8. threatMult: 1,
  9. source: this.caster,
  10. target: target,
  11. spellName: 'smokeBomb'
  12. });
  13. },
  14. collisionEnter: function (o) {
  15. if (!o.aggro)
  16. return;
  17. if (!this.caster.aggro.canAttack(o))
  18. return;
  19. this.contents.push(o);
  20. },
  21. collisionExit: function (o) {
  22. let contents = this.contents;
  23. let cLen = contents.length;
  24. for (let i = 0; i < cLen; i++) {
  25. if (contents[i] === o) {
  26. contents.splice(i, 1);
  27. return;
  28. }
  29. }
  30. },
  31. update: function () {
  32. this.ttl--;
  33. if (this.ttl <= 0)
  34. this.obj.destroyed = true;
  35. let contents = this.contents;
  36. for (let i = 0; i < contents.length; i++) {
  37. let c = contents[i];
  38. if (c) {
  39. let damage = this.getDamage(c);
  40. this.applyDamage(c, damage);
  41. }
  42. }
  43. }
  44. };
  45. const particles = {
  46. scale: {
  47. start: {
  48. min: 16,
  49. max: 30
  50. },
  51. end: {
  52. min: 8,
  53. max: 14
  54. }
  55. },
  56. opacity: {
  57. start: 0.02,
  58. end: 0
  59. },
  60. lifetime: {
  61. min: 1,
  62. max: 3
  63. },
  64. speed: {
  65. start: 12,
  66. end: 2
  67. },
  68. color: {
  69. start: ['fcfcfc', '80f643'],
  70. end: ['c0c3cf', '2b4b3e']
  71. },
  72. chance: 0.03,
  73. randomColor: true,
  74. randomScale: true,
  75. blendMode: 'screen'
  76. };
  77. module.exports = {
  78. type: 'smokeBomb',
  79. cdMax: 20,
  80. manaCost: 0,
  81. damage: 1,
  82. duration: 10,
  83. isAttack: true,
  84. radius: 1,
  85. targetGround: true,
  86. targetPlayerPos: true,
  87. particles: particles,
  88. update: function () {
  89. let selfCast = this.selfCast;
  90. if (!selfCast)
  91. return;
  92. if ((selfCast !== true) && (Math.random() >= selfCast))
  93. return;
  94. if (this.canCast()) {
  95. this.cd = this.cdMax;
  96. this.cast();
  97. }
  98. },
  99. cast: function (action) {
  100. let obj = this.obj;
  101. let radius = this.radius;
  102. let repeat = this.repeat || 1;
  103. const particleEvent = {
  104. source: this,
  105. particleConfig: extend({}, this.particles)
  106. };
  107. obj.fireEvent('beforeSpawnParticles', particleEvent);
  108. for (let r = 0; r < repeat; r++) {
  109. let x = obj.x;
  110. let y = obj.y;
  111. if (this.randomPos) {
  112. let range = this.range;
  113. while ((x === obj.x) && (y === obj.y)) {
  114. x = obj.x + ~~(Math.random() * range * 2) - range;
  115. y = obj.y + ~~(Math.random() * range * 2) - range;
  116. }
  117. }
  118. let objects = this.obj.instance.objects;
  119. let patches = [];
  120. let physics = this.obj.instance.physics;
  121. for (let i = x - radius; i <= x + radius; i++) {
  122. let dx = Math.abs(x - i);
  123. for (let j = y - radius; j <= y + radius; j++) {
  124. let distance = dx + Math.abs(j - y);
  125. if (distance > radius + 1)
  126. continue;
  127. if (!physics.hasLos(x, y, i, j))
  128. continue;
  129. let patch = objects.buildObjects([{
  130. x: i,
  131. y: j,
  132. properties: {
  133. cpnSmokePatch: cpnSmokePatch,
  134. cpnParticles: {
  135. simplify: function () {
  136. return {
  137. type: 'particles',
  138. blueprint: this.blueprint
  139. };
  140. },
  141. blueprint: particleEvent.particleConfig
  142. }
  143. },
  144. extraProperties: {
  145. smokePatch: {
  146. caster: obj,
  147. statType: this.statType,
  148. getDamage: this.getDamage.bind(this),
  149. ttl: this.duration
  150. }
  151. }
  152. }]);
  153. patches.push(patch);
  154. }
  155. }
  156. if (!this.castEvent) {
  157. this.sendBump({
  158. x: x,
  159. y: y - 1
  160. });
  161. }
  162. }
  163. return true;
  164. }
  165. };