@occultus/task-api 0.20.0 → 0.21.0-alpha
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 +4 -4
- package/src/api/Task.ts +1 -1
- package/src/api/TaskServer.ts +45 -0
- package/src/api/awards/ExpAwards.ts +22 -0
- package/src/api/awards/LevelAwards.ts +22 -0
- package/src/api/awards/index.ts +4 -0
- package/src/api/conditions/KillEntityCondition.ts +41 -0
- package/src/api/conditions/KillEntityFamilyCondition.ts +41 -0
- package/src/api/conditions/LevelCondition.ts +36 -0
- package/src/api/conditions/index.ts +5 -0
- package/src/index.ts +10 -11
- package/src/ui/TaskListScreen.ts +1 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@occultus/task-api",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.21.0-alpha",
|
|
4
4
|
"repository": {
|
|
5
5
|
"type": "git",
|
|
6
6
|
"url": "https://codeberg.org/TeamOccultus/StarTenonAPI"
|
|
@@ -24,10 +24,10 @@
|
|
|
24
24
|
"author": "CTN Studios",
|
|
25
25
|
"type": "module",
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@occultus/format-api": "0.
|
|
27
|
+
"@occultus/format-api": "0.21.0-alpha",
|
|
28
|
+
"@occultus/item-api": "0.20.0",
|
|
28
29
|
"@occultus/text-api": "0.20.0",
|
|
29
|
-
"@occultus/entity-api": "0.20.0"
|
|
30
|
-
"@occultus/item-api": "0.20.0"
|
|
30
|
+
"@occultus/entity-api": "0.20.0"
|
|
31
31
|
},
|
|
32
32
|
"peerDependencies": {
|
|
33
33
|
"@minecraft/server": ">=2.1.0",
|
package/src/api/Task.ts
CHANGED
|
@@ -116,7 +116,7 @@ export class Task {
|
|
|
116
116
|
protected giveAwards(player: Player) {
|
|
117
117
|
this.options.awards.forEach((award) => award.give(player));
|
|
118
118
|
}
|
|
119
|
-
|
|
119
|
+
complete(player: Player) {
|
|
120
120
|
player.addTag("done:" + this.id);
|
|
121
121
|
this.giveAwards(player);
|
|
122
122
|
player.onScreenDisplay.setActionBar({
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import {
|
|
2
|
+
EntityDamageCause,
|
|
3
|
+
Player,
|
|
4
|
+
world,
|
|
5
|
+
} from "@minecraft/server";
|
|
6
|
+
import { KillEntityConditions } from "./conditions/KillEntityCondition";
|
|
7
|
+
import { KillEntityFamilyConditions } from "./conditions/KillEntityFamilyCondition";
|
|
8
|
+
import { TaskConditions } from "./conditions/TaskConditions";
|
|
9
|
+
import { Task } from "./Task";
|
|
10
|
+
|
|
11
|
+
export class TaskServer {
|
|
12
|
+
private startUp() {
|
|
13
|
+
world.afterEvents.entityDie.subscribe((event) => {
|
|
14
|
+
const { deadEntity, damageSource } = event;
|
|
15
|
+
const task = this.entities.get(deadEntity.typeId);
|
|
16
|
+
if (!task) return;
|
|
17
|
+
if (damageSource.cause !== EntityDamageCause.entityAttack) return;
|
|
18
|
+
if (!damageSource.damagingEntity) return;
|
|
19
|
+
if (!(damageSource.damagingEntity instanceof Player)) return;
|
|
20
|
+
task.complete(damageSource.damagingEntity);
|
|
21
|
+
});
|
|
22
|
+
world.afterEvents.entityDie.subscribe((event) => {
|
|
23
|
+
const { deadEntity, damageSource } = event;
|
|
24
|
+
const task = this.entities.get(deadEntity.typeId);
|
|
25
|
+
if (!task) return;
|
|
26
|
+
if (damageSource.cause !== EntityDamageCause.entityAttack) return;
|
|
27
|
+
if (!damageSource.damagingEntity) return;
|
|
28
|
+
if (!(damageSource.damagingEntity instanceof Player)) return;
|
|
29
|
+
task.complete(damageSource.damagingEntity);
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
entities: Map<string, Task> = new Map();
|
|
33
|
+
families: Map<string, Task> = new Map();
|
|
34
|
+
constructor() {
|
|
35
|
+
this.startUp();
|
|
36
|
+
}
|
|
37
|
+
addCondition(condition: TaskConditions) {
|
|
38
|
+
if (condition instanceof KillEntityConditions) {
|
|
39
|
+
this.entities.set(condition.entityType, condition.bindTo);
|
|
40
|
+
}
|
|
41
|
+
if (condition instanceof KillEntityFamilyConditions) {
|
|
42
|
+
this.families.set(condition.family, condition.bindTo);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Player } from "@minecraft/server";
|
|
2
|
+
import { TaskAwards } from "./TaskAwards";
|
|
3
|
+
|
|
4
|
+
export class ExpAwards extends TaskAwards {
|
|
5
|
+
constructor(
|
|
6
|
+
protected amount: number
|
|
7
|
+
) {
|
|
8
|
+
super(amount);
|
|
9
|
+
}
|
|
10
|
+
give(player: Player) {
|
|
11
|
+
player.addExperience(this.amount);
|
|
12
|
+
}
|
|
13
|
+
getTextProvider() {
|
|
14
|
+
return {
|
|
15
|
+
rawtext: [
|
|
16
|
+
{ translate: "task.awards.exp" },
|
|
17
|
+
{ text: " × " },
|
|
18
|
+
{ text: this.amount.toString() },
|
|
19
|
+
],
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { Player } from "@minecraft/server";
|
|
2
|
+
import { TaskAwards } from "./TaskAwards";
|
|
3
|
+
|
|
4
|
+
export class LevelAwards extends TaskAwards {
|
|
5
|
+
constructor(
|
|
6
|
+
protected amount: number
|
|
7
|
+
) {
|
|
8
|
+
super(amount);
|
|
9
|
+
}
|
|
10
|
+
give(player: Player) {
|
|
11
|
+
player.addLevels(this.amount);
|
|
12
|
+
}
|
|
13
|
+
getTextProvider() {
|
|
14
|
+
return {
|
|
15
|
+
rawtext: [
|
|
16
|
+
{ translate: "task.awards.level" },
|
|
17
|
+
{ text: " × " },
|
|
18
|
+
{ text: this.amount.toString() },
|
|
19
|
+
],
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { Player } from "@minecraft/server";
|
|
2
|
+
import { TaskConditions } from "./TaskConditions";
|
|
3
|
+
import { Task } from "../Task";
|
|
4
|
+
import { Localization } from "@occultus/format-api";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* 击杀实体条件
|
|
8
|
+
*/
|
|
9
|
+
export class KillEntityConditions extends TaskConditions {
|
|
10
|
+
/**
|
|
11
|
+
* @param entityType 满足条件所需要的实体类型
|
|
12
|
+
*/
|
|
13
|
+
constructor(
|
|
14
|
+
public entityType: string,
|
|
15
|
+
public bindTo: Task
|
|
16
|
+
) {
|
|
17
|
+
super(entityType);
|
|
18
|
+
}
|
|
19
|
+
check(player: Player) {
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
getTextProvider() {
|
|
23
|
+
return {
|
|
24
|
+
rawtext: [
|
|
25
|
+
// 击杀实体:
|
|
26
|
+
{ translate: "task.condition.killentity" },
|
|
27
|
+
{ translate: Localization.getEntityKey(this.entityType) },
|
|
28
|
+
],
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
getFailedReason() {
|
|
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 } from "@minecraft/server";
|
|
2
|
+
import { TaskConditions } from "./TaskConditions";
|
|
3
|
+
import { Task } from "../Task";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* 击杀实体条件
|
|
7
|
+
*/
|
|
8
|
+
export class KillEntityFamilyConditions extends TaskConditions {
|
|
9
|
+
/**
|
|
10
|
+
* @param family 满足条件所需要的实体类型
|
|
11
|
+
*/
|
|
12
|
+
constructor(
|
|
13
|
+
public family: string,
|
|
14
|
+
public localizationKey: string,
|
|
15
|
+
public bindTo: Task
|
|
16
|
+
) {
|
|
17
|
+
super(family);
|
|
18
|
+
}
|
|
19
|
+
check(player: Player) {
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
getTextProvider() {
|
|
23
|
+
return {
|
|
24
|
+
rawtext: [
|
|
25
|
+
// 击杀此类实体:
|
|
26
|
+
{ translate: "task.condition.killEntityFamily" },
|
|
27
|
+
{ translate: this.localizationKey },
|
|
28
|
+
],
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
getFailedReason() {
|
|
32
|
+
return {
|
|
33
|
+
rawtext: [
|
|
34
|
+
// 你需要击杀此类实体:
|
|
35
|
+
{ translate: "task.condition.killEntityFamily.failed" },
|
|
36
|
+
{ text: " " },
|
|
37
|
+
{ translate: this.localizationKey },
|
|
38
|
+
],
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { Player, RawMessage } from "@minecraft/server";
|
|
2
|
+
import { TaskConditions } from "./TaskConditions";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* 击杀实体条件
|
|
6
|
+
*/
|
|
7
|
+
export class LevelConditions extends TaskConditions {
|
|
8
|
+
constructor(public level: number) {
|
|
9
|
+
super(level);
|
|
10
|
+
}
|
|
11
|
+
check(player: Player) {
|
|
12
|
+
return player.level >= this.level;
|
|
13
|
+
}
|
|
14
|
+
getTextProvider(): RawMessage {
|
|
15
|
+
return {
|
|
16
|
+
rawtext: [
|
|
17
|
+
// 达到 %s 级
|
|
18
|
+
{
|
|
19
|
+
translate: "task.condition.level",
|
|
20
|
+
with: { text: this.level.toString() },
|
|
21
|
+
},
|
|
22
|
+
],
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
getFailedReason(): RawMessage {
|
|
26
|
+
return {
|
|
27
|
+
rawtext: [
|
|
28
|
+
// 你需要达到 %s 级
|
|
29
|
+
{
|
|
30
|
+
translate: "task.condition.level.failed",
|
|
31
|
+
with: { text: this.level.toString() },
|
|
32
|
+
},
|
|
33
|
+
],
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
|
-
export * from "./api/Task"
|
|
2
|
-
export * from "./api/TaskGroup"
|
|
3
|
-
export * from "./api/TaskCenter"
|
|
4
|
-
export * from "./api/awards
|
|
5
|
-
export * from "./api/
|
|
6
|
-
export * from "./
|
|
7
|
-
export * from "./
|
|
8
|
-
export * from "./
|
|
9
|
-
export * from "./interface/
|
|
10
|
-
export * from "./
|
|
11
|
-
export * from "./interface/TaskOptions"
|
|
1
|
+
export * from "./api/Task";
|
|
2
|
+
export * from "./api/TaskGroup";
|
|
3
|
+
export * from "./api/TaskCenter";
|
|
4
|
+
export * from "./api/awards";
|
|
5
|
+
export * from "./api/conditions";
|
|
6
|
+
export * from "./enum/TaskStaus";
|
|
7
|
+
export * from "./interface/TaskCenterOptions";
|
|
8
|
+
export * from "./interface/TaskGroupOptions";
|
|
9
|
+
export * from "./interface/TaskOptions";
|
|
10
|
+
export * from "./api/TaskServer";
|
package/src/ui/TaskListScreen.ts
CHANGED
|
@@ -20,7 +20,7 @@ export class TaskListScreen {
|
|
|
20
20
|
form.body(parseToRaw(origin.description, player));
|
|
21
21
|
if (origin instanceof TaskGroup) {
|
|
22
22
|
// 获取奖励
|
|
23
|
-
form.button({ translate: "" });
|
|
23
|
+
form.button({ translate: "ui.getAward" });
|
|
24
24
|
}
|
|
25
25
|
const tasks: (Task | TaskGroup)[] = [];
|
|
26
26
|
origin.options.tasks.forEach((task) => {
|