@occultus/task-api 0.23.0 → 0.23.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 +2 -2
- package/src/api/Task.ts +7 -1
- package/src/api/TaskServer.ts +49 -5
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@occultus/task-api",
|
|
3
|
-
"version": "0.23.
|
|
3
|
+
"version": "0.23.2",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://codeberg.org/TeamOccultus/StarTenonAPI"
|
|
@@ -27,7 +27,7 @@
|
|
|
27
27
|
"@occultus/format-api": "0.21.0",
|
|
28
28
|
"@occultus/toolkit": "0.24.0",
|
|
29
29
|
"@occultus/text-api": "0.24.0",
|
|
30
|
-
"@occultus/condition-api": "0.23.
|
|
30
|
+
"@occultus/condition-api": "0.23.1"
|
|
31
31
|
},
|
|
32
32
|
"peerDependencies": {
|
|
33
33
|
"@minecraft/server": "^2.4.0",
|
package/src/api/Task.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { parseText, parseToRaw, TextProvider } from "@occultus/text-api";
|
|
2
|
-
import { Player } from "@minecraft/server";
|
|
2
|
+
import { Player, world } from "@minecraft/server";
|
|
3
3
|
import { TaskOptions } from "../interface/TaskOptions";
|
|
4
4
|
import { TaskStatus } from "../enum/TaskStatus";
|
|
5
5
|
import { TaskGroup } from "./TaskGroup";
|
|
@@ -129,6 +129,12 @@ export class Task extends FormLike {
|
|
|
129
129
|
parseToRaw(this.name, player)
|
|
130
130
|
]
|
|
131
131
|
});
|
|
132
|
+
world.sendMessage({
|
|
133
|
+
rawtext: [
|
|
134
|
+
{ translate: "ui.task.complete.world", with: [player.name] },
|
|
135
|
+
parseToRaw(this.name, player)
|
|
136
|
+
]
|
|
137
|
+
});
|
|
132
138
|
player.playSound(this.options.completeSound ?? "random.levelup");
|
|
133
139
|
}
|
|
134
140
|
/**
|
package/src/api/TaskServer.ts
CHANGED
|
@@ -2,13 +2,18 @@ import { EntityDamageCause, Player, world } from "@minecraft/server";
|
|
|
2
2
|
import {
|
|
3
3
|
KillEntityConditions,
|
|
4
4
|
KillEntityFamilyConditions,
|
|
5
|
-
Conditions
|
|
5
|
+
Conditions,
|
|
6
|
+
ItemConditions,
|
|
7
|
+
ItemTagConditions
|
|
6
8
|
} from "@occultus/condition-api";
|
|
7
9
|
|
|
8
10
|
import { Task } from "./Task";
|
|
9
11
|
import { getFamilies } from "@occultus/toolkit";
|
|
10
12
|
import { TaskStatus } from "../enum/TaskStatus";
|
|
11
13
|
|
|
14
|
+
/**
|
|
15
|
+
* 用于实现任务智能提交的类
|
|
16
|
+
*/
|
|
12
17
|
export class TaskServer {
|
|
13
18
|
private startUp() {
|
|
14
19
|
world.afterEvents.entityDie.subscribe((event) => {
|
|
@@ -35,10 +40,32 @@ export class TaskServer {
|
|
|
35
40
|
task.complete(damagingEntity);
|
|
36
41
|
});
|
|
37
42
|
});
|
|
43
|
+
world.afterEvents.playerInventoryItemChange.subscribe((arg) => {
|
|
44
|
+
const { player, itemStack } = arg;
|
|
45
|
+
if (!itemStack) return;
|
|
46
|
+
if (!this.items.has(itemStack.typeId)) return;
|
|
47
|
+
const task = this.items.get(itemStack.typeId);
|
|
48
|
+
if (task?.getStatus(player) === TaskStatus.Done) return;
|
|
49
|
+
task?.complete(player);
|
|
50
|
+
});
|
|
51
|
+
world.afterEvents.playerInventoryItemChange.subscribe((arg) => {
|
|
52
|
+
const { player, itemStack } = arg;
|
|
53
|
+
if (!itemStack) return;
|
|
54
|
+
const itemTags = itemStack.getTags();
|
|
55
|
+
if (!itemTags || itemTags.length === 0) return;
|
|
56
|
+
itemTags.forEach((tag) => {
|
|
57
|
+
if (!this.itemTags.has(tag)) return;
|
|
58
|
+
const tagTask = this.itemTags.get(tag);
|
|
59
|
+
if (tagTask?.getStatus(player) === TaskStatus.Done) return;
|
|
60
|
+
tagTask?.complete(player);
|
|
61
|
+
});
|
|
62
|
+
});
|
|
38
63
|
console.log("[Occultus SDK] Task Server Started");
|
|
39
64
|
}
|
|
40
65
|
entities: Map<string, Task> = new Map();
|
|
41
66
|
families: Map<string, Task> = new Map();
|
|
67
|
+
items: Map<string, Task> = new Map();
|
|
68
|
+
itemTags: Map<string, Task> = new Map();
|
|
42
69
|
constructor() {
|
|
43
70
|
this.startUp();
|
|
44
71
|
}
|
|
@@ -49,10 +76,27 @@ export class TaskServer {
|
|
|
49
76
|
if (condition instanceof KillEntityFamilyConditions) {
|
|
50
77
|
this.families.set(condition.family, bindTo);
|
|
51
78
|
}
|
|
79
|
+
if (condition instanceof ItemConditions) {
|
|
80
|
+
this.items.set(condition.itemType, bindTo);
|
|
81
|
+
}
|
|
82
|
+
if (condition instanceof ItemTagConditions) {
|
|
83
|
+
this.itemTags.set(condition.tag, bindTo);
|
|
84
|
+
}
|
|
52
85
|
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
86
|
+
/**
|
|
87
|
+
* 向任务服务器添加任务,以启用智能提交功能
|
|
88
|
+
*
|
|
89
|
+
* **IMPORTANT: 倘若启用智能提交功能,则当玩家完成`conditons`数组中任意条件时,任务都会自动设置为已完成状态**
|
|
90
|
+
* @param task
|
|
91
|
+
*/
|
|
92
|
+
addTask(...task: Task[]) {
|
|
93
|
+
if (Array.isArray(task)) {
|
|
94
|
+
task.forEach((task) => {
|
|
95
|
+
task.options.conditions.forEach((condition) =>
|
|
96
|
+
this.addCondition(condition, task)
|
|
97
|
+
);
|
|
98
|
+
});
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
57
101
|
}
|
|
58
102
|
}
|