| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172 |
- 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<number, PastureData> = new Map<number, PastureData>();
- public pastureIcons: Array<PastureIcon> = [];
- 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;
- }
- }
|