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.
 
 
 

51 lines
932 B

  1. module.exports = {
  2. mobs: null,
  3. init: function () {
  4. if (!this.mobs.push)
  5. this.mobs = [ this.mobs ];
  6. let mobs = this.mobs;
  7. let objects = this.instance.objects.objects;
  8. let oLen = objects.length;
  9. for (let i = 0; i < oLen; i++) {
  10. let o = objects[i];
  11. let index = mobs.indexOf(o.id);
  12. if (index === -1)
  13. continue;
  14. mobs.splice(index, 1, o);
  15. }
  16. },
  17. update: function () {
  18. let players = this.instance.objects.objects.filter(function (o) {
  19. return o.player;
  20. });
  21. let pLen = players.length;
  22. let distance = this.distance;
  23. let mobs = this.mobs;
  24. let mLen = mobs.length;
  25. for (let i = 0; i < mLen; i++) {
  26. let m = mobs[i];
  27. for (let j = 0; j < pLen; j++) {
  28. let p = players[j];
  29. if ((Math.abs(p.x - m.x) <= distance) && (Math.abs(p.y - m.y) <= distance)) {
  30. mobs.splice(i, 1);
  31. mLen--;
  32. i--;
  33. break;
  34. }
  35. }
  36. }
  37. if (mobs.length === 0)
  38. this.end = true;
  39. }
  40. };