PastureSystem.ts 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172
  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 (copyData[index] < 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. //if(isHaveEmpty.state)
  81. {
  82. let len = this.pastureIcons.length;
  83. for (var i = 0; i < len; i++) {
  84. if (this.pastureIcons[i].data.state == PastureState.Empty) {
  85. gData.gameData.nextCanProduct = gData.gameData.getProductMap(this.pastureIcons[i].data.productID);
  86. gData.gameData.nextMake = this.pastureIcons[i];
  87. gData.gameData.nextType = 2;
  88. return this.pastureIcons[i];
  89. }
  90. }
  91. }
  92. }
  93. }
  94. return null;
  95. }
  96. async btnMake() {
  97. let f = await gData.gameData.nextMake.onEat();
  98. if (f) {
  99. return true;
  100. } else {
  101. return false;
  102. }
  103. }
  104. setHarvest() {
  105. let len = this.pastureIcons.length;
  106. let sendToServer = false;
  107. for (var i = 0; i < len; i++) {
  108. if (this.pastureIcons[i].data.state == PastureState.Growing) {
  109. this.pastureIcons[i].countDown.riped(false);
  110. sendToServer = true;
  111. }
  112. }
  113. if (sendToServer) {
  114. gData.gameData.freshSendToServer(2);
  115. }
  116. }
  117. canSpeedUp() {
  118. let can = false;
  119. let len = this.pastureIcons.length;
  120. for (var i = 0; i < len; i++) {
  121. if (this.pastureIcons[i].data.state == PastureState.Growing) {
  122. can = true;
  123. break;
  124. }
  125. }
  126. return can;
  127. }
  128. canHarvest() {
  129. let can = false;
  130. let len = this.pastureIcons.length;
  131. for (var i = 0; i < len; i++) {
  132. if (this.pastureIcons[i].data.state == PastureState.Ripe) {
  133. this.pastureIcons[i].canHarvest();
  134. can = true;
  135. break;
  136. }
  137. }
  138. return can;
  139. }
  140. canClearSick() {
  141. let can = false;
  142. let len = this.pastureIcons.length;
  143. for (var i = 0; i < len; i++) {
  144. if (this.pastureIcons[i].data.state == PastureState.Sick) {
  145. this.pastureIcons[i].canClearSick();
  146. can = true;
  147. break;
  148. }
  149. }
  150. return can;
  151. }
  152. }