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.
 
 
 

139 lines
2.6 KiB

  1. let mobBuilder = require('../../world/mobBuilder');
  2. module.exports = {
  3. spawnRect: null,
  4. mobs: null,
  5. init: function () {
  6. let objects = this.instance.objects;
  7. let spawnRect = this.spawnRect;
  8. if (!this.mobs.push)
  9. this.mobs = [this.mobs];
  10. let usedSpots = ['-1,-1'];
  11. this.mobs.forEach(function (l) {
  12. let amount = l.amount || 1;
  13. delete l.amount;
  14. l.walkDistance = 0;
  15. for (let i = 0; i < amount; i++) {
  16. let x = -1;
  17. let y = -1;
  18. let pos = l.pos;
  19. if (pos) {
  20. if (pos instanceof Array) {
  21. x = pos[i].x;
  22. y = pos[i].y;
  23. } else {
  24. x = pos.x;
  25. y = pos.y;
  26. }
  27. if (spawnRect) {
  28. x += spawnRect.x;
  29. y += spawnRect.y;
  30. }
  31. } else {
  32. while (usedSpots.indexOf(x + ',' + y) > -1) {
  33. x = spawnRect.x + ~~(Math.random() * spawnRect.w);
  34. y = spawnRect.y + ~~(Math.random() * spawnRect.h);
  35. }
  36. usedSpots.push(x + ',' + y);
  37. }
  38. if (l.exists) {
  39. let mob = objects.objects.find(o => (o.name === l.name));
  40. mob.mob.walkDistance = 0;
  41. this.spawnAnimation(mob);
  42. mob.performMove({
  43. force: true,
  44. data: {
  45. x: x,
  46. y: y
  47. }
  48. });
  49. this.spawnAnimation(mob);
  50. this.event.objects.push(mob);
  51. } else {
  52. let mob = objects.buildObjects([{
  53. x: x,
  54. y: y,
  55. sheetName: l.sheetName || 'mobs',
  56. cell: l.cell,
  57. name: l.name,
  58. properties: l.properties
  59. }]);
  60. mobBuilder.build(mob, l);
  61. this.spawnAnimation(mob);
  62. if (l.id) {
  63. let id = l.id.split('$').join(i);
  64. mob.id = id;
  65. }
  66. this.event.objects.push(mob);
  67. if (l.dialogue) {
  68. mob.addComponent('dialogue', {
  69. config: l.dialogue.config
  70. });
  71. if (l.dialogue.auto) {
  72. mob.dialogue.trigger = objects.buildObjects([{
  73. properties: {
  74. x: mob.x - 1,
  75. y: mob.y - 1,
  76. width: 3,
  77. height: 3,
  78. cpnNotice: {
  79. actions: {
  80. enter: {
  81. cpn: 'dialogue',
  82. method: 'talk',
  83. args: [{
  84. targetName: 'angler nayla'
  85. }]
  86. },
  87. exit: {
  88. cpn: 'dialogue',
  89. method: 'stopTalk'
  90. }
  91. }
  92. }
  93. }
  94. }]);
  95. }
  96. }
  97. if (l.trade)
  98. mob.addComponent('trade', l.trade);
  99. if (l.chats)
  100. mob.addComponent('chatter', l.chats);
  101. }
  102. }
  103. }, this);
  104. if (!this.endMark)
  105. this.end = true;
  106. },
  107. spawnAnimation: function (mob) {
  108. this.instance.syncer.queue('onGetObject', {
  109. x: mob.x,
  110. y: mob.y,
  111. components: [{
  112. type: 'attackAnimation',
  113. row: 0,
  114. col: 4
  115. }]
  116. }, -1);
  117. }
  118. };