| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261 |
- /** 工厂数据类 */
- 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<FactoryIcon> = [];
- 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;
- }
- }
|