PastureSystem.ts 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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() {
  26. let len = this.pastureIcons.length;
  27. for (var i = 0; i < len; i++) {
  28. if (this.pastureIcons[i].data.state == PastureState.Empty) {
  29. gData.gameData.nextCanProduct = gData.gameData.getProductMap(this.pastureIcons[i].data.productID);
  30. gData.gameData.nextMake = this.pastureIcons[i];
  31. return this.pastureIcons[i];
  32. }
  33. }
  34. return null;
  35. }
  36. btnMake() {
  37. gData.gameData.nextMake.onEat();
  38. }
  39. setHarvest() {
  40. let len = this.pastureIcons.length;
  41. let sendToServer = false;
  42. for (var i = 0; i < len; i++) {
  43. if (this.pastureIcons[i].data.state == PastureState.Growing) {
  44. this.pastureIcons[i].countDown.riped(false);
  45. sendToServer = true;
  46. }
  47. }
  48. if (sendToServer) {
  49. gData.gameData.freshSendToServer(2);
  50. }
  51. }
  52. canSpeedUp() {
  53. let can = false;
  54. let len = this.pastureIcons.length;
  55. for (var i = 0; i < len; i++) {
  56. if (this.pastureIcons[i].data.state == PastureState.Growing) {
  57. can = true;
  58. break;
  59. }
  60. }
  61. return can;
  62. }
  63. canHarvest() {
  64. let can = false;
  65. let len = this.pastureIcons.length;
  66. for (var i = 0; i < len; i++) {
  67. if (this.pastureIcons[i].data.state == PastureState.Ripe) {
  68. this.pastureIcons[i].canHarvest();
  69. can = true;
  70. break;
  71. }
  72. }
  73. return can;
  74. }
  75. canClearSick() {
  76. let can = false;
  77. let len = this.pastureIcons.length;
  78. for (var i = 0; i < len; i++) {
  79. if (this.pastureIcons[i].data.state == PastureState.Sick) {
  80. this.pastureIcons[i].canClearSick();
  81. can = true;
  82. break;
  83. }
  84. }
  85. return can;
  86. }
  87. }