/** 工厂数据类 */ import { FactroyState, GameProp, ProductType } from "../../game/data/GameData"; import { FactoryIcon } from "./FactoryIcon"; const { ccclass } = cc._decorator; @ccclass export default class FactorySystem { private _currSelectFactory: FactoryIcon = null; public factoryIcons: Array = []; public set currSelectFactory(factory: FactoryIcon) { this._currSelectFactory = factory; } public get currSelectFactory(): FactoryIcon { return this._currSelectFactory; } public async make(id: number) { if (this._currSelectFactory) { return await this._currSelectFactory.make(id); } else { return false; } } public addFactory(factory) { this.factoryIcons.push(factory); } public nextFactory(out?: any) { let data = gData.gameData.playerProp.orderData; let copyData = gData.gameData.playerProp.copyOrderData if (data && data.orderTaskList) { if (out.state == 1) { let orderData = data.orderTaskList; let productJson = gData.gameData.configs.Product; for (let index = 0; index != orderData.length; ++index) { let dataE = orderData[index]; if (dataE.Id <= productJson.length) { if(copyData[index] < dataE.taskCount) { let productData = productJson[dataE.Id - 1]; let len = this.factoryIcons.length; for (let j = 0; j < len; j++) { let tab = gData.gameData.getTabByConfigID(this.factoryIcons[j].configID); let max = gData.gameData.getMaxProduct(tab); if (tab == productData.tab && this.factoryIcons[j].data.state == FactroyState.Empty && productData.picture <= max) { gData.gameData.nextCanProduct = gData.gameData.getProductMap(productData.picture); gData.gameData.nextMake = this.factoryIcons[j]; gData.gameData.nextType = 3; console.log("nextFactory ===== successs"); return this.factoryIcons[j]; } } } } else { let len = this.factoryIcons.length; for (let i = 0; i < len; i++) { if (this.factoryIcons[i].data.state == FactroyState.Empty) { gData.gameData.nextCanProduct = gData.gameData.getRandomFactoryConfig(this.factoryIcons[i].configID); gData.gameData.nextMake = this.factoryIcons[i]; gData.gameData.nextType = 3; console.log("nextFactory ===== successs==="); return this.factoryIcons[i]; } } } } } else { return this.doSameCheckLogic(out); } } else { return this.doSameCheckLogic(out); } return null; } doSameCheckLogic(out: any) { if (out.state == 0) { let len = this.factoryIcons.length; for (var i = 0; i < len; i++) { if (this.factoryIcons[i].data.state == FactroyState.Empty) { gData.gameData.nextCanProduct = gData.gameData.getRandomFactoryConfig(this.factoryIcons[i].configID); gData.gameData.nextMake = this.factoryIcons[i]; gData.gameData.nextType = 3; return this.factoryIcons[i]; } } } else { let isHaveEmpty = {state: false}; let picId = gData.gameData.doFarmMapDataCheck(2, isHaveEmpty); if (picId) { return picId; } else { //if(isHaveEmpty.state) { let len = this.factoryIcons.length; for (var i = 0; i < len; i++) { if (this.factoryIcons[i].data.state == FactroyState.Empty) { gData.gameData.nextCanProduct = gData.gameData.getRandomFactoryConfig(this.factoryIcons[i].configID); gData.gameData.nextMake = this.factoryIcons[i]; gData.gameData.nextType = 3; return this.factoryIcons[i]; } } } } } return null; } public async btnMake() { return await gData.gameData.nextMake.make(gData.gameData.nextCanProduct.picture); } setHarvest() { let len = this.factoryIcons.length; let sendToServer = false; for (var i = 0; i < len; i++) { if (this.factoryIcons[i].data.state == FactroyState.Producting) { this.factoryIcons[i].countDown.riped(false); sendToServer = true; } } if (sendToServer) { gData.gameData.freshSendToServer(3); } } canSpeedUp() { let can = false; let len = this.factoryIcons.length; for (var i = 0; i < len; i++) { if (this.factoryIcons[i].data.state == FactroyState.Producting) { can = true; break; } } return can; } canHarvest() { let can = false; let len = this.factoryIcons.length; for (var i = 0; i < len; i++) { if (this.factoryIcons[i].data.state == FactroyState.Ripe) { this.factoryIcons[i].canHarvest(); can = true; break; } } return can; } canClearSick() { let can = false; let len = this.factoryIcons.length; for (var i = 0; i < len; i++) { if (this.factoryIcons[i].data.state == FactroyState.Sick) { this.factoryIcons[i].canClearSick(); can = true; break; } } return can; } }