mirror of
https://github.com/gongxh0901/kunpocc-behaviortree.git
synced 2025-12-26 16:48:56 +00:00
添加条件装饰节点
This commit is contained in:
@@ -5,8 +5,9 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import { Status } from "../header";
|
import { Status } from "../header";
|
||||||
import { LeafNode } from "./AbstractNodes";
|
import { Decorator, LeafNode } from "./AbstractNodes";
|
||||||
|
|
||||||
|
/** 条件叶子节点 */
|
||||||
export abstract class Condition extends LeafNode {
|
export abstract class Condition extends LeafNode {
|
||||||
/**
|
/**
|
||||||
* 判断是否满足条件
|
* 判断是否满足条件
|
||||||
@@ -18,3 +19,16 @@ export abstract class Condition extends LeafNode {
|
|||||||
return this.isEligible() ? Status.SUCCESS : Status.FAILURE;
|
return this.isEligible() ? Status.SUCCESS : Status.FAILURE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** 条件装饰节点 */
|
||||||
|
export abstract class ConditionDecorator extends Decorator {
|
||||||
|
/**
|
||||||
|
* 判断是否满足条件
|
||||||
|
* @returns 是否满足条件
|
||||||
|
*/
|
||||||
|
protected abstract isEligible(): boolean;
|
||||||
|
|
||||||
|
public tick(): Status {
|
||||||
|
return this.isEligible() ? this.children[0]!._execute() : Status.FAILURE;
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user