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.
 
 
 

118 lines
2.2 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. ], function (
  8. client,
  9. events,
  10. tpl,
  11. templateQuest,
  12. styles
  13. ) {
  14. return {
  15. tpl: tpl,
  16. quests: [],
  17. container: '.right',
  18. postRender: function () {
  19. this.onEvent('onRezone', this.onRezone.bind(this));
  20. this.onEvent('onObtainQuest', this.onObtainQuest.bind(this));
  21. this.onEvent('onUpdateQuest', this.onUpdateQuest.bind(this));
  22. this.onEvent('onCompleteQuest', this.onCompleteQuest.bind(this));
  23. },
  24. onRezone: function () {
  25. this.quests = [];
  26. this.el.find('.list').empty();
  27. },
  28. onObtainQuest: function (quest) {
  29. let list = this.el.find('.list');
  30. let html = templateQuest
  31. .replace('$ZONE$', quest.zoneName)
  32. .replace('$NAME$', quest.name)
  33. .replace('$DESCRIPTION$', quest.description)
  34. .replace('$REWARD$', quest.xp + ' xp');
  35. let el = $(html)
  36. .appendTo(list);
  37. if (quest.isReady)
  38. el.addClass('ready');
  39. if (quest.active)
  40. el.addClass('active');
  41. else if (!quest.isReady)
  42. el.addClass('disabled');
  43. el.on('click', this.onClick.bind(this, el, quest));
  44. this.quests.push({
  45. id: quest.id,
  46. el: el,
  47. quest: quest
  48. });
  49. let quests = list.find('.quest');
  50. quests
  51. .sort(function (a, b) {
  52. a = $(a).hasClass('active') ? 1 : 0;
  53. b = $(b).hasClass('active') ? 1 : 0;
  54. return b - a;
  55. })
  56. .appendTo(list);
  57. },
  58. onClick: function (el, quest) {
  59. if (!el.hasClass('ready'))
  60. return;
  61. client.request({
  62. cpn: 'player',
  63. method: 'performAction',
  64. data: {
  65. cpn: 'quests',
  66. method: 'complete',
  67. data: quest.id
  68. }
  69. });
  70. },
  71. onUpdateQuest: function (quest) {
  72. let q = this.quests.find(function (q) {
  73. return (q.id == quest.id);
  74. });
  75. q.quest.isReady = quest.isReady;
  76. q.el.find('.description').html(quest.description);
  77. q.el.removeClass('ready');
  78. if (quest.isReady) {
  79. q.el.removeClass('disabled');
  80. q.el.addClass('ready');
  81. }
  82. },
  83. onCompleteQuest: function (id) {
  84. let q = this.quests.find(function (q) {
  85. return (q.id == id);
  86. });
  87. if (!q)
  88. return;
  89. q.el.remove();
  90. this.quests.spliceWhere(function (q) {
  91. return (q.id == id);
  92. });
  93. }
  94. };
  95. });