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.

107 lines
2.8 KiB

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