Files
kunpocc-behaviortree/src/behaviortree/BTNode/Condition.ts

20 lines
525 B
TypeScript
Raw Normal View History

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
}
}