import { PastureState, ProductType } from "../../game/data/GameData"; import PastureData from "./PastureData"; import PastureIcon from "./PastureIcon"; /** 动物移动管理系统 */ const { ccclass } = cc._decorator; @ccclass export default class PastureSystem { private pastureDataMap: Map = new Map(); public pastureIcons: Array = []; setPastureData(configID) { if (this.getPastureData(configID)) { return; } let data = new PastureData(); this.pastureDataMap.set(configID, data); return data; } getPastureData(configID) { return this.pastureDataMap.get(configID); } addPastureIcon(pasture) { this.pastureIcons.push(pasture); } /** 下一个空置饲养场 */ nextPasture(out?: any) { let data = gData.gameData.playerProp.orderData; let copyData = gData.gameData.playerProp.copyOrderData if (data && data.orderTaskList) { let orderData = data.orderTaskList; let productJson = gData.gameData.configs.Product; for (let index = 0; index != orderData.length; ++index) { let dataE = orderData[index]; if (copyData[index] < dataE.taskCount && dataE.Id <= productJson.length) { let productData = productJson[dataE.Id - 1]; let len = this.pastureIcons.length; for (var i = 0; i < len; i++) { if (productData.picture == this.pastureIcons[i].data.productID && this.pastureIcons[i].data.state == PastureState.Empty) { gData.gameData.nextCanProduct = gData.gameData.getProductMap(this.pastureIcons[i].data.productID); gData.gameData.nextMake = this.pastureIcons[i]; gData.gameData.nextType = 2; return this.pastureIcons[i]; } } } else { break; } } //工厂有匹配的 if (out.state == 1) { console.log("nextPasture=======null"); return null; } else { return this.doSameCheckLogic(out); } } else { return this.doSameCheckLogic(out); } return null; } doSameCheckLogic(out:any) { if (out.state == 0) { let len = this.pastureIcons.length; for (var i = 0; i < len; i++) { if (this.pastureIcons[i].data.state == PastureState.Empty) { gData.gameData.nextCanProduct = gData.gameData.getProductMap(this.pastureIcons[i].data.productID); gData.gameData.nextMake = this.pastureIcons[i]; gData.gameData.nextType = 2; return this.pastureIcons[i]; } } } else { let isHaveEmpty = {state: false}; let picId = gData.gameData.doFarmMapDataCheck(1, isHaveEmpty); if (picId) { return picId; } else { //if(isHaveEmpty.state) { let len = this.pastureIcons.length; for (var i = 0; i < len; i++) { if (this.pastureIcons[i].data.state == PastureState.Empty) { gData.gameData.nextCanProduct = gData.gameData.getProductMap(this.pastureIcons[i].data.productID); gData.gameData.nextMake = this.pastureIcons[i]; gData.gameData.nextType = 2; return this.pastureIcons[i]; } } } } } return null; } async btnMake() { let f = await gData.gameData.nextMake.onEat(); if (f) { return true; } else { return false; } } setHarvest() { let len = this.pastureIcons.length; let sendToServer = false; for (var i = 0; i < len; i++) { if (this.pastureIcons[i].data.state == PastureState.Growing) { this.pastureIcons[i].countDown.riped(false); sendToServer = true; } } if (sendToServer) { gData.gameData.freshSendToServer(2); } } canSpeedUp() { let can = false; let len = this.pastureIcons.length; for (var i = 0; i < len; i++) { if (this.pastureIcons[i].data.state == PastureState.Growing) { can = true; break; } } return can; } canHarvest() { let can = false; let len = this.pastureIcons.length; for (var i = 0; i < len; i++) { if (this.pastureIcons[i].data.state == PastureState.Ripe) { this.pastureIcons[i].canHarvest(); can = true; break; } } return can; } canClearSick() { let can = false; let len = this.pastureIcons.length; for (var i = 0; i < len; i++) { if (this.pastureIcons[i].data.state == PastureState.Sick) { this.pastureIcons[i].canClearSick(); can = true; break; } } return can; } }