@drincs/nqtr 0.1.20 → 0.2.1
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.
- package/dist/{ActivityProps-_79x9-BX.d.ts → ActivityProps-BkHX8xkA.d.ts} +1 -1
- package/dist/{ActivityProps-BoJeWa2B.d.mts → ActivityProps-D45DQdcT.d.mts} +1 -1
- package/dist/{Commitment-Cc2kZEy0.d.ts → Commitment-BJTIpBQ5.d.ts} +4 -2
- package/dist/{Commitment-C3Nc2RJH.d.mts → Commitment-CtNWnNQX.d.mts} +4 -2
- package/dist/{Quest-BQ1pwvQ_.d.ts → StageProps-BFsiCaZT.d.ts} +160 -81
- package/dist/{Quest-DaNlPBHb.d.mts → StageProps-CkXejAbn.d.mts} +160 -81
- package/dist/classes/Activity.d.mts +2 -2
- package/dist/classes/Activity.d.ts +2 -2
- package/dist/classes/Activity.js +1 -1
- package/dist/classes/Activity.js.map +1 -1
- package/dist/classes/Activity.mjs +1 -1
- package/dist/classes/Activity.mjs.map +1 -1
- package/dist/classes/ActivityStoredAbstract.d.mts +1 -1
- package/dist/classes/ActivityStoredAbstract.d.ts +1 -1
- package/dist/classes/ActivityStoredAbstract.js +1 -1
- package/dist/classes/ActivityStoredAbstract.js.map +1 -1
- package/dist/classes/ActivityStoredAbstract.mjs +1 -1
- package/dist/classes/ActivityStoredAbstract.mjs.map +1 -1
- package/dist/classes/Commitment.d.mts +2 -2
- package/dist/classes/Commitment.d.ts +2 -2
- package/dist/classes/Commitment.js +2 -2
- package/dist/classes/Commitment.js.map +1 -1
- package/dist/classes/Commitment.mjs +2 -2
- package/dist/classes/Commitment.mjs.map +1 -1
- package/dist/classes/index.d.mts +3 -3
- package/dist/classes/index.d.ts +3 -3
- package/dist/classes/index.js +133 -318
- package/dist/classes/index.js.map +1 -1
- package/dist/classes/index.mjs +134 -318
- package/dist/classes/index.mjs.map +1 -1
- package/dist/classes/navigation/ActivityRoom.d.mts +2 -2
- package/dist/classes/navigation/ActivityRoom.d.ts +2 -2
- package/dist/classes/navigation/ActivityRoom.js +1 -1
- package/dist/classes/navigation/ActivityRoom.js.map +1 -1
- package/dist/classes/navigation/ActivityRoom.mjs +1 -1
- package/dist/classes/navigation/ActivityRoom.mjs.map +1 -1
- package/dist/classes/navigation/Location.d.mts +2 -2
- package/dist/classes/navigation/Location.d.ts +2 -2
- package/dist/classes/navigation/Map.d.mts +2 -2
- package/dist/classes/navigation/Map.d.ts +2 -2
- package/dist/classes/navigation/Room.d.mts +2 -2
- package/dist/classes/navigation/Room.d.ts +2 -2
- package/dist/classes/navigation/Room.js +34 -36
- package/dist/classes/navigation/Room.js.map +1 -1
- package/dist/classes/navigation/Room.mjs +34 -36
- package/dist/classes/navigation/Room.mjs.map +1 -1
- package/dist/classes/quest/Goal.d.mts +18 -0
- package/dist/classes/quest/Goal.d.ts +18 -0
- package/dist/classes/quest/Goal.js +18 -0
- package/dist/classes/quest/Goal.js.map +1 -1
- package/dist/classes/quest/Goal.mjs +18 -0
- package/dist/classes/quest/Goal.mjs.map +1 -1
- package/dist/classes/quest/Quest.d.mts +1 -1
- package/dist/classes/quest/Quest.d.ts +1 -1
- package/dist/classes/quest/Quest.js +107 -8
- package/dist/classes/quest/Quest.js.map +1 -1
- package/dist/classes/quest/Quest.mjs +107 -8
- package/dist/classes/quest/Quest.mjs.map +1 -1
- package/dist/classes/quest/Stage.d.mts +1 -1
- package/dist/classes/quest/Stage.d.ts +1 -1
- package/dist/classes/quest/Stage.js +62 -0
- package/dist/classes/quest/Stage.js.map +1 -1
- package/dist/classes/quest/Stage.mjs +62 -0
- package/dist/classes/quest/Stage.mjs.map +1 -1
- package/dist/decorators/ActivityDecorator.d.mts +1 -1
- package/dist/decorators/ActivityDecorator.d.ts +1 -1
- package/dist/decorators/CommitmentDecorator.d.mts +9 -3
- package/dist/decorators/CommitmentDecorator.d.ts +9 -3
- package/dist/decorators/CommitmentDecorator.js +16 -1
- package/dist/decorators/CommitmentDecorator.js.map +1 -1
- package/dist/decorators/CommitmentDecorator.mjs +16 -2
- package/dist/decorators/CommitmentDecorator.mjs.map +1 -1
- package/dist/decorators/QuestDecorator.d.mts +8 -10
- package/dist/decorators/QuestDecorator.d.ts +8 -10
- package/dist/decorators/QuestDecorator.js +667 -9
- package/dist/decorators/QuestDecorator.js.map +1 -1
- package/dist/decorators/QuestDecorator.mjs +667 -9
- package/dist/decorators/QuestDecorator.mjs.map +1 -1
- package/dist/decorators/RoomDecorator.d.mts +2 -2
- package/dist/decorators/RoomDecorator.d.ts +2 -2
- package/dist/decorators/index.d.mts +5 -5
- package/dist/decorators/index.d.ts +5 -5
- package/dist/decorators/index.js +679 -10
- package/dist/decorators/index.js.map +1 -1
- package/dist/decorators/index.mjs +679 -11
- package/dist/decorators/index.mjs.map +1 -1
- package/dist/functions/ActivityFunctions.d.mts +2 -2
- package/dist/functions/ActivityFunctions.d.ts +2 -2
- package/dist/functions/ActivityFunctions.js.map +1 -1
- package/dist/functions/ActivityFunctions.mjs.map +1 -1
- package/dist/functions/NavigationFunctions.d.mts +2 -2
- package/dist/functions/NavigationFunctions.d.ts +2 -2
- package/dist/functions/NavigationFunctions.js.map +1 -1
- package/dist/functions/NavigationFunctions.mjs.map +1 -1
- package/dist/functions/RoutineFunctions.d.mts +2 -2
- package/dist/functions/RoutineFunctions.d.ts +2 -2
- package/dist/functions/RoutineFunctions.js.map +1 -1
- package/dist/functions/RoutineFunctions.mjs.map +1 -1
- package/dist/functions/index.d.mts +2 -2
- package/dist/functions/index.d.ts +2 -2
- package/dist/functions/index.js.map +1 -1
- package/dist/functions/index.mjs.map +1 -1
- package/dist/index.d.mts +5 -5
- package/dist/index.d.ts +5 -5
- package/dist/index.js +505 -392
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +504 -391
- package/dist/index.mjs.map +1 -1
- package/dist/interface/ActivityProps.d.mts +1 -1
- package/dist/interface/ActivityProps.d.ts +1 -1
- package/dist/interface/CommitmentProps.d.mts +2 -2
- package/dist/interface/CommitmentProps.d.ts +2 -2
- package/dist/interface/RoomActivityMemory.d.mts +1 -1
- package/dist/interface/RoomActivityMemory.d.ts +1 -1
- package/dist/interface/RoomProps.d.mts +2 -2
- package/dist/interface/RoomProps.d.ts +2 -2
- package/dist/interface/index.d.mts +3 -3
- package/dist/interface/index.d.ts +3 -3
- package/dist/interface/navigation/LocationProps.d.mts +2 -2
- package/dist/interface/navigation/LocationProps.d.ts +2 -2
- package/dist/interface/navigation/MapProps.d.mts +2 -2
- package/dist/interface/navigation/MapProps.d.ts +2 -2
- package/dist/interface/quest/QuestProps.d.mts +1 -1
- package/dist/interface/quest/QuestProps.d.ts +1 -1
- package/dist/interface/quest/StageProps.d.mts +1 -1
- package/dist/interface/quest/StageProps.d.ts +1 -1
- package/dist/types/QuestsRequired.d.mts +1 -1
- package/dist/types/QuestsRequired.d.ts +1 -1
- package/dist/types/index.d.mts +1 -1
- package/dist/types/index.d.ts +1 -1
- package/package.json +2 -2
|
@@ -1,16 +1,674 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
var pixiVn = require('@drincs/pixi-vn');
|
|
4
|
+
|
|
5
|
+
// src/classes/quest/Quest.ts
|
|
6
|
+
var TIME_SETTINGS_KEY = "___nqtr-time_manager_settings___";
|
|
7
|
+
var TIME_DATA_KEY = "___nqtr-time_manager_data___";
|
|
8
|
+
var TimeManager = class _TimeManager {
|
|
9
|
+
constructor() {
|
|
10
|
+
}
|
|
11
|
+
static editSettings(settings) {
|
|
12
|
+
let data = {};
|
|
13
|
+
if (typeof settings.minDayHours === "number") {
|
|
14
|
+
data["minDayHours"] = settings.minDayHours;
|
|
15
|
+
}
|
|
16
|
+
if (typeof settings.maxDayHours === "number") {
|
|
17
|
+
data["maxDayHours"] = settings.maxDayHours;
|
|
18
|
+
}
|
|
19
|
+
if (typeof settings.minDayHours === "number") {
|
|
20
|
+
data["defaultTimeSpent"] = settings.defaultTimeSpent;
|
|
21
|
+
}
|
|
22
|
+
if (Array.isArray(settings.timeSlots)) {
|
|
23
|
+
data["timeSlots"] = settings.timeSlots;
|
|
24
|
+
}
|
|
25
|
+
if (typeof settings.weekLength === "number") {
|
|
26
|
+
data["weekLength"] = settings.weekLength;
|
|
27
|
+
}
|
|
28
|
+
if (typeof settings.weekendStartDay === "number") {
|
|
29
|
+
let weekLength = settings.weekLength || _TimeManager.weekLength;
|
|
30
|
+
if (settings.weekendStartDay >= weekLength) {
|
|
31
|
+
console.warn(`[NQTR] Weekend start day should be less than week length ${weekLength}`);
|
|
32
|
+
}
|
|
33
|
+
data["weekendStartDay"] = settings.weekendStartDay;
|
|
34
|
+
}
|
|
35
|
+
if (Array.isArray(settings.weekDaysNames)) {
|
|
36
|
+
let weekLength = settings.weekLength || _TimeManager.weekLength;
|
|
37
|
+
if (settings.weekDaysNames.length !== weekLength) {
|
|
38
|
+
console.warn(`[NQTR] Week days names should be equal to week length ${weekLength}`);
|
|
39
|
+
}
|
|
40
|
+
data["weekDaysNames"] = settings.weekDaysNames;
|
|
41
|
+
}
|
|
42
|
+
pixiVn.GameStorageManager.setVariable(TIME_SETTINGS_KEY, data);
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Get time settings
|
|
46
|
+
* @default {}
|
|
47
|
+
*/
|
|
48
|
+
static get settings() {
|
|
49
|
+
let settings = pixiVn.GameStorageManager.getVariable(TIME_SETTINGS_KEY) || {};
|
|
50
|
+
return settings;
|
|
51
|
+
}
|
|
52
|
+
/**
|
|
53
|
+
* Set time settings, Is very important to set the settings before using the nqtr library, bacause more of the features are based on the time settings.
|
|
54
|
+
*/
|
|
55
|
+
static set settings(value) {
|
|
56
|
+
_TimeManager.editSettings(value);
|
|
57
|
+
}
|
|
58
|
+
static get minDayHours() {
|
|
59
|
+
let result = 0;
|
|
60
|
+
let settings = pixiVn.GameStorageManager.getVariable(TIME_SETTINGS_KEY);
|
|
61
|
+
if (settings && settings.hasOwnProperty("minDayHours")) {
|
|
62
|
+
result = settings.minDayHours || 0;
|
|
63
|
+
}
|
|
64
|
+
return result;
|
|
65
|
+
}
|
|
66
|
+
static get maxDayHours() {
|
|
67
|
+
let result = 24;
|
|
68
|
+
let settings = pixiVn.GameStorageManager.getVariable(TIME_SETTINGS_KEY);
|
|
69
|
+
if (settings && settings.hasOwnProperty("maxDayHours")) {
|
|
70
|
+
result = settings.maxDayHours || 24;
|
|
71
|
+
}
|
|
72
|
+
return result;
|
|
73
|
+
}
|
|
74
|
+
static get defaultTimeSpent() {
|
|
75
|
+
let result = 1;
|
|
76
|
+
let settings = pixiVn.GameStorageManager.getVariable(TIME_SETTINGS_KEY);
|
|
77
|
+
if (settings && settings.hasOwnProperty("defaultTimeSpent")) {
|
|
78
|
+
result = settings.defaultTimeSpent || 1;
|
|
79
|
+
}
|
|
80
|
+
return result;
|
|
81
|
+
}
|
|
82
|
+
static get timeSlots() {
|
|
83
|
+
let result = [];
|
|
84
|
+
let settings = pixiVn.GameStorageManager.getVariable(TIME_SETTINGS_KEY);
|
|
85
|
+
if (settings && settings.hasOwnProperty("timeSlots")) {
|
|
86
|
+
result = settings.timeSlots || [];
|
|
87
|
+
}
|
|
88
|
+
return result;
|
|
89
|
+
}
|
|
90
|
+
static get weekLength() {
|
|
91
|
+
let result = 7;
|
|
92
|
+
let settings = pixiVn.GameStorageManager.getVariable(TIME_SETTINGS_KEY);
|
|
93
|
+
if (settings && settings.hasOwnProperty("weekLength")) {
|
|
94
|
+
result = settings.weekLength || 7;
|
|
95
|
+
}
|
|
96
|
+
return result;
|
|
97
|
+
}
|
|
98
|
+
static get weekendStartDay() {
|
|
99
|
+
let result = _TimeManager.weekLength - 1;
|
|
100
|
+
let settings = pixiVn.GameStorageManager.getVariable(TIME_SETTINGS_KEY);
|
|
101
|
+
if (settings && settings.hasOwnProperty("weekendStartDay")) {
|
|
102
|
+
result = settings.weekendStartDay || _TimeManager.weekLength - 1;
|
|
103
|
+
}
|
|
104
|
+
return result;
|
|
105
|
+
}
|
|
106
|
+
static get weekDaysNames() {
|
|
107
|
+
let result = [];
|
|
108
|
+
let settings = pixiVn.GameStorageManager.getVariable(TIME_SETTINGS_KEY);
|
|
109
|
+
if (settings && settings.hasOwnProperty("weekDaysNames")) {
|
|
110
|
+
result = settings.weekDaysNames || result;
|
|
111
|
+
}
|
|
112
|
+
return result;
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Get the current hour
|
|
116
|
+
*/
|
|
117
|
+
static get currentHour() {
|
|
118
|
+
let data = pixiVn.GameStorageManager.getVariable(TIME_DATA_KEY) || {};
|
|
119
|
+
if (data.hasOwnProperty("currentHour") && typeof data.currentHour === "number") {
|
|
120
|
+
return data.currentHour;
|
|
121
|
+
}
|
|
122
|
+
return _TimeManager.minDayHours;
|
|
123
|
+
}
|
|
124
|
+
static set currentHour(value) {
|
|
125
|
+
let data = pixiVn.GameStorageManager.getVariable(TIME_DATA_KEY) || {};
|
|
126
|
+
if (typeof value === "number") {
|
|
127
|
+
data.currentHour = value;
|
|
128
|
+
} else {
|
|
129
|
+
delete data.currentHour;
|
|
130
|
+
}
|
|
131
|
+
pixiVn.GameStorageManager.setVariable(TIME_DATA_KEY, data);
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Get the current day
|
|
135
|
+
*/
|
|
136
|
+
static get currentDay() {
|
|
137
|
+
let data = pixiVn.GameStorageManager.getVariable(TIME_DATA_KEY) || {};
|
|
138
|
+
if (data.hasOwnProperty("currentDay") && typeof data.currentDay === "number") {
|
|
139
|
+
return data.currentDay;
|
|
140
|
+
}
|
|
141
|
+
return 0;
|
|
142
|
+
}
|
|
143
|
+
static set currentDay(value) {
|
|
144
|
+
let data = pixiVn.GameStorageManager.getVariable(TIME_DATA_KEY) || {};
|
|
145
|
+
if (typeof value === "number") {
|
|
146
|
+
data.currentDay = value;
|
|
147
|
+
} else {
|
|
148
|
+
delete data.currentDay;
|
|
149
|
+
}
|
|
150
|
+
pixiVn.GameStorageManager.setVariable(TIME_DATA_KEY, data);
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
* If the current day is greater than or equal to the weekend start day, then it will return true.
|
|
154
|
+
*/
|
|
155
|
+
static get isWeekend() {
|
|
156
|
+
return _TimeManager.currentWeekDayNumber >= _TimeManager.weekendStartDay;
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Get the current week day number (1-TimeManager.weekLength).
|
|
160
|
+
* For example, if the week length is 7 and the current day is 10, then the result will be 4.
|
|
161
|
+
*/
|
|
162
|
+
static get currentWeekDayNumber() {
|
|
163
|
+
let result = _TimeManager.currentDay % _TimeManager.weekLength;
|
|
164
|
+
return result + 1;
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Get the current week day name. If the week days names are not defined, then it will return undefined.
|
|
168
|
+
* For example, if the week days names are ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'] and the current day is 10, then the result will be 'Thursday'.
|
|
169
|
+
* @default ""
|
|
170
|
+
*/
|
|
171
|
+
static get currentDayName() {
|
|
172
|
+
let weekDayNumber = _TimeManager.currentWeekDayNumber - 1;
|
|
173
|
+
if (weekDayNumber >= _TimeManager.weekDaysNames.length) {
|
|
174
|
+
console.warn(`[NQTR] Week day name is not defined for day ${weekDayNumber}`, _TimeManager.weekDaysNames);
|
|
175
|
+
return "";
|
|
176
|
+
}
|
|
177
|
+
return _TimeManager.weekDaysNames[weekDayNumber];
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Get the current TimeManager.timeSlots index.
|
|
181
|
+
* You can use this property to create "Image that changes based on the time period":
|
|
182
|
+
* @example
|
|
183
|
+
* ```tsx
|
|
184
|
+
* import { TimeManager } from '@drincs/nqtr';
|
|
185
|
+
*
|
|
186
|
+
* function changeBackground() {
|
|
187
|
+
* return (
|
|
188
|
+
* <img src={`background-${TimeManager.currentTimeSlot}.png`} />
|
|
189
|
+
* )
|
|
190
|
+
* }
|
|
191
|
+
*/
|
|
192
|
+
static get currentTimeSlot() {
|
|
193
|
+
if (_TimeManager.timeSlots.length === 0) {
|
|
194
|
+
console.warn("[NQTR] Time slots are not defined");
|
|
195
|
+
return 0;
|
|
196
|
+
}
|
|
197
|
+
for (let index = 0; index < _TimeManager.timeSlots.length; index++) {
|
|
198
|
+
let slot = _TimeManager.timeSlots[index];
|
|
199
|
+
if (_TimeManager.timeSlots.length > index + 1) {
|
|
200
|
+
if (_TimeManager.nowIsBetween(slot.startHour, _TimeManager.timeSlots[index + 1].startHour)) {
|
|
201
|
+
return index;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
return _TimeManager.timeSlots.length - 1;
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* This function will increase the current hour by the given time spent.
|
|
209
|
+
* If the new hour is greater than or equal to the max day hours, then it will increase the day and set the new hour.
|
|
210
|
+
* @param timeSpent is the time spent in hours (default: TimeManager.defaultTimeSpent)
|
|
211
|
+
* @returns TimeManager.currentHour
|
|
212
|
+
*/
|
|
213
|
+
static increaseHour(timeSpent = _TimeManager.defaultTimeSpent) {
|
|
214
|
+
let newHour = _TimeManager.currentHour + timeSpent;
|
|
215
|
+
if (newHour >= _TimeManager.maxDayHours) {
|
|
216
|
+
_TimeManager.increaseDay();
|
|
217
|
+
newHour = _TimeManager.minDayHours + (newHour - _TimeManager.maxDayHours);
|
|
218
|
+
}
|
|
219
|
+
_TimeManager.currentHour = newHour;
|
|
220
|
+
return _TimeManager.currentHour;
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
223
|
+
* This function will increase the current day by the given days.
|
|
224
|
+
* @param newDayHour is the hour of the new day (default: TimeManager.minDayHours)
|
|
225
|
+
* @param days is the number of days to increase (default: 1)
|
|
226
|
+
* @returns TimeManager.currentDay
|
|
227
|
+
*/
|
|
228
|
+
static increaseDay(newDayHour = _TimeManager.minDayHours, days = 1) {
|
|
229
|
+
let newDay = _TimeManager.currentDay + days;
|
|
230
|
+
_TimeManager.currentDay = newDay;
|
|
231
|
+
_TimeManager.currentHour = newDayHour;
|
|
232
|
+
return _TimeManager.currentDay;
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* This function will check if the current hour is between the given hours.
|
|
236
|
+
* @param fromHour the starting hour. If the TimeManager.currentHour is equal to this hour, the function will return true.
|
|
237
|
+
* @param toHour the ending hour.
|
|
238
|
+
* @returns true if the current hour is between the given hours, otherwise false.
|
|
239
|
+
*/
|
|
240
|
+
static nowIsBetween(fromHour, toHour) {
|
|
241
|
+
let currentHour = _TimeManager.currentHour;
|
|
242
|
+
if (fromHour < toHour) {
|
|
243
|
+
return currentHour >= fromHour && currentHour < toHour;
|
|
244
|
+
}
|
|
245
|
+
return currentHour >= fromHour || currentHour < toHour;
|
|
246
|
+
}
|
|
247
|
+
};
|
|
248
|
+
var GOAL_CATEGORY = "__nqtr-goal__";
|
|
249
|
+
var Goal = class extends pixiVn.StoredClassModel {
|
|
250
|
+
constructor(id, props) {
|
|
251
|
+
super(GOAL_CATEGORY, id);
|
|
252
|
+
this._description = props.description;
|
|
253
|
+
this._need = props.need || 1;
|
|
254
|
+
this._defaultHave = props.have || 0;
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* The description of the goal.
|
|
258
|
+
*/
|
|
259
|
+
get description() {
|
|
260
|
+
return this._description;
|
|
261
|
+
}
|
|
262
|
+
/**
|
|
263
|
+
* The number of times the goal must be completed.
|
|
264
|
+
*/
|
|
265
|
+
get need() {
|
|
266
|
+
return this._need;
|
|
267
|
+
}
|
|
268
|
+
/**
|
|
269
|
+
* The default number of times the goal has been completed.
|
|
270
|
+
*/
|
|
271
|
+
get defaultHave() {
|
|
272
|
+
return this._defaultHave;
|
|
273
|
+
}
|
|
274
|
+
};
|
|
275
|
+
var GoalStage = class extends Goal {
|
|
276
|
+
constructor(id, stageId, props) {
|
|
277
|
+
super(id, props);
|
|
278
|
+
this._stageId = stageId;
|
|
279
|
+
}
|
|
280
|
+
/**
|
|
281
|
+
* The id of the stage that the goal belongs to.
|
|
282
|
+
*/
|
|
283
|
+
get stageId() {
|
|
284
|
+
return this._stageId;
|
|
285
|
+
}
|
|
286
|
+
set stageId(value) {
|
|
287
|
+
this._stageId = value;
|
|
288
|
+
}
|
|
289
|
+
/**
|
|
290
|
+
* The number of times the goal has been completed.
|
|
291
|
+
*/
|
|
292
|
+
get have() {
|
|
293
|
+
return this.getStorageProperty("have-" + this._stageId) || this.defaultHave;
|
|
294
|
+
}
|
|
295
|
+
set have(value) {
|
|
296
|
+
if (!this._stageId) {
|
|
297
|
+
console.error(`[NQTR] The stage id is not set for the goal ${this.id}, so the have value can't be set.`);
|
|
298
|
+
return;
|
|
299
|
+
}
|
|
300
|
+
this.setStorageProperty("have-" + this._stageId, value);
|
|
301
|
+
}
|
|
302
|
+
/**
|
|
303
|
+
* If the goal is completed.
|
|
304
|
+
*/
|
|
305
|
+
get completed() {
|
|
306
|
+
return this.have >= this.need;
|
|
307
|
+
}
|
|
308
|
+
set completed(value) {
|
|
309
|
+
if (value) {
|
|
310
|
+
this.have = this.need;
|
|
311
|
+
} else {
|
|
312
|
+
console.warn(`[NQTR] The goal can't be set as not completed. You must edit the have value manually.`);
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
/**
|
|
316
|
+
* Find the goal. It will increment the have value.
|
|
317
|
+
*/
|
|
318
|
+
find() {
|
|
319
|
+
this.have++;
|
|
320
|
+
}
|
|
321
|
+
};
|
|
322
|
+
|
|
323
|
+
// src/classes/quest/Stage.ts
|
|
324
|
+
var STAGE_CATEGORY = "__nqtr-stage__";
|
|
325
|
+
var Stage = class extends pixiVn.StoredClassModel {
|
|
326
|
+
constructor(id, props) {
|
|
327
|
+
super(STAGE_CATEGORY, id);
|
|
328
|
+
this._name = props.name || "";
|
|
329
|
+
this._defaultGoals = props.goals || [];
|
|
330
|
+
this._flags = props.flags || [];
|
|
331
|
+
this._description = props.description || "";
|
|
332
|
+
this._adviceDescription = props.adviceDescription || "";
|
|
333
|
+
this._renderImage = props.renderImage;
|
|
334
|
+
this._daysRequiredToStart = props.daysRequiredToStart;
|
|
335
|
+
this._flagsRequiredToStart = props.flagsRequired || [];
|
|
336
|
+
this._questsRequiredToStart = props.questsRequired || [];
|
|
337
|
+
this._requestDescriptionToStart = props.requestDescription || "";
|
|
338
|
+
this._onStart = props.onStart;
|
|
339
|
+
this._onEnd = props.onEnd;
|
|
340
|
+
}
|
|
341
|
+
/**
|
|
342
|
+
* The name of the stage.
|
|
343
|
+
*/
|
|
344
|
+
get name() {
|
|
345
|
+
return this._name;
|
|
346
|
+
}
|
|
347
|
+
/**
|
|
348
|
+
* The description of the stage.
|
|
349
|
+
*/
|
|
350
|
+
get description() {
|
|
351
|
+
return this._description;
|
|
352
|
+
}
|
|
353
|
+
/**
|
|
354
|
+
* The advice description of the stage.
|
|
355
|
+
*/
|
|
356
|
+
get adviceDescription() {
|
|
357
|
+
return this._adviceDescription;
|
|
358
|
+
}
|
|
359
|
+
/**
|
|
360
|
+
* The function for rendering the image of the stage.
|
|
361
|
+
*/
|
|
362
|
+
get renderImage() {
|
|
363
|
+
let render = this._renderImage;
|
|
364
|
+
if (render === void 0) {
|
|
365
|
+
return void 0;
|
|
366
|
+
}
|
|
367
|
+
if (typeof render === "function") {
|
|
368
|
+
return (props) => {
|
|
369
|
+
return render(this, props);
|
|
370
|
+
};
|
|
371
|
+
}
|
|
372
|
+
return (props) => render;
|
|
373
|
+
}
|
|
374
|
+
/**
|
|
375
|
+
* The list of goals that the player needs to complete to finish the stage.
|
|
376
|
+
* This is the list set by the developer. if you want to get the current goals, use the goals property.
|
|
377
|
+
*/
|
|
378
|
+
get defaultGoals() {
|
|
379
|
+
return this._defaultGoals;
|
|
380
|
+
}
|
|
381
|
+
/**
|
|
382
|
+
* The list of flags that the player must complete to finish the stage.
|
|
383
|
+
*/
|
|
384
|
+
get flags() {
|
|
385
|
+
return this._flags;
|
|
386
|
+
}
|
|
387
|
+
/**
|
|
388
|
+
* The number of days required to start the stage.
|
|
389
|
+
*/
|
|
390
|
+
get daysRequiredToStart() {
|
|
391
|
+
return this._daysRequiredToStart || 0;
|
|
392
|
+
}
|
|
393
|
+
/**
|
|
394
|
+
* The list of flags required to start the stage.
|
|
395
|
+
*/
|
|
396
|
+
get flagsRequiredToStart() {
|
|
397
|
+
return this._flagsRequiredToStart;
|
|
398
|
+
}
|
|
399
|
+
/**
|
|
400
|
+
* The list of quests required to start the stage.
|
|
401
|
+
*/
|
|
402
|
+
get questsRequiredToStart() {
|
|
403
|
+
return this._questsRequiredToStart || [];
|
|
404
|
+
}
|
|
405
|
+
/**
|
|
406
|
+
* The description of the request to start the stage.
|
|
407
|
+
*/
|
|
408
|
+
get requestDescriptionToStart() {
|
|
409
|
+
return this._requestDescriptionToStart;
|
|
410
|
+
}
|
|
411
|
+
/**
|
|
412
|
+
* The function that will be called when the stage starts.
|
|
413
|
+
*/
|
|
414
|
+
get onStart() {
|
|
415
|
+
return this._onStart;
|
|
416
|
+
}
|
|
417
|
+
/**
|
|
418
|
+
* The function that will be called when the stage ends.
|
|
419
|
+
*/
|
|
420
|
+
get onEnd() {
|
|
421
|
+
return this._onEnd;
|
|
422
|
+
}
|
|
423
|
+
};
|
|
424
|
+
var StageQuest = class extends Stage {
|
|
425
|
+
constructor(id, props) {
|
|
426
|
+
super(id, props);
|
|
427
|
+
}
|
|
428
|
+
/**
|
|
429
|
+
* Check if the flag and goals are completed.
|
|
430
|
+
* You can force the completion of the stage by setting the completed property to true.
|
|
431
|
+
*/
|
|
432
|
+
get completed() {
|
|
433
|
+
let storedCompleted = this.getStorageProperty("completed");
|
|
434
|
+
if (storedCompleted) {
|
|
435
|
+
return storedCompleted;
|
|
436
|
+
}
|
|
437
|
+
if (!this.flags.every((flag) => pixiVn.getFlag(flag.flag))) {
|
|
438
|
+
return false;
|
|
439
|
+
}
|
|
440
|
+
if (!this.goals.every((goal) => goal.completed)) {
|
|
441
|
+
return false;
|
|
442
|
+
}
|
|
443
|
+
return true;
|
|
444
|
+
}
|
|
445
|
+
set completed(value) {
|
|
446
|
+
this.setStorageProperty("completed", value);
|
|
447
|
+
}
|
|
448
|
+
/**
|
|
449
|
+
* The list of goals that the player needs to complete to finish the stage.
|
|
450
|
+
*/
|
|
451
|
+
get goals() {
|
|
452
|
+
return this.defaultGoals.map((goal) => {
|
|
453
|
+
return new GoalStage(goal.id, this.id, goal);
|
|
454
|
+
});
|
|
455
|
+
}
|
|
456
|
+
get prevStageEndDay() {
|
|
457
|
+
return this.getStorageProperty("prevStageEndDay");
|
|
458
|
+
}
|
|
459
|
+
set prevStageEndDay(value) {
|
|
460
|
+
this.setStorageProperty("prevStageEndDay", value);
|
|
461
|
+
}
|
|
462
|
+
/**
|
|
463
|
+
* The day when the stage starts.
|
|
464
|
+
*/
|
|
465
|
+
get startDay() {
|
|
466
|
+
let prevStageEndDay = this.prevStageEndDay;
|
|
467
|
+
if (prevStageEndDay === void 0) {
|
|
468
|
+
return void 0;
|
|
469
|
+
}
|
|
470
|
+
return prevStageEndDay + this.daysRequiredToStart;
|
|
471
|
+
}
|
|
472
|
+
/**
|
|
473
|
+
* Check if the stage can start.
|
|
474
|
+
*/
|
|
475
|
+
get canStart() {
|
|
476
|
+
let daysRequired = this.daysRequiredToStart;
|
|
477
|
+
if (daysRequired > 0) {
|
|
478
|
+
let prevStageEndDay = this.prevStageEndDay;
|
|
479
|
+
if (prevStageEndDay === void 0) {
|
|
480
|
+
return false;
|
|
481
|
+
}
|
|
482
|
+
if (prevStageEndDay + daysRequired > TimeManager.currentDay) {
|
|
483
|
+
return false;
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
if (this.flagsRequiredToStart.length > 0 && !this.flagsRequiredToStart.every((flag) => pixiVn.getFlag(flag.flag))) {
|
|
487
|
+
return false;
|
|
488
|
+
}
|
|
489
|
+
if (this.questsRequiredToStart.length > 0 && !this.questsRequiredToStart.every(
|
|
490
|
+
(q) => q.quest.currentStageIndex && q.quest.currentStageIndex >= q.stageNumber
|
|
491
|
+
)) {
|
|
492
|
+
return false;
|
|
493
|
+
}
|
|
494
|
+
return true;
|
|
495
|
+
}
|
|
496
|
+
/**
|
|
497
|
+
* The function that will be called when the stage starts.
|
|
498
|
+
*/
|
|
499
|
+
get onStart() {
|
|
500
|
+
if (this.daysRequiredToStart > 0) {
|
|
501
|
+
this.prevStageEndDay = TimeManager.currentDay;
|
|
502
|
+
}
|
|
503
|
+
return super.onStart;
|
|
504
|
+
}
|
|
505
|
+
};
|
|
506
|
+
|
|
507
|
+
// src/classes/quest/Quest.ts
|
|
508
|
+
var QUEST_CATEGORY = "__nqtr-quest__";
|
|
509
|
+
var Quest = class extends pixiVn.StoredClassModel {
|
|
510
|
+
constructor(id, stages, props) {
|
|
511
|
+
super(QUEST_CATEGORY, id);
|
|
512
|
+
this._stages = stages;
|
|
513
|
+
this._name = props.name || "";
|
|
514
|
+
this._description = props.description || "";
|
|
515
|
+
this._renderIcon = props.renderIcon;
|
|
516
|
+
this._renderImage = props.renderImage;
|
|
517
|
+
this._isInDevelopment = props.isInDevelopment || false;
|
|
518
|
+
}
|
|
519
|
+
/**
|
|
520
|
+
* The stages of the quest.
|
|
521
|
+
*/
|
|
522
|
+
get stages() {
|
|
523
|
+
return this._stages.map((stage, index) => {
|
|
524
|
+
return new StageQuest(stage.id, stage);
|
|
525
|
+
});
|
|
526
|
+
}
|
|
527
|
+
/**
|
|
528
|
+
* The name of the quest.
|
|
529
|
+
*/
|
|
530
|
+
get name() {
|
|
531
|
+
return this._name;
|
|
532
|
+
}
|
|
533
|
+
/**
|
|
534
|
+
* The description of the quest.
|
|
535
|
+
*/
|
|
536
|
+
get description() {
|
|
537
|
+
return this._description;
|
|
538
|
+
}
|
|
539
|
+
/**
|
|
540
|
+
* The function for rendering the icon of the quest.
|
|
541
|
+
*/
|
|
542
|
+
get renderIcon() {
|
|
543
|
+
let render = this._renderIcon;
|
|
544
|
+
if (render === void 0) {
|
|
545
|
+
return void 0;
|
|
546
|
+
}
|
|
547
|
+
if (typeof render === "function") {
|
|
548
|
+
return (props) => {
|
|
549
|
+
return render(this, props);
|
|
550
|
+
};
|
|
551
|
+
}
|
|
552
|
+
return (props) => render;
|
|
553
|
+
}
|
|
554
|
+
/**
|
|
555
|
+
* The function for rendering the image of the quest.
|
|
556
|
+
*/
|
|
557
|
+
get renderImage() {
|
|
558
|
+
let render = this._renderImage;
|
|
559
|
+
if (render === void 0) {
|
|
560
|
+
return void 0;
|
|
561
|
+
}
|
|
562
|
+
if (typeof render === "function") {
|
|
563
|
+
return (props) => {
|
|
564
|
+
return render(this, props);
|
|
565
|
+
};
|
|
566
|
+
}
|
|
567
|
+
return (props) => render;
|
|
568
|
+
}
|
|
569
|
+
/**
|
|
570
|
+
* If the quest is in development.
|
|
571
|
+
*/
|
|
572
|
+
get isInDevelopment() {
|
|
573
|
+
return this._isInDevelopment;
|
|
574
|
+
}
|
|
575
|
+
/**
|
|
576
|
+
* The index of the current stage.
|
|
577
|
+
*/
|
|
578
|
+
get currentStageIndex() {
|
|
579
|
+
return this.getStorageProperty("currentStageIndex");
|
|
580
|
+
}
|
|
581
|
+
set currentStageIndex(value) {
|
|
582
|
+
this.setStorageProperty("currentStageIndex", value);
|
|
583
|
+
}
|
|
584
|
+
/**
|
|
585
|
+
* The current stage.
|
|
586
|
+
*/
|
|
587
|
+
get currentStage() {
|
|
588
|
+
let index = this.currentStageIndex;
|
|
589
|
+
if (index === void 0 || index >= this.stages.length) {
|
|
590
|
+
return void 0;
|
|
591
|
+
}
|
|
592
|
+
return this.stages[index];
|
|
593
|
+
}
|
|
594
|
+
/**
|
|
595
|
+
* If the quest is started.
|
|
596
|
+
*/
|
|
597
|
+
get started() {
|
|
598
|
+
return this.currentStageIndex !== void 0;
|
|
599
|
+
}
|
|
600
|
+
/**
|
|
601
|
+
* If the quest is completed.
|
|
602
|
+
*/
|
|
603
|
+
get completed() {
|
|
604
|
+
return this.currentStageIndex === this.stages.length;
|
|
605
|
+
}
|
|
606
|
+
/**
|
|
607
|
+
* Start the quest.
|
|
608
|
+
* @param props The properties for the start stage. If you not want to pass any property, you can pass an {}.
|
|
609
|
+
* @returns
|
|
610
|
+
*/
|
|
611
|
+
start(props) {
|
|
612
|
+
if (this.started) {
|
|
613
|
+
console.warn(`[NQTR] Quest ${this.id} is already started`);
|
|
614
|
+
return;
|
|
615
|
+
}
|
|
616
|
+
if (this.stages.length === 0) {
|
|
617
|
+
console.error(`[NQTR] Quest ${this.id} has no stages`);
|
|
618
|
+
return;
|
|
619
|
+
}
|
|
620
|
+
this.currentStageIndex = 0;
|
|
621
|
+
let currentStage = this.currentStage;
|
|
622
|
+
if (currentStage && currentStage.onStart) {
|
|
623
|
+
return currentStage.onStart(props);
|
|
624
|
+
} else {
|
|
625
|
+
console.error(`[NQTR] Quest ${this.id} has no start stage`);
|
|
626
|
+
}
|
|
627
|
+
}
|
|
628
|
+
/**
|
|
629
|
+
* Try to go to the next stage.
|
|
630
|
+
* @param startProps The properties for the start stage. If you not want to pass any property, you can pass an {}.
|
|
631
|
+
* @param endProps The properties for the end stage. If you not want to pass any property, you can pass an {}.
|
|
632
|
+
* @returns true if the stage was changed, false otherwise.
|
|
633
|
+
*/
|
|
634
|
+
tryToGoNextStage(startProps, endProps) {
|
|
635
|
+
if (!this.started) {
|
|
636
|
+
return false;
|
|
637
|
+
}
|
|
638
|
+
if (this.completed) {
|
|
639
|
+
return false;
|
|
640
|
+
}
|
|
641
|
+
let currentStage = this.currentStage;
|
|
642
|
+
let currentStageIndex = this.currentStageIndex;
|
|
643
|
+
if (!currentStage || currentStageIndex === void 0) {
|
|
644
|
+
console.error(`[NQTR] Quest ${this.id} has no current stage`);
|
|
645
|
+
return false;
|
|
646
|
+
}
|
|
647
|
+
if (currentStage.completed) {
|
|
648
|
+
let nextStageIndex = currentStageIndex + 1;
|
|
649
|
+
currentStageIndex = nextStageIndex;
|
|
650
|
+
let nextStage = this.currentStage;
|
|
651
|
+
if (currentStage && currentStage.onEnd) {
|
|
652
|
+
currentStage.onEnd(endProps);
|
|
653
|
+
}
|
|
654
|
+
if (nextStage && nextStage.onStart) {
|
|
655
|
+
nextStage.onStart(startProps);
|
|
656
|
+
}
|
|
657
|
+
return true;
|
|
658
|
+
}
|
|
659
|
+
return false;
|
|
660
|
+
}
|
|
661
|
+
};
|
|
662
|
+
|
|
3
663
|
// src/decorators/QuestDecorator.ts
|
|
4
664
|
var registeredQuests = {};
|
|
5
|
-
function
|
|
6
|
-
if (
|
|
7
|
-
|
|
8
|
-
return;
|
|
9
|
-
}
|
|
10
|
-
if (registeredQuests[quest.id]) {
|
|
11
|
-
console.warn(`[NQTR] Quest id ${quest.id} already exists, it will be overwritten`);
|
|
665
|
+
function newQuest(id, stages, props) {
|
|
666
|
+
if (registeredQuests[id]) {
|
|
667
|
+
console.warn(`[NQTR] Quest ${id} already exists, it will be overwritten`);
|
|
12
668
|
}
|
|
13
|
-
|
|
669
|
+
let quest = new Quest(id, stages, props);
|
|
670
|
+
registeredQuests[id] = quest;
|
|
671
|
+
return quest;
|
|
14
672
|
}
|
|
15
673
|
function getQuestById(id) {
|
|
16
674
|
try {
|
|
@@ -27,7 +685,7 @@ function getQuestById(id) {
|
|
|
27
685
|
}
|
|
28
686
|
|
|
29
687
|
exports.getQuestById = getQuestById;
|
|
688
|
+
exports.newQuest = newQuest;
|
|
30
689
|
exports.registeredQuests = registeredQuests;
|
|
31
|
-
exports.saveQuest = saveQuest;
|
|
32
690
|
//# sourceMappingURL=out.js.map
|
|
33
691
|
//# sourceMappingURL=QuestDecorator.js.map
|