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.
 
 
 

79 lines
1.7 KiB

  1. let slots = require('../../../items/generators/slots');
  2. module.exports = {
  3. type: 'gatherResource',
  4. need: null,
  5. gatherType: null,
  6. requiredQuality: 0,
  7. have: 0,
  8. build: function () {
  9. if (!this.need) {
  10. this.need = 2 + ~~(Math.random() * 3);
  11. this.gatherType = ['herb', 'fish'][~~(Math.random() * 2)];
  12. if (this.gatherType === 'fish') {
  13. this.name = 'Lure of the Sea';
  14. let isQualityQ = (Math.random() < 0.3);
  15. if (isQualityQ) {
  16. this.requiredQuality = 1 + ~~(Math.random() * 2);
  17. this.need = 1;
  18. }
  19. }
  20. }
  21. if (['herb', 'fish'].indexOf(this.gatherType) === -1)
  22. this.gatherType = 'herb';
  23. this.typeName = (this.gatherType === 'herb') ? 'herbs' : 'fish';
  24. this.updateDescription();
  25. return true;
  26. },
  27. getXpMultiplier: function () {
  28. if (this.requiredQuality === 2)
  29. return 8;
  30. else if (this.requiredQuality === 1)
  31. return 6;
  32. return this.need;
  33. },
  34. updateDescription: function () {
  35. let typeName = this.typeName;
  36. if (this.requiredQuality > 0)
  37. typeName = ['big', 'giant'][this.requiredQuality - 1] + ' ' + typeName;
  38. let action = ({
  39. herb: 'Gather',
  40. fish: 'Catch'
  41. })[this.gatherType];
  42. this.description = `${action} ${this.have}/${this.need} ${typeName}`;
  43. },
  44. events: {
  45. afterGatherResource: function (gatherResult) {
  46. if (gatherResult.nodeType !== this.gatherType)
  47. return;
  48. else if ((this.requiredQuality) && (gatherResult.items[0].quality < this.requiredQuality))
  49. return;
  50. if ((this.obj.zoneName !== this.zoneName) || (this.have >= this.need))
  51. return;
  52. this.have++;
  53. this.updateDescription();
  54. this.obj.syncer.setArray(true, 'quests', 'updateQuests', this.simplify(true));
  55. if (this.have >= this.need)
  56. this.ready();
  57. }
  58. }
  59. };