添加条件装饰节点

This commit is contained in:
gongxh
2025-09-17 14:10:19 +08:00
parent b1107805d0
commit 63d9855658

View File

@@ -5,8 +5,9 @@
*/ */
import { Status } from "../header"; import { Status } from "../header";
import { LeafNode } from "./AbstractNodes"; import { Decorator, LeafNode } from "./AbstractNodes";
/** 条件叶子节点 */
export abstract class Condition extends LeafNode { export abstract class Condition extends LeafNode {
/** /**
* 判断是否满足条件 * 判断是否满足条件
@@ -18,3 +19,16 @@ export abstract class Condition extends LeafNode {
return this.isEligible() ? Status.SUCCESS : Status.FAILURE; 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;
}
}