mirror of
https://github.com/gongxh0901/kunpocc-behaviortree.git
synced 2025-12-26 16:48:56 +00:00
20 lines
525 B
TypeScript
20 lines
525 B
TypeScript
import { Status } from "../header";
|
|
import { LeafNode } from "./AbstractNodes";
|
|
import { IBTNode } from "./BTNode";
|
|
|
|
/**
|
|
* 条件节点
|
|
* 根据条件函数返回SUCCESS或FAILURE
|
|
*/
|
|
export class Condition extends LeafNode {
|
|
/** 执行函数 @internal */
|
|
private readonly _func: (node: IBTNode) => boolean;
|
|
constructor(func: (node: IBTNode) => boolean) {
|
|
super();
|
|
this._func = func;
|
|
}
|
|
|
|
public tick(): Status {
|
|
return this._func?.(this) ? Status.SUCCESS : Status.FAILURE;
|
|
}
|
|
} |