TeamDynamicPlan.ts 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. import BasicObject from "../../../Basic/BasicObject";
  2. import { _IBehaviorTreeConfig } from "../../../Data/CommonDataType";
  3. import { _IDynamicPlanTaskConfig } from "./Data/DynamicPlanConfig";
  4. import DynamicPlan from "./DynamicPlan";
  5. /**
  6. * 团队动态规划 - 逻辑层
  7. */
  8. export default class TeamDynamicPlan extends BasicObject {
  9. /**动态规划配置 */
  10. protected readonly dynamicPlanConfig: _IBehaviorTreeConfig;
  11. /**动态规划任务配置 */
  12. protected readonly dynamicPlanTaskConfig: _IDynamicPlanTaskConfig;
  13. /**动态规划列表 */
  14. private dynamicPlans: Map<any, DynamicPlan>;
  15. /**动态规划任务列表 */
  16. private dynamicPlanTasks: Map<any, _IDynamicPlanTaskConfig>;
  17. constructor (dynamicPlanConfig: _IBehaviorTreeConfig, dynamicPlanTaskConfig: _IDynamicPlanTaskConfig) {
  18. super();
  19. this.dynamicPlanConfig = dynamicPlanConfig;
  20. this.dynamicPlanTaskConfig = dynamicPlanTaskConfig;
  21. this.dynamicPlans = new Map<any, DynamicPlan>();
  22. this.dynamicPlanTasks = new Map<any, _IDynamicPlanTaskConfig>();
  23. }
  24. /**获得动态规划 */
  25. protected getDynamicPlan (unitID: any): DynamicPlan {
  26. return this.dynamicPlans.get(unitID);
  27. }
  28. /**获得动态规划任务 */
  29. protected getDynamicPlanTask (unitID: any): _IDynamicPlanTaskConfig {
  30. return this.dynamicPlanTasks.get(unitID);
  31. }
  32. /**是否有动态规划任务 */
  33. protected hasDynamicPlanTask (type: any): boolean {
  34. return this.dynamicPlanTasks.has(type);
  35. }
  36. /**添加实体单元 */
  37. protected addUnit (unitID: any): void {
  38. if (this.dynamicPlans.has(unitID) == false) {
  39. this.dynamicPlans.set(unitID, new DynamicPlan(unitID, this.dynamicPlanConfig));
  40. }
  41. }
  42. /**删除实体单元 */
  43. protected removeUnit (unitID: any): void {
  44. if (this.dynamicPlans.has(unitID) == true) {
  45. this.dynamicPlans.get(unitID)._destroy();
  46. this.dynamicPlans.delete(unitID);
  47. }
  48. }
  49. /**添加动态规划 */
  50. protected addDynamicPlan (unitID: any, type: any): void {
  51. if (this.dynamicPlans.has(unitID) == true) {
  52. let dynamicPlan: DynamicPlan = this.dynamicPlans.get(unitID);
  53. dynamicPlan.addDynamicPlan(type);
  54. }
  55. }
  56. /**删除动态规划 */
  57. protected removeDynamicPlan (unitID: any, type: any): void {
  58. if (this.dynamicPlans.has(unitID) == true) {
  59. let dynamicPlan: DynamicPlan = this.dynamicPlans.get(unitID);
  60. dynamicPlan.removeDynamicPlan(type);
  61. this.removeDynamicPlanTaskUnit(unitID, type);
  62. }
  63. }
  64. /**是否可以添加动态规划任务 */
  65. protected isAddDynamicPlanTask (unitID: any, type: any): boolean {
  66. if (this.dynamicPlanTasks.has(type) == false) {
  67. return true;
  68. }
  69. else {
  70. let task: _IDynamicPlanTaskConfig = this.dynamicPlanTasks.get(type);
  71. if (task.unitCount > task.unitIDs.length) {
  72. return true;
  73. }
  74. else {
  75. return task.unitIDs.includes(unitID);
  76. }
  77. }
  78. }
  79. /**添加动态规划任务 */
  80. protected addDynamicPlanTask (type: any, task: _IDynamicPlanTaskConfig): void {
  81. if (this.dynamicPlanTasks.has(type) == false) {
  82. this.dynamicPlanTasks.set(type, task);
  83. }
  84. }
  85. /**删除动态规划任务 */
  86. protected removeDynamicPlanTask (type: any): void {
  87. if (this.dynamicPlanTasks.has(type) == true) {
  88. this.dynamicPlanTasks.delete(type);
  89. }
  90. }
  91. /**添加动态规划任务实体单元 */
  92. protected addDynamicPlanTaskUnit (unitID: any, type: any): void {
  93. if (this.dynamicPlanTasks.has(type) == true) {
  94. let task: _IDynamicPlanTaskConfig = this.dynamicPlanTasks.get(type);
  95. if (this.isAddDynamicPlanTask(unitID, type) == true) {
  96. if (task.unitIDs.includes(unitID) == false) {
  97. task.unitIDs.push(unitID);
  98. this.dynamicPlanTasks.set(type, task);
  99. }
  100. }
  101. }
  102. }
  103. /**删除动态规划任务实体单元 */
  104. protected removeDynamicPlanTaskUnit (unitID: any, type: any): void {
  105. if (this.dynamicPlanTasks.has(type) == true) {
  106. let task: _IDynamicPlanTaskConfig = this.dynamicPlanTasks.get(type);
  107. if (task.unitIDs.includes(unitID) == true) {
  108. task.unitIDs.splice(task.unitIDs.indexOf(unitID), 1);
  109. if (task.unitIDs.length > 0) {
  110. this.dynamicPlanTasks.set(type, task);
  111. }
  112. else {
  113. this.dynamicPlanTasks.delete(type);
  114. }
  115. }
  116. }
  117. }
  118. }