Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.
 
 
 

126 lignes
3.3 KiB

  1. const resetQuest = q => {
  2. q.mobName = null;
  3. q.mobType = null;
  4. q.item = null;
  5. };
  6. module.exports = {
  7. type: 'lootGen',
  8. need: 10,
  9. have: 0,
  10. mobType: null,
  11. mobName: null,
  12. item: null,
  13. build: function () {
  14. //If we're not in the correct zone, don't do this check, it'll just crash the server
  15. // since the mob won't be available (most likely) in the zoneFile
  16. if (this.obj.zoneName === this.zoneName) {
  17. let mobTypes = this.obj.instance.zoneConfig.mobs;
  18. if (this.mobType && this.item) {
  19. //Check if the zoneFile changed
  20. const mobBlueprint = mobTypes[this.mobType];
  21. if (!mobBlueprint || !mobBlueprint.questItem || mobBlueprint.questItem.name !== this.item.name)
  22. resetQuest(this);
  23. }
  24. if (!this.mobName || !this.item) {
  25. let keys = Object.keys(mobTypes).filter(function (m) {
  26. let mobBlueprint = mobTypes[m];
  27. return (
  28. (m !== 'default') &&
  29. (mobBlueprint.questItem) &&
  30. (mobBlueprint.level <= (this.obj.stats.values.level * 1.35))
  31. );
  32. }, this);
  33. //No level appropriate mobs found
  34. if (keys.length === 0)
  35. return false;
  36. this.mobType = keys[~~(Math.random() * keys.length)];
  37. let needMax = 8;
  38. this.mobName = this.mobType.replace(/\w\S*/g, function (txt) {
  39. return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();
  40. });
  41. this.need = Math.max(1, ~~((needMax * 0.2) + (Math.random() * needMax * 0.8)));
  42. this.item = mobTypes[this.mobType].questItem || mobTypes.default.questItem;
  43. }
  44. }
  45. if (!this.item) {
  46. this.setAsync({
  47. key: new Date(),
  48. table: 'error',
  49. value: this.obj.name + ' ' + this.mobType
  50. });
  51. }
  52. this.name = this.item.name + ' Gatherer';
  53. this.description = 'Loot ' + this.have + '/' + this.need + ' ' + this.item.name + ' from ' + this.mobName;
  54. return true;
  55. },
  56. getXpMultiplier: function () {
  57. return (this.need * 1.5);
  58. },
  59. oComplete: function () {
  60. let inventory = this.obj.inventory;
  61. let item = inventory.items.find((i => i.name === this.item.name).bind(this));
  62. if (item)
  63. this.obj.inventory.destroyItem({ itemId: item.id }, this.need);
  64. },
  65. events: {
  66. beforeTargetDeath: function (target, dropItems) {
  67. if ((this.obj.zoneName !== this.zoneName) || (target.name.toLowerCase() !== this.mobType) || (this.have >= this.need))
  68. return;
  69. let roll = Math.random();
  70. if (roll < 0.5)
  71. return;
  72. dropItems.push({
  73. name: this.item.name,
  74. quality: 0,
  75. quantity: 1,
  76. quest: true,
  77. sprite: this.item.sprite,
  78. ownerName: this.obj.name
  79. });
  80. },
  81. afterLootMobItem: function (item) {
  82. if ((this.obj.zoneName !== this.zoneName) || (item.name.toLowerCase() !== this.item.name.toLowerCase()))
  83. return;
  84. this.have++;
  85. if (this.have === this.need)
  86. this.ready();
  87. this.description = 'Loot ' + this.have + '/' + this.need + ' ' + this.item.name + ' from ' + this.mobName;
  88. this.obj.syncer.setArray(true, 'quests', 'updateQuests', this.simplify(true));
  89. },
  90. afterDestroyItem: function (item, quantity) {
  91. if (item.name.toLowerCase() !== this.item.name.toLowerCase())
  92. return;
  93. this.have -= quantity;
  94. if (this.have < 0)
  95. this.have = 0;
  96. this.description = 'Loot ' + this.have + '/' + this.need + ' ' + this.item.name + ' from ' + this.mobName;
  97. this.obj.syncer.setArray(true, 'quests', 'updateQuests', this.simplify(true));
  98. }
  99. }
  100. };