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