PastureSystem.ts 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. import { PastureState, ProductType } from "../../game/data/GameData";
  2. import PastureData from "./PastureData";
  3. import PastureIcon from "./PastureIcon";
  4. /** 动物移动管理系统 */
  5. const { ccclass } = cc._decorator;
  6. @ccclass
  7. export default class PastureSystem {
  8. private pastureDataMap: Map<number, PastureData> = new Map<number, PastureData>();
  9. public pastureIcons: Array<PastureIcon> = [];
  10. setPastureData(configID) {
  11. if (this.getPastureData(configID)) {
  12. return;
  13. }
  14. let data = new PastureData();
  15. this.pastureDataMap.set(configID, data);
  16. return data;
  17. }
  18. getPastureData(configID) {
  19. return this.pastureDataMap.get(configID);
  20. }
  21. addPastureIcon(pasture) {
  22. this.pastureIcons.push(pasture);
  23. }
  24. /** 下一个空置饲养场 */
  25. nextPasture(out?: any) {
  26. let data = gData.gameData.playerProp.orderData;
  27. //let copyData = gData.gameData.playerProp.copyOrderData
  28. if (data && data.orderTaskList) {
  29. let orderData = data.orderTaskList;
  30. let productJson = gData.gameData.configs.Product;
  31. for (let index = 0; index != orderData.length; ++index) {
  32. let dataE = orderData[index];
  33. if (dataE.completeCount < dataE.taskCount && dataE.Id <= productJson.length) {
  34. let productData = productJson[dataE.Id - 1];
  35. let len = this.pastureIcons.length;
  36. for (var i = 0; i < len; i++) {
  37. if (productData.picture == this.pastureIcons[i].data.productID && this.pastureIcons[i].data.state == PastureState.Empty) {
  38. gData.gameData.nextCanProduct = gData.gameData.getProductMap(this.pastureIcons[i].data.productID);
  39. gData.gameData.nextMake = this.pastureIcons[i];
  40. gData.gameData.nextType = 2;
  41. return this.pastureIcons[i];
  42. }
  43. }
  44. } else {
  45. break;
  46. }
  47. }
  48. //工厂有匹配的
  49. if (out.state == 1) {
  50. console.log("nextPasture=======null");
  51. return null;
  52. } else
  53. {
  54. return this.doSameCheckLogic(out);
  55. }
  56. } else {
  57. return this.doSameCheckLogic(out);
  58. }
  59. return null;
  60. }
  61. doSameCheckLogic(out:any)
  62. {
  63. if (out.state == 0) {
  64. let len = this.pastureIcons.length;
  65. for (var i = 0; i < len; i++) {
  66. if (this.pastureIcons[i].data.state == PastureState.Empty) {
  67. gData.gameData.nextCanProduct = gData.gameData.getProductMap(this.pastureIcons[i].data.productID);
  68. gData.gameData.nextMake = this.pastureIcons[i];
  69. gData.gameData.nextType = 2;
  70. return this.pastureIcons[i];
  71. }
  72. }
  73. }
  74. else {
  75. // let isHaveEmpty = {state: false};
  76. // let picId = gData.gameData.doFarmMapDataCheck(1, isHaveEmpty);
  77. // if (picId) {
  78. // return picId;
  79. // } else
  80. {
  81. //if(isHaveEmpty.state)
  82. {
  83. let len = this.pastureIcons.length;
  84. for (var i = 0; i < len; i++) {
  85. if (this.pastureIcons[i].data.state == PastureState.Empty) {
  86. gData.gameData.nextCanProduct = gData.gameData.getProductMap(this.pastureIcons[i].data.productID);
  87. gData.gameData.nextMake = this.pastureIcons[i];
  88. gData.gameData.nextType = 2;
  89. return this.pastureIcons[i];
  90. }
  91. }
  92. }
  93. }
  94. }
  95. return null;
  96. }
  97. async btnMake() {
  98. let f = await gData.gameData.nextMake.onEat();
  99. if (f) {
  100. return true;
  101. } else {
  102. return false;
  103. }
  104. }
  105. setHarvest() {
  106. let len = this.pastureIcons.length;
  107. let sendToServer = false;
  108. for (var i = 0; i < len; i++) {
  109. if (this.pastureIcons[i].data.state == PastureState.Growing) {
  110. this.pastureIcons[i].countDown.riped(false);
  111. sendToServer = true;
  112. }
  113. }
  114. if (sendToServer) {
  115. gData.gameData.freshSendToServer(2);
  116. }
  117. }
  118. canSpeedUp() {
  119. let can = false;
  120. let len = this.pastureIcons.length;
  121. for (var i = 0; i < len; i++) {
  122. if (this.pastureIcons[i].data.state == PastureState.Growing) {
  123. can = true;
  124. break;
  125. }
  126. }
  127. return can;
  128. }
  129. canHarvest() {
  130. let can = false;
  131. let len = this.pastureIcons.length;
  132. for (var i = 0; i < len; i++) {
  133. if (this.pastureIcons[i].data.state == PastureState.Ripe) {
  134. this.pastureIcons[i].canHarvest();
  135. can = true;
  136. break;
  137. }
  138. }
  139. return can;
  140. }
  141. canClearSick() {
  142. let can = false;
  143. let len = this.pastureIcons.length;
  144. for (var i = 0; i < len; i++) {
  145. if (this.pastureIcons[i].data.state == PastureState.Sick) {
  146. this.pastureIcons[i].canClearSick();
  147. can = true;
  148. break;
  149. }
  150. }
  151. return can;
  152. }
  153. }