@occultus/task-api 0.21.0 → 0.22.0-alpha.2

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",
3
+ "version": "0.22.0-alpha.2",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://codeberg.org/TeamOccultus/StarTenonAPI"
@@ -25,9 +25,9 @@
25
25
  "type": "module",
26
26
  "dependencies": {
27
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"
28
+ "@occultus/condition-api": "0.22.0-alpha.2",
29
+ "@occultus/text-api": "0.20.0",
30
+ "@occultus/toolkit": "0.22.0"
31
31
  },
32
32
  "peerDependencies": {
33
33
  "@minecraft/server": ">=2.1.0",
@@ -1,8 +1,7 @@
1
1
  import { Player } from "@minecraft/server";
2
- import { parseToRaw, TextProvider } from "@occultus/text-api";
2
+ import { TextProvider } from "@occultus/text-api";
3
3
  import { TaskGroupOptions } from "../interface/TaskGroupOptions";
4
4
  import { TaskStatus } from "../enum/TaskStatus";
5
- import { ActionFormData, MessageFormData } from "@minecraft/server-ui";
6
5
  import { Task } from "./Task";
7
6
  import { TaskCenter } from "./TaskCenter";
8
7
  import { LockedScreen } from "../ui/LockedScreen";
@@ -1,9 +1,12 @@
1
1
  import { EntityDamageCause, Player, world } from "@minecraft/server";
2
- import { KillEntityConditions } from "./conditions/KillEntityCondition";
3
- import { KillEntityFamilyConditions } from "./conditions/KillEntityFamilyCondition";
4
- import { TaskConditions } from "./conditions/TaskConditions";
2
+ import {
3
+ KillEntityConditions,
4
+ KillEntityFamilyConditions,
5
+ Conditions,
6
+ } from "@occultus/condition-api";
7
+
5
8
  import { Task } from "./Task";
6
- import { getFamilies } from "@occultus/entity-api";
9
+ import { getFamilies } from "@occultus/toolkit";
7
10
  import { TaskStatus } from "../enum/TaskStatus";
8
11
 
9
12
  export class TaskServer {
@@ -15,7 +18,8 @@ export class TaskServer {
15
18
  if (damageSource.cause !== EntityDamageCause.entityAttack) return;
16
19
  if (!damageSource.damagingEntity) return;
17
20
  if (!(damageSource.damagingEntity instanceof Player)) return;
18
- if(task.getStatus(damageSource.damagingEntity) === TaskStatus.Done) return;
21
+ if (task.getStatus(damageSource.damagingEntity) === TaskStatus.Done)
22
+ return;
19
23
  task.complete(damageSource.damagingEntity);
20
24
  });
21
25
  world.afterEvents.entityDie.subscribe((event) => {
@@ -27,18 +31,18 @@ export class TaskServer {
27
31
  getFamilies(deadEntity)?.forEach((family) => {
28
32
  const task = this.families.get(family);
29
33
  if (!task) return;
30
- if(task.getStatus(damagingEntity) === TaskStatus.Done) return;
34
+ if (task.getStatus(damagingEntity) === TaskStatus.Done) return;
31
35
  task.complete(damagingEntity);
32
36
  });
33
37
  });
34
- console.log("[Occultus SDK] Task Server Started")
38
+ console.log("[Occultus SDK] Task Server Started");
35
39
  }
36
40
  entities: Map<string, Task> = new Map();
37
41
  families: Map<string, Task> = new Map();
38
42
  constructor() {
39
43
  this.startUp();
40
44
  }
41
- addCondition(condition: TaskConditions, bindTo: Task) {
45
+ addCondition(condition: Conditions, bindTo: Task) {
42
46
  if (condition instanceof KillEntityConditions) {
43
47
  this.entities.set(condition.entityType, bindTo);
44
48
  }
@@ -1,7 +1,6 @@
1
1
  import { ItemStack, Player } from "@minecraft/server";
2
- import { TextProvider } from "@occultus/text-api";
3
2
  import { TaskAwards } from "./TaskAwards";
4
- import { giveItem } from "@occultus/entity-api";
3
+ import { giveItem } from "@occultus/toolkit";
5
4
 
6
5
  export class ItemAwards extends TaskAwards {
7
6
  constructor(
package/src/index.ts CHANGED
@@ -1,8 +1,10 @@
1
+ /**
2
+ * @module @occultus/task-api
3
+ */
1
4
  export * from "./api/Task";
2
5
  export * from "./api/TaskGroup";
3
6
  export * from "./api/TaskCenter";
4
7
  export * from "./api/awards";
5
- export * from "./api/conditions";
6
8
  export * from "./enum/TaskStatus";
7
9
  export * from "./interface/TaskCenterOptions";
8
10
  export * from "./interface/TaskGroupOptions";
@@ -1,6 +1,6 @@
1
1
  import { TextProvider } from "@occultus/text-api";
2
2
  import { TaskAwards } from "../api/awards/TaskAwards";
3
- import { TaskConditions } from "../api/conditions/TaskConditions";
3
+ import { Conditions } from "@occultus/condition-api";
4
4
  import { Task } from "../api/Task";
5
5
 
6
6
  /**
@@ -15,7 +15,7 @@ export interface TaskOptions {
15
15
  /**
16
16
  * 任务完成所需满足的条件列表
17
17
  */
18
- conditions: TaskConditions[];
18
+ conditions: Conditions[];
19
19
 
20
20
  /**
21
21
  * 前置任务
@@ -1,52 +0,0 @@
1
- import { ItemStack, Player } from "@minecraft/server";
2
- import { TaskConditions } from "./TaskConditions";
3
- import { getItemAmountInContainer } from "@occultus/item-api";
4
-
5
- /**
6
- * 物品条件
7
- */
8
- export class ItemConditions extends TaskConditions {
9
- /**
10
- * @param itemType 满足条件所需要的物品类型
11
- * @param amount 满足条件所需要的物品数量,默认为 1
12
- */
13
- constructor(
14
- protected itemType: string,
15
- protected amount?: number
16
- ) {
17
- super(itemType);
18
- }
19
- getItem(){
20
- return new ItemStack(this.itemType, this.amount)
21
- }
22
- check(player: Player) {
23
- const container = player.getComponent("minecraft:inventory")?.container;
24
- if (!container) return false;
25
- const amount = getItemAmountInContainer(
26
- container,
27
- this.getItem().typeId
28
- );
29
- return amount >= this.getItem().amount;
30
- }
31
- getTextProvider(){
32
- return {
33
- rawtext: [
34
- { translate: this.getItem().localizationKey },
35
- { text: " × " },
36
- { text: this.getItem().amount.toString() },
37
- ],
38
- };
39
- };
40
- getFailedReason(){
41
- return {
42
- rawtext: [
43
- // 你缺少这些物品:
44
- { translate: "task.condition.item.failed" },
45
- { text: " " },
46
- { translate: this.getItem().localizationKey },
47
- { text: " × " },
48
- { text: this.getItem().amount.toString() },
49
- ],
50
- }
51
- };
52
- }
@@ -1,42 +0,0 @@
1
- import { Player } from "@minecraft/server";
2
- import { TaskConditions } from "./TaskConditions";
3
- import { Task } from "../Task";
4
- import { Localization } from "@occultus/format-api";
5
-
6
- /**
7
- * 击杀实体条件
8
- *
9
- * **IMPORTANT: 此条件必须调用 {@link Task.pushToServer()} 方法才能生效**
10
- */
11
- export class KillEntityConditions extends TaskConditions {
12
- /**
13
- * @param entityType 满足条件所需要的实体类型
14
- */
15
- constructor(
16
- public entityType: string
17
- ) {
18
- super(entityType);
19
- }
20
- check(player: Player) {
21
- return false;
22
- }
23
- getTextProvider() {
24
- return {
25
- rawtext: [
26
- // 击杀实体:
27
- { translate: "task.condition.killentity" },
28
- { translate: Localization.getEntityKey(this.entityType) },
29
- ],
30
- };
31
- }
32
- getFailedReason() {
33
- return {
34
- rawtext: [
35
- // 你需要击杀实体:
36
- { translate: "task.condition.killentity.failed" },
37
- { text: " " },
38
- { translate: Localization.getEntityKey(this.entityType) },
39
- ],
40
- };
41
- }
42
- }
@@ -1,42 +0,0 @@
1
- import { Player } from "@minecraft/server";
2
- import { TaskConditions } from "./TaskConditions";
3
- import { Task } from "../Task";
4
-
5
- /**
6
- * 击杀实体条件
7
- *
8
- * **IMPORTANT: 此条件必须调用 {@link Task.pushToServer()} 方法才能生效**
9
- */
10
- export class KillEntityFamilyConditions extends TaskConditions {
11
- /**
12
- * @param family 满足条件所需要的实体类型
13
- */
14
- constructor(
15
- public family: string,
16
- public localizationKey: string
17
- ) {
18
- super(family);
19
- }
20
- check(player: Player) {
21
- return false;
22
- }
23
- getTextProvider() {
24
- return {
25
- rawtext: [
26
- // 击杀此类实体:
27
- { translate: "task.condition.killEntityFamily" },
28
- { translate: this.localizationKey },
29
- ],
30
- };
31
- }
32
- getFailedReason() {
33
- return {
34
- rawtext: [
35
- // 你需要击杀此类实体:
36
- { translate: "task.condition.killEntityFamily.failed" },
37
- { text: " " },
38
- { translate: this.localizationKey },
39
- ],
40
- };
41
- }
42
- }
@@ -1,36 +0,0 @@
1
- import { Player, RawMessage } from "@minecraft/server";
2
- import { TaskConditions } from "./TaskConditions";
3
-
4
- /**
5
- * 击杀实体条件
6
- */
7
- export class LevelConditions extends TaskConditions {
8
- constructor(public level: number) {
9
- super(level);
10
- }
11
- check(player: Player) {
12
- return player.level >= this.level;
13
- }
14
- getTextProvider(): RawMessage {
15
- return {
16
- rawtext: [
17
- // 达到 %s 级
18
- {
19
- translate: "task.condition.level",
20
- with: { text: this.level.toString() },
21
- },
22
- ],
23
- };
24
- }
25
- getFailedReason(): RawMessage {
26
- return {
27
- rawtext: [
28
- // 你需要达到 %s 级
29
- {
30
- translate: "task.condition.level.failed",
31
- with: { text: this.level.toString() },
32
- },
33
- ],
34
- };
35
- }
36
- }
@@ -1,35 +0,0 @@
1
- import { Player } from "@minecraft/server";
2
- import { TextProvider } from "@occultus/text-api";
3
- import { TaskServer } from "../TaskServer";
4
-
5
- /**
6
- * 任务条件的抽象类
7
- *
8
- * 定义了任务条件的基本结构和必须实现的方法,所有具体的任务条件类都应该继承此抽象类并实现其抽象方法
9
- */
10
- export abstract class TaskConditions {
11
- /**
12
- * @param data 任务条件所需的数据
13
- */
14
- constructor(protected data: unknown) {}
15
- /**
16
- * 检查玩家是否满足任务条件
17
- *
18
- * @param player 要检查的玩家对象
19
- * @return 如果玩家满足条件返回`true`,否则返回`false`
20
- */
21
- abstract check(player: Player): boolean;
22
-
23
- /**
24
- * 获取任务条件的文本,该文本将会在任务面板中显示
25
- *
26
- * @return 用于显示任务条件描述的文本
27
- */
28
- abstract getTextProvider(): TextProvider;
29
- /**
30
- * 获取条件检查失败时的原因说明文本
31
- *
32
- * @return 用于显示失败原因的文本
33
- */
34
- abstract getFailedReason(): TextProvider;
35
- }
@@ -1,5 +0,0 @@
1
- export * from "./ItemConditions";
2
- export * from "./KillEntityCondition";
3
- export * from "./KillEntityFamilyCondition";
4
- export * from "./LevelCondition";
5
- export * from "./TaskConditions";