@occultus/condition-api 0.22.0-alpha.4 → 0.22.0-alpha.6

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/condition-api",
3
- "version": "0.22.0-alpha.4",
3
+ "version": "0.22.0-alpha.6",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://codeberg.org/TeamOccultus/StarTenonAPI"
@@ -7,17 +7,15 @@ import { TextProvider } from "@occultus/text-api";
7
7
  * 定义了条件的基本结构和必须实现的方法,所有具体的条件类都应该继承此抽象类并实现其抽象方法
8
8
  */
9
9
  export abstract class Conditions {
10
- /**
11
- * @param data 条件所需的数据
12
- */
13
- constructor(protected data: unknown) {}
10
+ constructor() {}
14
11
  /**
15
12
  * 检查玩家是否满足条件
16
13
  *
17
14
  * @param player 要检查的玩家对象
15
+ * @param visual 将这次检查设置为虚拟检查,不会消耗条件对应游戏元素的数量
18
16
  * @return 如果玩家满足条件返回`true`,否则返回`false`
19
17
  */
20
- abstract check(player: Player): boolean;
18
+ abstract check(player: Player, visual?: boolean): boolean;
21
19
  /**
22
20
  * 获取条件的文本,该文本将会在任务面板中显示
23
21
  *
@@ -10,14 +10,12 @@ export class ExpConditions extends Conditions {
10
10
  * @param experience 满足条件所需的最低等级
11
11
  * @param consumeAmount 倘若为`true`,则条件检查通过后会自动消耗对应等级
12
12
  */
13
- constructor(
14
- protected experience: number,
15
- protected consumeAmount = false
16
- ) {
17
- super(experience);
13
+ constructor(protected experience: number, protected consumeAmount = false) {
14
+ super();
18
15
  }
19
- check(player: Player) {
16
+ check(player: Player, visual = false) {
20
17
  if (getAllExp(player) >= this.experience) {
18
+ if (visual) return true;
21
19
  if (!this.consumeAmount) return true;
22
20
  player.addExperience(-this.experience);
23
21
  return true;
@@ -30,9 +28,9 @@ export class ExpConditions extends Conditions {
30
28
  // 达到 %s 级
31
29
  {
32
30
  translate: "task.condition.level",
33
- with: { text: this.experience.toString() }
34
- }
35
- ]
31
+ with: { text: this.experience.toString() },
32
+ },
33
+ ],
36
34
  };
37
35
  }
38
36
  getFailedReason(): RawMessage {
@@ -41,9 +39,9 @@ export class ExpConditions extends Conditions {
41
39
  // 你需要达到 %s 级
42
40
  {
43
41
  translate: "task.condition.level.failed",
44
- with: { text: this.experience.toString() }
45
- }
46
- ]
42
+ with: { text: this.experience.toString() },
43
+ },
44
+ ],
47
45
  };
48
46
  }
49
47
  }
@@ -2,7 +2,7 @@ import { ItemStack, Player, RawMessage } from "@minecraft/server";
2
2
  import { Conditions } from "./Conditions";
3
3
  import {
4
4
  getItemAmountInContainer,
5
- removeItemInContainer
5
+ removeItemInContainer,
6
6
  } from "@occultus/toolkit";
7
7
  import { TextProvider } from "@occultus/text-api";
8
8
 
@@ -20,7 +20,7 @@ export class ItemConditions extends Conditions {
20
20
  protected amount: number = 1,
21
21
  protected consumeAmount = false
22
22
  ) {
23
- super(itemType);
23
+ super();
24
24
  }
25
25
  /**
26
26
  * 获取条件对应的 ItemStack
@@ -36,11 +36,12 @@ export class ItemConditions extends Conditions {
36
36
  * @param player
37
37
  * @return
38
38
  */
