PastureSystem.ts 5.2 KB

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