wuwangdong před 4 roky
rodič
revize
6181725a6b

+ 60 - 12
assets/script/before/main/FactorySystem.ts

@@ -18,29 +18,77 @@ export default class FactorySystem {
         return this._currSelectFactory;
     }
 
-    public async make(id: number){
-        if(this._currSelectFactory)
-        {
+    public async make(id: number) {
+        if (this._currSelectFactory) {
             return await this._currSelectFactory.make(id);
-        }else{
+        } else {
             return false;
         }
-        
+
     }
 
     public addFactory(factory) {
         this.factoryIcons.push(factory);
     }
 
-    public nextFactory() {
-        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];
-                return this.factoryIcons[i];
+    public nextFactory(out?: any) {
+
+        let data = gData.gameData.playerProp.orderData;
+        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.completeCount < dataE.taskCount && dataE.Id <= productJson.length) {
+                        let productData = productJson[dataE.Id - 1];
+    
+                        let len = this.factoryIcons.length;
+                        for (var 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[i];
+                                return this.factoryIcons[i];
+                            }
+                        }
+                    } else {
+    
+                        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];
+                                return this.factoryIcons[i];
+                            }
+                        }
+                    }
+                }
+            }else{
+                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];
+                        return this.factoryIcons[i];
+                    }
+                }
+            }
+            
+        } else {
+            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];
+                    return this.factoryIcons[i];
+                }
             }
         }
+
+        return null;
     }
 
     public async btnMake() {

+ 13 - 7
assets/script/before/main/FarmSystem.ts

@@ -39,8 +39,8 @@ export class FarmSystem {
         }
         // this._lastSeletFarm = this._currSelectFarm;
     }
-    public selectNextFarm(sel = true): FarmIcon | null {
-        let nextFarm = this.getCanPlantFarm();
+    public selectNextFarm(out?: any ,sel = true): FarmIcon | null {
+        let nextFarm = this.getCanPlantFarm(out);
         if (this._lastSeletFarm) {
             this._lastSeletFarm.selectFarm(false);
         }
@@ -57,14 +57,20 @@ export class FarmSystem {
     }
 
     /**获取可种植农田 */
-    private getCanPlantFarm(): FarmIcon | null {
+    private getCanPlantFarm(out?: any): FarmIcon | null {
         let len = this.farms.length;
         for (let i = 0; i < len; i++) {
             if (this.farms[i] != this.currSelectFarm && this.farms[i].data.state == FarmState.Empty) {
-                gData.gameData.nextCanProduct = gData.gameData.getRandomPlantConfig();
-                gData.gameData.nextMake = this.farms[i];
-                mk.console.logSingle('getCanPlantFarm  ', this.farms[i].data);
-                return this.farms[i];
+                let nextProduct = gData.gameData.getRandomPlantConfig(out);
+                if(nextProduct)
+                {
+                    gData.gameData.nextCanProduct = nextProduct
+                    gData.gameData.nextMake = this.farms[i];
+                    mk.console.logSingle('getCanPlantFarm  ', this.farms[i].data);
+                    return this.farms[i];
+                }else{
+                    return null;
+                }               
             }
         }
         return null;

+ 54 - 11
assets/script/before/main/PastureSystem.ts

@@ -28,13 +28,58 @@ export default class PastureSystem {
     }
 
     /** 下一个空置饲养场 */
-    nextPasture() {
-        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];
-                return this.pastureIcons[i];
+    nextPasture(out?: any) {
+        let data = gData.gameData.playerProp.orderData;
+        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 (dataE.completeCount < 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];
+                            return this.pastureIcons[i];
+                        }
+                    }
+                } else {
+                    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];
+                            return this.pastureIcons[i];
+                        }
+                    }
+                }
+            }
+
+            //工厂有匹配的
+            if(out.state == 1)
+            {
+                return null;
+            }else{
+                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];
+                        return this.pastureIcons[i];
+                    }
+                }
+            }
+        } else {
+            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];
+                    return this.pastureIcons[i];
+                }
             }
         }
         return null;
