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.7 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. oComplete: function() {
  41. var inventory = this.obj.inventory;
  42. var item = inventory.items.find((i => i.name == this.item.name).bind(this));
  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. var 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. };
  81. });