@occultus/condition-api 0.22.0-alpha.1 → 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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@occultus/condition-api",
3
- "version": "0.22.0-alpha.1",
3
+ "version": "0.22.0-alpha.3",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://codeberg.org/TeamOccultus/StarTenonAPI"
@@ -23,17 +23,16 @@
23
23
  "license": "MIT",
24
24
  "author": "CTN Studios",
25
25
  "peerDependencies": {
26
- "@minecraft/server": ">=2.0.0",
27
- "@occultus/core": ">=0.18.4 || <0.19.0"
26
+ "@minecraft/server": "^2.4.0",
27
+ "@occultus/core": "~0.18.4"
28
28
  },
29
29
  "dependencies": {
30
30
  "@occultus/format-api": "0.21.0",
31
- "@occultus/item-api": "0.22.0-alpha",
32
- "@occultus/entity-api": "0.21.1",
31
+ "@occultus/toolkit": "0.22.1",
33
32
  "@occultus/text-api": "0.20.0"
34
33
  },
35
34
  "devDependencies": {
36
- "typedoc": "^0.28.9"
35
+ "typedoc": "^0.28.15"
37
36
  },
38
37
  "scripts": {
39
38
  "test": "tsc"
@@ -30,5 +30,4 @@ export abstract class Conditions {
30
30
  * @return 用于显示失败原因的文本
31
31
  */
32
32
  abstract getFailedReason(): TextProvider;
33
-
34
33
  }
@@ -1,6 +1,6 @@
1
1
  import { Player, RawMessage } from "@minecraft/server";
2
2
  import { Conditions } from "./Conditions";
3
- import { getAllExp } from "@occultus/entity-api";
3
+ import { getAllExp } from "@occultus/toolkit";
4
4
 
5
5
  /**
6
6
  * 等级条件
@@ -30,9 +30,9 @@ export class ExpConditions extends Conditions {
30
30
  // 达到 %s 级
31
31
  {
32
32
  translate: "task.condition.level",
33
- with: { text: this.experience.toString() },
34
- },
35
- ],
33
+ with: { text: this.experience.toString() }
34
+ }
35
+ ]
36
36
  };
37
37
  }
38
38
  getFailedReason(): RawMessage {
@@ -41,9 +41,9 @@ export class ExpConditions extends Conditions {
41
41
  // 你需要达到 %s 级
42
42
  {
43
43
  translate: "task.condition.level.failed",
44
- with: { text: this.experience.toString() },
45
- },
46
- ],
44
+ with: { text: this.experience.toString() }
45
+ }
46
+ ]
47
47
  };
48
48
  }
49
49
  }
@@ -2,8 +2,8 @@ import { ItemStack, Player, RawMessage } from "@minecraft/server";
2
2
  import { Conditions } from "./Conditions";
3
3
  import {
4
4
  getItemAmountInContainer,
5
- removeItemInContainer,
6
- } from "@occultus/item-api";
5
+ removeItemInContainer
6
+ } from "@occultus/toolkit";
7
7
  import { TextProvider } from "@occultus/text-api";
8
8
 
9
9
  /**
@@ -24,17 +24,17 @@ export class ItemConditions extends Conditions {
24
24
  }
25
25
  /**
26
26
  * 获取条件对应的 ItemStack
27
- * @returns
27
+ * @returns
28
28
  */
29
29
  getItem() {
30
30
  return new ItemStack(this.itemType, this.amount);
31
31
  }
32
32
  /**
33
33
  * 检查玩家是否符合该条件的要求
34
- *
34
+ *
35
35
  * **IMPORTANT: 若`consumeAmount`属性被设置为`true`,则当检查通过时将对玩家的背包进行修改**
36
- * @param player
37
- * @return
36
+ * @param player
37
+ * @return
38
38
  */
39
39
  check(player: Player) {
40
40
  const container = player.getComponent("minecraft:inventory")?.container;
@@ -49,20 +49,20 @@ export class ItemConditions extends Conditions {
49
49
  }
50
50
  /**
51
51
  * 获得条件对应的 {@link TextProvider}
52
- * @returns
52
+ * @returns
53
53
  */
54
54
  getTextProvider(): RawMessage {
55
55
  return {
56
56
  rawtext: [
57
57
  { translate: this.getItem().localizationKey },
58
58
  { text: " × " },
59
- { text: this.getItem().amount.toString() },
60
- ],
59
+ { text: this.getItem().amount.toString() }
60
+ ]
61
61
  };
62
62
  }
63
63
  /**
64
64
  * 获得条件对应的失败原因
65
- * @returns
65
+ * @returns
66
66
  */
67
67
  getFailedReason(): RawMessage {
68
68
  return {
@@ -72,8 +72,8 @@ export class ItemConditions extends Conditions {
72
72
  { text: " " },
73
73
  { translate: this.getItem().localizationKey },
74
74
  { text: " × " },
75
- { text: this.getItem().amount.toString() },
76
- ],
75
+ { text: this.getItem().amount.toString() }
76
+ ]
77
77
  };
78
78
  }
79
79
  }
