From b1107805d01999ebc5ecf6af821102163e5d7d17 Mon Sep 17 00:00:00 2001 From: gongxh Date: Wed, 17 Sep 2025 11:05:23 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AF=BC=E5=87=BA=20Status=20=E6=9E=9A?= =?UTF-8?q?=E4=B8=BE;=E5=AF=BC=E5=87=BA=E5=8F=82=E6=95=B0=E7=B1=BB?= =?UTF-8?q?=E5=9E=8B;=E6=B7=BB=E5=8A=A0=E6=9D=A1=E4=BB=B6=E8=8A=82?= =?UTF-8?q?=E7=82=B9=E5=9F=BA=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/behaviortree/BTNode/Action.ts | 4 ++-- src/behaviortree/BTNode/Condition.ts | 20 ++++++++++++++++++++ src/index.ts | 4 +++- 3 files changed, 25 insertions(+), 3 deletions(-) create mode 100644 src/behaviortree/BTNode/Condition.ts diff --git a/src/behaviortree/BTNode/Action.ts b/src/behaviortree/BTNode/Action.ts index b75df39..9c29263 100644 --- a/src/behaviortree/BTNode/Action.ts +++ b/src/behaviortree/BTNode/Action.ts @@ -9,7 +9,7 @@ import { LeafNode } from "./AbstractNodes"; */ @BT.ActionNode("WaitTicks", { name: "等待次数", - group: "等待行为", + group: "基础行为节点", desc: "等待指定次数后返回成功", }) export class WaitTicks extends LeafNode { @@ -42,7 +42,7 @@ export class WaitTicks extends LeafNode { */ @BT.ActionNode("WaitTime", { name: "等待时间", - group: "等待行为", + group: "基础行为节点", desc: "等待指定时间(秒)后返回成功", }) export class WaitTime extends LeafNode { diff --git a/src/behaviortree/BTNode/Condition.ts b/src/behaviortree/BTNode/Condition.ts new file mode 100644 index 0000000..12f4be4 --- /dev/null +++ b/src/behaviortree/BTNode/Condition.ts @@ -0,0 +1,20 @@ +/** + * @Author: Gongxh + * @Date: 2025-09-17 + * @Description: 条件节点基类 + */ + +import { Status } from "../header"; +import { LeafNode } from "./AbstractNodes"; + +export abstract class Condition extends LeafNode { + /** + * 判断是否满足条件 + * @returns 是否满足条件 + */ + protected abstract isEligible(): boolean; + + public tick(): Status { + return this.isEligible() ? Status.SUCCESS : Status.FAILURE; + } +} diff --git a/src/index.ts b/src/index.ts index 67c8290..9127dda 100644 --- a/src/index.ts +++ b/src/index.ts @@ -7,9 +7,11 @@ export * from "./behaviortree/BTNode/AbstractNodes"; export * from "./behaviortree/BTNode/Action"; export { IBTNode } from "./behaviortree/BTNode/BTNode"; export * from "./behaviortree/BTNode/Composite"; +export * from "./behaviortree/BTNode/Condition"; export * from "./behaviortree/BTNode/Decorator"; export { createBehaviorTree } from "./behaviortree/Factory"; +export { Status } from "./behaviortree/header"; // 导出装饰器内容 import { BT } from "./behaviortree/BT"; -export const { ActionNode, ConditionNode, CompositeNode, DecoratorNode, prop } = BT; \ No newline at end of file +export const { ActionNode, ConditionNode, CompositeNode, DecoratorNode, prop, ParamType } = BT; \ No newline at end of file