FactorySystem.ts 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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. let copyData = gData.gameData.playerProp.copyOrderData
  28. if (data && data.orderTaskList) {
  29. if(out.state == 1)
  30. {
  31. let orderData = data.orderTaskList;
  32. let productJson = gData.gameData.configs.Product;
  33. for (let index = 0; index != orderData.length; ++index) {
  34. let dataE = orderData[index];
  35. if (copyData[index] < dataE.taskCount && dataE.Id <= productJson.length) {
  36. let productData = productJson[dataE.Id - 1];
  37. let len = this.factoryIcons.length;
  38. for (var j = 0; j < len; j++) {
  39. let tab = gData.gameData.getTabByConfigID(this.factoryIcons[j].configID);
  40. let max = gData.gameData.getMaxProduct(tab);
  41. if (tab == productData.tab && this.factoryIcons[j].data.state == FactroyState.Empty && productData.picture <= max) {
  42. gData.gameData.nextCanProduct = gData.gameData.getProductMap(productData.picture);
  43. gData.gameData.nextMake = this.factoryIcons[i];
  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. return this.factoryIcons[i];
  54. }
  55. }
  56. }
  57. }
  58. }else{
  59. let len = this.factoryIcons.length;
  60. for (var i = 0; i < len; i++) {
  61. if (this.factoryIcons[i].data.state == FactroyState.Empty) {
  62. gData.gameData.nextCanProduct = gData.gameData.getRandomFactoryConfig(this.factoryIcons[i].configID);
  63. gData.gameData.nextMake = this.factoryIcons[i];
  64. return this.factoryIcons[i];
  65. }
  66. }
  67. }
  68. } else {
  69. let len = this.factoryIcons.length;
  70. for (var i = 0; i < len; i++) {
  71. if (this.factoryIcons[i].data.state == FactroyState.Empty) {
  72. gData.gameData.nextCanProduct = gData.gameData.getRandomFactoryConfig(this.factoryIcons[i].configID);
  73. gData.gameData.nextMake = this.factoryIcons[i];
  74. return this.factoryIcons[i];
  75. }
  76. }
  77. }
  78. return null;
  79. }
  80. public async btnMake() {
  81. return await gData.gameData.nextMake.make(gData.gameData.nextCanProduct.picture);
  82. }
  83. setHarvest() {
  84. let len = this.factoryIcons.length;
  85. let sendToServer = false;
  86. for (var i = 0; i < len; i++) {
  87. if (this.factoryIcons[i].data.state == FactroyState.Producting) {
  88. this.factoryIcons[i].countDown.riped(false);
  89. sendToServer = true;
  90. }
  91. }
  92. if (sendToServer) {
  93. gData.gameData.freshSendToServer(3);
  94. }
  95. }
  96. canSpeedUp() {
  97. let can = false;
  98. let len = this.factoryIcons.length;
  99. for (var i = 0; i < len; i++) {
  100. if (this.factoryIcons[i].data.state == FactroyState.Producting) {
  101. can = true;
  102. break;
  103. }
  104. }
  105. return can;
  106. }
  107. canHarvest() {
  108. let can = false;
  109. let len = this.factoryIcons.length;
  110. for (var i = 0; i < len; i++) {
  111. if (this.factoryIcons[i].data.state == FactroyState.Ripe) {
  112. this.factoryIcons[i].canHarvest();
  113. can = true;
  114. break;
  115. }
  116. }
  117. return can;
  118. }
  119. canClearSick() {
  120. let can = false;
  121. let len = this.factoryIcons.length;
  122. for (var i = 0; i < len; i++) {
  123. if (this.factoryIcons[i].data.state == FactroyState.Sick) {
  124. this.factoryIcons[i].canClearSick();
  125. can = true;
  126. break;
  127. }
  128. }
  129. return can;
  130. }
  131. }