PastureSystem.ts 5.5 KB

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