@drincs/nqtr 0.1.19 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (155) hide show
  1. package/dist/{ActivityProps-_79x9-BX.d.ts → ActivityProps-BkHX8xkA.d.ts} +1 -1
  2. package/dist/{ActivityProps-BoJeWa2B.d.mts → ActivityProps-D45DQdcT.d.mts} +1 -1
  3. package/dist/{Commitment-Cc2kZEy0.d.ts → Commitment-BJTIpBQ5.d.ts} +4 -2
  4. package/dist/{Commitment-C3Nc2RJH.d.mts → Commitment-CtNWnNQX.d.mts} +4 -2
  5. package/dist/StageProps-DCZkZHwZ.d.ts +197 -0
  6. package/dist/StageProps-xLLR0rjD.d.mts +197 -0
  7. package/dist/classes/Activity.d.mts +2 -2
  8. package/dist/classes/Activity.d.ts +2 -2
  9. package/dist/classes/Activity.js +1 -1
  10. package/dist/classes/Activity.js.map +1 -1
  11. package/dist/classes/Activity.mjs +1 -1
  12. package/dist/classes/Activity.mjs.map +1 -1
  13. package/dist/classes/ActivityStoredAbstract.d.mts +1 -1
  14. package/dist/classes/ActivityStoredAbstract.d.ts +1 -1
  15. package/dist/classes/ActivityStoredAbstract.js +1 -1
  16. package/dist/classes/ActivityStoredAbstract.js.map +1 -1
  17. package/dist/classes/ActivityStoredAbstract.mjs +1 -1
  18. package/dist/classes/ActivityStoredAbstract.mjs.map +1 -1
  19. package/dist/classes/Commitment.d.mts +2 -2
  20. package/dist/classes/Commitment.d.ts +2 -2
  21. package/dist/classes/Commitment.js +2 -2
  22. package/dist/classes/Commitment.js.map +1 -1
  23. package/dist/classes/Commitment.mjs +2 -2
  24. package/dist/classes/Commitment.mjs.map +1 -1
  25. package/dist/classes/index.d.mts +4 -4
  26. package/dist/classes/index.d.ts +4 -4
  27. package/dist/classes/index.js +290 -322
  28. package/dist/classes/index.js.map +1 -1
  29. package/dist/classes/index.mjs +289 -321
  30. package/dist/classes/index.mjs.map +1 -1
  31. package/dist/classes/navigation/ActivityRoom.d.mts +2 -2
  32. package/dist/classes/navigation/ActivityRoom.d.ts +2 -2
  33. package/dist/classes/navigation/ActivityRoom.js +2 -2
  34. package/dist/classes/navigation/ActivityRoom.js.map +1 -1
  35. package/dist/classes/navigation/ActivityRoom.mjs +2 -2
  36. package/dist/classes/navigation/ActivityRoom.mjs.map +1 -1
  37. package/dist/classes/navigation/Location.d.mts +2 -2
  38. package/dist/classes/navigation/Location.d.ts +2 -2
  39. package/dist/classes/navigation/Map.d.mts +2 -2
  40. package/dist/classes/navigation/Map.d.ts +2 -2
  41. package/dist/classes/navigation/Room.d.mts +2 -2
  42. package/dist/classes/navigation/Room.d.ts +2 -2
  43. package/dist/classes/navigation/Room.js +34 -36
  44. package/dist/classes/navigation/Room.js.map +1 -1
  45. package/dist/classes/navigation/Room.mjs +34 -36
  46. package/dist/classes/navigation/Room.mjs.map +1 -1
  47. package/dist/classes/quest/Goal.d.mts +21 -13
  48. package/dist/classes/quest/Goal.d.ts +21 -13
  49. package/dist/classes/quest/Goal.js +50 -15
  50. package/dist/classes/quest/Goal.js.map +1 -1
  51. package/dist/classes/quest/Goal.mjs +47 -15
  52. package/dist/classes/quest/Goal.mjs.map +1 -1
  53. package/dist/classes/quest/Quest.d.mts +3 -2
  54. package/dist/classes/quest/Quest.d.ts +3 -2
  55. package/dist/classes/quest/Quest.js +536 -9
  56. package/dist/classes/quest/Quest.js.map +1 -1
  57. package/dist/classes/quest/Quest.mjs +537 -10
  58. package/dist/classes/quest/Quest.mjs.map +1 -1
  59. package/dist/classes/quest/Stage.d.mts +3 -2
  60. package/dist/classes/quest/Stage.d.ts +3 -2
  61. package/dist/classes/quest/Stage.js +396 -51
  62. package/dist/classes/quest/Stage.js.map +1 -1
  63. package/dist/classes/quest/Stage.mjs +394 -52
  64. package/dist/classes/quest/Stage.mjs.map +1 -1
  65. package/dist/decorators/ActivityDecorator.d.mts +1 -1
  66. package/dist/decorators/ActivityDecorator.d.ts +1 -1
  67. package/dist/decorators/CommitmentDecorator.d.mts +9 -3
  68. package/dist/decorators/CommitmentDecorator.d.ts +9 -3
  69. package/dist/decorators/CommitmentDecorator.js +15 -0
  70. package/dist/decorators/CommitmentDecorator.js.map +1 -1
  71. package/dist/decorators/CommitmentDecorator.mjs +15 -1
  72. package/dist/decorators/CommitmentDecorator.mjs.map +1 -1
  73. package/dist/decorators/QuestDecorator.d.mts +26 -0
  74. package/dist/decorators/QuestDecorator.d.ts +26 -0
  75. package/dist/decorators/QuestDecorator.js +592 -0
  76. package/dist/decorators/QuestDecorator.js.map +1 -0
  77. package/dist/decorators/QuestDecorator.mjs +588 -0
  78. package/dist/decorators/QuestDecorator.mjs.map +1 -0
  79. package/dist/decorators/RoomDecorator.d.mts +2 -2
  80. package/dist/decorators/RoomDecorator.d.ts +2 -2
  81. package/dist/decorators/index.d.mts +8 -3
  82. package/dist/decorators/index.d.ts +8 -3
  83. package/dist/decorators/index.js +598 -0
  84. package/dist/decorators/index.js.map +1 -1
  85. package/dist/decorators/index.mjs +597 -2
  86. package/dist/decorators/index.mjs.map +1 -1
  87. package/dist/functions/ActivityFunctions.d.mts +2 -2
  88. package/dist/functions/ActivityFunctions.d.ts +2 -2
  89. package/dist/functions/ActivityFunctions.js.map +1 -1
  90. package/dist/functions/ActivityFunctions.mjs.map +1 -1
  91. package/dist/functions/NavigationFunctions.d.mts +2 -2
  92. package/dist/functions/NavigationFunctions.d.ts +2 -2
  93. package/dist/functions/NavigationFunctions.js.map +1 -1
  94. package/dist/functions/NavigationFunctions.mjs.map +1 -1
  95. package/dist/functions/RoutineFunctions.d.mts +2 -2
  96. package/dist/functions/RoutineFunctions.d.ts +2 -2
  97. package/dist/functions/RoutineFunctions.js.map +1 -1
  98. package/dist/functions/RoutineFunctions.mjs.map +1 -1
  99. package/dist/functions/index.d.mts +2 -2
  100. package/dist/functions/index.d.ts +2 -2
  101. package/dist/functions/index.js.map +1 -1
  102. package/dist/functions/index.mjs.map +1 -1
  103. package/dist/index.d.mts +6 -5
  104. package/dist/index.d.ts +6 -5
  105. package/dist/index.js +540 -308
  106. package/dist/index.js.map +1 -1
  107. package/dist/index.mjs +536 -307
  108. package/dist/index.mjs.map +1 -1
  109. package/dist/interface/ActivityProps.d.mts +1 -1
  110. package/dist/interface/ActivityProps.d.ts +1 -1
  111. package/dist/interface/CommitmentProps.d.mts +2 -2
  112. package/dist/interface/CommitmentProps.d.ts +2 -2
  113. package/dist/interface/RoomActivityMemory.d.mts +1 -1
  114. package/dist/interface/RoomActivityMemory.d.ts +1 -1
  115. package/dist/interface/RoomProps.d.mts +2 -2
  116. package/dist/interface/RoomProps.d.ts +2 -2
  117. package/dist/interface/index.d.mts +4 -4
  118. package/dist/interface/index.d.ts +4 -4
  119. package/dist/interface/navigation/LocationProps.d.mts +2 -2
  120. package/dist/interface/navigation/LocationProps.d.ts +2 -2
  121. package/dist/interface/navigation/MapProps.d.mts +2 -2
  122. package/dist/interface/navigation/MapProps.d.ts +2 -2
  123. package/dist/interface/quest/GoalProps.d.mts +12 -0
  124. package/dist/interface/quest/GoalProps.d.ts +12 -0
  125. package/dist/interface/quest/QuestProps.d.mts +6 -9
  126. package/dist/interface/quest/QuestProps.d.ts +6 -9
  127. package/dist/interface/quest/StageFlags.d.mts +12 -0
  128. package/dist/interface/quest/StageFlags.d.ts +12 -0
  129. package/dist/interface/quest/StageFlags.js +4 -0
  130. package/dist/interface/quest/StageFlags.js.map +1 -0
  131. package/dist/interface/quest/StageFlags.mjs +3 -0
  132. package/dist/interface/quest/StageFlags.mjs.map +1 -0
  133. package/dist/interface/quest/StageProps.d.mts +3 -2
  134. package/dist/interface/quest/StageProps.d.ts +3 -2
  135. package/dist/override/OnEndStage.d.mts +19 -0
  136. package/dist/override/OnEndStage.d.ts +19 -0
  137. package/dist/override/OnEndStage.js +4 -0
  138. package/dist/override/OnEndStage.js.map +1 -0
  139. package/dist/override/OnEndStage.mjs +3 -0
  140. package/dist/override/OnEndStage.mjs.map +1 -0
  141. package/dist/override/OnStartStage.d.mts +19 -0
  142. package/dist/override/OnStartStage.d.ts +19 -0
  143. package/dist/override/OnStartStage.js +4 -0
  144. package/dist/override/OnStartStage.js.map +1 -0
  145. package/dist/override/OnStartStage.mjs +3 -0
  146. package/dist/override/OnStartStage.mjs.map +1 -0
  147. package/dist/override/index.d.mts +2 -0
  148. package/dist/override/index.d.ts +2 -0
  149. package/dist/types/QuestsRequired.d.mts +3 -2
  150. package/dist/types/QuestsRequired.d.ts +3 -2
  151. package/dist/types/index.d.mts +3 -2
  152. package/dist/types/index.d.ts +3 -2
  153. package/package.json +2 -2
  154. package/dist/Quest-Bdm0R9LA.d.mts +0 -71
  155. package/dist/Quest-CxJcXETG.d.ts +0 -71
