import BasicObject from "../../../Basic/BasicObject"; import { _IBehaviorTreeConfig } from "../../../Data/CommonDataType"; import { _IDynamicPlanTaskConfig } from "./Data/DynamicPlanConfig"; import DynamicPlan from "./DynamicPlan"; /** * 团队动态规划 - 逻辑层 */ export default class TeamDynamicPlan extends BasicObject { /**动态规划配置 */ protected readonly dynamicPlanConfig: _IBehaviorTreeConfig; /**动态规划任务配置 */ protected readonly dynamicPlanTaskConfig: _IDynamicPlanTaskConfig; /**动态规划列表 */ private dynamicPlans: Map; /**动态规划任务列表 */ private dynamicPlanTasks: Map; constructor (dynamicPlanConfig: _IBehaviorTreeConfig, dynamicPlanTaskConfig: _IDynamicPlanTaskConfig) { super(); this.dynamicPlanConfig = dynamicPlanConfig; this.dynamicPlanTaskConfig = dynamicPlanTaskConfig; this.dynamicPlans = new Map(); this.dynamicPlanTasks = new Map(); } /**获得动态规划 */ protected getDynamicPlan (unitID: any): DynamicPlan { return this.dynamicPlans.get(unitID); } /**获得动态规划任务 */ protected getDynamicPlanTask (unitID: any): _IDynamicPlanTaskConfig { return this.dynamicPlanTasks.get(unitID); } /**是否有动态规划任务 */ protected hasDynamicPlanTask (type: any): boolean { return this.dynamicPlanTasks.has(type); } /**添加实体单元 */ protected addUnit (unitID: any): void { if (this.dynamicPlans.has(unitID) == false) { this.dynamicPlans.set(unitID, new DynamicPlan(unitID, this.dynamicPlanConfig)); } } /**删除实体单元 */ protected removeUnit (unitID: any): void { if (this.dynamicPlans.has(unitID) == true) { this.dynamicPlans.get(unitID)._destroy(); this.dynamicPlans.delete(unitID); } } /**添加动态规划 */ protected addDynamicPlan (unitID: any, type: any): void { if (this.dynamicPlans.has(unitID) == true) { let dynamicPlan: DynamicPlan = this.dynamicPlans.get(unitID); dynamicPlan.addDynamicPlan(type); } } /**删除动态规划 */ protected removeDynamicPlan (unitID: any, type: any): void { if (this.dynamicPlans.has(unitID) == true) { let dynamicPlan: DynamicPlan = this.dynamicPlans.get(unitID); dynamicPlan.removeDynamicPlan(type); this.removeDynamicPlanTaskUnit(unitID, type); } } /**是否可以添加动态规划任务 */ protected isAddDynamicPlanTask (unitID: any, type: any): boolean { if (this.dynamicPlanTasks.has(type) == false) { return true; } else { let task: _IDynamicPlanTaskConfig = this.dynamicPlanTasks.get(type); if (task.unitCount > task.unitIDs.length) { return true; } else { return task.unitIDs.includes(unitID); } } } /**添加动态规划任务 */ protected addDynamicPlanTask (type: any, task: _IDynamicPlanTaskConfig): void { if (this.dynamicPlanTasks.has(type) == false) { this.dynamicPlanTasks.set(type, task); } } /**删除动态规划任务 */ protected removeDynamicPlanTask (type: any): void { if (this.dynamicPlanTasks.has(type) == true) { this.dynamicPlanTasks.delete(type); } } /**添加动态规划任务实体单元 */ protected addDynamicPlanTaskUnit (unitID: any, type: any): void { if (this.dynamicPlanTasks.has(type) == true) { let task: _IDynamicPlanTaskConfig = this.dynamicPlanTasks.get(type); if (this.isAddDynamicPlanTask(unitID, type) == true) { if (task.unitIDs.includes(unitID) == false) { task.unitIDs.push(unitID); this.dynamicPlanTasks.set(type, task); } } } } /**删除动态规划任务实体单元 */ protected removeDynamicPlanTaskUnit (unitID: any, type: any): void { if (this.dynamicPlanTasks.has(type) == true) { let task: _IDynamicPlanTaskConfig = this.dynamicPlanTasks.get(type); if (task.unitIDs.includes(unitID) == true) { task.unitIDs.splice(task.unitIDs.indexOf(unitID), 1); if (task.unitIDs.length > 0) { this.dynamicPlanTasks.set(type, task); } else { this.dynamicPlanTasks.delete(type); } } } } }