| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- import { FarmState } from '../../game/data/GameData';
- import { FarmIcon } from './FarmIcon';
- const { ccclass } = cc._decorator;
- @ccclass
- export class FarmSystem {
- public farms: Array<FarmIcon> = [];
- 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 plant(id: number): void {
- this.currSelectFarm && this.currSelectFarm.plant(id);
- // 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 btnMake() {
- gData.gameData.nextMake.plant(gData.gameData.nextCanProduct.picture);
- }
- public setHarvest() {
- let len = this.farms.length;
- 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();
- }
- }
- }
- }
|