@@ -42,11 +87,9 @@ export default class PastureSystem {
 
     async btnMake() {
         let f = await gData.gameData.nextMake.onEat();
-        if(f)
-        {
+        if (f) {
             return true;
-        }else
-        {
+        } else {
             return false;
         }
     }

+ 113 - 6
assets/script/game/data/GameData.ts

@@ -446,9 +446,114 @@ export class GameData {
     public needFreshArr = [];
 
     /** 随机获取可种植物品 */
-    getRandomPlantConfig() {
-        let id = Util.rnd(10001, this.getMaxProduct(ProductType.nzw));
-        return this.getProductMap(id);
+    getRandomPlantConfig(out?:any) {
+        let id = 0;
+        let isNoHaveCurTab = true;
+        let isNoAllComplete = false;
+        let isOrderDataInvalid = false;
+        let productType = [];
+        let animalId = [];
+        let data = gData.gameData.playerProp.orderData;
+        let orderData =  data.orderTaskList;
+        if(data && orderData)
+        {
+            let productJson = gData.gameData.configs.Product;
+            for(let i = 0; i != orderData.length; ++i)
+            {
+                let dataE = orderData[i];
+                if (dataE.completeCount < dataE.taskCount && dataE.Id <= productJson.length) {
+                    
+                    isNoAllComplete = true;
+                    let productData = productJson[dataE.Id - 1];
+                    if(productData.tab == ProductType.nzw)
+                    {
+                        let max = gData.gameData.getMaxProduct(ProductType.nzw);
+                        if(productData.picture <= max)
+                        {
+                            id = productData.picture;
+                            isNoHaveCurTab = false;
+                            mk.console.logSingle("getRandomPlantConfig=>", id);
+                            break;
+                        }            
+                    }else if(productData.tab == ProductType.dw)
+                    {
+                        animalId.push(productData.picture);
+                    }else{
+                        productType.push(productData.tab);
+                    }
+                    
+                }else{
+                    isOrderDataInvalid = true;
+                    id = Util.rnd(10001, this.getMaxProduct(ProductType.nzw));
+                    console.log("订单数据有问题,随机id");
+                    break;
+                }
+            }
+
+            id = Util.rnd(10001, this.getMaxProduct(ProductType.nzw));
+            console.log("订单数据没有合适的物品");
+        }else{
+            isOrderDataInvalid = true;
+            id = Util.rnd(10001, this.getMaxProduct(ProductType.nzw));
+            console.log("订单数据为null");
+        }
+
+        if(isOrderDataInvalid)
+        {
+            return this.getProductMap(id);
+        }else{
+            if(isNoHaveCurTab)
+            {
+                if(isNoAllComplete)
+                {
+                    let isHaveEmpty = false;
+                    for(let i = 0; i != productType.length; ++i)
+                    {
+                        let factoryIcon = gData.factorySystem.factoryIcons;
+                        let len = factoryIcon.length;
+                        for (var j = 0; j < len; j++) {
+                            let tab = this.getTabByConfigID(factoryIcon[j].configID);
+                            if (tab == productType[j] && factoryIcon[j].data.state == FactroyState.Empty) {
+                                isHaveEmpty = true;
+                                out.state = 1;
+                               break;
+                            }
+                        }
+                    }
+
+                    if(!isHaveEmpty)
+                    {
+                        for(let i = 0; i != animalId.length; ++i)
+                        {
+                            let pastureIcon = gData.pastureSystem.pastureIcons;
+                            let len = pastureIcon.length;
+                            for (var j = 0; j < len; j++) {
+                                if (pastureIcon[j].data.productID ==animalId[i] && pastureIcon[j].data.state == PastureState.Empty) {
+                                    isHaveEmpty = true;
+                                    out.state = 2;
+                                    break;
+                                }
+                            }
+                        }
+                    }
+
+                    if(isHaveEmpty)
+                    {
+                        return null;
+
+                    }else{
+                        return this.getProductMap(id);
+                    }
+                }else{
+                    return this.getProductMap(id);
+                }
+            }else{
+                return this.getProductMap(id);
+            }    
+        }
+
+        //id = Util.rnd(10001, this.getMaxProduct(ProductType.nzw));
+        //return this.getProductMap(id);
     }
 
     /** 随机获取可生产产品 */
@@ -477,11 +582,13 @@ export class GameData {
         if (this.nextMake) {
             return;
         }
-        let next = gData.farmSystem.selectNextFarm(sel);
+        //-1无效,1:工厂有空位,2:饲养厂有空位
+        let haveEmpty = {state: -1};
+        let next = gData.farmSystem.selectNextFarm(haveEmpty, sel);
         if (!next) {
-            let next1 = gData.pastureSystem.nextPasture();
+            let next1 = gData.pastureSystem.nextPasture(haveEmpty);
             if (!next1) {
-                let next2 = gData.factorySystem.nextFactory();
+                let next2 = gData.factorySystem.nextFactory(haveEmpty);
                 if (!next2) {
                     this.nextType = 0;
                 }