FactorySystem.ts 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  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, parentNode = null) {
  16. if (this._currSelectFactory) {
  17. return await this._currSelectFactory.make(id, parentNode);
  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(dataE.completeCount < 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. // }
  90. // else
  91. {
  92. //if(isHaveEmpty.state)
  93. {
  94. let len = this.factoryIcons.length;
  95. for (var i = 0; i < len; i++) {
  96. if (this.factoryIcons[i].data.state == FactroyState.Empty) {
  97. gData.gameData.nextCanProduct = gData.gameData.getRandomFactoryConfig(this.factoryIcons[i].configID);
  98. gData.gameData.nextMake = this.factoryIcons[i];
  99. gData.gameData.nextType = 3;
  100. return this.factoryIcons[i];
  101. }
  102. }
  103. }
  104. }
  105. }
  106. return null;
  107. }
  108. public async btnMake() {
  109. return await gData.gameData.nextMake.make(gData.gameData.nextCanProduct.picture);
  110. }
  111. setHarvest() {
  112. let len = this.factoryIcons.length;
  113. let sendToServer = false;
  114. for (var i = 0; i < len; i++) {
  115. if (this.factoryIcons[i].data.state == FactroyState.Producting) {
  116. this.factoryIcons[i].countDown.riped(false);
  117. sendToServer = true;
  118. }
  119. }
  120. if (sendToServer) {
  121. gData.gameData.freshSendToServer(3);
  122. }
  123. }
  124. canSpeedUp() {
  125. let can = false;
  126. let len = this.factoryIcons.length;
  127. for (var i = 0; i < len; i++) {
  128. if (this.factoryIcons[i].data.state == FactroyState.Producting) {
  129. can = true;
  130. break;
  131. }
  132. }
  133. return can;
  134. }
  135. canHarvest() {
  136. let can = false;
  137. let len = this.factoryIcons.length;
  138. for (var i = 0; i < len; i++) {
  139. if (this.factoryIcons[i].data.state == FactroyState.Ripe) {
  140. this.factoryIcons[i].canHarvest();
  141. can = true;
  142. break;
  143. }
  144. }
  145. return can;
  146. }
  147. canClearSick() {
  148. let can = false;
  149. let len = this.factoryIcons.length;
  150. for (var i = 0; i < len; i++) {
  151. if (this.factoryIcons[i].data.state == FactroyState.Sick) {
  152. this.factoryIcons[i].canClearSick();
  153. can = true;
  154. break;
  155. }
  156. }
  157. return can;
  158. }
  159. }