package/dist/index.js CHANGED
@@ -361,7 +361,7 @@ var ActivityModel = class {
361
361
  /**
362
362
  * The function that is called when the activity is runned.
363
363
  */
364
- get onRun() {
364
+ get run() {
365
365
  return (props) => this._onRun(this, props);
366
366
  }
367
367
  /**
@@ -491,6 +491,7 @@ var CommitmentBaseModel = class extends pixiVn.StoredClassModel {
491
491
  }
492
492
  /**
493
493
  * Execution type. If is "automatic" the onRun() runned automatically when the palayer is in the room. If is "interaction" the player must interact with the character to run the onRun() function.
494
+ * If you set "automatic" remember to remove the commitment when it is no longer needed, because otherwise it repeats itself every time.
494
495
  */
495
496
  get executionType() {
496
497
  return this._executionType;
@@ -513,10 +514,9 @@ var CommitmentBaseModel = class extends pixiVn.StoredClassModel {
513
514
  /**
514
515
  * Is a function that is called when the player interacts with the character.
515
516
  */
516
- get onRun() {
517
+ get run() {
517
518
  let onRun = this._onRun;
518
519
  if (!onRun) {
519
- console.warn("[NQTR] onRun() is not defined for commitmen, so it will not run.", this);
520
520
  return;
521
521
  }
522
522
  return (props) => onRun(this, props);
@@ -577,6 +577,199 @@ var CommitmentBaseModel = class extends pixiVn.StoredClassModel {
577
577
  return false;
578
578
  }
579
579
  };
580
+ var ActivityStoredAbstract = class {
581
+ /**
582
+ * @param onRun The function that is called when the activity is runned. Have 2 parameters: the runned activity and the yourParams object, that is an object with the parameters that you want to pass to the onRun function.
583
+ * @param props The activity properties.
584
+ */
585
+ constructor(onRun, props) {
586
+ this.defaultName = props.name;
587
+ this.defaultFromHour = props.fromHour;
588
+ this.defaultToHour = props.toHour;
589
+ this.defaultFromDay = props.fromDay;
590
+ this.defaultToDay = props.toDay;
591
+ this.defaultDisabled = props.disabled || false;
592
+ this.defaultHidden = props.hidden || false;
593
+ this._renderIcon = props.renderIcon;
594
+ this._onRun = onRun;
595
+ }
596
+ /**
597
+ * The name
598
+ */
599
+ get name() {
600
+ return this.getStorageProperty("name") || this.defaultName || "";
601
+ }
602
+ set name(value) {
603
+ this.setStorageProperty("name", value);
604
+ }
605
+ /**
606
+ * The hour when the activity starts. If the activity is not started yet, it will be hidden.
607
+ */
608
+ get fromHour() {
609
+ return this.getStorageProperty("fromHour") || this.defaultFromHour || TimeManager.minDayHours;
610
+ }
611
+ set fromHour(value) {
612
+ this.setStorageProperty("fromHour", value);
613
+ }
614
+ /**
615
+ * The hour when the activity ends. If the activity is ended yet, it will be hidden.
616
+ */
617
+ get toHour() {
618
+ return this.getStorageProperty("toHour") || this.defaultToHour || TimeManager.maxDayHours + 1;
619
+ }
620
+ set toHour(value) {
621
+ this.setStorageProperty("toHour", value);
622
+ }
623
+ /**
624
+ * The day when the activity starts. If the activity is not started yet, it will be hidden.
625
+ */
626
+ get fromDay() {
627
+ return this.getStorageProperty("fromDay") || this.defaultFromDay;
628
+ }
629
+ set fromDay(value) {
630
+ this.setStorageProperty("fromDay", value);
631
+ }
632
+ /**
633
+ * The day when the activity ends. If the activity is ended yet, it will be deleted or hidden.
634
+ */
635
+ get toDay() {
636
+ return this.getStorageProperty("toDay") || this.defaultToDay;
637
+ }
638
+ set toDay(value) {
639
+ this.setStorageProperty("toDay", value);
640
+ }
641
+ /**
642
+ * Whether is disabled.
643
+ */
644
+ get disabled() {
645
+ let value = this.getStorageProperty("disabled") || this.defaultDisabled;
646
+ if (typeof value === "string") {
647
+ return pixiVn.getFlag(value);
648
+ }
649
+ return value;
650
+ }
651
+ set disabled(value) {
652
+ this.setStorageProperty("disabled", value);
653
+ }
654
+ /**
655
+ * Whether is hidden. If the activity is not started yet, it will be hidden.
656
+ */
657
+ get hidden() {
658
+ if (this.fromDay && this.fromDay > TimeManager.currentDay) {
659
+ return true;
660
+ }
661
+ if (!TimeManager.nowIsBetween(this.fromHour, this.toHour)) {
662
+ return true;
663
+ }
664
+ if (!this.isExpired) {
665
+ return true;
666
+ }
667
+ let value = this.getStorageProperty("hidden") || this.defaultHidden;
668
+ if (typeof value === "string") {
669
+ return pixiVn.getFlag(value);
670
+ }
671
+ return value;
672
+ }
673
+ set hidden(value) {
674
+ this.setStorageProperty("hidden", value);
675
+ }
676
+ /**
677
+ * The function for rendering the icon of the activity.
678
+ */
679
+ get renderIcon() {
680
+ let render = this._renderIcon;
681
+ if (render === void 0) {
682
+ return void 0;
683
+ }
684
+ if (typeof render === "function") {
685
+ return (props) => {
686
+ return render(this, props);
687
+ };
688
+ }
689
+ return (props) => render;
690
+ }
691
+ /**
692
+ * The function that is called when the activity is runned.
693
+ */
694
+ get run() {
695
+ return (props) => {
696
+ return this._onRun(this, props);
697
+ };
698
+ }
699
+ /**
700
+ * Whether the activity is a deadline.
701
+ * @returns Whether the activity is a deadline.
702
+ */
703
+ isExpired() {
704
+ if (this.toDay && this.toDay <= TimeManager.currentDay) {
705
+ return true;
706
+ }
707
+ return false;
708
+ }
709
+ /**
710
+ * Export the activity properties.
711
+ * @returns The activity properties.
712
+ */
713
+ export() {
714
+ return {
715
+ name: this.getStorageProperty("name") || this.defaultName,
716
+ fromHour: this.getStorageProperty("fromHour") || this.defaultFromHour,
717
+ toHour: this.getStorageProperty("toHour") || this.defaultToHour,
718
+ fromDay: this.getStorageProperty("fromDay") || this.defaultFromDay,
719
+ toDay: this.getStorageProperty("toDay") || this.defaultToDay,
720
+ disabled: this.getStorageProperty("disabled") || this.defaultDisabled,
721
+ hidden: this.getStorageProperty("hidden") || this.defaultHidden,
722
+ renderIcon: this._renderIcon
723
+ };
724
+ }
725
+ };
726
+
727
+ // src/classes/navigation/ActivityRoom.ts
728
+ var ActivityRoom = class extends ActivityStoredAbstract {
729
+ constructor(id, room, onRun, props) {
730
+ super(onRun, props);
731
+ this._id = id;
732
+ this._room = room;
733
+ }
734
+ setStorageProperty(_, __) {
735
+ this._room.setActivity(this);
736
+ }
737
+ getStorageProperty(propertyName) {
738
+ let activity = this._room.getActivityMemory(this.id);
739
+ if (!activity || !activity.hasOwnProperty(propertyName)) {
740
+ return void 0;
741
+ }
742
+ return activity[propertyName];
743
+ }
744
+ get id() {
745
+ return this._id;
746
+ }
747
+ get room() {
748
+ return this._room;
749
+ }
750
+ export() {
751
+ let result = {};
752
+ if (this.name !== void 0) {
753
+ result["name"] = this.name;
754
+ }
755
+ if (this.fromHour !== void 0) {
756
+ result["fromHour"] = this.fromHour;
757
+ }
758
+ if (this.toHour !== void 0) {
759
+ result["toHour"] = this.toHour;
760
+ }
761
+ if (this.fromDay !== void 0) {
762
+ result["fromDay"] = this.fromDay;
763
+ }
764
+ if (this.toDay !== void 0) {
765
+ result["toDay"] = this.toDay;
766
+ }
767
+ if (this.disabled !== void 0) {
768
+ result["disabled"] = this.disabled;
769
+ }
770
+ return result;
771
+ }
772
+ };
580
773
 
581
774
  // src/decorators/RoomDecorator.ts
582
775
  var registeredRooms = {};
@@ -893,6 +1086,20 @@ function addCommitment(commitment) {
893
1086
  }).filter((id) => id !== void 0);
894
1087
  pixiVn.GameStorageManager.setVariable(TEMPORARY_COMMITMENT_CATEGORY_MEMORY_KEY, [commitmentsIds]);
895
1088
  }
1089
+ function removeCommitment(commitment) {
1090
+ if (!Array.isArray(commitment)) {
1091
+ commitment = [commitment];
1092
+ }
1093
+ let commitmentsIds = commitment.map((commitment2) => {
1094
+ return commitment2.id;
1095
+ });
1096
+ let currentCommitments = pixiVn.GameStorageManager.getVariable(TEMPORARY_COMMITMENT_CATEGORY_MEMORY_KEY);
1097
+ if (!currentCommitments) {
1098
+ return;
1099
+ }
1100
+ currentCommitments = currentCommitments.filter((id) => !commitmentsIds.includes(id));
1101
+ pixiVn.GameStorageManager.setVariable(TEMPORARY_COMMITMENT_CATEGORY_MEMORY_KEY, currentCommitments);
1102
+ }
896
1103
  function getFixedRoutine() {
897
1104
  return Object.values(fixedCommitments);
898
1105
  }
@@ -904,153 +1111,228 @@ function getTemporaryCommitments() {
904
1111
  let commitments = commitmentsIds.map((id) => getCommitmentById(id)).filter((commitment) => commitment !== void 0);
905
1112
  return commitments;
906
1113
  }
907
-
908
- // src/functions/RoutineFunctions.ts
909
- function clearExpiredRoutine() {
910
- Object.entries(registeredCommitments).forEach(([_, commitment]) => {
911
- if (commitment.isExpired()) {
912
- delete registeredCommitments[commitment.id];
913
- }
914
- });
915
- }
916
- function getCurrentRoutine() {
917
- let character_commitments = {};
918
- getTemporaryCommitments().reverse().forEach((c) => {
919
- if (!c.hidden) {
920
- if (c.characters.length > 0) {
921
- let allAvailable = c.characters.every((ch) => !character_commitments[ch.id] || c.priority > character_commitments[ch.id].priority);
922
- if (allAvailable) {
923
- c.characters.forEach((ch) => {
924
- character_commitments[ch.id] = c;
925
- });
926
- }
927
- } else {
928
- console.error(`[NQTR] The commitment ${c.id} has no characters assigned`);
929
- }
930
- }
931
- });
932
- getFixedRoutine().reverse().forEach((c) => {
933
- if (!c.hidden) {
934
- if (c.characters.length > 0) {
935
- let allAvailable = c.characters.every((ch) => !character_commitments[ch.id] || c.priority > character_commitments[ch.id].priority);
936
- if (allAvailable) {
937
- c.characters.forEach((ch) => {
938
- character_commitments[ch.id] = c;
939
- });
940
- }
941
- } else {
942
- console.error(`[NQTR] The commitment ${c.id} has no characters assigned`);
943
- }
944
- }
945
- });
946
- return Object.values(character_commitments);
947
- }
948
- function getCommitmentByCharacter(character) {
949
- getCurrentRoutine().forEach((c) => {
950
- if (c.characters.map((ch) => ch.id).includes(character.id)) {
951
- return c;
952
- }
953
- });
954
- return void 0;
955
- }
956
- var ActivityStoredAbstract = class {
1114
+ var GOAL_CATEGORY = "__nqtr-goal__";
1115
+ var Goal = class extends pixiVn.StoredClassModel {
1116
+ constructor(id, props) {
1117
+ super(GOAL_CATEGORY, id);
1118
+ this._description = props.description;
1119
+ this._need = props.need || 1;
1120
+ this._defaultHave = props.have || 0;
1121
+ }
957
1122
  /**
958
- * @param onRun The function that is called when the activity is runned. Have 2 parameters: the runned activity and the yourParams object, that is an object with the parameters that you want to pass to the onRun function.
959
- * @param props The activity properties.
1123
+ * The description of the goal.
960
1124
  */
961
- constructor(onRun, props) {
962
- this.defaultName = props.name;
963
- this.defaultFromHour = props.fromHour;
964
- this.defaultToHour = props.toHour;
965
- this.defaultFromDay = props.fromDay;
966
- this.defaultToDay = props.toDay;
967
- this.defaultDisabled = props.disabled || false;
968
- this.defaultHidden = props.hidden || false;
969
- this._renderIcon = props.renderIcon;
970
- this._onRun = onRun;
1125
+ get description() {
1126
+ return this._description;
1127
+ }
1128
+ get need() {
1129
+ return this._need;
1130
+ }
1131
+ get defaultHave() {
1132
+ return this._defaultHave;
1133
+ }
1134
+ };
1135
+ var GoalStage = class extends Goal {
1136
+ constructor(id, stageId, props) {
1137
+ super(id, props);
1138
+ this._stageId = stageId;
1139
+ }
1140
+ get stageId() {
1141
+ return this._stageId;
1142
+ }
1143
+ set stageId(value) {
1144
+ this._stageId = value;
1145
+ }
1146
+ get have() {
1147
+ return this.getStorageProperty("have-" + this._stageId) || this.defaultHave;
1148
+ }
1149
+ set have(value) {
1150
+ if (!this._stageId) {
1151
+ console.error(`[NQTR] The stage id is not set for the goal ${this.id}, so the have value can't be set.`);
1152
+ return;
1153
+ }
1154
+ this.setStorageProperty("have-" + this._stageId, value);
1155
+ }
1156
+ get completed() {
1157
+ return this.have >= this.need;
1158
+ }
1159
+ set completed(value) {
1160
+ if (value) {
1161
+ this.have = this.need;
1162
+ } else {
1163
+ console.warn(`[NQTR] The goal can't be set as not completed. You must edit the have value manually.`);
1164
+ }
1165
+ }
1166
+ find() {
1167
+ this.have++;
1168
+ }
1169
+ };
1170
+
1171
+ // src/classes/quest/Stage.ts
1172
+ var STAGE_CATEGORY = "__nqtr-stage__";
1173
+ var Stage = class extends pixiVn.StoredClassModel {
1174
+ constructor(id, props) {
1175
+ super(STAGE_CATEGORY, id);
1176
+ this._name = props.name || "";
1177
+ this._defaultGoals = props.goals || [];
1178
+ this._flags = props.flags || [];
1179
+ this._description = props.description || "";
1180
+ this._adviceDescription = props.adviceDescription || "";
1181
+ this._renderImage = props.renderImage;
1182
+ this._daysRequiredToStart = props.daysRequiredToStart;
1183
+ this._flagsRequiredToStart = props.flagsRequired || [];
1184
+ this._questsRequiredToStart = props.questsRequired || [];
1185
+ this._requestDescriptionToStart = props.requestDescription || "";
1186
+ this._onStart = props.onStart;
1187
+ this._onEnd = props.onEnd;
971
1188
  }
972
- /**
973
- * The name
974
- */
975
1189
  get name() {
976
- return this.getStorageProperty("name") || this.defaultName || "";
1190
+ return this._name;
977
1191
  }
978
- set name(value) {
979
- this.setStorageProperty("name", value);
1192
+ get description() {
1193
+ return this._description;
1194
+ }
1195
+ get adviceDescription() {
1196
+ return this._adviceDescription;
980
1197
  }
981
1198
  /**
982
- * The hour when the activity starts. If the activity is not started yet, it will be hidden.
1199
+ * The function for rendering the image of the stage.
983
1200
  */
984
- get fromHour() {
985
- return this.getStorageProperty("fromHour") || this.defaultFromHour || TimeManager.minDayHours;
1201
+ get renderImage() {
1202
+ let render = this._renderImage;
1203
+ if (render === void 0) {
1204
+ return void 0;
1205
+ }
1206
+ if (typeof render === "function") {
1207
+ return (props) => {
1208
+ return render(this, props);
1209
+ };
1210
+ }
1211
+ return (props) => render;
986
1212
  }
987
- set fromHour(value) {
988
- this.setStorageProperty("fromHour", value);
1213
+ get defaultGoals() {
1214
+ return this._defaultGoals;
989
1215
  }
990
1216
  /**
991
- * The hour when the activity ends. If the activity is ended yet, it will be hidden.
1217
+ * The list of flags that the player must complete to finish the stage.
992
1218
  */
993
- get toHour() {
994
- return this.getStorageProperty("toHour") || this.defaultToHour || TimeManager.maxDayHours + 1;
1219
+ get flags() {
1220
+ return this._flags;
995
1221
  }
996
- set toHour(value) {
997
- this.setStorageProperty("toHour", value);
1222
+ get daysRequiredToStart() {
1223
+ return this._daysRequiredToStart || 0;
998
1224
  }
999
- /**
1000
- * The day when the activity starts. If the activity is not started yet, it will be hidden.
1001
- */
1002
- get fromDay() {
1003
- return this.getStorageProperty("fromDay") || this.defaultFromDay;
1225
+ get flagsRequiredToStart() {
1226
+ return this._flagsRequiredToStart;
1004
1227
  }
1005
- set fromDay(value) {
1006
- this.setStorageProperty("fromDay", value);
1228
+ get questsRequiredToStart() {
1229
+ return this._questsRequiredToStart || [];
1007
1230
  }
1008
- /**
1009
- * The day when the activity ends. If the activity is ended yet, it will be deleted or hidden.
1010
- */
1011
- get toDay() {
1012
- return this.getStorageProperty("toDay") || this.defaultToDay;
1231
+ get requestDescriptionToStart() {
1232
+ return this._requestDescriptionToStart;
1013
1233
  }
1014
- set toDay(value) {
1015
- this.setStorageProperty("toDay", value);
1234
+ get onStart() {
1235
+ return this._onStart;
1016
1236
  }
1017
- /**
1018
- * Whether is disabled.
1019
- */
1020
- get disabled() {
1021
- let value = this.getStorageProperty("disabled") || this.defaultDisabled;
1022
- if (typeof value === "string") {
1023
- return pixiVn.getFlag(value);
1237
+ get onEnd() {
1238
+ return this._onEnd;
1239
+ }
1240
+ };
1241
+ var StageQuest = class extends Stage {
1242
+ constructor(id, props) {
1243
+ super(id, props);
1244
+ }
1245
+ get completed() {
1246
+ let storedCompleted = this.getStorageProperty("completed");
1247
+ if (storedCompleted) {
1248
+ return storedCompleted;
1024
1249
  }
1025
- return value;
1250
+ if (!this.flags.every((flag) => pixiVn.getFlag(flag.flag))) {
1251
+ return false;
1252
+ }
1253
+ if (!this.goals.every((goal) => goal.completed)) {
1254
+ return false;
1255
+ }
1256
+ return true;
1026
1257
  }
1027
- set disabled(value) {
1028
- this.setStorageProperty("disabled", value);
1258
+ set completed(value) {
1259
+ this.setStorageProperty("completed", value);
1029
1260
  }
1030
1261
  /**
1031
- * Whether is hidden. If the activity is not started yet, it will be hidden.
1262
+ * The list of goals that the player needs to complete to finish the stage.
1032
1263
  */
1033
- get hidden() {
1034
- if (this.fromDay && this.fromDay > TimeManager.currentDay) {
1035
- return true;
1264
+ get goals() {
1265
+ return this.defaultGoals.map((goal) => {
1266
+ return new GoalStage(goal.id, this.id, goal);
1267
+ });
1268
+ }
1269
+ get prevStageEndDay() {
1270
+ return this.getStorageProperty("prevStageEndDay");
1271
+ }
1272
+ set prevStageEndDay(value) {
1273
+ this.setStorageProperty("prevStageEndDay", value);
1274
+ }
1275
+ get startDay() {
1276
+ let prevStageEndDay = this.prevStageEndDay;
1277
+ if (prevStageEndDay === void 0) {
1278
+ return void 0;
1036
1279
  }
1037
- if (!TimeManager.nowIsBetween(this.fromHour, this.toHour)) {
1038
- return true;
1280
+ return prevStageEndDay + this.daysRequiredToStart;
1281
+ }
1282
+ get canStart() {
1283
+ let daysRequired = this.daysRequiredToStart;
1284
+ if (daysRequired > 0) {
1285
+ let prevStageEndDay = this.prevStageEndDay;
1286
+ if (prevStageEndDay === void 0) {
1287
+ return false;
1288
+ }
1289
+ if (prevStageEndDay + daysRequired > TimeManager.currentDay) {
1290
+ return false;
1291
+ }
1039
1292
  }
1040
- if (!this.isExpired) {
1041
- return true;
1293
+ if (this.flagsRequiredToStart.length > 0 && !this.flagsRequiredToStart.every((flag) => pixiVn.getFlag(flag.flag))) {
1294
+ return false;
1042
1295
  }
1043
- let value = this.getStorageProperty("hidden") || this.defaultHidden;
1044
- if (typeof value === "string") {
1045
- return pixiVn.getFlag(value);
1296
+ if (this.questsRequiredToStart.length > 0 && !this.questsRequiredToStart.every(
1297
+ (q) => q.quest.currentStageIndex && q.quest.currentStageIndex >= q.stageNumber
1298
+ )) {
1299
+ return false;
1046
1300
  }
1047
- return value;
1301
+ return true;
1048
1302
  }
1049
- set hidden(value) {
1050
- this.setStorageProperty("hidden", value);
1303
+ get onStart() {
1304
+ if (this.daysRequiredToStart > 0) {
1305
+ this.prevStageEndDay = TimeManager.currentDay;
1306
+ }
1307
+ return super.onStart;
1308
+ }
1309
+ };
1310
+
1311
+ // src/classes/quest/Quest.ts
1312
+ var QUEST_CATEGORY = "__nqtr-quest__";
1313
+ var Quest = class extends pixiVn.StoredClassModel {
1314
+ constructor(id, stages, props) {
1315
+ super(QUEST_CATEGORY, id);
1316
+ this._stages = stages;
1317
+ this._name = props.name || "";
1318
+ this._description = props.description || "";
1319
+ this._renderIcon = props.renderIcon;
1320
+ this._renderImage = props.renderImage;
1321
+ this._isInDevelopment = props.isInDevelopment || false;
1322
+ }
1323
+ get stages() {
1324
+ return this._stages.map((stage, index) => {
1325
+ return new StageQuest(stage.id, stage);
1326
+ });
1327
+ }
1328
+ get name() {
1329
+ return this._name;
1330
+ }
1331
+ get description() {
1332
+ return this._description;
1051
1333
  }
1052
1334
  /**
1053
- * The function for rendering the icon of the activity.
1335
+ * The function for rendering the icon of the quest.
1054
1336
  */
1055
1337
  get renderIcon() {
1056
1338
  let render = this._renderIcon;
@@ -1065,88 +1347,159 @@ var ActivityStoredAbstract = class {
1065
1347
  return (props) => render;
1066
1348
  }
1067
1349
  /**
1068
- * The function that is called when the activity is runned.
1350
+ * The function for rendering the image of the quest.
1069
1351
  */
1070
- get onRun() {
1071
- return (props) => {
1072
- return this._onRun(this, props);
1073
- };
1074
- }
1075
- /**
1076
- * Whether the activity is a deadline.
1077
- * @returns Whether the activity is a deadline.
1078
- */
1079
- isExpired() {
1080
- if (this.toDay && this.toDay <= TimeManager.currentDay) {
1081
- return true;
1352
+ get renderImage() {
1353
+ let render = this._renderImage;
1354
+ if (render === void 0) {
1355
+ return void 0;
1082
1356
  }
1083
- return false;
1357
+ if (typeof render === "function") {
1358
+ return (props) => {
1359
+ return render(this, props);
1360
+ };
1361
+ }
1362
+ return (props) => render;
1084
1363
  }
1085
- /**
1086
- * Export the activity properties.
1087
- * @returns The activity properties.
1088
- */
1089
- export() {
1090
- return {
1091
- name: this.getStorageProperty("name") || this.defaultName,
1092
- fromHour: this.getStorageProperty("fromHour") || this.defaultFromHour,
1093
- toHour: this.getStorageProperty("toHour") || this.defaultToHour,
1094
- fromDay: this.getStorageProperty("fromDay") || this.defaultFromDay,
1095
- toDay: this.getStorageProperty("toDay") || this.defaultToDay,
1096
- disabled: this.getStorageProperty("disabled") || this.defaultDisabled,
1097
- hidden: this.getStorageProperty("hidden") || this.defaultHidden,
1098
- renderIcon: this._renderIcon
1099
- };
1364
+ get isInDevelopment() {
1365
+ return this._isInDevelopment;
1100
1366
  }
1101
- };
1102
-
1103
- // src/classes/navigation/ActivityRoom.ts
1104
- var ActivityRoom = class extends ActivityStoredAbstract {
1105
- constructor(id, room, onRun, props) {
1106
- super(onRun, props);
1107
- this._id = id;
1108
- this._room = room;
1367
+ get currentStageIndex() {
1368
+ return this.getStorageProperty("currentStageIndex");
1109
1369
  }
1110
- setStorageProperty(_, __) {
1111
- this._room.setActivity(this);
1370
+ set currentStageIndex(value) {
1371
+ this.setStorageProperty("currentStageIndex", value);
1112
1372
  }
1113
- getStorageProperty(propertyName) {
1114
- let activity = this._room.getActivityMemory(this.id);
1115
- if (!activity || !activity.hasOwnProperty(propertyName)) {
1373
+ get currentStage() {
1374
+ let index = this.currentStageIndex;
1375
+ if (index === void 0 || index >= this.stages.length) {
1116
1376
  return void 0;
1117
1377
  }
1118
- return activity[propertyName];
1378
+ return this.stages[index];
1119
1379
  }
1120
- get id() {
1121
- return this._id;
1380
+ get started() {
1381
+ return this.currentStageIndex !== void 0;
1122
1382
  }
1123
- get room() {
1124
- return this._room;
1383
+ get completed() {
1384
+ return this.currentStageIndex === this.stages.length;
1125
1385
  }
1126
- export() {
1127
- let result = {};
1128
- if (this.name !== void 0) {
1129
- result["name"] = this.name;
1386
+ start(props) {
1387
+ if (this.started) {
1388
+ console.warn(`[NQTR] Quest ${this.id} is already started`);
1389
+ return;
1130
1390
  }
1131
- if (this.fromHour !== void 0) {
1132
- result["fromHour"] = this.fromHour;
1391
+ if (this.stages.length === 0) {
1392
+ console.error(`[NQTR] Quest ${this.id} has no stages`);
1393
+ return;
1133
1394
  }
1134
- if (this.toHour !== void 0) {
1135
- result["toHour"] = this.toHour;
1395
+ this.currentStageIndex = 0;
1396
+ let currentStage = this.currentStage;
1397
+ if (currentStage && currentStage.onStart) {
1398
+ return currentStage.onStart(props);
1399
+ } else {
1400
+ console.error(`[NQTR] Quest ${this.id} has no start stage`);
1136
1401
  }
1137
- if (this.fromDay !== void 0) {
1138
- result["fromDay"] = this.fromDay;
1402
+ }
1403
+ tryToGoNextStage(startProps, endProps) {
1404
+ if (!this.started) {
1405
+ return;
1139
1406
  }
1140
- if (this.toDay !== void 0) {
1141
- result["toDay"] = this.toDay;
1407
+ if (this.completed) {
1408
+ return;
1142
1409
  }
1143
- if (this.disabled !== void 0) {
1144
- result["disabled"] = this.disabled;
1410
+ let currentStage = this.currentStage;
1411
+ let currentStageIndex = this.currentStageIndex;
1412
+ if (!currentStage || currentStageIndex === void 0) {
1413
+ console.error(`[NQTR] Quest ${this.id} has no current stage`);
1414
+ return;
1415
+ }
1416
+ if (currentStage.completed) {
1417
+ let nextStageIndex = currentStageIndex + 1;
1418
+ currentStageIndex = nextStageIndex;
1419
+ let nextStage = this.currentStage;
1420
+ if (currentStage && currentStage.onEnd) {
1421
+ currentStage.onEnd(endProps);
1422
+ }
1423
+ if (nextStage && nextStage.onStart) {
1424
+ return nextStage.onStart(startProps);
1425
+ }
1145
1426
  }
1146
- return result;
1147
1427
  }
1148
1428
  };
1149
1429
 
1430
+ // src/decorators/QuestDecorator.ts
1431
+ var registeredQuests = {};
1432
+ function newQuest(id, stages, props) {
1433
+ if (registeredQuests[id]) {
1434
+ console.warn(`[NQTR] Quest ${id} already exists, it will be overwritten`);
1435
+ }
1436
+ let quest = new Quest(id, stages, props);
1437
+ registeredQuests[id] = quest;
1438
+ return quest;
1439
+ }
1440
+ function getQuestById(id) {
1441
+ try {
1442
+ let quest = registeredQuests[id];
1443
+ if (!quest) {
1444
+ console.error(`[NQTR] Quest ${id} not found`);
1445
+ return;
1446
+ }
1447
+ return quest;
1448
+ } catch (e) {
1449
+ console.error(`[NQTR] Error while getting Quest ${id}`, e);
1450
+ return;
1451
+ }
1452
+ }
1453
+
1454
+ // src/functions/RoutineFunctions.ts
1455
+ function clearExpiredRoutine() {
1456
+ Object.entries(registeredCommitments).forEach(([_, commitment]) => {
1457
+ if (commitment.isExpired()) {
1458
+ delete registeredCommitments[commitment.id];
1459
+ }
1460
+ });
1461
+ }
1462
+ function getCurrentRoutine() {
1463
+ let character_commitments = {};
1464
+ getTemporaryCommitments().reverse().forEach((c) => {
1465
+ if (!c.hidden) {
1466
+ if (c.characters.length > 0) {
1467
+ let allAvailable = c.characters.every((ch) => !character_commitments[ch.id] || c.priority > character_commitments[ch.id].priority);
1468
+ if (allAvailable) {
1469
+ c.characters.forEach((ch) => {
1470
+ character_commitments[ch.id] = c;
1471
+ });
1472
+ }
1473
+ } else {
1474
+ console.error(`[NQTR] The commitment ${c.id} has no characters assigned`);
1475
+ }
1476
+ }
1477
+ });
1478
+ getFixedRoutine().reverse().forEach((c) => {
1479
+ if (!c.hidden) {
1480
+ if (c.characters.length > 0) {
1481
+ let allAvailable = c.characters.every((ch) => !character_commitments[ch.id] || c.priority > character_commitments[ch.id].priority);
1482
+ if (allAvailable) {
1483
+ c.characters.forEach((ch) => {
1484
+ character_commitments[ch.id] = c;
1485
+ });
1486
+ }
1487
+ } else {
1488
+ console.error(`[NQTR] The commitment ${c.id} has no characters assigned`);
1489
+ }
1490
+ }
1491
+ });
1492
+ return Object.values(character_commitments);
1493
+ }
1494
+ function getCommitmentByCharacter(character) {
1495
+ getCurrentRoutine().forEach((c) => {
1496
+ if (c.characters.map((ch) => ch.id).includes(character.id)) {
1497
+ return c;
1498
+ }
1499
+ });
1500
+ return void 0;
1501
+ }
1502
+
1150
1503
  // src/classes/navigation/Room.ts
1151
1504
  var ROOM_CATEGORY = "__nqtr-room__";
1152
1505
  var RoomBaseModel = class extends pixiVn.StoredClassModel {
@@ -1383,130 +1736,6 @@ var RoomBaseModel = class extends pixiVn.StoredClassModel {
1383
1736
  return commitments.filter((c) => c.room.id === this.id);
1384
1737
  }
1385
1738
  };
1386
-
1387
- // src/classes/quest/Goal.ts
1388
- var Goal = class {
1389
- constructor(props) {
1390
- this._description = props.description;
1391
- this.need = props.need || 1;
1392
- this.have = props.have || 0;
1393
- }
1394
- get description() {
1395
- return this._description;
1396
- }
1397
- get isComplete() {
1398
- return this.have >= this.need;
1399
- }
1400
- setComplete() {
1401
- this.have = this.need;
1402
- }
1403
- find() {
1404
- this.have++;
1405
- }
1406
- get export() {
1407
- return {
1408
- description: this.description,
1409
- need: this.need,
1410
- have: this.have
1411
- };
1412
- }
1413
- };
1414
- var QUEST_CATEGORY = "__nqtr-quest__";
1415
- var QuestBaseModel = class extends pixiVn.StoredClassModel {
1416
- constructor(id, stages, props) {
1417
- super(QUEST_CATEGORY, id);
1418
- this._stages = stages;
1419
- this._name = props.name || "";
1420
- this._description = props.description || "";
1421
- this._icon = props.icon || "";
1422
- this._image = props.image || "";
1423
- this._isInDevelopment = props.isInDevelopment || false;
1424
- }
1425
- get stages() {
1426
- return this._stages;
1427
- }
1428
- get name() {
1429
- return this._name;
1430
- }
1431
- get description() {
1432
- return this._description;
1433
- }
1434
- get icon() {
1435
- return this._icon;
1436
- }
1437
- get image() {
1438
- return this._image;
1439
- }
1440
- get isInDevelopment() {
1441
- return this._isInDevelopment;
1442
- }
1443
- };
1444
- var STAGE_CATEGORY = "__nqtr-stage__";
1445
- var StageBaseModel = class extends pixiVn.StoredClassModel {
1446
- constructor(id, props) {
1447
- super(STAGE_CATEGORY, id);
1448
- this._completed = false;
1449
- this._active = false;
1450
- this.defaultGoals = [];
1451
- this._name = props.name || "";
1452
- this._description = props.description || "";
1453
- this._adviceDescription = props.adviceDescription || "";
1454
- this._image = props.image || "";
1455
- this._daysRequiredToStart = props.daysRequiredToStart;
1456
- this._flagsRequired = props.flagsRequired;
1457
- this._questsRequired = props.questsRequired;
1458
- this._requestDescription = props.requestDescription || "";
1459
- this._onStart = props.onStart;
1460
- this._onEnd = props.onEnd;
1461
- }
1462
- get completed() {
1463
- return this._completed;
1464
- }
1465
- get active() {
1466
- return this._active;
1467
- }
1468
- get goals() {
1469
- let list = this.getStorageProperty("goals");
1470
- if (!list) {
1471
- return this.defaultGoals;
1472
- }
1473
- return list.map((goal) => new Goal(goal));
1474
- }
1475
- set goals(value) {
1476
- let list = value.map((goal) => goal.export);
1477
- this.setStorageProperty("goals", list);
1478
- }
1479
- get name() {
1480
- return this._name;
1481
- }
1482
- get description() {
1483
- return this._description;
1484
- }
1485
- get adviceDescription() {
1486
- return this._adviceDescription;
1487
- }
1488
- get image() {
1489
- return this._image;
1490
- }
1491
- get daysRequiredToStart() {
1492
- return this._daysRequiredToStart;
1493
- }
1494
- get flagsRequired() {
1495
- return this._flagsRequired;
1496
- }
1497
- get questsRequired() {
1498
- return this._questsRequired;
1499
- }
1500
- get requestDescription() {
1501
- return this._requestDescription;
1502
- }
1503
- get onStart() {
1504
- return this._onStart;
1505
- }
1506
- get onEnd() {
1507
- return this._onEnd;
1508
- }
1509
- };
1510
1739
  var CURRENT_ROOM_MEMORY_KEY = "___nqtr-current_room_memory___";
1511
1740
  function setCurrentRoom(room) {
1512
1741
  if (room instanceof LocationBaseModel) {
@@ -1568,13 +1797,13 @@ function currentActivities() {
1568
1797
  }
1569
1798
 
1570
1799
  exports.ActivityModel = ActivityModel;
1800
+ exports.ActivityRoom = ActivityRoom;
1571
1801
  exports.CommitmentBaseModel = CommitmentBaseModel;
1572
1802
  exports.Goal = Goal;
1573
1803
  exports.LocationBaseModel = LocationBaseModel;
1574
1804
  exports.MapBaseModel = MapBaseModel;
1575
- exports.QuestBaseModel = QuestBaseModel;
1576
1805
  exports.RoomBaseModel = RoomBaseModel;
1577
- exports.StageBaseModel = StageBaseModel;
1806
+ exports.Stage = Stage;
1578
1807
  exports.TimeManager = TimeManager;
1579
1808
  exports.addCommitment = addCommitment;
1580
1809
  exports.clearExpiredActivities = clearExpiredActivities;
@@ -1589,7 +1818,10 @@ exports.getCueerntMap = getCueerntMap;
1589
1818
  exports.getCurrenrLocation = getCurrenrLocation;
1590
1819
  exports.getCurrentRoom = getCurrentRoom;
1591
1820
  exports.getCurrentRoutine = getCurrentRoutine;
1821
+ exports.getQuestById = getQuestById;
1592
1822
  exports.getRoomById = getRoomById;
1823
+ exports.newQuest = newQuest;
1824
+ exports.removeCommitment = removeCommitment;
1593
1825
  exports.saveActivity = saveActivity;
1594
1826
  exports.saveCommitment = saveCommitment;
1595
1827
  exports.saveRoom = saveRoom;