FactorySystem.ts 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. /** 工厂数据类 */
  2. import { FactroyState, GameProp } from "../../game/data/GameData";
  3. import { FactoryIcon } from "./FactoryIcon";
  4. const { ccclass } = cc._decorator;
  5. @ccclass
  6. export default class FactorySystem {
  7. private _currSelectFactory: FactoryIcon = null;
  8. public factoryIcons: Array<FactoryIcon> = [];
  9. public set currSelectFactory(factory: FactoryIcon) {
  10. this._currSelectFactory = factory;
  11. }
  12. public get currSelectFactory(): FactoryIcon {
  13. return this._currSelectFactory;
  14. }
  15. public async make(id: number) {
  16. if (this._currSelectFactory) {
  17. return await this._currSelectFactory.make(id);
  18. } else {
  19. return false;
  20. }
  21. }
  22. public addFactory(factory) {
  23. this.factoryIcons.push(factory);
  24. }
  25. public nextFactory(out?: any) {
  26. let data = gData.gameData.playerProp.orderData;
  27. if (data && data.orderTaskList) {
  28. if(out.state == 1)
  29. {
  30. let orderData = data.orderTaskList;
  31. let productJson = gData.gameData.configs.Product;
  32. for (let index = 0; index != orderData.length; ++index) {
  33. let dataE = orderData[index];
  34. if (dataE.completeCount < dataE.taskCount && dataE.Id <= productJson.length) {
  35. let productData = productJson[dataE.Id - 1];
  36. let len = this.factoryIcons.length;
  37. for (var j = 0; j < len; j++) {
  38. let tab = gData.gameData.getTabByConfigID(this.factoryIcons[j].configID);
  39. let max = gData.gameData.getMaxProduct(tab);
  40. if (tab == productData.tab && this.factoryIcons[j].data.state == FactroyState.Empty && productData.picture <= max) {
  41. gData.gameData.nextCanProduct = gData.gameData.getProductMap(productData.picture);
  42. gData.gameData.nextMake = this.factoryIcons[i];
  43. return this.factoryIcons[i];
  44. }
  45. }
  46. } else {
  47. let len = this.factoryIcons.length;
  48. for (var i = 0; i < len; i++) {
  49. if (this.factoryIcons[i].data.state == FactroyState.Empty) {
  50. gData.gameData.nextCanProduct = gData.gameData.getRandomFactoryConfig(this.factoryIcons[i].configID);
  51. gData.gameData.nextMake = this.factoryIcons[i];
  52. return this.factoryIcons[i];
  53. }
  54. }
  55. }
  56. }
  57. }else{
  58. let len = this.factoryIcons.length;
  59. for (var i = 0; i < len; i++) {
  60. if (this.factoryIcons[i].data.state == FactroyState.Empty) {
  61. gData.gameData.nextCanProduct = gData.gameData.getRandomFactoryConfig(this.factoryIcons[i].configID);
  62. gData.gameData.nextMake = this.factoryIcons[i];
  63. return this.factoryIcons[i];
  64. }
  65. }
  66. }
  67. } else {
  68. let len = this.factoryIcons.length;
  69. for (var i = 0; i < len; i++) {
  70. if (this.factoryIcons[i].data.state == FactroyState.Empty) {
  71. gData.gameData.nextCanProduct = gData.gameData.getRandomFactoryConfig(this.factoryIcons[i].configID);
  72. gData.gameData.nextMake = this.factoryIcons[i];
  73. return this.factoryIcons[i];
  74. }
  75. }
  76. }
  77. return null;
  78. }
  79. public async btnMake() {
  80. return await gData.gameData.nextMake.make(gData.gameData.nextCanProduct.picture);
  81. }
  82. setHarvest() {
  83. let len = this.factoryIcons.length;
  84. let sendToServer = false;
  85. for (var i = 0; i < len; i++) {
  86. if (this.factoryIcons[i].data.state == FactroyState.Producting) {
  87. this.factoryIcons[i].countDown.riped(false);
  88. sendToServer = true;
  89. }
  90. }
  91. if (sendToServer) {
  92. gData.gameData.freshSendToServer(3);
  93. }
  94. }
  95. canSpeedUp() {
  96. let can = false;
  97. let len = this.factoryIcons.length;
  98. for (var i = 0; i < len; i++) {
  99. if (this.factoryIcons[i].data.state == FactroyState.Producting) {
  100. can = true;
  101. break;
  102. }
  103. }
  104. return can;
  105. }
  106. canHarvest() {
  107. let can = false;
  108. let len = this.factoryIcons.length;
  109. for (var i = 0; i < len; i++) {
  110. if (this.factoryIcons[i].data.state == FactroyState.Ripe) {
  111. this.factoryIcons[i].canHarvest();
  112. can = true;
  113. break;
  114. }
  115. }
  116. return can;
  117. }
  118. canClearSick() {
  119. let can = false;
  120. let len = this.factoryIcons.length;
  121. for (var i = 0; i < len; i++) {
  122. if (this.factoryIcons[i].data.state == FactroyState.Sick) {
  123. this.factoryIcons[i].canClearSick();
  124. can = true;
  125. break;
  126. }
  127. }
  128. return can;
  129. }
  130. }