FactorySystem.ts 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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 (copyData[index] < 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. gData.gameData.nextType = 3;
  44. return this.factoryIcons[i];
  45. }
  46. }
  47. } else {
  48. let len = this.factoryIcons.length;
  49. for (var i = 0; i < len; i++) {
  50. if (this.factoryIcons[i].data.state == FactroyState.Empty) {
  51. gData.gameData.nextCanProduct = gData.gameData.getRandomFactoryConfig(this.factoryIcons[i].configID);
  52. gData.gameData.nextMake = this.factoryIcons[i];
  53. gData.gameData.nextType = 3;
  54. return this.factoryIcons[i];
  55. }
  56. }
  57. }
  58. }
  59. }
  60. else {
  61. return this.doSameCheckLogic(out);
  62. }
  63. } else {
  64. return this.doSameCheckLogic(out);
  65. }
  66. return null;
  67. }
  68. doSameCheckLogic(out: any) {
  69. if (out.state == 0) {
  70. let len = this.factoryIcons.length;
  71. for (var i = 0; i < len; i++) {
  72. if (this.factoryIcons[i].data.state == FactroyState.Empty) {
  73. gData.gameData.nextCanProduct = gData.gameData.getRandomFactoryConfig(this.factoryIcons[i].configID);
  74. gData.gameData.nextMake = this.factoryIcons[i];
  75. gData.gameData.nextType = 3;
  76. return this.factoryIcons[i];
  77. }
  78. }
  79. } else {
  80. let isHaveEmpty = {state: false};
  81. let picId = gData.gameData.doFarmMapDataCheck(2, isHaveEmpty);
  82. if (picId) {
  83. return picId;
  84. } else {
  85. //if(isHaveEmpty.state)
  86. {
  87. let len = this.factoryIcons.length;
  88. for (var i = 0; i < len; i++) {
  89. if (this.factoryIcons[i].data.state == FactroyState.Empty) {
  90. gData.gameData.nextCanProduct = gData.gameData.getRandomFactoryConfig(this.factoryIcons[i].configID);
  91. gData.gameData.nextMake = this.factoryIcons[i];
  92. gData.gameData.nextType = 3;
  93. return this.factoryIcons[i];
  94. }
  95. }
  96. }
  97. }
  98. }
  99. return null;
  100. }
  101. public async btnMake() {
  102. return await gData.gameData.nextMake.make(gData.gameData.nextCanProduct.picture);
  103. }
  104. setHarvest() {
  105. let len = this.factoryIcons.length;
  106. let sendToServer = false;
  107. for (var i = 0; i < len; i++) {
  108. if (this.factoryIcons[i].data.state == FactroyState.Producting) {
  109. this.factoryIcons[i].countDown.riped(false);
  110. sendToServer = true;
  111. }
  112. }
  113. if (sendToServer) {
  114. gData.gameData.freshSendToServer(3);
  115. }
  116. }
  117. canSpeedUp() {
  118. let can = false;
  119. let len = this.factoryIcons.length;
  120. for (var i = 0; i < len; i++) {
  121. if (this.factoryIcons[i].data.state == FactroyState.Producting) {
  122. can = true;
  123. break;
  124. }
  125. }
  126. return can;
  127. }
  128. canHarvest() {
  129. let can = false;
  130. let len = this.factoryIcons.length;
  131. for (var i = 0; i < len; i++) {
  132. if (this.factoryIcons[i].data.state == FactroyState.Ripe) {
  133. this.factoryIcons[i].canHarvest();
  134. can = true;
  135. break;
  136. }
  137. }
  138. return can;
  139. }
  140. canClearSick() {
  141. let can = false;
  142. let len = this.factoryIcons.length;
  143. for (var i = 0; i < len; i++) {
  144. if (this.factoryIcons[i].data.state == FactroyState.Sick) {
  145. this.factoryIcons[i].canClearSick();
  146. can = true;
  147. break;
  148. }
  149. }
  150. return can;
  151. }
  152. }