@occultus/task-api 0.22.0-alpha.2 → 0.22.0-alpha.3
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/package.json +8 -8
- package/src/api/Task.ts +12 -11
- package/src/api/TaskGroup.ts +4 -2
- package/src/api/TaskServer.ts +1 -1
- package/src/api/awards/ExpAwards.ts +3 -5
- package/src/api/awards/ItemAwards.ts +2 -2
- package/src/api/awards/LevelAwards.ts +3 -5
- package/src/api/awards/TaskAwards.ts +2 -2
- package/src/enum/TaskStatus.ts +2 -2
- package/src/interface/TaskCenterOptions.ts +2 -2
- package/src/interface/TaskOptions.ts +6 -6
- package/src/ui/LockedScreen.ts +2 -2
- package/src/ui/TaskListScreen.ts +4 -1
- package/src/utils/TaskUtils.ts +8 -8
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@occultus/task-api",
|
|
3
|
-
"version": "0.22.0-alpha.
|
|
3
|
+
"version": "0.22.0-alpha.3",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://codeberg.org/TeamOccultus/StarTenonAPI"
|
|
@@ -25,17 +25,17 @@
|
|
|
25
25
|
"type": "module",
|
|
26
26
|
"dependencies": {
|
|
27
27
|
"@occultus/format-api": "0.21.0",
|
|
28
|
-
"@occultus/
|
|
29
|
-
"@occultus/
|
|
30
|
-
"@occultus/
|
|
28
|
+
"@occultus/toolkit": "0.22.1",
|
|
29
|
+
"@occultus/condition-api": "0.22.0-alpha.5",
|
|
30
|
+
"@occultus/text-api": "0.20.0"
|
|
31
31
|
},
|
|
32
32
|
"peerDependencies": {
|
|
33
|
-
"@minecraft/server": "
|
|
34
|
-
"@minecraft/server-ui": "
|
|
35
|
-
"@occultus/core": "
|
|
33
|
+
"@minecraft/server": "^2.4.0",
|
|
34
|
+
"@minecraft/server-ui": "^2.0.0",
|
|
35
|
+
"@occultus/core": "~0.18.4"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
|
-
"typedoc": "^0.28.
|
|
38
|
+
"typedoc": "^0.28.15"
|
|
39
39
|
},
|
|
40
40
|
"scripts": {
|
|
41
41
|
"test": "tsc"
|
package/src/api/Task.ts
CHANGED
|
@@ -60,18 +60,19 @@ export class Task {
|
|
|
60
60
|
}
|
|
61
61
|
/**
|
|
62
62
|
* 返回玩家是否可以在任务列表中看到该任务
|
|
63
|
-
* @param player
|
|
63
|
+
* @param player
|
|
64
64
|
* @return 倘若玩家可以在任务列表中看到该任务返回`true`,否则返回`false`
|
|
65
65
|
*/
|
|
66
66
|
isVisible(player: Player): boolean {
|
|
67
|
-
if(this.isAvailable(player)) return true;
|
|
68
|
-
if(this.options.hiddenWhenLocked) return false;
|
|
67
|
+
if (this.isAvailable(player)) return true;
|
|
68
|
+
if (this.options.hiddenWhenLocked) return false;
|
|
69
69
|
return true;
|
|
70
70
|
}
|
|
71
71
|
isAvailable(player: Player): boolean {
|
|
72
|
-
if(this.getStatus(player) === TaskStatus.Done) return true;
|
|
73
|
-
if(this.options.previousTask === "none") return true;
|
|
74
|
-
if(this.options.previousTask.getStatus(player) === TaskStatus.Done)
|
|
72
|
+
if (this.getStatus(player) === TaskStatus.Done) return true;
|
|
73
|
+
if (this.options.previousTask === "none") return true;
|
|
74
|
+
if (this.options.previousTask.getStatus(player) === TaskStatus.Done)
|
|
75
|
+
return true;
|
|
75
76
|
return false;
|
|
76
77
|
}
|
|
77
78
|
protected lockedDisplay(
|
|
@@ -124,18 +125,18 @@ export class Task {
|
|
|
124
125
|
rawtext: [
|
|
125
126
|
// 你完成了任务:
|
|
126
127
|
{ translate: "ui.task.complete" },
|
|
127
|
-
parseToRaw(this.name, player)
|
|
128
|
-
]
|
|
128
|
+
parseToRaw(this.name, player)
|
|
129
|
+
]
|
|
129
130
|
});
|
|
130
131
|
player.playSound(this.options.completeSound ?? "random.levelup");
|
|
131
132
|
}
|
|
132
133
|
/**
|
|
133
134
|
* 直接将任务上传到服务端监听器中
|
|
134
|
-
*
|
|
135
|
+
*
|
|
135
136
|
* **IMPORTANT: 除非任务使用的条件有特殊说明,否则此方法一般无用**
|
|
136
|
-
* @param server
|
|
137
|
+
* @param server
|
|
137
138
|
*/
|
|
138
|
-
pushToServer(server: TaskServer){
|
|
139
|
+
pushToServer(server: TaskServer) {
|
|
139
140
|
server.addTask(this);
|
|
140
141
|
}
|
|
141
142
|
}
|
package/src/api/TaskGroup.ts
CHANGED
|
@@ -28,9 +28,11 @@ export class TaskGroup {
|
|
|
28
28
|
return backTo?.display(player);
|
|
29
29
|
}
|
|
30
30
|
if (response.selection === 0) {
|
|
31
|
-
if(this.hasOwnedAward(player)){
|
|
31
|
+
if (this.hasOwnedAward(player)) {
|
|
32
32
|
// 你已经领取过该奖励!
|
|
33
|
-
player.onScreenDisplay.setActionBar({
|
|
33
|
+
player.onScreenDisplay.setActionBar({
|
|
34
|
+
translate: "ui.taskGroup.award.owned"
|
|
35
|
+
});
|
|
34
36
|
}
|
|
35
37
|
if (this.getStatus(player) === TaskStatus.Done) {
|
|
36
38
|
this.giveAward(player);
|
package/src/api/TaskServer.ts
CHANGED
|
@@ -2,9 +2,7 @@ import { Player } from "@minecraft/server";
|
|
|
2
2
|
import { TaskAwards } from "./TaskAwards";
|
|
3
3
|
|
|
4
4
|
export class ExpAwards extends TaskAwards {
|
|
5
|
-
constructor(
|
|
6
|
-
protected amount: number
|
|
7
|
-
) {
|
|
5
|
+
constructor(protected amount: number) {
|
|
8
6
|
super(amount);
|
|
9
7
|
}
|
|
10
8
|
give(player: Player) {
|
|
@@ -15,8 +13,8 @@ export class ExpAwards extends TaskAwards {
|
|
|
15
13
|
rawtext: [
|
|
16
14
|
{ translate: "task.awards.exp" },
|
|
17
15
|
{ text: " × " },
|
|
18
|
-
{ text: this.amount.toString() }
|
|
19
|
-
]
|
|
16
|
+
{ text: this.amount.toString() }
|
|
17
|
+
]
|
|
20
18
|
};
|
|
21
19
|
}
|
|
22
20
|
}
|
|
@@ -2,9 +2,7 @@ import { Player } from "@minecraft/server";
|
|
|
2
2
|
import { TaskAwards } from "./TaskAwards";
|
|
3
3
|
|
|
4
4
|
export class LevelAwards extends TaskAwards {
|
|
5
|
-
constructor(
|
|
6
|
-
protected amount: number
|
|
7
|
-
) {
|
|
5
|
+
constructor(protected amount: number) {
|
|
8
6
|
super(amount);
|
|
9
7
|
}
|
|
10
8
|
give(player: Player) {
|
|
@@ -15,8 +13,8 @@ export class LevelAwards extends TaskAwards {
|
|
|
15
13
|
rawtext: [
|
|
16
14
|
{ translate: "task.awards.level" },
|
|
17
15
|
{ text: " × " },
|
|
18
|
-
{ text: this.amount.toString() }
|
|
19
|
-
]
|
|
16
|
+
{ text: this.amount.toString() }
|
|
17
|
+
]
|
|
20
18
|
};
|
|
21
19
|
}
|
|
22
20
|
}
|
|
@@ -3,7 +3,7 @@ import { TextProvider } from "@occultus/text-api";
|
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* 任务奖励抽象基类
|
|
6
|
-
*
|
|
6
|
+
*
|
|
7
7
|
* 该类定义了游戏中任务奖励系统的基础结构,用于管理和分发各种类型的任务奖励,所有具体的奖励类型(如经验奖励、物品奖励、货币奖励等)都应继承此抽象类。
|
|
8
8
|
*/
|
|
9
9
|
export abstract class TaskAwards {
|
|
@@ -13,7 +13,7 @@ export abstract class TaskAwards {
|
|
|
13
13
|
constructor(protected data: unknown) {}
|
|
14
14
|
/**
|
|
15
15
|
* 向玩家发放奖励
|
|
16
|
-
* @param player
|
|
16
|
+
* @param player
|
|
17
17
|
*/
|
|
18
18
|
abstract give(player: Player): void;
|
|
19
19
|
/**
|
package/src/enum/TaskStatus.ts
CHANGED
|
@@ -11,34 +11,34 @@ export interface TaskOptions {
|
|
|
11
11
|
* 任务完成后的奖励列表
|
|
12
12
|
*/
|
|
13
13
|
awards: TaskAwards[];
|
|
14
|
-
|
|
14
|
+
|
|
15
15
|
/**
|
|
16
16
|
* 任务完成所需满足的条件列表
|
|
17
17
|
*/
|
|
18
18
|
conditions: Conditions[];
|
|
19
|
-
|
|
19
|
+
|
|
20
20
|
/**
|
|
21
21
|
* 前置任务
|
|
22
22
|
* 可以是其他任务或无前置任务("none")
|
|
23
23
|
*/
|
|
24
24
|
previousTask: Task | "none";
|
|
25
|
-
|
|
25
|
+
|
|
26
26
|
/**
|
|
27
27
|
* 是否在锁定状态下隐藏该任务
|
|
28
28
|
* @default false
|
|
29
29
|
*/
|
|
30
30
|
hiddenWhenLocked?: boolean;
|
|
31
|
-
|
|
31
|
+
|
|
32
32
|
/**
|
|
33
33
|
* 任务完成时的音效资源路径
|
|
34
34
|
*/
|
|
35
35
|
completeSound?: string;
|
|
36
|
-
|
|
36
|
+
|
|
37
37
|
/**
|
|
38
38
|
* 任务提示信息
|
|
39
39
|
*/
|
|
40
40
|
tips?: TextProvider;
|
|
41
|
-
|
|
41
|
+
|
|
42
42
|
/**
|
|
43
43
|
* 任务图标的资源路径
|
|
44
44
|
*/
|
package/src/ui/LockedScreen.ts
CHANGED
|
@@ -19,8 +19,8 @@ export class LockedScreen {
|
|
|
19
19
|
rawtext: [
|
|
20
20
|
{ translate: "task.locked.body" },
|
|
21
21
|
{ text: Format.newLine },
|
|
22
|
-
parseToRaw(previous.name, player)
|
|
23
|
-
]
|
|
22
|
+
parseToRaw(previous.name, player)
|
|
23
|
+
]
|
|
24
24
|
});
|
|
25
25
|
form.button1({ translate: "gui.back" });
|
|
26
26
|
// 前往完成
|
package/src/ui/TaskListScreen.ts
CHANGED
|
@@ -25,7 +25,10 @@ export class TaskListScreen {
|
|
|
25
25
|
const tasks: (Task | TaskGroup)[] = [];
|
|
26
26
|
origin.options.tasks.forEach((task) => {
|
|
27
27
|
if (!task.isVisible(player)) return;
|
|
28
|
-
form.button(
|
|
28
|
+
form.button(
|
|
29
|
+
TaskUtils.getTaskListButtonName(task, player),
|
|
30
|
+
task.options.iconPath
|
|
31
|
+
);
|
|
29
32
|
tasks.push(task);
|
|
30
33
|
});
|
|
31
34
|
return { screen: form, tasks: tasks };
|
package/src/utils/TaskUtils.ts
CHANGED
|
@@ -4,7 +4,7 @@ import {
|
|
|
4
4
|
CustomCommandStatus,
|
|
5
5
|
Player,
|
|
6
6
|
RawMessage,
|
|
7
|
-
system
|
|
7
|
+
system
|
|
8
8
|
} from "@minecraft/server";
|
|
9
9
|
import { Task } from "../api/Task";
|
|
10
10
|
import { parseToRaw } from "@occultus/text-api";
|
|
@@ -42,7 +42,7 @@ export class TaskUtils {
|
|
|
42
42
|
texts.push({ text: Format.newLine });
|
|
43
43
|
|
|
44
44
|
return {
|
|
45
|
-
rawtext: texts
|
|
45
|
+
rawtext: texts
|
|
46
46
|
};
|
|
47
47
|
}
|
|
48
48
|
static generateFailMessage(task: Task, player: Player): RawMessage {
|
|
@@ -55,7 +55,7 @@ export class TaskUtils {
|
|
|
55
55
|
texts.push(parseToRaw(condition.getFailedReason(), player));
|
|
56
56
|
});
|
|
57
57
|
return {
|
|
58
|
-
rawtext: texts
|
|
58
|
+
rawtext: texts
|
|
59
59
|
};
|
|
60
60
|
}
|
|
61
61
|
static getTaskListButtonName(
|
|
@@ -86,7 +86,7 @@ export class TaskUtils {
|
|
|
86
86
|
arg.itemComponentRegistry.registerCustomComponent(componentName, {
|
|
87
87
|
onUse(arg0) {
|
|
88
88
|
center.display(arg0.source);
|
|
89
|
-
}
|
|
89
|
+
}
|
|
90
90
|
});
|
|
91
91
|
});
|
|
92
92
|
}
|
|
@@ -96,19 +96,19 @@ export class TaskUtils {
|
|
|
96
96
|
system.run(() => {
|
|
97
97
|
if (origin.sourceType !== CustomCommandSource.Entity)
|
|
98
98
|
return {
|
|
99
|
-
status: CustomCommandStatus.Failure
|
|
99
|
+
status: CustomCommandStatus.Failure
|
|
100
100
|
};
|
|
101
101
|
if (!(origin.sourceEntity instanceof Player))
|
|
102
102
|
return {
|
|
103
|
-
status: CustomCommandStatus.Failure
|
|
103
|
+
status: CustomCommandStatus.Failure
|
|
104
104
|
};
|
|
105
105
|
center.display(origin.sourceEntity);
|
|
106
106
|
return {
|
|
107
|
-
status: CustomCommandStatus.Success
|
|
107
|
+
status: CustomCommandStatus.Success
|
|
108
108
|
};
|
|
109
109
|
});
|
|
110
110
|
return {
|
|
111
|
-
status: CustomCommandStatus.Failure
|
|
111
|
+
status: CustomCommandStatus.Failure
|
|
112
112
|
};
|
|
113
113
|
});
|
|
114
114
|
});
|