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.
 
 
 

75 lines
1.9 KiB

  1. module.exports = {
  2. need: 10,
  3. have: 0,
  4. mobType: null,
  5. type: 'killX',
  6. build: function () {
  7. //If we're not in the correct zone, don't do this check, it'll just crash the server
  8. // since the mob won't be available (most likely) in the zoneFile
  9. if (this.obj.zoneName === this.zoneName) {
  10. let mobTypes = this.obj.instance.spawners.zone.mobs;
  11. if (this.mobName) {
  12. let mobType = mobTypes[this.mobName.toLowerCase()];
  13. //Maybe the zoneFile changed in the meantime. If so, regenerate
  14. if ((!mobType) || (mobType.attackable === false))
  15. this.mobName = null;
  16. }
  17. if (!this.mobName) {
  18. let mobCounts = this.obj.instance.spawners.mobTypes;
  19. let keys = Object.keys(mobTypes).filter(function (m) {
  20. let mobBlueprint = mobTypes[m];
  21. return (
  22. (m !== 'default') &&
  23. (
  24. (mobBlueprint.attackable) ||
  25. (mobBlueprint.attackable === null)
  26. ) &&
  27. (mobBlueprint.level <= ~~(this.obj.stats.values.level * 1.35)) &&
  28. (mobCounts[m] > 1)
  29. );
  30. }, this);
  31. //No level appropriate mobs found
  32. if (keys.length === 0)
  33. return false;
  34. this.mobType = keys[~~(Math.random() * keys.length)];
  35. let needMax = 8;
  36. this.mobName = this.mobType.replace(/\w\S*/g, function (txt) {
  37. return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();
  38. });
  39. this.need = Math.max(1, ~~((needMax * 0.2) + (Math.random() * needMax * 0.8)));
  40. }
  41. }
  42. this.description = 'Kill ' + this.have + '/' + this.need + ' ' + this.mobName;
  43. return true;
  44. },
  45. getXpMultiplier: function () {
  46. return this.need;
  47. },
  48. events: {
  49. afterKillMob: function (mob) {
  50. if ((mob.name.toLowerCase() !== this.mobName.toLowerCase()) || (this.have >= this.need))
  51. return;
  52. this.have++;
  53. this.description = 'Kill ' + this.have + '/' + this.need + ' ' + this.mobName;
  54. if (this.have >= this.need)
  55. this.ready();
  56. this.obj.syncer.setArray(true, 'quests', 'updateQuests', this.simplify(true));
  57. }
  58. }
  59. };