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.
 
 
 

103 lines
2.7 KiB

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