Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 
 

105 rindas
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. this.event.objects.push(mob);
  55. } else {
  56. var mob = objects.buildObjects([{
  57. x: x,
  58. y: y,
  59. sheetName: 'mobs',
  60. cell: l.cell,
  61. name: l.name
  62. }]);
  63. mobBuilder.build(mob, l);
  64. this.spawnAnimation(mob);
  65. //TESTCODE
  66. mob.stats.values.hp = 0.1;
  67. mob.stats.values.hpMax = 0.1;
  68. if (l.id) {
  69. var id = l.id.split('$').join(i);
  70. mob.id = id;
  71. }
  72. this.event.objects.push(mob);
  73. }
  74. }
  75. }, this);
  76. this.end = true;
  77. },
  78. spawnAnimation: function(mob) {
  79. this.instance.syncer.queue('onGetObject', {
  80. x: mob.x,
  81. y: mob.y,
  82. components: [{
  83. type: 'attackAnimation',
  84. row: 0,
  85. col: 4
  86. }]
  87. });
  88. }
  89. };
  90. });