PastureSystem.ts 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. }