浏览代码

1.修改防多触发兑换种子

slambb 3 年之前
父节点
当前提交
eb5901b4e9
共有 3 个文件被更改,包括 21 次插入7 次删除
  1. 1 0
      assets/Scene/MyCityScene - 004.fire
  2. 1 1
      assets/Script/UI/BuildingView.js
  3. 19 6
      assets/Script/public/GameData.js

+ 1 - 0
assets/Scene/MyCityScene - 004.fire

@@ -65861,6 +65861,7 @@
     "isOnAddFruit": false,
     "isOnSaleFruit": false,
     "isOnGrantFruit": false,
+    "isExchangeSeed": false,
     "AutoSaveData": null,
     "_id": "4a0Gepxu1Aso5f0MropwBw"
   },

+ 1 - 1
assets/Script/UI/BuildingView.js

@@ -144,7 +144,7 @@ cc.Class({
             this.mySeedList = vaule.data.seed;
             this.myFruitList = vaule.data.fruit;
 
-            console.log(this.mySeedList, this.myFruitList);
+            //console.log(this.mySeedList, this.myFruitList);
             for (let i = 0; i < this.mySeedList.length; i++) {
                 //没有种子数量不显示 todo 看看后续需不需要处理删除
                 if (this.mySeedList[i].amount < 1) continue;

+ 19 - 6
assets/Script/public/GameData.js

@@ -92,6 +92,7 @@ cc.Class({
         isOnAddFruit: false,
         isOnSaleFruit: false,
         isOnGrantFruit: false,
+        isExchangeSeed: false,
 
         //自动存储数据
         AutoSaveData: null
@@ -556,23 +557,29 @@ cc.Class({
     GetDiamond: function () {
         return parseInt(this.Diamond);
     },
-    SetDiamond: function (num) {
+    SetDiamond: function (num, bPush) {
         let LastMoney = this.Diamond;
         this.Diamond = num;
         let CurrentMoney = num;
-        
+
         this.ManageUI.getComponent("ManageUI").DiamondNowlabel.string = this.Diamond + '/30000'
 
         this.ManageUI.getComponent('ManageUI').DiamondChangeCallBack(this.GetDiamond(), LastMoney, CurrentMoney);
 
+        console.log("Diamond:", bPush);
+        if (bPush) {
+            //每次砖石操作。更新一次数据
+            this.pushData(true);
+        } 
+       
 
     },
     PlusDiamond: function (num) {
         if (this.Diamond + num < 0) {
-            this.SetDiamond(0);
+            this.SetDiamond(0, true);
         }
         else {
-            this.SetDiamond(this.Diamond + num);
+            this.SetDiamond(this.Diamond + num, true);
         }
     },
 
@@ -957,7 +964,7 @@ cc.Class({
 
             /** 推送信息 */
             utils.post(utils.api.playerPushInfo, data, (res, playerPushInfoTemp) => {
-                // console.log('playerPushInfoTemp', playerPushInfoTemp);
+                // console.log('playerPushInfoTemp');
             })
         } else {
             console.log("存储本地:" + isNetwork);
@@ -973,6 +980,11 @@ cc.Class({
      * 扣除相应的钻石
      */
     exchangeSeed(diamondAmount, callback) {
+        if (this.isExchangeSeed) {
+            console.warn("正在兑换中...");
+            return;
+        }
+        this.isExchangeSeed = true;
         //先暂停存储
         this.unschedule(this.AutoSaveData);
 
@@ -984,10 +996,11 @@ cc.Class({
                 let _playerData = JSON.parse(value.data.playerData);
                 console.log("兑换后的钻石:", _playerData.Diamond);
                 //更新本地钻石数据
-                this.SetDiamond(_playerData.Diamond);
+                this.SetDiamond(_playerData.Diamond, false);
 
             }
             callback(res, value);
+            this.isExchangeSeed = false;
             //重新开启存储
             this.schedule(this.AutoSaveData, 15);
         })