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.

80 lines
1.6 KiB

  1. module.exports = {
  2. rewards: [],
  3. init: function (hideMessage) {
  4. if (!this.build())
  5. return false;
  6. if (!this.xp) {
  7. let level = this.obj.instance.zoneConfig.level;
  8. level = level[0];
  9. let xp = ~~(level * 22 * this.getXpMultiplier());
  10. this.xp = xp;
  11. }
  12. this.obj.syncer.setArray(true, 'quests', 'obtainQuests', this.simplify(true));
  13. if (!hideMessage) {
  14. const message = `Quest obtained (${this.name})`;
  15. this.obj.social.notifySelf({
  16. message,
  17. className: 'color-yellowB'
  18. });
  19. }
  20. return true;
  21. },
  22. ready: function () {
  23. this.isReady = true;
  24. if (this.oReady)
  25. this.oReady();
  26. const message = `Quest ready for turn-in (${this.name})`;
  27. this.obj.social.notifySelf({
  28. message,
  29. className: 'color-yellowB'
  30. });
  31. this.obj.syncer.setArray(true, 'quests', 'updateQuests', this.simplify(true));
  32. this.obj.fireEvent('onQuestReady', this);
  33. },
  34. complete: function () {
  35. if (this.oComplete)
  36. this.oComplete();
  37. const obj = this.obj;
  38. obj.instance.eventEmitter.emit('beforeCompleteAutoquest', this, obj);
  39. const message = `Quest completed (${this.name})`;
  40. obj.social.notifySelf({
  41. message,
  42. className: 'color-yellowB'
  43. });
  44. obj.syncer.setArray(true, 'quests', 'completeQuests', this.id);
  45. obj.instance.eventEmitter.emit('onCompleteQuest', this);
  46. this.rewards.forEach(reward => obj.inventory.getItem(reward));
  47. obj.stats.getXp(this.xp || 10, obj, this);
  48. },
  49. simplify: function (self) {
  50. let values = {};
  51. for (let p in this) {
  52. let value = this[p];
  53. if (typeof (value) === 'function' || ['obj', 'events'].includes(p))
  54. continue;
  55. values[p] = value;
  56. }
  57. return values;
  58. }
  59. };