| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136 |
- 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 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;
- }
- }
|