@occultus/task-api 0.21.0-beta.2 → 0.21.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.
- package/package.json +5 -5
- package/src/api/Task.ts +1 -1
- package/src/api/TaskCenter.ts +7 -0
- package/src/api/TaskGroup.ts +1 -1
- package/src/api/TaskServer.ts +8 -5
- package/src/api/conditions/KillEntityCondition.ts +2 -3
- package/src/api/conditions/KillEntityFamilyCondition.ts +2 -3
- package/src/api/conditions/TaskConditions.ts +0 -11
- package/src/index.ts +1 -1
- package/src/utils/TaskUtils.ts +1 -1
- /package/src/enum/{TaskStaus.ts → TaskStatus.ts} +0 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@occultus/task-api",
|
|
3
|
-
"version": "0.21.0
|
|
3
|
+
"version": "0.21.0",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://codeberg.org/TeamOccultus/StarTenonAPI"
|
|
@@ -24,10 +24,10 @@
|
|
|
24
24
|
"author": "CTN Studios",
|
|
25
25
|
"type": "module",
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@occultus/format-api": "0.21.0
|
|
28
|
-
"@occultus/
|
|
29
|
-
"@occultus/
|
|
30
|
-
"@occultus/
|
|
27
|
+
"@occultus/format-api": "0.21.0",
|
|
28
|
+
"@occultus/item-api": "0.20.0",
|
|
29
|
+
"@occultus/entity-api": "0.21.0",
|
|
30
|
+
"@occultus/text-api": "0.20.0"
|
|
31
31
|
},
|
|
32
32
|
"peerDependencies": {
|
|
33
33
|
"@minecraft/server": ">=2.1.0",
|
package/src/api/Task.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { parseText, parseToRaw, TextProvider } from "@occultus/text-api";
|
|
2
2
|
import { Player } from "@minecraft/server";
|
|
3
3
|
import { TaskOptions } from "../interface/TaskOptions";
|
|
4
|
-
import { TaskStatus } from "../enum/
|
|
4
|
+
import { TaskStatus } from "../enum/TaskStatus";
|
|
5
5
|
import { TaskGroup } from "./TaskGroup";
|
|
6
6
|
import { TaskCenter } from "./TaskCenter";
|
|
7
7
|
import { ActionFormData } from "@minecraft/server-ui";
|
package/src/api/TaskCenter.ts
CHANGED
|
@@ -4,6 +4,9 @@ import { TaskCenterOptions } from "../interface/TaskCenterOptions";
|
|
|
4
4
|
import { TaskListScreen } from "../ui/TaskListScreen";
|
|
5
5
|
import { TaskUtils } from "../utils/TaskUtils";
|
|
6
6
|
|
|
7
|
+
/**
|
|
8
|
+
* 表示任务中心的类,即所谓「任务书/任务面板」
|
|
9
|
+
*/
|
|
7
10
|
export class TaskCenter {
|
|
8
11
|
constructor(
|
|
9
12
|
readonly id: string,
|
|
@@ -11,6 +14,10 @@ export class TaskCenter {
|
|
|
11
14
|
public description: TextProvider,
|
|
12
15
|
public options: TaskCenterOptions
|
|
13
16
|
) {}
|
|
17
|
+
/**
|
|
18
|
+
* 向玩家展示任务中心
|
|
19
|
+
* @param player 要展示的玩家
|
|
20
|
+
*/
|
|
14
21
|
display(player: Player) {
|
|
15
22
|
const { screen, tasks } = TaskListScreen.create(this, player);
|
|
16
23
|
screen.show(player).then((response) => {
|
package/src/api/TaskGroup.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { Player } from "@minecraft/server";
|
|
2
2
|
import { parseToRaw, TextProvider } from "@occultus/text-api";
|
|
3
3
|
import { TaskGroupOptions } from "../interface/TaskGroupOptions";
|
|
4
|
-
import { TaskStatus } from "../enum/
|
|
4
|
+
import { TaskStatus } from "../enum/TaskStatus";
|
|
5
5
|
import { ActionFormData, MessageFormData } from "@minecraft/server-ui";
|
|
6
6
|
import { Task } from "./Task";
|
|
7
7
|
import { TaskCenter } from "./TaskCenter";
|
package/src/api/TaskServer.ts
CHANGED
|
@@ -4,6 +4,7 @@ import { KillEntityFamilyConditions } from "./conditions/KillEntityFamilyConditi
|
|
|
4
4
|
import { TaskConditions } from "./conditions/TaskConditions";
|
|
5
5
|
import { Task } from "./Task";
|
|
6
6
|
import { getFamilies } from "@occultus/entity-api";
|
|
7
|
+
import { TaskStatus } from "../enum/TaskStatus";
|
|
7
8
|
|
|
8
9
|
export class TaskServer {
|
|
9
10
|
private startUp() {
|
|
@@ -14,6 +15,7 @@ export class TaskServer {
|
|
|
14
15
|
if (damageSource.cause !== EntityDamageCause.entityAttack) return;
|
|
15
16
|
if (!damageSource.damagingEntity) return;
|
|
16
17
|
if (!(damageSource.damagingEntity instanceof Player)) return;
|
|
18
|
+
if(task.getStatus(damageSource.damagingEntity) === TaskStatus.Done) return;
|
|
17
19
|
task.complete(damageSource.damagingEntity);
|
|
18
20
|
});
|
|
19
21
|
world.afterEvents.entityDie.subscribe((event) => {
|
|
@@ -23,8 +25,9 @@ export class TaskServer {
|
|
|
23
25
|
if (!damagingEntity) return;
|
|
24
26
|
if (!(damagingEntity instanceof Player)) return;
|
|
25
27
|
getFamilies(deadEntity)?.forEach((family) => {
|
|
26
|
-
const task = this.families.get(
|
|
28
|
+
const task = this.families.get(family);
|
|
27
29
|
if (!task) return;
|
|
30
|
+
if(task.getStatus(damagingEntity) === TaskStatus.Done) return;
|
|
28
31
|
task.complete(damagingEntity);
|
|
29
32
|
});
|
|
30
33
|
});
|
|
@@ -35,17 +38,17 @@ export class TaskServer {
|
|
|
35
38
|
constructor() {
|
|
36
39
|
this.startUp();
|
|
37
40
|
}
|
|
38
|
-
addCondition(condition: TaskConditions) {
|
|
41
|
+
addCondition(condition: TaskConditions, bindTo: Task) {
|
|
39
42
|
if (condition instanceof KillEntityConditions) {
|
|
40
|
-
this.entities.set(condition.entityType,
|
|
43
|
+
this.entities.set(condition.entityType, bindTo);
|
|
41
44
|
}
|
|
42
45
|
if (condition instanceof KillEntityFamilyConditions) {
|
|
43
|
-
this.families.set(condition.family,
|
|
46
|
+
this.families.set(condition.family, bindTo);
|
|
44
47
|
}
|
|
45
48
|
}
|
|
46
49
|
addTask(task: Task) {
|
|
47
50
|
task.options.conditions.forEach((condition) => {
|
|
48
|
-
this.addCondition(condition);
|
|
51
|
+
this.addCondition(condition, task);
|
|
49
52
|
});
|
|
50
53
|
}
|
|
51
54
|
}
|
|
@@ -6,15 +6,14 @@ import { Localization } from "@occultus/format-api";
|
|
|
6
6
|
/**
|
|
7
7
|
* 击杀实体条件
|
|
8
8
|
*
|
|
9
|
-
* **IMPORTANT: 此条件必须调用 {@link
|
|
9
|
+
* **IMPORTANT: 此条件必须调用 {@link Task.pushToServer()} 方法才能生效**
|
|
10
10
|
*/
|
|
11
11
|
export class KillEntityConditions extends TaskConditions {
|
|
12
12
|
/**
|
|
13
13
|
* @param entityType 满足条件所需要的实体类型
|
|
14
14
|
*/
|
|
15
15
|
constructor(
|
|
16
|
-
public entityType: string
|
|
17
|
-
public bindTo: Task
|
|
16
|
+
public entityType: string
|
|
18
17
|
) {
|
|
19
18
|
super(entityType);
|
|
20
19
|
}
|
|
@@ -5,7 +5,7 @@ import { Task } from "../Task";
|
|
|
5
5
|
/**
|
|
6
6
|
* 击杀实体条件
|
|
7
7
|
*
|
|
8
|
-
* **IMPORTANT: 此条件必须调用 {@link
|
|
8
|
+
* **IMPORTANT: 此条件必须调用 {@link Task.pushToServer()} 方法才能生效**
|
|
9
9
|
*/
|
|
10
10
|
export class KillEntityFamilyConditions extends TaskConditions {
|
|
11
11
|
/**
|
|
@@ -13,8 +13,7 @@ export class KillEntityFamilyConditions extends TaskConditions {
|
|
|
13
13
|
*/
|
|
14
14
|
constructor(
|
|
15
15
|
public family: string,
|
|
16
|
-
public localizationKey: string
|
|
17
|
-
public bindTo: Task
|
|
16
|
+
public localizationKey: string
|
|
18
17
|
) {
|
|
19
18
|
super(family);
|
|
20
19
|
}
|
|
@@ -12,17 +12,6 @@ export abstract class TaskConditions {
|
|
|
12
12
|
* @param data 任务条件所需的数据
|
|
13
13
|
*/
|
|
14
14
|
constructor(protected data: unknown) {}
|
|
15
|
-
/**
|
|
16
|
-
* 直接将条件上传到服务端监听器中
|
|
17
|
-
*
|
|
18
|
-
* **IMPORTANT: 除非有特殊说明,否则此方法一般无用**
|
|
19
|
-
* @param server 要上传的服务端监听器
|
|
20
|
-
* @return 条件自身
|
|
21
|
-
*/
|
|
22
|
-
pushToServer(server: TaskServer): TaskConditions {
|
|
23
|
-
server.addCondition(this);
|
|
24
|
-
return this;
|
|
25
|
-
}
|
|
26
15
|
/**
|
|
27
16
|
* 检查玩家是否满足任务条件
|
|
28
17
|
*
|
package/src/index.ts
CHANGED
|
@@ -3,7 +3,7 @@ export * from "./api/TaskGroup";
|
|
|
3
3
|
export * from "./api/TaskCenter";
|
|
4
4
|
export * from "./api/awards";
|
|
5
5
|
export * from "./api/conditions";
|
|
6
|
-
export * from "./enum/
|
|
6
|
+
export * from "./enum/TaskStatus";
|
|
7
7
|
export * from "./interface/TaskCenterOptions";
|
|
8
8
|
export * from "./interface/TaskGroupOptions";
|
|
9
9
|
export * from "./interface/TaskOptions";
|
package/src/utils/TaskUtils.ts
CHANGED
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
import { Task } from "../api/Task";
|
|
10
10
|
import { parseToRaw } from "@occultus/text-api";
|
|
11
11
|
import { Format, Color } from "@occultus/format-api";
|
|
12
|
-
import { TaskStatus } from "../enum/
|
|
12
|
+
import { TaskStatus } from "../enum/TaskStatus";
|
|
13
13
|
import { TaskGroup } from "../api/TaskGroup";
|
|
14
14
|
import { TaskCenter } from "../api/TaskCenter";
|
|
15
15
|
|
|
File without changes
|