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.
 
 
 

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