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.
 
 
 

39 lines
867 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(q => events.emit('onObtainQuest', q));
  11. },
  12. extend: function (blueprint) {
  13. if (blueprint.updateQuests) {
  14. blueprint.updateQuests.forEach(function (q) {
  15. events.emit('onUpdateQuest', q);
  16. let index = this.quests.findIndex(f => f.id === q.id);
  17. this.quests.splice(index, 1, q);
  18. }, this);
  19. }
  20. if (blueprint.completeQuests) {
  21. blueprint.completeQuests.forEach(function (q) {
  22. events.emit('onCompleteQuest', q);
  23. this.quests.spliceWhere(function (qq) {
  24. return (qq.id === q);
  25. });
  26. }, this);
  27. }
  28. if (blueprint.obtainQuests) {
  29. blueprint.obtainQuests.forEach(function (q) {
  30. events.emit('onObtainQuest', q);
  31. this.quests.push(q);
  32. }, this);
  33. }
  34. }
  35. };
  36. });