@@ -0,0 +1,75 @@
1
+ import { Player, RawMessage } from "@minecraft/server";
2
+ import { Conditions } from "./Conditions";
3
+ import {
4
+ getTagItemAmountInContainer,
5
+ removeTagItemInContainer,
6
+ } from "@occultus/toolkit";
7
+ import { TextProvider } from "@occultus/text-api";
8
+
9
+ /**
10
+ * 物品标签条件
11
+ */
12
+ export class ItemTagConditions extends Conditions {
13
+ /**
14
+ * @param tag 满足条件所需要的物品标签
15
+ * @param amount 满足条件所需要的物品数量,默认为 1
16
+ * @param translateKey 条件对应的翻译键
17
+ * @param consumeAmount 检查通过时是否消耗物品,默认为 false
18
+ */
19
+ constructor(
20
+ protected tag: string,
21
+ protected amount: number = 1,
22
+ protected translateKey: string,
23
+ protected consumeAmount: boolean = false
24
+ ) {
25
+ super(tag);
26
+ }
27
+ /**
28
+ * 检查玩家是否符合该条件的要求
29
+ *
30
+ * **IMPORTANT: 若`consumeAmount`属性被设置为`true`,则当检查通过时将对玩家的背包进行修改**
31
+ * @param player
32
+ * @return
33
+ */
34
+ check(player: Player) {
35
+ const container = player.getComponent("minecraft:inventory")?.container;
36
+ if (!container) return false;
37
+ const amount = getTagItemAmountInContainer(container, this.tag);
38
+
39
+ if (amount >= this.amount) {
40
+ if (!this.consumeAmount) return true;
41
+ removeTagItemInContainer(container, this.tag, this.amount);
42
+ return true;
43
+ }
44
+ return false;
45
+ }
46
+ /**
47
+ * 获得条件对应的 {@link TextProvider}
48
+ * @returns
49
+ */
50
+ getTextProvider(): RawMessage {
51
+ return {
52
+ rawtext: [
53
+ { translate: "task.condition.itemTag" },
54
+ { text: " × " },
55
+ { text: this.translateKey },
56
+ ],
57
+ };
58
+ }
59
+ /**
60
+ * 获得条件对应的失败原因
61
+ * @returns
62
+ */
63
+ getFailedReason(): RawMessage {
64
+ return {
65
+ rawtext: [
66
+ // 你缺少这些物品:
67
+ { translate: "task.condition.itemTag.failed" },
68
+ { text: " " },
69
+ { translate: this.translateKey },
70
+ { text: " × " },
71
+ { text: this.amount.toString() },
72
+ ],
73
+ };
74
+ }
75
+ }
@@ -4,16 +4,14 @@ import { Localization } from "@occultus/format-api";
4
4
 
5
5
  /**
6
6
  * 击杀实体条件
7
- *
7
+ *
8
8
  * **IMPORTANT: 此条件必须调用 {@link Task.pushToServer()} 方法才能生效**
9
9
  */
10
10
  export class KillEntityConditions extends Conditions {
11
11
  /**
12
12
  * @param entityType 满足条件所需要的实体类型
13
13
  */
14
- constructor(
15
- public entityType: string
16
- ) {
14
+ constructor(public entityType: string) {
17
15
  super(entityType);
18
16
  }
19
17
  check(player: Player) {
@@ -24,8 +22,8 @@ export class KillEntityConditions extends Conditions {
24
22
  rawtext: [
25
23
  // 击杀实体:
26
24
  { translate: "task.condition.killentity" },
27
- { translate: Localization.getEntityKey(this.entityType) },
28
- ],
25
+ { translate: Localization.getEntityKey(this.entityType) }
26
+ ]
29
27
  };
30
28
  }
31
29
  getFailedReason(): RawMessage {
@@ -34,8 +32,8 @@ export class KillEntityConditions extends Conditions {
34
32
  // 你需要击杀实体:
35
33
  { translate: "task.condition.killentity.failed" },
36
34
  { text: " " },
37
- { translate: Localization.getEntityKey(this.entityType) },
38
- ],
35
+ { translate: Localization.getEntityKey(this.entityType) }
36
+ ]
39
37
  };
40
38
  }
41
39
  }
@@ -3,7 +3,7 @@ import { Conditions } from "./Conditions";
3
3
 
4
4
  /**
5
5
  * 击杀实体条件
6
- *
6
+ *
7
7
  * **IMPORTANT: 此条件必须调用 {@link Task.pushToServer()} 方法才能生效**
8
8
  */
9
9
  export class KillEntityFamilyConditions extends Conditions {
@@ -24,8 +24,8 @@ export class KillEntityFamilyConditions extends Conditions {
24
24
  rawtext: [
25
25
  // 击杀此类实体:
26
26
  { translate: "task.condition.killEntityFamily" },
27
- { translate: this.localizationKey },
28
- ],
27
+ { translate: this.localizationKey }
28
+ ]
29
29
  };
30
30
  }
31
31
  getFailedReason(): RawMessage {
@@ -34,8 +34,8 @@ export class KillEntityFamilyConditions extends Conditions {
34
34
  // 你需要击杀此类实体:
35
35
  { translate: "task.condition.killEntityFamily.failed" },
36
36
  { text: " " },
37
- { translate: this.localizationKey },
38
- ],
37
+ { translate: this.localizationKey }
38
+ ]
39
39
  };
40
40
  }
41
41
  }
@@ -29,9 +29,9 @@ export class LevelConditions extends Conditions {
29
29
  // 达到 %s 级
30
30
  {
31
31
  translate: "task.condition.level",
32
- with: { text: this.level.toString() },
33
- },
34
- ],
32
+ with: { text: this.level.toString() }
33
+ }
34
+ ]
35
35
  };
36
36
  }
37
37
  getFailedReason(): RawMessage {
@@ -40,9 +40,9 @@ export class LevelConditions extends Conditions {
40
40
  // 你需要达到 %s 级
41
41
  {
42
42
  translate: "task.condition.level.failed",
43
- with: { text: this.level.toString() },
44
- },
45
- ],
43
+ with: { text: this.level.toString() }
44
+ }
45
+ ]
46
46
  };
47
47
  }
48
48
  }