123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135 |
- 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<any, DynamicPlan>;
- /**动态规划任务列表 */
- private dynamicPlanTasks: Map<any, _IDynamicPlanTaskConfig>;
-
- constructor (dynamicPlanConfig: _IBehaviorTreeConfig, dynamicPlanTaskConfig: _IDynamicPlanTaskConfig) {
- super();
- this.dynamicPlanConfig = dynamicPlanConfig;
- this.dynamicPlanTaskConfig = dynamicPlanTaskConfig;
- this.dynamicPlans = new Map<any, DynamicPlan>();
- this.dynamicPlanTasks = new Map<any, _IDynamicPlanTaskConfig>();
- }
- /**获得动态规划 */
- 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);
- }
- }
- }
- }
- }
|