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.
 
 
 

43 lines
921 B

  1. define([
  2. 'js/system/events'
  3. ], function (
  4. events
  5. ) {
  6. return {
  7. type: 'quests',
  8. quests: [],
  9. init: function () {
  10. this.quests.forEach(function (q) {
  11. events.emit('onObtainQuest', q);
  12. });
  13. },
  14. extend: function (blueprint) {
  15. if (blueprint.updateQuests) {
  16. blueprint.updateQuests.forEach(function (q) {
  17. events.emit('onUpdateQuest', q);
  18. let index = this.quests.firstIndex(function (qq) {
  19. return (qq.id == q.id);
  20. });
  21. this.quests.splice(index, 1, q);
  22. }, this);
  23. }
  24. if (blueprint.completeQuests) {
  25. blueprint.completeQuests.forEach(function (q) {
  26. events.emit('onCompleteQuest', q);
  27. this.quests.spliceWhere(function (qq) {
  28. return (qq.id == q);
  29. });
  30. }, this);
  31. }
  32. if (blueprint.obtainQuests) {
  33. blueprint.obtainQuests.forEach(function (q) {
  34. events.emit('onObtainQuest', q);
  35. this.quests.push(q);
  36. }, this);
  37. }
  38. }
  39. };
  40. });