Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 

144 linhas
2.9 KiB

  1. define([
  2. 'js/system/client',
  3. 'js/system/events',
  4. 'html!ui/templates/quests/template',
  5. 'html!ui/templates/quests/templateQuest',
  6. 'css!ui/templates/quests/styles',
  7. 'js/config'
  8. ], function (
  9. client,
  10. events,
  11. tpl,
  12. templateQuest,
  13. styles,
  14. config
  15. ) {
  16. return {
  17. tpl: tpl,
  18. quests: [],
  19. container: '.right',
  20. postRender: function () {
  21. if (isMobile) {
  22. this.el.on('click', this.toggleButtons.bind(this));
  23. this.find('.btnCollapse').on('click', this.toggleButtons.bind(this));
  24. }
  25. this.onEvent('clearUis', this.clear.bind(this));
  26. this.onEvent('onObtainQuest', this.onObtainQuest.bind(this));
  27. this.onEvent('onUpdateQuest', this.onUpdateQuest.bind(this));
  28. this.onEvent('onCompleteQuest', this.onCompleteQuest.bind(this));
  29. this.onEvent('onToggleQuestsVisibility', this.onToggleQuestsVisibility.bind(this));
  30. this.onToggleQuestsVisibility(config.showQuests);
  31. },
  32. clear: function () {
  33. this.quests = [];
  34. this.el.find('.list').empty();
  35. },
  36. onObtainQuest: function (quest) {
  37. let list = this.el.find('.list');
  38. let html = templateQuest
  39. .replace('$ZONE$', quest.zoneName)
  40. .replace('$NAME$', quest.name)
  41. .replace('$DESCRIPTION$', quest.description)
  42. .replace('$REWARD$', quest.xp + ' xp');
  43. let el = $(html)
  44. .appendTo(list);
  45. if (quest.isReady)
  46. el.addClass('ready');
  47. if (quest.active)
  48. el.addClass('active');
  49. else if (!quest.isReady)
  50. el.addClass('disabled');
  51. el.on('click', this.onClick.bind(this, el, quest));
  52. this.quests.push({
  53. id: quest.id,
  54. el: el,
  55. quest: quest
  56. });
  57. let quests = list.find('.quest');
  58. quests.toArray().forEach(c => {
  59. let childEl = $(c);
  60. if (childEl.hasClass('active'))
  61. childEl.prependTo(list);
  62. });
  63. },
  64. onClick: function (el, quest) {
  65. if (!el.hasClass('ready'))
  66. return;
  67. client.request({
  68. cpn: 'player',
  69. method: 'performAction',
  70. data: {
  71. cpn: 'quests',
  72. method: 'complete',
  73. data: quest.id
  74. }
  75. });
  76. },
  77. onUpdateQuest: function (quest) {
  78. let q = this.quests.find(f => f.id === quest.id);
  79. q.quest.isReady = quest.isReady;
  80. q.el.find('.description').html(quest.description);
  81. q.el.removeClass('ready');
  82. if (quest.isReady) {
  83. q.el.removeClass('disabled');
  84. q.el.addClass('ready');
  85. if (isMobile) {
  86. events.emit('onGetAnnouncement', {
  87. msg: 'Quest ready for turn-in'
  88. });
  89. }
  90. events.emit('onQuestReady', quest);
  91. }
  92. },
  93. onCompleteQuest: function (id) {
  94. let q = this.quests.find(f => f.id === id);
  95. if (!q)
  96. return;
  97. q.el.remove();
  98. this.quests.spliceWhere(f => f.id === id);
  99. },
  100. toggleButtons: function (e) {
  101. this.el.toggleClass('active');
  102. e.stopPropagation();
  103. },
  104. onToggleQuestsVisibility: function (state) {
  105. const shouldHide = state === 'off';
  106. if (shouldHide)
  107. this.hide();
  108. else
  109. this.show();
  110. this.el.removeClass('minimal');
  111. if (state === 'minimal')
  112. this.el.addClass('minimal');
  113. }
  114. };
  115. });