PastureSystem.ts 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. import { PastureState } 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. return this.pastureIcons[i];
  41. }
  42. }
  43. } else {
  44. let len = this.pastureIcons.length;
  45. for (var i = 0; i < len; i++) {
  46. if (this.pastureIcons[i].data.state == PastureState.Empty) {
  47. gData.gameData.nextCanProduct = gData.gameData.getProductMap(this.pastureIcons[i].data.productID);
  48. gData.gameData.nextMake = this.pastureIcons[i];
  49. return this.pastureIcons[i];
  50. }
  51. }
  52. }
  53. }
  54. //工厂有匹配的
  55. if(out.state == 1)
  56. {
  57. return null;
  58. }else{
  59. let len = this.pastureIcons.length;
  60. for (var i = 0; i < len; i++) {
  61. if (this.pastureIcons[i].data.state == PastureState.Empty) {
  62. gData.gameData.nextCanProduct = gData.gameData.getProductMap(this.pastureIcons[i].data.productID);
  63. gData.gameData.nextMake = this.pastureIcons[i];
  64. return this.pastureIcons[i];
  65. }
  66. }
  67. }
  68. } else {
  69. let len = this.pastureIcons.length;
  70. for (var i = 0; i < len; i++) {
  71. if (this.pastureIcons[i].data.state == PastureState.Empty) {
  72. gData.gameData.nextCanProduct = gData.gameData.getProductMap(this.pastureIcons[i].data.productID);
  73. gData.gameData.nextMake = this.pastureIcons[i];
  74. return this.pastureIcons[i];
  75. }
  76. }
  77. }
  78. return null;
  79. }
  80. async btnMake() {
  81. let f = await gData.gameData.nextMake.onEat();
  82. if (f) {
  83. return true;
  84. } else {
  85. return false;
  86. }
  87. }
  88. setHarvest() {
  89. let len = this.pastureIcons.length;
  90. let sendToServer = false;
  91. for (var i = 0; i < len; i++) {
  92. if (this.pastureIcons[i].data.state == PastureState.Growing) {
  93. this.pastureIcons[i].countDown.riped(false);
  94. sendToServer = true;
  95. }
  96. }
  97. if (sendToServer) {
  98. gData.gameData.freshSendToServer(2);
  99. }
  100. }
  101. canSpeedUp() {
  102. let can = false;
  103. let len = this.pastureIcons.length;
  104. for (var i = 0; i < len; i++) {
  105. if (this.pastureIcons[i].data.state == PastureState.Growing) {
  106. can = true;
  107. break;
  108. }
  109. }
  110. return can;
  111. }
  112. canHarvest() {
  113. let can = false;
  114. let len = this.pastureIcons.length;
  115. for (var i = 0; i < len; i++) {
  116. if (this.pastureIcons[i].data.state == PastureState.Ripe) {
  117. this.pastureIcons[i].canHarvest();
  118. can = true;
  119. break;
  120. }
  121. }
  122. return can;
  123. }
  124. canClearSick() {
  125. let can = false;
  126. let len = this.pastureIcons.length;
  127. for (var i = 0; i < len; i++) {
  128. if (this.pastureIcons[i].data.state == PastureState.Sick) {
  129. this.pastureIcons[i].canClearSick();
  130. can = true;
  131. break;
  132. }
  133. }
  134. return can;
  135. }
  136. }