/** 工厂数据类 */ 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, parentNode = null) { if (this._currSelectFactory) { return await this._currSelectFactory.make(id, parentNode); } 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(dataE.completeCount < 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) { gData.gameData.nextCanProduct = gData.gameData.getProductMap(productData.picture); gData.gameData.nextMake = this.factoryIcons[j]; gData.gameData.nextType = 3; 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; } nextFactoryExtra() { let factoryArray = []; let data = gData.gameData.playerProp.orderData; if (data) { let orderData = data.orderTaskList; let productJson = gData.gameData.configs.Product; for (let i = 0; i != orderData.length; ++i) { let dataE = orderData[i]; if (dataE.completeCount < dataE.taskCount) { if (dataE.Id <= productJson.length) { let productData = productJson[dataE.Id - 1]; if (productData.tab == ProductType.nzw || productData.tab == ProductType.dw) { continue; } else { factoryArray.push(productData); } } } } //从两种类型随机选择逻辑 let isMatch = false; let matchSuccessFactorys = null; if (factoryArray.length > 0) { matchSuccessFactorys = this.isHaveEmptyFactory(factoryArray); if (matchSuccessFactorys.length > 0) { isMatch = true; } } if (isMatch) { let randFactory = mk.math.random(0, matchSuccessFactorys.length-1); let factory = matchSuccessFactorys[randFactory]; gData.gameData.nextCanProduct = gData.gameData.getProductMap(factory.picture); gData.gameData.nextMake = factory.key; gData.gameData.nextType = 3; return gData.gameData.nextMake; } 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(`nextFactoryExtra========${this.factoryIcons[i].configID}`); console.log(`nextFactoryExtra22========${gData.gameData.nextCanProduct}`); return this.factoryIcons[i]; } } } } 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; return this.factoryIcons[i]; } } } 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; } isHaveEmptyFactory(factoryTabArray: any[]) { let factoryArr = []; for (let i = 0; i != factoryTabArray.length; ++i) { let len = this.factoryIcons.length; for (var j = 0; j < len; j++) { let tab = gData.gameData.getTabByConfigID(this.factoryIcons[j].configID); if (tab == factoryTabArray[i].tab && this.factoryIcons[j].data.state == FactroyState.Empty) { let map = new Map(); map.set(this.factoryIcons[j], factoryTabArray[i].picture); factoryArr.push(map); } } } return factoryArr; } }