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

20 lines
567 B
TypeScript
Raw Normal View History

2025-09-02 17:05:46 +08:00
import type { BehaviorTree } from "../BehaviorTree";
2025-06-04 23:10:59 +08:00
import { Status } from "../header";
2025-09-02 17:05:46 +08:00
import { BaseNode } from "./BaseNode";
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-02 17:05:46 +08:00
export class Condition extends BaseNode {
2025-06-04 23:10:59 +08:00
/** 执行函数 @internal */
2025-09-02 17:05:46 +08:00
private readonly _func: (subject: any) => boolean;
2025-06-04 23:10:59 +08:00
constructor(func: (subject: any) => boolean) {
super();
this._func = func;
}
2025-09-02 17:05:46 +08:00
public tick<T>(tree: BehaviorTree<T>): Status {
return this._func?.(tree.subject) ? Status.SUCCESS : Status.FAILURE;
2025-06-04 23:10:59 +08:00
}
}