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.
 
 
 

101 lines
2.6 KiB

  1. module.exports = {
  2. type: 'lootGen',
  3. need: 10,
  4. have: 0,
  5. mobType: null,
  6. mobName: null,
  7. item: null,
  8. build: function () {
  9. if ((!this.mobName) || (!this.item)) {
  10. let mobTypes = this.obj.instance.spawners.zone.mobs;
  11. let keys = Object.keys(mobTypes).filter(function (m) {
  12. let mobBlueprint = mobTypes[m];
  13. return (
  14. (m !== 'default') &&
  15. (mobBlueprint.questItem) &&
  16. (mobBlueprint.level <= (this.obj.stats.values.level * 1.35))
  17. );
  18. }, this);
  19. //No level appropriate mobs found
  20. if (keys.length === 0)
  21. return false;
  22. this.mobType = keys[~~(Math.random() * keys.length)];
  23. let needMax = 8;
  24. this.mobName = this.mobType.replace(/\w\S*/g, function (txt) {
  25. return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();
  26. });
  27. this.need = Math.max(1, ~~((needMax * 0.2) + (Math.random() * needMax * 0.8)));
  28. this.item = mobTypes[this.mobType].questItem || mobTypes.default.questItem;
  29. }
  30. this.name = this.item.name + ' Gatherer';
  31. this.description = 'Loot ' + this.have + '/' + this.need + ' ' + this.item.name + ' from ' + this.mobName;
  32. return true;
  33. },
  34. getXpMultiplier: function () {
  35. return (this.need * 1.5);
  36. },
  37. oComplete: function () {
  38. let inventory = this.obj.inventory;
  39. let item = inventory.items.find((i => i.name === this.item.name).bind(this));
  40. if (item)
  41. this.obj.inventory.destroyItem(item.id, this.need);
  42. },
  43. events: {
  44. beforeTargetDeath: function (target, dropItems) {
  45. if ((this.obj.zoneName !== this.zoneName) || (target.name.toLowerCase() !== this.mobType) || (this.have >= this.need))
  46. return;
  47. let roll = Math.random();
  48. if (roll < 0.5)
  49. return;
  50. dropItems.push({
  51. name: this.item.name,
  52. quality: 0,
  53. quantity: 1,
  54. quest: true,
  55. sprite: this.item.sprite,
  56. ownerName: this.obj.name
  57. });
  58. },
  59. afterLootMobItem: function (item) {
  60. if ((this.obj.zoneName !== this.zoneName) || (item.name.toLowerCase() !== this.item.name.toLowerCase()))
  61. return;
  62. this.have++;
  63. if (this.have === this.need)
  64. this.ready();
  65. this.description = 'Loot ' + this.have + '/' + this.need + ' ' + this.item.name + ' from ' + this.mobName;
  66. this.obj.syncer.setArray(true, 'quests', 'updateQuests', this.simplify(true));
  67. },
  68. afterDestroyItem: function (item, quantity) {
  69. if (item.name.toLowerCase() !== this.item.name.toLowerCase())
  70. return;
  71. this.have -= quantity;
  72. if (this.have < 0)
  73. this.have = 0;
  74. this.description = 'Loot ' + this.have + '/' + this.need + ' ' + this.item.name + ' from ' + this.mobName;
  75. this.obj.syncer.setArray(true, 'quests', 'updateQuests', this.simplify(true));
  76. }
  77. }
  78. };