diff --git a/src/behaviortree/BTNode/Condition.ts b/src/behaviortree/BTNode/Condition.ts index 12f4be4..ced9b5a 100644 --- a/src/behaviortree/BTNode/Condition.ts +++ b/src/behaviortree/BTNode/Condition.ts @@ -5,8 +5,9 @@ */ import { Status } from "../header"; -import { LeafNode } from "./AbstractNodes"; +import { Decorator, LeafNode } from "./AbstractNodes"; +/** 条件叶子节点 */ export abstract class Condition extends LeafNode { /** * 判断是否满足条件 @@ -18,3 +19,16 @@ export abstract class Condition extends LeafNode { return this.isEligible() ? Status.SUCCESS : Status.FAILURE; } } + +/** 条件装饰节点 */ +export abstract class ConditionDecorator extends Decorator { + /** + * 判断是否满足条件 + * @returns 是否满足条件 + */ + protected abstract isEligible(): boolean; + + public tick(): Status { + return this.isEligible() ? this.children[0]!._execute() : Status.FAILURE; + } +} \ No newline at end of file