@occultus/task-api 0.21.0-beta.0 → 0.21.0-beta.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 +3 -3
- package/src/api/Task.ts +15 -5
- package/src/api/TaskServer.ts +16 -10
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@occultus/task-api",
|
|
3
|
-
"version": "0.21.0-beta.
|
|
3
|
+
"version": "0.21.0-beta.2",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://codeberg.org/TeamOccultus/StarTenonAPI"
|
|
@@ -24,8 +24,8 @@
|
|
|
24
24
|
"author": "CTN Studios",
|
|
25
25
|
"type": "module",
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@occultus/format-api": "0.21.0-beta.
|
|
28
|
-
"@occultus/entity-api": "0.
|
|
27
|
+
"@occultus/format-api": "0.21.0-beta.2",
|
|
28
|
+
"@occultus/entity-api": "0.21.0-beta.2",
|
|
29
29
|
"@occultus/text-api": "0.20.0",
|
|
30
30
|
"@occultus/item-api": "0.20.0"
|
|
31
31
|
},
|
package/src/api/Task.ts
CHANGED
|
@@ -4,9 +4,10 @@ import { TaskOptions } from "../interface/TaskOptions";
|
|
|
4
4
|
import { TaskStatus } from "../enum/TaskStaus";
|
|
5
5
|
import { TaskGroup } from "./TaskGroup";
|
|
6
6
|
import { TaskCenter } from "./TaskCenter";
|
|
7
|
-
import {
|
|
7
|
+
import { ActionFormData } from "@minecraft/server-ui";
|
|
8
8
|
import { TaskUtils } from "../utils/TaskUtils";
|
|
9
9
|
import { LockedScreen } from "../ui/LockedScreen";
|
|
10
|
+
import { TaskServer } from "./TaskServer";
|
|
10
11
|
|
|
11
12
|
export class Task {
|
|
12
13
|
/**
|
|
@@ -31,16 +32,16 @@ export class Task {
|
|
|
31
32
|
this.lockedDisplay(player, backTo);
|
|
32
33
|
return;
|
|
33
34
|
}
|
|
34
|
-
const form = new
|
|
35
|
+
const form = new ActionFormData();
|
|
35
36
|
form.title(parseText(this.name, player));
|
|
36
37
|
form.body(TaskUtils.generateTaskBody(this, player));
|
|
37
|
-
form.
|
|
38
|
+
form.button({ translate: "gui.back" });
|
|
38
39
|
if (this.getStatus(player) === TaskStatus.Done) {
|
|
39
40
|
// 任务已完成
|
|
40
|
-
form.
|
|
41
|
+
form.button({ translate: "ui.task.done" });
|
|
41
42
|
} else {
|
|
42
43
|
// 提交任务
|
|
43
|
-
form.
|
|
44
|
+
form.button({ translate: "ui.task.submit" });
|
|
44
45
|
}
|
|
45
46
|
form.show(player).then((result) => {
|
|
46
47
|
if (result.selection === 1) {
|
|
@@ -128,4 +129,13 @@ export class Task {
|
|
|
128
129
|
});
|
|
129
130
|
player.playSound(this.options.completeSound ?? "random.levelup");
|
|
130
131
|
}
|
|
132
|
+
/**
|
|
133
|
+
* 直接将任务上传到服务端监听器中
|
|
134
|
+
*
|
|
135
|
+
* **IMPORTANT: 除非任务使用的条件有特殊说明,否则此方法一般无用**
|
|
136
|
+
* @param server
|
|
137
|
+
*/
|
|
138
|
+
pushToServer(server: TaskServer){
|
|
139
|
+
server.addTask(this);
|
|
140
|
+
}
|
|
131
141
|
}
|
package/src/api/TaskServer.ts
CHANGED
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
EntityDamageCause,
|
|
3
|
-
Player,
|
|
4
|
-
world,
|
|
5
|
-
} from "@minecraft/server";
|
|
1
|
+
import { EntityDamageCause, Player, world } from "@minecraft/server";
|
|
6
2
|
import { KillEntityConditions } from "./conditions/KillEntityCondition";
|
|
7
3
|
import { KillEntityFamilyConditions } from "./conditions/KillEntityFamilyCondition";
|
|
8
4
|
import { TaskConditions } from "./conditions/TaskConditions";
|
|
9
5
|
import { Task } from "./Task";
|
|
6
|
+
import { getFamilies } from "@occultus/entity-api";
|
|
10
7
|
|
|
11
8
|
export class TaskServer {
|
|
12
9
|
private startUp() {
|
|
@@ -21,13 +18,17 @@ export class TaskServer {
|
|
|
21
18
|
});
|
|
22
19
|
world.afterEvents.entityDie.subscribe((event) => {
|
|
23
20
|
const { deadEntity, damageSource } = event;
|
|
24
|
-
const
|
|
25
|
-
if (!task) return;
|
|
21
|
+
const damagingEntity = damageSource.damagingEntity;
|
|
26
22
|
if (damageSource.cause !== EntityDamageCause.entityAttack) return;
|
|
27
|
-
if (!
|
|
28
|
-
if (!(
|
|
29
|
-
|
|
23
|
+
if (!damagingEntity) return;
|
|
24
|
+
if (!(damagingEntity instanceof Player)) return;
|
|
25
|
+
getFamilies(deadEntity)?.forEach((family) => {
|
|
26
|
+
const task = this.families.get(deadEntity.typeId);
|
|
27
|
+
if (!task) return;
|
|
28
|
+
task.complete(damagingEntity);
|
|
29
|
+
});
|
|
30
30
|
});
|
|
31
|
+
console.log("[Occultus SDK] Task Server Started")
|
|
31
32
|
}
|
|
32
33
|
entities: Map<string, Task> = new Map();
|
|
33
34
|
families: Map<string, Task> = new Map();
|
|
@@ -42,4 +43,9 @@ export class TaskServer {
|
|
|
42
43
|
this.families.set(condition.family, condition.bindTo);
|
|
43
44
|
}
|
|
44
45
|
}
|
|
46
|
+
addTask(task: Task) {
|
|
47
|
+
task.options.conditions.forEach((condition) => {
|
|
48
|
+
this.addCondition(condition);
|
|
49
|
+
});
|
|
50
|
+
}
|
|
45
51
|
}
|