import BasicObject from "../../../Basic/BasicObject"; import { _IBehaviorTreeConfig } from "../../../Data/CommonDataType"; /** * 动态规划 - 逻辑层 */ export default class DynamicPlan extends BasicObject { /**动态规划配置 */ protected readonly dynamicPlanConfig: _IBehaviorTreeConfig; /**当前规划列表 */ protected _currentDynamicPlans: Array; constructor (unitID: any, dynamicPlanConfig: _IBehaviorTreeConfig) { super(); this._id = unitID; this.dynamicPlanConfig = dynamicPlanConfig; this._currentDynamicPlans = new Array(); } /**获得当前规划列表 */ public get currentDynamicPlans (): Array { return this._currentDynamicPlans; } /**是否可以动态规划 */ public isDynamicPlan (type: any): boolean { let priority: number = this.dynamicPlanConfig.priority[type]; // 判断优先级 for (let index in this._currentDynamicPlans) { if (this.dynamicPlanConfig.priority[index] > priority) { return false; } } return true; } /**添加动态规划 */ public addDynamicPlan (type: any): void { this.removeMutexDynamicPlan(type); this._currentDynamicPlans.push(type); } /**删除动态规划*/ public removeDynamicPlan (type: any): void { if (this._currentDynamicPlans.includes(type) == true) { this._currentDynamicPlans.splice(this._currentDynamicPlans.indexOf(type), 1); } } /**删除互斥动态规划 */ private removeMutexDynamicPlan (type: any): void { // 判断兼容或排斥 let mutexChild: Array = this.dynamicPlanConfig.mutexChild[type]; let compatibilityChild: Array = this.dynamicPlanConfig.compatibilityChild[type]; // 若两者为空,排斥其他所有子节点 if (mutexChild == null && compatibilityChild == null) { this._currentDynamicPlans = []; } else if (mutexChild != null) { for (let index: number = 0; index < this._currentDynamicPlans.length; index++) { // 若是互斥行为 if (this._currentDynamicPlans[index] != type && mutexChild.includes(this._currentDynamicPlans[index]) == true) { this._currentDynamicPlans.splice(index, 1); index--; } } } else if (compatibilityChild != null) { for (let index: number = 0; index < this._currentDynamicPlans.length; index++) { // 若不是兼容行为 if (this._currentDynamicPlans[index] != type && compatibilityChild.includes(this._currentDynamicPlans[index]) == false) { this._currentDynamicPlans.splice(index, 1); index--; } } } } }