| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179 |
- /** 工厂数据类 */
- 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) {
- 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;
- }
- }
|