Files
2025-09-15 09:57:14 +08:00

40 lines
911 B
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/*
* @Author: dgflash
* @Date: 2022-06-21 12:05:14
* @LastEditors: dgflash
* @LastEditTime: 2022-07-20 14:05:40
*/
import { BranchNode } from './BranchNode';
/**
* 逻辑或关系
* 只要子节点有一个返回true则停止执行其它子节点并且Selector返回true。如果所有子节点都返回false则Selector返回false。
*/
export class Selector extends BranchNode {
success() {
super.success()
this._control.success();
}
fail() {
super.fail()
this._actualTask += 1;
if (this._actualTask < this.children.length) {
this._run(this._blackboard);
}
else {
this._control.fail();
}
}
protected _run(blackboard?: any) {
if (this._nodeRunning) {
this._nodeRunning.run(this._blackboard);
}
else {
super._run();
}
}
}