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.

46 lines
828 B

  1. define([
  2. '../../world/mobBuilder'
  3. ], function(
  4. mobBuilder
  5. ) {
  6. return {
  7. spawnRect: null,
  8. mob: null,
  9. init: function() {
  10. var objects = this.instance.objects;
  11. var spawnRect = this.spawnRect;
  12. if (!this.mob.push)
  13. this.mob = [ this.mob ];
  14. this.mob.forEach(function(l) {
  15. var amount = l.amount || 1;
  16. delete l.amount;
  17. l.walkDistance = 0;
  18. for (var i = 0; i < amount; i++) {
  19. var x = spawnRect.x + ~~(Math.random() * spawnRect.w);
  20. var y = spawnRect.y + ~~(Math.random() * spawnRect.h);
  21. var mob = objects.buildObjects([{
  22. x: x,
  23. y: y,
  24. sheetName: 'mobs',
  25. cell: l.cell,
  26. name: l.name
  27. }]);
  28. mobBuilder.build(mob, l);
  29. if (l.id) {
  30. var id = l.id.split('$').join(i);
  31. mob.id = id;
  32. }
  33. }
  34. });
  35. this.end = true;
  36. }
  37. };
  38. });