39
- check(player: Player) {
39
+ check(player: Player, visual = false) {
40
40
  const container = player.getComponent("minecraft:inventory")?.container;
41
41
  if (!container) return false;
42
42
  const amount = getItemAmountInContainer(container, this.getItem().typeId);
43
43
  if (amount >= this.getItem().amount) {
44
+ if (visual) return true;
44
45
  if (!this.consumeAmount) return true;
45
46
  removeItemInContainer(container, this.itemType, this.amount);
46
47
  return true;
@@ -56,8 +57,8 @@ export class ItemConditions extends Conditions {
56
57
  rawtext: [
57
58
  { translate: this.getItem().localizationKey },
58
59
  { text: " × " },
59
- { text: this.getItem().amount.toString() }
60
- ]
60
+ { text: this.getItem().amount.toString() },
61
+ ],
61
62
  };
62
63
  }
63
64
  /**
@@ -72,8 +73,8 @@ export class ItemConditions extends Conditions {
72
73
  { text: " " },
73
74
  { translate: this.getItem().localizationKey },
74
75
  { text: " × " },
75
- { text: this.getItem().amount.toString() }
76
- ]
76
+ { text: this.getItem().amount.toString() },
77
+ ],
77
78
  };
78
79
  }
79
80
  }
@@ -22,7 +22,7 @@ export class ItemTagConditions extends Conditions {
22
22
  protected translateKey: string,
23
23
  protected consumeAmount: boolean = false
24
24
  ) {
25
- super(tag);
25
+ super();
26
26
  }
27
27
  /**
28
28
  * 检查玩家是否符合该条件的要求
@@ -31,12 +31,12 @@ export class ItemTagConditions extends Conditions {
31
31
  * @param player
32
32
  * @return
33
33
  */
34
- check(player: Player) {
34
+ check(player: Player, visual = false) {
35
35
  const container = player.getComponent("minecraft:inventory")?.container;
36
36
  if (!container) return false;
37
37
  const amount = getTagItemAmountInContainer(container, this.tag);
38
-
39
38
  if (amount >= this.amount) {
39
+ if (visual) return true;
40
40
  if (!this.consumeAmount) return true;
41
41
  removeTagItemInContainer(container, this.tag, this.amount);
42
42
  return true;
@@ -12,9 +12,9 @@ export class KillEntityConditions extends Conditions {
12
12
  * @param entityType 满足条件所需要的实体类型
13
13
  */
14
14
  constructor(public entityType: string) {
15
- super(entityType);
15
+ super();
16
16
  }
17
- check(player: Player) {
17
+ check(player: Player, visual = false) {
18
18
  return false;
19
19
  }
20
20
  getTextProvider(): RawMessage {
@@ -14,9 +14,9 @@ export class KillEntityFamilyConditions extends Conditions {
14
14
  public family: string,
15
15
  public localizationKey: string
16
16
  ) {
17
- super(family);
17
+ super();
18
18
  }
19
- check(player: Player) {
19
+ check(player: Player, visual = false) {
20
20
  return false;
21
21
  }
22
22
  getTextProvider(): RawMessage {
@@ -9,14 +9,12 @@ export class LevelConditions extends Conditions {
9
9
  * @param level 满足条件所需的最低等级
10
10
  * @param consumeAmount 倘若为`true`,则条件检查通过后会自动消耗对应等级
11
11
  */
12
- constructor(
13
- protected level: number,
14
- protected consumeAmount = false
15
- ) {
16
- super(level);
12
+ constructor(protected level: number, protected consumeAmount = false) {
13
+ super();
17
14
  }
18
- check(player: Player) {
15
+ check(player: Player, visual = false) {
19
16
  if (player.level >= this.level) {
17
+ if (visual) return true;
20
18
  if (!this.consumeAmount) return true;
21
19
  player.addLevels(-this.level);
22
20
  return true;
@@ -29,9 +27,9 @@ export class LevelConditions extends Conditions {
29
27
  // 达到 %s 级
30
28
  {
31
29
  translate: "task.condition.level",
32
- with: { text: this.level.toString() }
33
- }
34
- ]
30
+ with: { text: this.level.toString() },
31
+ },
32
+ ],
35
33
  };
36
34
  }
37
35
  getFailedReason(): RawMessage {
@@ -40,9 +38,9 @@ export class LevelConditions extends Conditions {
40
38
  // 你需要达到 %s 级
41
39
  {
42
40
  translate: "task.condition.level.failed",
43
- with: { text: this.level.toString() }
44
- }
45
- ]
41
+ with: { text: this.level.toString() },
42
+ },
43
+ ],
46
44
  };
47
45
  }
48
46
  }
package/src/index.ts CHANGED
@@ -2,9 +2,9 @@
2
2
  * @module @occultus/condition-api
3
3
  */
4
4
  export * from "./api/ItemConditions";
5
- export * from "./api/KillEntityCondition";
5
+ export * from "./api/KillEntityConditions";
6
6
  export * from "./api/KillEntityFamilyCondition";
7
- export * from "./api/LevelCondition";
7
+ export * from "./api/LevelConditions";
8
8
  export * from "./api/ExpCondition";
9
9
  export * from "./api/ItemTagConditions"
10
10
  export * from "./api/Conditions";