فهرست منبع

修复产品解锁的条件导致旧版本出现问题的bug

wuwangdong 4 سال پیش
والد
کامیت
67a971a5ec

+ 2 - 2
assets/script/before/main/FactorySystem.ts

@@ -48,8 +48,8 @@ export default class FactorySystem {
                             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) {
+                                //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;

+ 6 - 5
assets/script/before/view/uiItem/PlantItem.ts

@@ -69,10 +69,11 @@ export default class PlantItem extends cc.Component {
         let times = 0;
         //根据上个商品种植次数
         if (list_data.unlock == 1) {
-            times = gData.gameData.getProductMakeTimesById(list_data.picture - 1);
-            if (times >= list_data.value) {
-                unlock = true;
-            }
+            // times = gData.gameData.getProductMakeTimesById(list_data.picture - 1);
+            // if (times >= list_data.value) {
+            //     unlock = true;
+            // }
+            unlock = gData.gameData.getProductUnlockById(this.data.tab, this.data.picture);
         }
         //根据农场等级
         else if (list_data.unlock == 2) {
@@ -86,7 +87,7 @@ export default class PlantItem extends cc.Component {
         if (!unlock) {
             let des = this.getDesByType();
             let plantName = gData.gameData.getProductMap(this.data.picture - 1).name;
-            if (list_data.picture - 1 == gData.gameData.getMaxProduct(this.data.tab)) {
+            if (list_data.picture - 1 == gData.gameData.getMaxProductExtra(this.data.tab)) {
                 this.labUnlock.string = `${des}${this.data.value}次\n${plantName}`;
                 this.lbl_progress.string = `${times}/${this.data.value}`;
                 this.labUnlock.node.active = true;

+ 128 - 30
assets/script/game/data/GameData.ts

@@ -407,8 +407,7 @@ export class GameData {
         }
         gData.gameData.setProp(GameProp.leftTimes, gData.gameData.leftTimes);
 
-        if(isRefresh)
-        {
+        if (isRefresh) {
             gData.gameData.init_leftTimes = true;
         }
     }
@@ -524,7 +523,7 @@ export class GameData {
                         isNoAllComplete = true;
                         let productData = productJson[dataE.Id - 1];
                         if (productData.tab == ProductType.nzw) {
-                            let max = this.getMaxProduct(ProductType.nzw);
+                            let max = this.getMaxProductExtra(ProductType.nzw);
                             if (max && productData.picture <= max) {
                                 id = productData.picture;
                                 isNoHaveCurTab = false;
@@ -552,7 +551,7 @@ export class GameData {
                 if (picId) {
                     id = picId;
                 } else {
-                    id = Util.rnd(10001, this.getMaxProduct(ProductType.nzw));
+                    id = Util.rnd(10001, this.getMaxProductExtra(ProductType.nzw));
                     this.nextType = 1
                 }
                 console.log("订单数据没有匹配成功====1");
@@ -563,7 +562,7 @@ export class GameData {
             if (picId) {
                 id = picId;
             } else {
-                id = Util.rnd(10001, this.getMaxProduct(ProductType.nzw));
+                id = Util.rnd(10001, this.getMaxProductExtra(ProductType.nzw));
                 this.nextType = 1
             }
             console.log("订单数据为null");
@@ -625,8 +624,7 @@ export class GameData {
         //return this.getProductMap(id);
     }
 
-    public doJudgeOrderLogic(out?: any)
-    {
+    public doJudgeOrderLogic(out?: any) {
         let data = this.playerProp.orderData;
         let orderData = data.orderTaskList;
         if (data && orderData) {
@@ -638,8 +636,7 @@ export class GameData {
                         let productData = productJson[dataE.Id - 1];
                         if (productData.tab == ProductType.nzw) {
                             continue;
-                        }else if(productData.tab == ProductType.dw)
-                        {
+                        } else if (productData.tab == ProductType.dw) {
                             console.log(`doJudgeOrderLogic=====${dataE.Id}`);
                             let pastureIcon = gData.pastureSystem.pastureIcons;
                             let len = pastureIcon.length;
@@ -652,7 +649,7 @@ export class GameData {
                                 }
                             }
 
-                        }else{
+                        } else {
                             let factoryIcon = gData.factorySystem.factoryIcons;
                             let len = factoryIcon.length;
                             for (var j = 0; j < len; j++) {
@@ -675,7 +672,7 @@ export class GameData {
     getRandomFactoryConfig(configID) {
         let tab = gData.gameData.getTabByConfigID(configID);
         let arr = this.getProductArrByType(tab);
-        let max = this.getMaxProduct(tab);
+        let max = this.getMaxProductExtra(tab);
         let canArr = [];
         let len = arr.length;
         for (var i = 0; i < len; i++) {
@@ -696,7 +693,7 @@ export class GameData {
         let value = 0;
         for (let key in ProductType) {
             if (startIndex <= value) {
-                let max = this.getMaxProduct(ProductType[key]);
+                let max = this.getMaxProductExtra(ProductType[key]);
                 if (max) {
                     let list_data = this.getProductArrByType(ProductType[key]);
                     for (let i = 0; i != list_data.length; ++i) {
@@ -771,8 +768,7 @@ export class GameData {
         let haveEmpty = { state: -1 };
         let next = gData.farmSystem.selectNextFarm(haveEmpty, sel);
         if (!next) {
-            if(haveEmpty.state == -1)
-            {
+            if (haveEmpty.state == -1) {
                 this.doJudgeOrderLogic(haveEmpty);
             }
             let next1 = gData.pastureSystem.nextPasture(haveEmpty);
@@ -849,7 +845,7 @@ export class GameData {
             if (com >= count) {
                 if (!this.gameStyle.getIsCanGetOrderReward()) {
                     mk.tip.pop('任务红包进度已满,快去提现');
-                }else{
+                } else {
                     mk.tip.pop("订单已完成,快领奖吧!");
                 }
                 return false;
@@ -984,20 +980,50 @@ export class GameData {
     }
 
     /** 产品生产/种植次数 服务器数据 */
-    private _productMakeTimesData = [];
+    private _productMakeTimesData: any = {};
     /** 产品生产/种植次数 */
     private _productMakeTimesMap: Map<number, number> = new Map();
 
+    //产品解锁最大id
+    private _productUnlockMaxId: Map<string, number> = new Map();
+
     private initProductTimes() {
-        this._productMakeTimesData = this.getProp(GameProp.productMakeTimes);
-        if (!this._productMakeTimesData) {
-            this._productMakeTimesData = [];
+        let value = this.getProp(GameProp.productMakeTimes);
+        if (!value) {
+            this._productMakeTimesData.makeTimes = [];
+            this._productMakeTimesData.productUnlockMaxId = new Map<string, number>();
+            this._productMakeTimesData.productUnlockMaxId.set(ProductType.nzw, 10003);
+        } else {
+            if (value instanceof Array) {
+
+                this._productMakeTimesData.makeTimes = value;
+                this._productMakeTimesData.productUnlockMaxId = new Map<string, number>();
+                this._productMakeTimesData.productUnlockMaxId.set(ProductType.nzw, 10003);
+
+                let len = value.length;
+                for (let i = 0; i != len; ++i) {
+                    let data = value[i];
+                    let config = this.getProductMap(data.id);
+
+                    let v = this._productMakeTimesData.productUnlockMaxId.get(config.tab);
+                    if (v) {
+                        if (v < data.id) {
+                            this._productMakeTimesData.productUnlockMaxId.set(config.tab, data.id);
+                        }
+                    } else {
+                        this._productMakeTimesData.productUnlockMaxId.set(config.tab, data.id);
+                    }
+                }
+            } else {
+                this._productMakeTimesData.makeTimes = value.makeTimes;
+                this._productMakeTimesData.productUnlockMaxId = this.objToMap(JSON.parse(value.productUnlockMaxId));
+            }
         }
 
-        let len = this._productMakeTimesData.length;
+        let len = this._productMakeTimesData.makeTimes.length;
         for (var i = 0; i < len; i++) {
-            this._productMakeTimesMap.set(this._productMakeTimesData[i].id, this._productMakeTimesData[i].times);
-            this.setMaxProduct(this._productMakeTimesData[i].id);
+            this._productMakeTimesMap.set(this._productMakeTimesData.makeTimes[i].id, this._productMakeTimesData.makeTimes[i].times);
+            this.setMaxProduct(this._productMakeTimesData.makeTimes[i].id);
         }
     }
 
@@ -1012,17 +1038,17 @@ export class GameData {
 
         //更新到服务器
         let has = false;
-        let len = this._productMakeTimesData.length;
+        let len = this._productMakeTimesData.makeTimes.length;
         for (var i = 0; i < len; i++) {
-            if (this._productMakeTimesData[i].id == id) {
-                this._productMakeTimesData[i].times = times;
+            if (this._productMakeTimesData.makeTimes[i].id == id) {
+                this._productMakeTimesData.makeTimes[i].times = times;
                 has = true;
                 break;
             }
         }
         if (!has) {
             let data = { 'id': id, 'times': times };
-            this._productMakeTimesData.push(data);
+            this._productMakeTimesData.makeTimes.push(data);
         }
 
         //设置可种植/生产最大id
@@ -1030,19 +1056,20 @@ export class GameData {
         let curConfig = this.getProductMap(id);
         let nextConfig = this.getProductMap(nextID);
 
-        if (id == this.getMaxProduct(curConfig.tab)) {
+        if (id == this.getMaxProductExtra(curConfig.tab)) {
             if (nextConfig) {
                 gData.plantData.init_itemIndex = nextID;
             }
         }
 
         if (nextConfig) {
-            if (nextConfig.tab == curConfig.tab && nextID > this.getMaxProduct(curConfig.tab)) {
+            if (nextConfig.tab == curConfig.tab && nextID > this.getMaxProductExtra(curConfig.tab)) {
                 if (nextConfig.unlock == 1 && nextConfig.value <= times) {
                     isAddMaxProduct = true;
                     this._productMakeTimesMap.set(nextID, 0);
                     let data = { 'id': nextID, 'times': 0 };
-                    this._productMakeTimesData.push(data);
+                    this._productMakeTimesData.makeTimes.push(data);
+                    this._productMakeTimesData.productUnlockMaxId.set(nextConfig.tab, nextID);
                     this.setMaxProduct(nextID);
                     let nConfig = this.getProductMap(nextID + 1);
                     if (nConfig) {
@@ -1055,7 +1082,45 @@ export class GameData {
         if (!isAddMaxProduct) {
             mk.event.emit("refreshFarmMapUI");
         }
-        this.setProp(GameProp.productMakeTimes, this._productMakeTimesData);
+        let sss: any = {};
+        sss.makeTimes = this._productMakeTimesData.makeTimes;
+        let json = this.mapToObj(this._productMakeTimesData.productUnlockMaxId);
+        sss.productUnlockMaxId = JSON.stringify(json);
+
+        this.setProp(GameProp.productMakeTimes, sss);
+    }
+
+    mapToObj(mapData) {
+        let obj = {};
+        mapData.forEach(function (value, key) {
+            obj[key] = value;
+        });
+        return obj;
+    }
+
+    objToMap(obj) {
+        let map = new Map();
+        for (let k in obj) {
+            map.set(k, obj[k]);
+        }
+        return map;
+    }
+
+    //设置解锁的最大id
+    addProductUnlockMaxId(tab, id) {
+        if (this._productMakeTimesData.productUnlockMaxId) {
+            let productId = this._productMakeTimesData.productUnlockMaxId.get(tab);
+            if (productId && id > productId) {
+                this._productMakeTimesData.productUnlockMaxId.set(tab, id);
+
+                let sss: any = {};
+                sss.makeTimes = this._productMakeTimesData.makeTimes;
+                let json = this.mapToObj(this._productMakeTimesData.productUnlockMaxId);
+                sss.productUnlockMaxId = JSON.stringify(json);
+
+                this.setProp(GameProp.productMakeTimes, sss);
+            }
+        }
     }
 
     getProductMakeTimesById(id: number) {
@@ -1066,6 +1131,25 @@ export class GameData {
         return times;
     }
 
+    getProductUnlockById(tab, id:number){
+        if(this._productMakeTimesData.productUnlockMaxId)
+        {
+            let productId = this._productMakeTimesData.productUnlockMaxId.get(tab);
+            if(productId) 
+            {
+                if(productId >= id)
+                {
+                    return true;
+                }else{
+                    return false;
+                }
+            }else{
+                return false;
+            }
+        }
+        return false;
+    }
+
     //------------- 养殖场数据-----------
     /**  养殖场数据 服务器数据 */
     private _pastureData = [];
@@ -1188,6 +1272,7 @@ export class GameData {
                     data = { id: id, state: FactroyState.Empty, productID: 0, growSpan: 0 };
                     //更新最大可购买商品
                     this.setMaxProduct(arr[0].picture, true);
+                    this.addProductUnlockMaxId(tab, arr[0].picture);
                 }
                 this._factoryData.push(data);
                 this._factoryDataMap.set(id, data);
@@ -1212,14 +1297,17 @@ export class GameData {
                 if (this.playerProp.completeFarmTaskTimes >= arr[0].value) {
                     //更新最大可购买商品
                     this.setMaxProduct(arr[0].picture, true);
+                    this.addProductUnlockMaxId(tab, arr[0].picture);
                 }
                 id++;
             }
 
             this.RawInsectCurArr[2] = sickTimes;
         }
+
     }
 
+
     /** 通过工厂建筑物ID获取标签 */
     getTabByConfigID(configID: number): ProductType {
         let tab = ProductType.bmhc;
@@ -1347,6 +1435,14 @@ export class GameData {
         return null;
     }
 
+    getMaxProductExtra(tab) {
+        if (this._productMakeTimesData.productUnlockMaxId) {
+            let productId = this._productMakeTimesData.productUnlockMaxId.get(tab);
+            return productId;
+        }
+        return null;
+    }
+
     /** 设置最大可生产商品
      * @param id 产品id
      * @param unlock 是否是解锁增加
@@ -1414,6 +1510,7 @@ export class GameData {
                     if (maxId != 0) {
                         //更新最大可购买商品
                         this.setMaxProduct(maxId, true);
+                        this.addProductUnlockMaxId(tab, maxId);
                     }
 
                     //更新到服务器
@@ -1435,6 +1532,7 @@ export class GameData {
                         }
                         //更新最大可购买商品
                         this.setMaxProduct(configArr[0].picture, true);
+                        this.addProductUnlockMaxId(tab, configArr[0].picture);
                     }
 
                     if (needUpdate) {

+ 1 - 1
assets/script/game/data/module/FarmMapData.ts

@@ -27,6 +27,6 @@ export class FarmMapData extends Data {
 
     setChooseType(t: ProductType) {
         this.chooseType = t;
-        this.maxUnluckValue = gData.gameData.getMaxProduct(t);
+        this.maxUnluckValue = gData.gameData.getMaxProductExtra(t);
     }
 }

+ 1 - 1
assets/script/game/game/Game.ts

@@ -732,7 +732,7 @@ export default class Game extends cc.Component {
         //1:有可领奖的,2:正在解锁,3:所有奖励都领取完
         this.uiShowType = 3;
         for (let key in ProductType) {
-            let max = gData.gameData.getMaxProduct(ProductType[key]);
+            let max = gData.gameData.getMaxProductExtra(ProductType[key]);
             if (max) {
                 let list_data = gData.gameData.getProductArrByType(ProductType[key]);
                 for (let i = 0; i != list_data.length; ++i) {

+ 1 - 1
assets/script/game/game/RedPointControl.ts

@@ -38,7 +38,7 @@ export class RedPointControl extends cc.Component {
     private changeStatus()
     {
         for (let key in ProductType) {
-            let max = gData.gameData.getMaxProduct(ProductType[key]);
+            let max = gData.gameData.getMaxProductExtra(ProductType[key]);
             if (max) {
                 let list_data = gData.gameData.getProductArrByType(ProductType[key]);        
                 for (let i = 0; i != list_data.length; ++i) {

+ 1 - 1
assets/script/game/module/farmMap/FarmMap.ts

@@ -58,7 +58,7 @@ export default class FarmMap extends cc.Component {
     private refreshBtnState() {
         let index = 0;
         for (let key in ProductType) {
-            let max = gData.gameData.getMaxProduct(ProductType[key]);
+            let max = gData.gameData.getMaxProductExtra(ProductType[key]);
             if (max) {
                 this.itemName[index].toggle.interactable = true;
                 let list_data = gData.gameData.getProductArrByType(ProductType[key]);

+ 1 - 2
assets/script/mk/system/FlySystem2.ts

@@ -65,8 +65,7 @@ export default class FlySystem2 extends cc.Component {
         cc.tween(target)
             .to(dur, { scale: 0.8 })
             .start();
-
-            console.log('---');
+            
         let end_pos: cc.Vec2 = null;
         let end_node: cc.Node = null;
         if (typeof end === 'string') {