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.
 
 
 

191 lines
3.2 KiB

  1. let cpnPumpkinChunk = {
  2. type: 'pumpkinChunk',
  3. caster: null,
  4. isRotten: false,
  5. ttl: 250,
  6. update: function () {
  7. this.ttl--;
  8. if (this.ttl === 0)
  9. this.obj.destroyed = true;
  10. },
  11. collisionEnter: function (o) {
  12. if (!o.player)
  13. return;
  14. this.obj.destroyed = true;
  15. if (this.isRotten) {
  16. let drainCounts = this.caster.spellbook.spells.find(s => (s.type === 'scatterPumpkinPieces')).drainCounts;
  17. if (drainCounts[o.name])
  18. drainCounts[o.name] += 2;
  19. else
  20. drainCounts[o.name] = 1;
  21. o.effects.addEffect({
  22. type: 'lifeDrain',
  23. ttl: 10,
  24. amount: drainCounts[o.name],
  25. caster: this.caster
  26. });
  27. } else {
  28. o.effects.addEffect({
  29. type: 'frenzy',
  30. ttl: 40,
  31. newCd: 2
  32. });
  33. }
  34. }
  35. };
  36. module.exports = {
  37. type: 'scatterPumpkinPieces',
  38. cdMax: 20,
  39. manaCost: 0,
  40. spread: 5,
  41. range: 10,
  42. speed: 250,
  43. drainCounts: {},
  44. cast: function (action) {
  45. return this.shootChunk(action);
  46. },
  47. shootChunk: function (action) {
  48. let obj = this.obj;
  49. let physics = obj.instance.physics;
  50. let spread = this.spread;
  51. let toX = obj.x + ~~(Math.random() * spread * 2) - spread;
  52. let toY = obj.y + ~~(Math.random() * spread * 2) - spread;
  53. let target = physics.getClosestPos(
  54. obj.x,
  55. obj.y,
  56. toX,
  57. toY
  58. );
  59. if (!target)
  60. return false;
  61. let ttl = (Math.sqrt(Math.pow(target.x - obj.x, 2) + Math.pow(target.y - obj.y, 2)) * this.speed) - 50;
  62. let isRotten = (Math.random() < 0.3);
  63. let particles = null;
  64. if (!isRotten) {
  65. particles = {
  66. color: {
  67. start: ['ffeb38', 'db5538'],
  68. end: ['d43346', '763b3b']
  69. },
  70. scale: {
  71. start: {
  72. min: 4,
  73. max: 8
  74. },
  75. end: {
  76. min: 0,
  77. max: 4
  78. }
  79. },
  80. lifetime: {
  81. min: 2,
  82. max: 4
  83. },
  84. alpha: {
  85. start: 0.7,
  86. end: 0
  87. },
  88. randomScale: true,
  89. randomColor: true,
  90. chance: 0.6
  91. };
  92. } else {
  93. particles = {
  94. color: {
  95. start: ['fc66f7', 'a24eff'],
  96. end: ['533399', '393268']
  97. },
  98. scale: {
  99. start: {
  100. min: 4,
  101. max: 8
  102. },
  103. end: {
  104. min: 0,
  105. max: 4
  106. }
  107. },
  108. lifetime: {
  109. min: 2,
  110. max: 4
  111. },
  112. alpha: {
  113. start: 0.7,
  114. end: 0
  115. },
  116. randomScale: true,
  117. randomColor: true,
  118. chance: 0.6
  119. };
  120. }
  121. let projectileConfig = {
  122. caster: this.obj.id,
  123. components: [{
  124. idSource: this.obj.id,
  125. target: target,
  126. type: 'projectile',
  127. ttl: ttl,
  128. projectileOffset: null,
  129. particles: particles
  130. }]
  131. };
  132. this.sendAnimation(projectileConfig);
  133. this.queueCallback(this.createChunk.bind(this, isRotten, target, particles), ttl, null, target);
  134. return true;
  135. },
  136. createChunk: function (isRotten, pos, particles) {
  137. let cell = isRotten ? 73 : 72;
  138. particles.chance = 0.1;
  139. let obj = this.obj.instance.objects.buildObjects([{
  140. sheetName: `${this.folderName}/images/mobs.png`,
  141. cell: cell,
  142. x: pos.x,
  143. y: pos.y,
  144. properties: {
  145. cpnPumpkinChunk: cpnPumpkinChunk,
  146. cpnParticles: {
  147. simplify: function () {
  148. return {
  149. type: 'particles',
  150. blueprint: this.blueprint
  151. };
  152. },
  153. blueprint: particles
  154. }
  155. },
  156. extraProperties: {
  157. pumpkinChunk: {
  158. caster: this.obj,
  159. isRotten: isRotten
  160. }
  161. }
  162. }]);
  163. }
  164. };