48 lines
1.2 KiB
TypeScript
Raw Normal View History

2025-02-20 11:27:28 +08:00
import { BehaviorTree } from "./BehaviorTree";
import { Blackboard } from "./Blackboard";
import { Ticker } from "./Ticker";
/** 代理 */
export class Agent {
2025-03-07 16:02:00 +08:00
/** 行为树 */
2025-02-20 11:27:28 +08:00
public tree: BehaviorTree;
2025-03-07 16:02:00 +08:00
/** 黑板 */
2025-02-20 11:27:28 +08:00
public blackboard: Blackboard;
2025-03-07 16:02:00 +08:00
/** 更新器 */
2025-02-20 11:27:28 +08:00
public ticker: Ticker;
/**
* constructor
* @param subject // 主体
* @param tree
*/
constructor(subject: any, tree: BehaviorTree) {
this.tree = tree;
this.blackboard = new Blackboard();
this.ticker = new Ticker(subject, this.blackboard, tree);
}
2025-03-07 16:02:00 +08:00
/**
*
*/
2025-02-20 11:27:28 +08:00
public tick(): void {
this.tree.tick(this, this.blackboard, this.ticker);
if (this.blackboard.interrupt) {
this.blackboard.interrupt = false;
let ticker = this.ticker;
ticker.openNodes.length = 0;
ticker.nodeCount = 0;
this.blackboard.clear();
}
}
/**
*
*/
public interruptBTree(): void {
if (!this.blackboard.interruptDefend) {
this.blackboard.interrupt = true;
}
}
}