Просмотр исходного кода

更新最大可种植产品到服务器

kaka 4 лет назад
Родитель
Сommit
e9c24abb7f
2 измененных файлов с 26 добавлено и 17 удалено
  1. 20 11
      assets/script/game/data/GameData.ts
  2. 6 6
      assets/script/game/game/Game.ts

+ 20 - 11
assets/script/game/data/GameData.ts

@@ -103,6 +103,9 @@ export class GameData {
     //恢复生产次数
     public restoreProductTimes = 0;
 
+    /** 最大可种植产品可更新到服务器标识 */
+    public maxProductToServer = false;
+
     /**
      * 初始化游戏数据:网络配置信息,用户信息
      * @returns 
@@ -411,23 +414,20 @@ export class GameData {
 
     //提现次数
     public _cashOutTimes = 0;
-    public initCashOutTimes()
-    {
-        let v= this.getProp(GameProp.cashOutTimes);
-        if(v)
-        {
+    public initCashOutTimes() {
+        let v = this.getProp(GameProp.cashOutTimes);
+        if (v) {
             this._cashOutTimes = v;
-        }else{
+        } else {
             this._cashOutTimes = 0;
         }
-        console.log(`initCashOutTimes====>${this._cashOutTimes }`);
+        console.log(`initCashOutTimes====>${this._cashOutTimes}`);
     }
 
-    public addCashOutTimes()
-    {
+    public addCashOutTimes() {
         this._cashOutTimes += 1;
         this.setProp(GameProp.cashOutTimes, this._cashOutTimes);
-        console.log(`addCashOutTimes====>${this._cashOutTimes }`);
+        console.log(`addCashOutTimes====>${this._cashOutTimes}`);
     }
 
     /** 是否是新用户 */
@@ -1028,6 +1028,8 @@ export class GameData {
         }
 
         gData.farmMapData.isStateChange = true;
+
+        this.updateMaxProduct();
     }
 
     /** 农场升级时解锁工厂,检查最大可种植/生产商品 */
@@ -1158,6 +1160,13 @@ export class GameData {
             }
         }
     }
+
+    /** 更新最大可种植产品到服务器 */
+    updateMaxProduct() {
+        if (this.maxProductToServer) {
+            mk.http.sendData('updateMaxProduct', this._maxProduct);
+        }
+    }
 }
 
 /**
@@ -1204,7 +1213,7 @@ export enum GameProp {
 
     //提现次数
     cashOutTimes = 21,
-    
+
 }
 
 /**

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

@@ -101,6 +101,8 @@ export default class Game extends cc.Component {
         gData.gameData.gameStyle = this;
         this.span = gData.gameData.ProductionRecovery * 60 * 1000;
         gData.gameData.checkTaskFinishUnLock();
+        gData.gameData.maxProductToServer = true;
+        gData.gameData.updateMaxProduct();
         this.registerCallBack();
 
         console.log("===[Jsbsystem 显示开屏广告================================")
@@ -579,22 +581,20 @@ export default class Game extends cc.Component {
     }
 
     //图鉴部分logic
-    public initRefreshEvent()
-    {
+    public initRefreshEvent() {
 
     }
 
-    public initFarmMapUi()
-    {
+    public initFarmMapUi() {
         for (let key in ProductType) {
             let max = gData.gameData.getMaxProduct(ProductType[key]);
             if (max) {
-                let list_data = gData.gameData.getProductArrByType(ProductType[key]);        
+                let list_data = gData.gameData.getProductArrByType(ProductType[key]);
                 for (let i = 0; i != list_data.length; ++i) {
                     if (list_data[i].picture <= max) {
                         let state = gData.gameData.getFarmMapRewardState(this.getIndex(list_data[i]));
                         if (state == 0) {
-                            
+
                             return;
                         }
                     }