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.
 
 
 

94 lines
2.6 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. this.mobType = keys[~~(Math.random() * keys.length)];
  26. var needMax = 8;
  27. this.mobName = this.mobType.replace(/\w\S*/g, function(txt) {
  28. return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();
  29. });
  30. this.need = Math.max(1, ~~((needMax * 0.2) + (Math.random() * needMax * 0.8)));
  31. this.item = mobTypes[this.mobType].questItem || mobTypes.default.questItem;
  32. }
  33. this.name = this.item.name + ' Gatherer';
  34. this.description = 'Loot ' + this.have + '/' + this.need + ' ' + this.item.name + ' from ' + this.mobName;
  35. },
  36. oComplete: function() {
  37. var inventory = this.obj.inventory;
  38. var item = inventory.items.find((i => i.name == this.item.name).bind(this));
  39. this.obj.inventory.destroyItem(item.id, this.need);
  40. },
  41. events: {
  42. beforeTargetDeath: function(target, dropItems) {
  43. if ((this.obj.zoneName != this.zoneName) || (target.name.toLowerCase() != this.mobType) || (this.have >= this.need))
  44. return;
  45. var roll = Math.random();
  46. if (roll < 0.5)
  47. return;
  48. dropItems.push({
  49. name: this.item.name,
  50. quality: 0,
  51. quantity: 1,
  52. quest: true,
  53. sprite: this.item.sprite,
  54. ownerId: this.obj.serverId
  55. });
  56. },
  57. afterLootMobItem: function(item) {
  58. if ((this.obj.zoneName != this.zoneName) || (item.name.toLowerCase() != this.item.name.toLowerCase()))
  59. return;
  60. this.have++;
  61. if (this.have == this.need)
  62. this.ready();
  63. this.description = 'Loot ' + this.have + '/' + this.need + ' ' + this.item.name + ' from ' + this.mobName;
  64. this.obj.syncer.setArray(true, 'quests', 'updateQuests', this.simplify(true));
  65. },
  66. afterDestroyItem: function(item, quantity) {
  67. if (item.name.toLowerCase() != this.item.name.toLowerCase())
  68. return;
  69. this.have -= quantity;
  70. if (this.have < 0)
  71. this.have = 0;
  72. this.description = 'Loot ' + this.have + '/' + this.need + ' ' + this.item.name + ' from ' + this.mobName;
  73. this.obj.syncer.setArray(true, 'quests', 'updateQuests', this.simplify(true));
  74. }
  75. }
  76. };
  77. });