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.
 
 
 

125 lines
2.3 KiB

  1. let mobBuilder = require('../../world/mobBuilder');
  2. module.exports = {
  3. type: 'summonConsumableFollower',
  4. targetGround: true,
  5. cdMax: 30,
  6. manaCost: 0,
  7. range: 8,
  8. needLos: true,
  9. minions: [],
  10. walkCd: 0,
  11. walkCdMax: 5,
  12. explodes: false,
  13. cast: function (action) {
  14. let obj = this.obj;
  15. let target = {
  16. x: 0,
  17. y: 0
  18. };
  19. let angle = Math.random() * Math.PI * 2;
  20. target.x = obj.x + ~~(Math.cos(angle) * this.range);
  21. target.y = obj.y + ~~(Math.sin(angle) * this.range);
  22. target = obj.instance.physics.getClosestPos(target.x, target.y, target.x, target.y);
  23. if (!target)
  24. return false;
  25. obj.syncer.set(false, 'chatter', 'msg', '*tummy grumbles*');
  26. //Spawn a mob
  27. let mob = obj.instance.spawners.spawn({
  28. amountLeft: 1,
  29. blueprint: {
  30. x: target.x,
  31. y: target.y,
  32. cell: this.cell || 60,
  33. sheetName: this.sheetName || 'mobs',
  34. name: this.name || 'Slimy Offspring',
  35. properties: {
  36. },
  37. extraProperties: {
  38. }
  39. }
  40. });
  41. mobBuilder.build(mob, {
  42. level: obj.stats.values.level,
  43. faction: obj.aggro.faction,
  44. walkDistance: 2,
  45. regular: {
  46. drops: 0,
  47. hpMult: 0.5
  48. }
  49. }, 'regular');
  50. mob.aggro.getHighest = this.getFollowerAggro.bind(this, mob);
  51. mob.aggro.list.push({
  52. obj: this.obj
  53. });
  54. mob.mob.realUpdate = mob.mob.update.bind(mob.mob);
  55. this.minions.push(mob);
  56. return true;
  57. },
  58. getFollowerAggro: function (mob) {
  59. return this.obj;
  60. },
  61. update: function () {
  62. let obj = this.obj;
  63. let x = obj.x;
  64. let y = obj.y;
  65. this.walkCd--;
  66. if (this.walkCd < 0)
  67. this.walkCd = this.walkCdMax;
  68. let minions = this.minions;
  69. let mLen = minions.length;
  70. for (let i = 0; i < mLen; i++) {
  71. let m = minions[i];
  72. if (m.destroyed) {
  73. minions.splice(i, 1);
  74. i--;
  75. mLen--;
  76. } else if ((Math.abs(x - m.x) <= 1) && (Math.abs(y - m.y) <= 1)) {
  77. m.destroyed = true;
  78. obj.stats.getHp({
  79. heal: {
  80. amount: obj.stats.values.hpMax / 10
  81. },
  82. source: obj,
  83. target: obj
  84. });
  85. obj.instance.syncer.queue('onGetObject', {
  86. x: m.x,
  87. y: m.y,
  88. components: [{
  89. type: 'attackAnimation',
  90. row: 1,
  91. col: 4
  92. }]
  93. }, -1);
  94. } else
  95. m.mob.update = (this.walkCd === 0) ? m.mob.realUpdate : null;
  96. }
  97. },
  98. onAfterSimplify: function (simple) {
  99. delete simple.minions;
  100. }
  101. };