選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
 
 
 

102 行
1.9 KiB

  1. define([
  2. '../../world/mobBuilder'
  3. ], function(
  4. mobBuilder
  5. ) {
  6. return {
  7. spawnRect: null,
  8. mobs: null,
  9. init: function() {
  10. var objects = this.instance.objects;
  11. var spawnRect = this.spawnRect;
  12. if (!this.mobs.push)
  13. this.mobs = [this.mobs];
  14. var usedSpots = ['-1,-1'];
  15. this.mobs.forEach(function(l) {
  16. var amount = l.amount || 1;
  17. delete l.amount;
  18. l.walkDistance = 0;
  19. for (var i = 0; i < amount; i++) {
  20. var x = -1;
  21. var y = -1;
  22. var pos = l.pos;
  23. if (pos) {
  24. if (pos instanceof Array) {
  25. x = pos[i].x;
  26. y = pos[i].y;
  27. } else {
  28. x = pos.x;
  29. y = pos.y;
  30. }
  31. if (spawnRect) {
  32. x += spawnRect.x;
  33. y += spawnRect.y;
  34. }
  35. } else {
  36. while (usedSpots.indexOf(x + ',' + y) > -1) {
  37. x = spawnRect.x + ~~(Math.random() * spawnRect.w);
  38. y = spawnRect.y + ~~(Math.random() * spawnRect.h);
  39. }
  40. usedSpots.push(x + ',' + y);
  41. }
  42. if (l.exists) {
  43. var mob = objects.objects.find(o => (o.name == l.name));
  44. mob.mob.walkDistance = 0;
  45. this.spawnAnimation(mob);
  46. mob.performMove({
  47. force: true,
  48. data: {
  49. x: x,
  50. y: y
  51. }
  52. });
  53. this.spawnAnimation(mob);
  54. } else {
  55. var mob = objects.buildObjects([{
  56. x: x,
  57. y: y,
  58. sheetName: 'mobs',
  59. cell: l.cell,
  60. name: l.name
  61. }]);
  62. mobBuilder.build(mob, l);
  63. this.spawnAnimation(mob);
  64. //TESTCODE
  65. mob.stats.values.hp = 0.1;
  66. mob.stats.values.hpMax = 0.1;
  67. if (l.id) {
  68. var id = l.id.split('$').join(i);
  69. mob.id = id;
  70. }
  71. }
  72. }
  73. }, this);
  74. this.end = true;
  75. },
  76. spawnAnimation: function(mob) {
  77. this.instance.syncer.queue('onGetObject', {
  78. x: mob.x,
  79. y: mob.y,
  80. components: [{
  81. type: 'attackAnimation',
  82. row: 0,
  83. col: 4
  84. }]
  85. });
  86. }
  87. };
  88. });