PastureSystem.ts 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. for (var i = 0; i < len; i++) {
  42. if (this.pastureIcons[i].data.state == PastureState.Growing) {
  43. this.pastureIcons[i].countDown.riped();
  44. }
  45. }
  46. }
  47. canSpeedUp() {
  48. let can = false;
  49. let len = this.pastureIcons.length;
  50. for (var i = 0; i < len; i++) {
  51. if (this.pastureIcons[i].data.state == PastureState.Growing) {
  52. can = true;
  53. break;
  54. }
  55. }
  56. return can;
  57. }
  58. canHarvest() {
  59. let can = false;
  60. let len = this.pastureIcons.length;
  61. for (var i = 0; i < len; i++) {
  62. if (this.pastureIcons[i].data.state == PastureState.Ripe) {
  63. this.pastureIcons[i].canHarvest();
  64. can = true;
  65. break;
  66. }
  67. }
  68. return can;
  69. }
  70. canClearSick() {
  71. let can = false;
  72. let len = this.pastureIcons.length;
  73. for (var i = 0; i < len; i++) {
  74. if (this.pastureIcons[i].data.state == PastureState.Sick) {
  75. this.pastureIcons[i].canClearSick();
  76. can = true;
  77. break;
  78. }
  79. }
  80. return can;
  81. }
  82. }