2025-06-04 23:10:59 +08:00
|
|
|
import { Status } from "../header";
|
2025-09-03 10:54:07 +08:00
|
|
|
import { LeafNode } from "./AbstractNodes";
|
|
|
|
|
import { IBTNode } from "./BTNode";
|
2025-06-04 23:10:59 +08:00
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 条件节点
|
2025-09-02 17:05:46 +08:00
|
|
|
* 根据条件函数返回SUCCESS或FAILURE
|
2025-06-04 23:10:59 +08:00
|
|
|
*/
|
2025-09-03 10:54:07 +08:00
|
|
|
export class Condition extends LeafNode {
|
2025-06-04 23:10:59 +08:00
|
|
|
/** 执行函数 @internal */
|
2025-09-03 10:54:07 +08:00
|
|
|
private readonly _func: (node: IBTNode) => boolean;
|
|
|
|
|
constructor(func: (node: IBTNode) => boolean) {
|
2025-06-04 23:10:59 +08:00
|
|
|
super();
|
|
|
|
|
this._func = func;
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-03 10:54:07 +08:00
|
|
|
public tick(): Status {
|
|
|
|
|
return this._func?.(this) ? Status.SUCCESS : Status.FAILURE;
|
2025-06-04 23:10:59 +08:00
|
|
|
}
|
|
|
|
|
}
|