FarmSystem.ts 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. import { FarmState } from '../../game/data/GameData';
  2. import { FarmIcon } from './FarmIcon';
  3. const { ccclass } = cc._decorator;
  4. @ccclass
  5. export class FarmSystem {
  6. public farms: Array<FarmIcon> = [];
  7. private _currSelectFarm: FarmIcon = null;
  8. public plantWindowIsOpening = false;
  9. /** 种植冷却 */
  10. public plantIsRequesting = false;
  11. public set currSelectFarm(farm: FarmIcon) {
  12. if (this._currSelectFarm) {
  13. this._currSelectFarm.selectFarm(false);
  14. }
  15. this._currSelectFarm = farm;
  16. if (this._currSelectFarm) {
  17. let icon = this._currSelectFarm;
  18. icon.selectFarm(true);
  19. }
  20. }
  21. public get currSelectFarm(): FarmIcon {
  22. return this._currSelectFarm;
  23. }
  24. public addFram(fram: FarmIcon) {
  25. this.farms[fram.sortID] = fram;
  26. }
  27. public plant(id: number): void {
  28. this.currSelectFarm && this.currSelectFarm.plant(id);
  29. }
  30. public selectNextFarm(): FarmIcon | null {
  31. let nextFarm = this.getCanPlantFarm();
  32. if (nextFarm) {
  33. this.currSelectFarm = nextFarm;
  34. } else {
  35. //暂时注释
  36. // WindowManager.close();
  37. }
  38. return nextFarm;
  39. }
  40. /**获取可种植农田 */
  41. private getCanPlantFarm(): FarmIcon | null {
  42. for (let i = 0; i < this.farms.length; i++) {
  43. if (this.farms[i] != this.currSelectFarm && this.farms[i].data.state == FarmState.Empty) {
  44. gData.gameData.nextCanProduct = gData.gameData.getRandomPlantConfig();
  45. gData.gameData.nextMake = this.farms[i];
  46. return this.farms[i];
  47. }
  48. }
  49. return null;
  50. }
  51. public btnMake() {
  52. gData.gameData.nextMake.plant(gData.gameData.nextCanProduct.picture);
  53. }
  54. }