import { FarmState } from '../../game/data/GameData'; import { FarmIcon } from './FarmIcon'; const { ccclass } = cc._decorator; @ccclass export class FarmSystem { public farms: Array = []; private _currSelectFarm: FarmIcon = null; public plantWindowIsOpening = false; public _lastSeletFarm: FarmIcon = null; public set currSelectFarm(farm: FarmIcon) { if (this._currSelectFarm) { this._currSelectFarm.selectFarm(false); } this._currSelectFarm = farm; if (this._currSelectFarm) { let icon = this._currSelectFarm; icon.selectFarm(true); } } public get currSelectFarm(): FarmIcon { return this._currSelectFarm; } public addFram(fram: FarmIcon) { this.farms[fram.sortID] = fram; } public async plant(id: number){ if(this.currSelectFarm) { return await this.currSelectFarm.plant(id); } else { return false; } // this._lastSeletFarm = this._currSelectFarm; } public selectNextFarm(sel = true): FarmIcon | null { let nextFarm = this.getCanPlantFarm(); if (this._lastSeletFarm) { this._lastSeletFarm.selectFarm(false); } if (nextFarm) { if (sel) { this.currSelectFarm = nextFarm; } else { this._lastSeletFarm = this._currSelectFarm; this._currSelectFarm = nextFarm; } } return nextFarm; } /**获取可种植农田 */ private getCanPlantFarm(): FarmIcon | null { let len = this.farms.length; for (let i = 0; i < len; i++) { if (this.farms[i] != this.currSelectFarm && this.farms[i].data.state == FarmState.Empty) { gData.gameData.nextCanProduct = gData.gameData.getRandomPlantConfig(); gData.gameData.nextMake = this.farms[i]; mk.console.logSingle('getCanPlantFarm ', this.farms[i].data); return this.farms[i]; } } return null; } public async btnMake() { let flyRed = await gData.gameData.nextMake.plant(gData.gameData.nextCanProduct.picture); return flyRed; } public setHarvest() { let len = this.farms.length; let sendToServer = false; for (let i = 0; i < len; i++) { if (this.farms[i].data.state == FarmState.Growing) { this.farms[i].process.onSpeed(); this.farms[i].countDown.riped(false); sendToServer = true; } } if (sendToServer) { gData.gameData.freshSendToServer(1); } } public canSpeedUp() { let can = false; let len = this.farms.length; for (let i = 0; i < len; i++) { if (this.farms[i].data.state == FarmState.Growing) { can = true; break; } } return can; } public canHarvest() { let can = false; let len = this.farms.length; for (let i = 0; i < len; i++) { if (this.farms[i].data.state == FarmState.Ripe) { this.farms[i].canHarvest(); can = true; break; } } return can; } public canClearSick() { let can = false; let len = this.farms.length; for (let i = 0; i < len; i++) { if (this.farms[i].data.state == FarmState.Sick) { this.farms[i].canClearSick(); can = true; break; } } return can; } }