FactorySystem.ts 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. /** 工厂数据类 */
  2. import { FactroyState, GameProp, ProductType } 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. let copyData = gData.gameData.playerProp.copyOrderData
  28. if (data && data.orderTaskList) {
  29. if (out.state == 1) {
  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.Id <= productJson.length) {
  35. if(copyData[index] < dataE.taskCount)
  36. {
  37. let productData = productJson[dataE.Id - 1];
  38. let len = this.factoryIcons.length;
  39. for (let j = 0; j < len; j++) {
  40. let tab = gData.gameData.getTabByConfigID(this.factoryIcons[j].configID);
  41. let max = gData.gameData.getMaxProduct(tab);
  42. if (tab == productData.tab && this.factoryIcons[j].data.state == FactroyState.Empty && productData.picture <= max) {
  43. gData.gameData.nextCanProduct = gData.gameData.getProductMap(productData.picture);
  44. gData.gameData.nextMake = this.factoryIcons[j];
  45. gData.gameData.nextType = 3;
  46. console.log("nextFactory ===== successs");
  47. return this.factoryIcons[j];
  48. }
  49. }
  50. }
  51. } else {
  52. let len = this.factoryIcons.length;
  53. for (let i = 0; i < len; i++) {
  54. if (this.factoryIcons[i].data.state == FactroyState.Empty) {
  55. gData.gameData.nextCanProduct = gData.gameData.getRandomFactoryConfig(this.factoryIcons[i].configID);
  56. gData.gameData.nextMake = this.factoryIcons[i];
  57. gData.gameData.nextType = 3;
  58. console.log("nextFactory ===== successs===");
  59. return this.factoryIcons[i];
  60. }
  61. }
  62. }
  63. }
  64. }
  65. else {
  66. return this.doSameCheckLogic(out);
  67. }
  68. } else {
  69. return this.doSameCheckLogic(out);
  70. }
  71. return null;
  72. }
  73. doSameCheckLogic(out: any) {
  74. if (out.state == 0) {
  75. let len = this.factoryIcons.length;
  76. for (var i = 0; i < len; i++) {
  77. if (this.factoryIcons[i].data.state == FactroyState.Empty) {
  78. gData.gameData.nextCanProduct = gData.gameData.getRandomFactoryConfig(this.factoryIcons[i].configID);
  79. gData.gameData.nextMake = this.factoryIcons[i];
  80. gData.gameData.nextType = 3;
  81. return this.factoryIcons[i];
  82. }
  83. }
  84. } else {
  85. let isHaveEmpty = {state: false};
  86. let picId = gData.gameData.doFarmMapDataCheck(2, isHaveEmpty);
  87. if (picId) {
  88. return picId;
  89. } else {
  90. //if(isHaveEmpty.state)
  91. {
  92. let len = this.factoryIcons.length;
  93. for (var i = 0; i < len; i++) {
  94. if (this.factoryIcons[i].data.state == FactroyState.Empty) {
  95. gData.gameData.nextCanProduct = gData.gameData.getRandomFactoryConfig(this.factoryIcons[i].configID);
  96. gData.gameData.nextMake = this.factoryIcons[i];
  97. gData.gameData.nextType = 3;
  98. return this.factoryIcons[i];
  99. }
  100. }
  101. }
  102. }
  103. }
  104. return null;
  105. }
  106. public async btnMake() {
  107. return await gData.gameData.nextMake.make(gData.gameData.nextCanProduct.picture);
  108. }
  109. setHarvest() {
  110. let len = this.factoryIcons.length;
  111. let sendToServer = false;
  112. for (var i = 0; i < len; i++) {
  113. if (this.factoryIcons[i].data.state == FactroyState.Producting) {
  114. this.factoryIcons[i].countDown.riped(false);
  115. sendToServer = true;
  116. }
  117. }
  118. if (sendToServer) {
  119. gData.gameData.freshSendToServer(3);
  120. }
  121. }
  122. canSpeedUp() {
  123. let can = false;
  124. let len = this.factoryIcons.length;
  125. for (var i = 0; i < len; i++) {
  126. if (this.factoryIcons[i].data.state == FactroyState.Producting) {
  127. can = true;
  128. break;
  129. }
  130. }
  131. return can;
  132. }
  133. canHarvest() {
  134. let can = false;
  135. let len = this.factoryIcons.length;
  136. for (var i = 0; i < len; i++) {
  137. if (this.factoryIcons[i].data.state == FactroyState.Ripe) {
  138. this.factoryIcons[i].canHarvest();
  139. can = true;
  140. break;
  141. }
  142. }
  143. return can;
  144. }
  145. canClearSick() {
  146. let can = false;
  147. let len = this.factoryIcons.length;
  148. for (var i = 0; i < len; i++) {
  149. if (this.factoryIcons[i].data.state == FactroyState.Sick) {
  150. this.factoryIcons[i].canClearSick();
  151. can = true;
  152. break;
  153. }
  154. }
  155. return can;
  156. }
  157. }