@occultus/condition-api 0.22.0-alpha.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/LICENSE +9 -0
- package/README.md +30 -0
- package/package.json +41 -0
- package/src/api/Conditions.ts +34 -0
- package/src/api/ExpCondition.ts +49 -0
- package/src/api/ItemConditions.ts +79 -0
- package/src/api/KillEntityCondition.ts +41 -0
- package/src/api/KillEntityFamilyCondition.ts +41 -0
- package/src/api/LevelCondition.ts +48 -0
- package/src/index.ts +9 -0
- package/tsconfig.json +21 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright © 2025 CTN Studios
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
|
+
|
|
7
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
8
|
+
|
|
9
|
+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# Star Tenon Skill API
|
|
2
|
+
|
|
3
|
+
本包提供了方便的技能 API。
|
|
4
|
+
|
|
5
|
+
## 支持版本
|
|
6
|
+
|
|
7
|
+
本 API 支持任意可以运行 Script API v2.0.0+ 的游戏版本,包括:
|
|
8
|
+
|
|
9
|
+
- 1.21.90;
|
|
10
|
+
- 1.21.100;
|
|
11
|
+
- 1.21.110;
|
|
12
|
+
- 以及更多……
|
|
13
|
+
|
|
14
|
+
注意:本包理论上可以在部分更旧的版本上运作,但未经过严格的测试。
|
|
15
|
+
|
|
16
|
+
## 协议
|
|
17
|
+
|
|
18
|
+
本项目使用 MIT License 授权:
|
|
19
|
+
|
|
20
|
+
```text
|
|
21
|
+
The MIT License (MIT)
|
|
22
|
+
|
|
23
|
+
Copyright © 2025 CTN Studios
|
|
24
|
+
|
|
25
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
26
|
+
|
|
27
|
+
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
|
28
|
+
|
|
29
|
+
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
30
|
+
```
|
package/package.json
ADDED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@occultus/condition-api",
|
|
3
|
+
"version": "0.22.0-alpha.1",
|
|
4
|
+
"repository": {
|
|
5
|
+
"type": "git",
|
|
6
|
+
"url": "https://codeberg.org/TeamOccultus/StarTenonAPI"
|
|
7
|
+
},
|
|
8
|
+
"homepage": "https://codeberg.org/TeamOccultus/StarTenonAPI",
|
|
9
|
+
"bugs": {
|
|
10
|
+
"url": "https://codeberg.org/TeamOccultus/StarTenonAPI/issues",
|
|
11
|
+
"email": "FangLiulii@outlook.com"
|
|
12
|
+
},
|
|
13
|
+
"description": "Star Tenon condition api",
|
|
14
|
+
"main": "src/index.ts",
|
|
15
|
+
"keywords": [
|
|
16
|
+
"Minecraft",
|
|
17
|
+
"Occultus SDK",
|
|
18
|
+
"Script API"
|
|
19
|
+
],
|
|
20
|
+
"contributors": [
|
|
21
|
+
"FangLimao <FangLiulii@outlook.com>"
|
|
22
|
+
],
|
|
23
|
+
"license": "MIT",
|
|
24
|
+
"author": "CTN Studios",
|
|
25
|
+
"peerDependencies": {
|
|
26
|
+
"@minecraft/server": ">=2.0.0",
|
|
27
|
+
"@occultus/core": ">=0.18.4 || <0.19.0"
|
|
28
|
+
},
|
|
29
|
+
"dependencies": {
|
|
30
|
+
"@occultus/format-api": "0.21.0",
|
|
31
|
+
"@occultus/item-api": "0.22.0-alpha",
|
|
32
|
+
"@occultus/entity-api": "0.21.1",
|
|
33
|
+
"@occultus/text-api": "0.20.0"
|
|
34
|
+
},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"typedoc": "^0.28.9"
|
|
37
|
+
},
|
|
38
|
+
"scripts": {
|
|
39
|
+
"test": "tsc"
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { Player } from "@minecraft/server";
|
|
2
|
+
import { TextProvider } from "@occultus/text-api";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* 条件的抽象类
|
|
6
|
+
*
|
|
7
|
+
* 定义了条件的基本结构和必须实现的方法,所有具体的条件类都应该继承此抽象类并实现其抽象方法
|
|
8
|
+
*/
|
|
9
|
+
export abstract class Conditions {
|
|
10
|
+
/**
|
|
11
|
+
* @param data 条件所需的数据
|
|
12
|
+
*/
|
|
13
|
+
constructor(protected data: unknown) {}
|
|
14
|
+
/**
|
|
15
|
+
* 检查玩家是否满足条件
|
|
16
|
+
*
|
|
17
|
+
* @param player 要检查的玩家对象
|
|
18
|
+
* @return 如果玩家满足条件返回`true`,否则返回`false`
|
|
19
|
+
*/
|
|
20
|
+
abstract check(player: Player): boolean;
|
|
21
|
+
/**
|
|
22
|
+
* 获取条件的文本,该文本将会在任务面板中显示
|
|
23
|
+
*
|
|
24
|
+
* @return 用于显示条件描述的文本
|
|
25
|
+
*/
|
|
26
|
+
abstract getTextProvider(): TextProvider;
|
|
27
|
+
/**
|
|
28
|
+
* 获取条件检查失败时的原因说明文本
|
|
29
|
+
*
|
|
30
|
+
* @return 用于显示失败原因的文本
|
|
31
|
+
*/
|
|
32
|
+
abstract getFailedReason(): TextProvider;
|
|
33
|
+
|
|
34
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { Player, RawMessage } from "@minecraft/server";
|
|
2
|
+
import { Conditions } from "./Conditions";
|
|
3
|
+
import { getAllExp } from "@occultus/entity-api";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* 等级条件
|
|
7
|
+
*/
|
|
8
|
+
export class ExpConditions extends Conditions {
|
|
9
|
+
/**
|
|
10
|
+
* @param experience 满足条件所需的最低等级
|
|
11
|
+
* @param consumeAmount 倘若为`true`,则条件检查通过后会自动消耗对应等级
|
|
12
|
+
*/
|
|
13
|
+
constructor(
|
|
14
|
+
protected experience: number,
|
|
15
|
+
protected consumeAmount = false
|
|
16
|
+
) {
|
|
17
|
+
super(experience);
|
|
18
|
+
}
|
|
19
|
+
check(player: Player) {
|
|
20
|
+
if (getAllExp(player) >= this.experience) {
|
|
21
|
+
if (!this.consumeAmount) return true;
|
|
22
|
+
player.addExperience(-this.experience);
|
|
23
|
+
return true;
|
|
24
|
+
}
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
27
|
+
getTextProvider(): RawMessage {
|
|
28
|
+
return {
|
|
29
|
+
rawtext: [
|
|
30
|
+
// 达到 %s 级
|
|
31
|
+
{
|
|
32
|
+
translate: "task.condition.level",
|
|
33
|
+
with: { text: this.experience.toString() },
|
|
34
|
+
},
|
|
35
|
+
],
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
getFailedReason(): RawMessage {
|
|
39
|
+
return {
|
|
40
|
+
rawtext: [
|
|
41
|
+
// 你需要达到 %s 级
|
|
42
|
+
{
|
|
43
|
+
translate: "task.condition.level.failed",
|
|
44
|
+
with: { text: this.experience.toString() },
|
|
45
|
+
},
|
|
46
|
+
],
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import { ItemStack, Player, RawMessage } from "@minecraft/server";
|
|
2
|
+
import { Conditions } from "./Conditions";
|
|
3
|
+
import {
|
|
4
|
+
getItemAmountInContainer,
|
|
5
|
+
removeItemInContainer,
|
|
6
|
+
} from "@occultus/item-api";
|
|
7
|
+
import { TextProvider } from "@occultus/text-api";
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* 物品条件
|
|
11
|
+
*/
|
|
12
|
+
export class ItemConditions extends Conditions {
|
|
13
|
+
/**
|
|
14
|
+
* @param itemType 满足条件所需要的物品类型
|
|
15
|
+
* @param amount 满足条件所需要的物品数量,默认为 1
|
|
16
|
+
* @param consumeAmount 倘若为`true`,则条件检查通过后会自动消耗对应物品
|
|
17
|
+
*/
|
|
18
|
+
constructor(
|
|
19
|
+
protected itemType: string,
|
|
20
|
+
protected amount: number = 1,
|
|
21
|
+
protected consumeAmount = false
|
|
22
|
+
) {
|
|
23
|
+
super(itemType);
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* 获取条件对应的 ItemStack
|
|
27
|
+
* @returns
|
|
28
|
+
*/
|
|
29
|
+
getItem() {
|
|
30
|
+
return new ItemStack(this.itemType, this.amount);
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* 检查玩家是否符合该条件的要求
|
|
34
|
+
*
|
|
35
|
+
* **IMPORTANT: 若`consumeAmount`属性被设置为`true`,则当检查通过时将对玩家的背包进行修改**
|
|
36
|
+
* @param player
|
|
37
|
+
* @return
|
|
38
|
+
*/
|
|
39
|
+
check(player: Player) {
|
|
40
|
+
const container = player.getComponent("minecraft:inventory")?.container;
|
|
41
|
+
if (!container) return false;
|
|
42
|
+
const amount = getItemAmountInContainer(container, this.getItem().typeId);
|
|
43
|
+
if (amount >= this.getItem().amount) {
|
|
44
|
+
if (!this.consumeAmount) return true;
|
|
45
|
+
removeItemInContainer(container, this.itemType, this.amount);
|
|
46
|
+
return true;
|
|
47
|
+
}
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* 获得条件对应的 {@link TextProvider}
|
|
52
|
+
* @returns
|
|
53
|
+
*/
|
|
54
|
+
getTextProvider(): RawMessage {
|
|
55
|
+
return {
|
|
56
|
+
rawtext: [
|
|
57
|
+
{ translate: this.getItem().localizationKey },
|
|
58
|
+
{ text: " × " },
|
|
59
|
+
{ text: this.getItem().amount.toString() },
|
|
60
|
+
],
|
|
61
|
+
};
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* 获得条件对应的失败原因
|
|
65
|
+
* @returns
|
|
66
|
+
*/
|
|
67
|
+
getFailedReason(): RawMessage {
|
|
68
|
+
return {
|
|
69
|
+
rawtext: [
|
|
70
|
+
// 你缺少这些物品:
|
|
71
|
+
{ translate: "task.condition.item.failed" },
|
|
72
|
+
{ text: " " },
|
|
73
|
+
{ translate: this.getItem().localizationKey },
|
|
74
|
+
{ text: " × " },
|
|
75
|
+
{ text: this.getItem().amount.toString() },
|
|
76
|
+
],
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { Player, RawMessage } from "@minecraft/server";
|
|
2
|
+
import { Conditions } from "./Conditions";
|
|
3
|
+
import { Localization } from "@occultus/format-api";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* 击杀实体条件
|
|
7
|
+
*
|
|
8
|
+
* **IMPORTANT: 此条件必须调用 {@link Task.pushToServer()} 方法才能生效**
|
|
9
|
+
*/
|
|
10
|
+
export class KillEntityConditions extends Conditions {
|
|
11
|
+
/**
|
|
12
|
+
* @param entityType 满足条件所需要的实体类型
|
|
13
|
+
*/
|
|
14
|
+
constructor(
|
|
15
|
+
public entityType: string
|
|
16
|
+
) {
|
|
17
|
+
super(entityType);
|
|
18
|
+
}
|
|
19
|
+
check(player: Player) {
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
getTextProvider(): RawMessage {
|
|
23
|
+
return {
|
|
24
|
+
rawtext: [
|
|
25
|
+
// 击杀实体:
|
|
26
|
+
{ translate: "task.condition.killentity" },
|
|
27
|
+
{ translate: Localization.getEntityKey(this.entityType) },
|
|
28
|
+
],
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
getFailedReason(): RawMessage {
|
|
32
|
+
return {
|
|
33
|
+
rawtext: [
|
|
34
|
+
// 你需要击杀实体:
|
|
35
|
+
{ translate: "task.condition.killentity.failed" },
|
|
36
|
+
{ text: " " },
|
|
37
|
+
{ translate: Localization.getEntityKey(this.entityType) },
|
|
38
|
+
],
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { Player, RawMessage } from "@minecraft/server";
|
|
2
|
+
import { Conditions } from "./Conditions";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* 击杀实体条件
|
|
6
|
+
*
|
|
7
|
+
* **IMPORTANT: 此条件必须调用 {@link Task.pushToServer()} 方法才能生效**
|
|
8
|
+
*/
|
|
9
|
+
export class KillEntityFamilyConditions extends Conditions {
|
|
10
|
+
/**
|
|
11
|
+
* @param family 满足条件所需要的实体类型
|
|
12
|
+
*/
|
|
13
|
+
constructor(
|
|
14
|
+
public family: string,
|
|
15
|
+
public localizationKey: string
|
|
16
|
+
) {
|
|
17
|
+
super(family);
|
|
18
|
+
}
|
|
19
|
+
check(player: Player) {
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
getTextProvider(): RawMessage {
|
|
23
|
+
return {
|
|
24
|
+
rawtext: [
|
|
25
|
+
// 击杀此类实体:
|
|
26
|
+
{ translate: "task.condition.killEntityFamily" },
|
|
27
|
+
{ translate: this.localizationKey },
|
|
28
|
+
],
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
getFailedReason(): RawMessage {
|
|
32
|
+
return {
|
|
33
|
+
rawtext: [
|
|
34
|
+
// 你需要击杀此类实体:
|
|
35
|
+
{ translate: "task.condition.killEntityFamily.failed" },
|
|
36
|
+
{ text: " " },
|
|
37
|
+
{ translate: this.localizationKey },
|
|
38
|
+
],
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { Player, RawMessage } from "@minecraft/server";
|
|
2
|
+
import { Conditions } from "./Conditions";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* 等级条件
|
|
6
|
+
*/
|
|
7
|
+
export class LevelConditions extends Conditions {
|
|
8
|
+
/**
|
|
9
|
+
* @param level 满足条件所需的最低等级
|
|
10
|
+
* @param consumeAmount 倘若为`true`,则条件检查通过后会自动消耗对应等级
|
|
11
|
+
*/
|
|
12
|
+
constructor(
|
|
13
|
+
protected level: number,
|
|
14
|
+
protected consumeAmount = false
|
|
15
|
+
) {
|
|
16
|
+
super(level);
|
|
17
|
+
}
|
|
18
|
+
check(player: Player) {
|
|
19
|
+
if (player.level >= this.level) {
|
|
20
|
+
if (!this.consumeAmount) return true;
|
|
21
|
+
player.addLevels(-this.level);
|
|
22
|
+
return true;
|
|
23
|
+
}
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
getTextProvider(): RawMessage {
|
|
27
|
+
return {
|
|
28
|
+
rawtext: [
|
|
29
|
+
// 达到 %s 级
|
|
30
|
+
{
|
|
31
|
+
translate: "task.condition.level",
|
|
32
|
+
with: { text: this.level.toString() },
|
|
33
|
+
},
|
|
34
|
+
],
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
getFailedReason(): RawMessage {
|
|
38
|
+
return {
|
|
39
|
+
rawtext: [
|
|
40
|
+
// 你需要达到 %s 级
|
|
41
|
+
{
|
|
42
|
+
translate: "task.condition.level.failed",
|
|
43
|
+
with: { text: this.level.toString() },
|
|
44
|
+
},
|
|
45
|
+
],
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @module @occultus/condition-api
|
|
3
|
+
*/
|
|
4
|
+
export * from "./api/ItemConditions";
|
|
5
|
+
export * from "./api/KillEntityCondition";
|
|
6
|
+
export * from "./api/KillEntityFamilyCondition";
|
|
7
|
+
export * from "./api/LevelCondition";
|
|
8
|
+
export * from "./api/ExpCondition";
|
|
9
|
+
export * from "./api/Conditions";
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"include": ["src/**/*"],
|
|
3
|
+
"exclude": ["./out"],
|
|
4
|
+
"Modules": {
|
|
5
|
+
"resolvePackageJsonExports": true
|
|
6
|
+
},
|
|
7
|
+
"compilerOptions": {
|
|
8
|
+
"noEmit": true,
|
|
9
|
+
"noEmitOnError": true,
|
|
10
|
+
"target": "es2022",
|
|
11
|
+
"lib": ["es2020", "dom"],
|
|
12
|
+
"strict": true,
|
|
13
|
+
"moduleResolution": "bundler",
|
|
14
|
+
"esModuleInterop": true,
|
|
15
|
+
"module": "es2022",
|
|
16
|
+
"outDir": ".",
|
|
17
|
+
"removeComments": true,
|
|
18
|
+
"newLine": "lf",
|
|
19
|
+
"resolveJsonModule": true
|
|
20
|
+
}
|
|
21
|
+
}
|