@occultus/task-api 0.21.0-alpha → 0.21.0-beta.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@occultus/task-api",
3
- "version": "0.21.0-alpha",
3
+ "version": "0.21.0-beta.1",
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-alpha",
28
- "@occultus/item-api": "0.20.0",
27
+ "@occultus/format-api": "0.21.0-beta.1",
28
+ "@occultus/entity-api": "0.20.0",
29
29
  "@occultus/text-api": "0.20.0",
30
- "@occultus/entity-api": "0.20.0"
30
+ "@occultus/item-api": "0.20.0"
31
31
  },
32
32
  "peerDependencies": {
33
33
  "@minecraft/server": ">=2.1.0",
package/src/api/Task.ts CHANGED
@@ -7,6 +7,7 @@ import { TaskCenter } from "./TaskCenter";
7
7
  import { MessageFormData } from "@minecraft/server-ui";
8
8
  import { TaskUtils } from "../utils/TaskUtils";
9
9
  import { LockedScreen } from "../ui/LockedScreen";
10
+ import { TaskServer } from "./TaskServer";
10
11
 
11
12
  export class Task {
12
13
  /**
@@ -128,4 +129,13 @@ export class Task {
128
129
  });
129
130
  player.playSound(this.options.completeSound ?? "random.levelup");
130
131
  }
132
+ /**
133
+ * 直接将任务上传到服务端监听器中
134
+ *
135
+ * **IMPORTANT: 除非任务使用的条件有特殊说明,否则此方法一般无用**
136
+ * @param server
137
+ */
138
+ pushToServer(server: TaskServer){
139
+ server.addTask(this);
140
+ }
131
141
  }
@@ -42,4 +42,9 @@ export class TaskServer {
42
42
  this.families.set(condition.family, condition.bindTo);
43
43
  }
44
44
  }
45
+ addTask(task: Task) {
46
+ task.options.conditions.forEach((condition) => {
47
+ this.addCondition(condition);
48
+ });
49
+ }
45
50
  }
@@ -5,6 +5,8 @@ import { Localization } from "@occultus/format-api";
5
5
 
6
6
  /**
7
7
  * 击杀实体条件
8
+ *
9
+ * **IMPORTANT: 此条件必须调用 {@link TaskConditions.pushToServer()} 方法才能生效**
8
10
  */
9
11
  export class KillEntityConditions extends TaskConditions {
10
12
  /**
@@ -4,6 +4,8 @@ import { Task } from "../Task";
4
4
 
5
5
  /**
6
6
  * 击杀实体条件
7
+ *
8
+ * **IMPORTANT: 此条件必须调用 {@link TaskConditions.pushToServer()} 方法才能生效**
7
9
  */
8
10
  export class KillEntityFamilyConditions extends TaskConditions {
9
11
  /**
@@ -1,9 +1,10 @@
1
1
  import { Player } from "@minecraft/server";
2
2
  import { TextProvider } from "@occultus/text-api";
3
+ import { TaskServer } from "../TaskServer";
3
4
 
4
5
  /**
5
6
  * 任务条件的抽象类
6
- *
7
+ *
7
8
  * 定义了任务条件的基本结构和必须实现的方法,所有具体的任务条件类都应该继承此抽象类并实现其抽象方法
8
9
  */
9
10
  export abstract class TaskConditions {
@@ -11,24 +12,34 @@ export abstract class TaskConditions {
11
12
  * @param data 任务条件所需的数据
12
13
  */
13
14
  constructor(protected data: unknown) {}
14
-
15
15
  /**
16
- * 检查玩家是否满足任务条件
16
+ * 直接将条件上传到服务端监听器中
17
17
  *
18
+ * **IMPORTANT: 除非有特殊说明,否则此方法一般无用**
19
+ * @param server 要上传的服务端监听器
20
+ * @return 条件自身
21
+ */
22
+ pushToServer(server: TaskServer): TaskConditions {
23
+ server.addCondition(this);
24
+ return this;
25
+ }
26
+ /**
27
+ * 检查玩家是否满足任务条件
28
+ *
18
29
  * @param player 要检查的玩家对象
19
30
  * @return 如果玩家满足条件返回`true`,否则返回`false`
20
31
  */
21
32
  abstract check(player: Player): boolean;
22
-
33
+
23
34
  /**
24
35
  * 获取任务条件的文本,该文本将会在任务面板中显示
25
- *
36
+ *
26
37
  * @return 用于显示任务条件描述的文本
27
38
  */
28
39
  abstract getTextProvider(): TextProvider;
29
40
  /**
30
41
  * 获取条件检查失败时的原因说明文本
31
- *
42
+ *
32
43
  * @return 用于显示失败原因的文本
33
44
  */
34
45
  abstract getFailedReason(): TextProvider;