浏览代码

修改偷菜问题

slambb 3 年之前
父节点
当前提交
336f001e25

+ 6 - 4
assets/Script/Lease/LeaseSaleInfo.js

@@ -16,7 +16,7 @@ cc.Class({
         inputInviteValue: {
             default: 0,
             visible: false,
-            serializable:false
+            serializable: false
         },
         //当前操作的果实信息
         fruitInfo: {
@@ -62,7 +62,7 @@ cc.Class({
             console.log("请输入20整数的倍数", this.inputInviteValue);
         }
 
-        this.estimateAmount.string = Number(this.inputInviteValue * this.fruitInfo.priceSnb)+" SNB";
+        this.estimateAmount.string = Number(this.inputInviteValue * this.fruitInfo.priceSnb) + " SNB";
     },
     setInfo(saleName, amount) {
         this.saleName.string = saleName;
@@ -80,7 +80,7 @@ cc.Class({
             GlobalD.GameData.showToast(cc.find('Canvas/UICamera'), "销售的果实数量过多!", 1);
             return;
         }
-        if (this.inputInviteValue <=0) {
+        if (this.inputInviteValue <= 0) {
             GlobalD.GameData.showToast(cc.find('Canvas/UICamera'), "输入不为零的果实数量!", 1);
             return;
         }
@@ -109,7 +109,9 @@ cc.Class({
 
                 //更新ui snb
                 GlobalD.GameData.onGetUserSnb((value) => {
-                    this.saleAmount.string = parseInt(this.saleAmount.string) - this.inputInviteValue;
+                    // Number(this.myFruitList[i].amount + this.myFruitList[i].amountPart).toFixed(3);
+
+                    this.saleAmount.string = (parseFloat(this.saleAmount.string) - this.inputInviteValue).toFixed(3);
                 });
                 // GlobalD.GameData.SetSNB(GlobalD.GameData.GetSNB() + (this.inputInviteValue * this.fruitInfo.priceSnb));
                 // this.saleAmount.string = parseInt(this.saleAmount.string) - this.inputInviteValue;

+ 2 - 0
assets/Script/Network/netUtils.ts

@@ -40,6 +40,8 @@ var utils = {
         landConfig: 'configLand/getList',
         //获取用户已经租赁的土地
         userLandList: 'comPlayerLand/getList',
+        //获取用户土地信息和一个租赁状态
+        userLandAndCanStealList: 'comPlayerLand/getCanStealDetailList',
         //获取用户可以偷取的列表信息
         canStealUserList: 'comPlayerLand/getCanStealUserList',
 

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

@@ -221,7 +221,7 @@ cc.Class({
                 _fruit.parent = this.Fruit;
                 _fruit.zIndex = 999;
                 let _fruitScript = _fruit.getComponent("Content_Button");
-                _fruitScript.NumLabel.string = this.myFruitList[i].amount + Number(this.myFruitList[i].amountPart).toFixed(3);
+                _fruitScript.NumLabel.string =  Number(this.myFruitList[i].amount + this.myFruitList[i].amountPart).toFixed(3);
                 _fruitScript.NameLabel.string = this.myFruitList[i].name;
                 _fruitScript.Name = this.myFruitList[i].name;
                 _fruitScript.SNB = this.myFruitList[i].priceSnb;

+ 32 - 25
assets/Script/build/LeaseFarmlandInfo.js

@@ -183,7 +183,7 @@ cc.Class({
         _buildingView: null,
 
         //是否是自己的土地,记录一下
-        bSelfLand:true,
+        bSelfLand: true,
     },
 
     // LIFE-CYCLE CALLBACKS:
@@ -232,7 +232,7 @@ cc.Class({
         })
 
         this.stealHarvestNode.on(cc.Node.EventType.TOUCH_START, () => {
-            if (!this.bSelfLand){
+            if (!this.bSelfLand) {
                 console.log("点击偷菜按钮收取");
                 GlobalD.GameData.showToast(cc.find("Canvas/UICamera"), "请点击偷菜按钮收取!", 1);
                 return;
@@ -398,18 +398,6 @@ cc.Class({
     },
 
     updateLandState(bSelf) {
-        //显示剩余天数
-        this.upSliderNode.parent.active = bSelf;
-        this.multipleLabel.string = this.leaseLandInfo.leaseMultiple;
-        //  进去条按天算
-        let sliderProgressScript = this.upSliderNode.getComponent("slider_progress");
-        let _proccess = this.leaseLandInfo.leaseDays === 0 ? 0 : this.leaseLandInfo.leaseDaysRemaining / this.leaseLandInfo.leaseDays;
-        sliderProgressScript.onSetProcgress(_proccess);
-
-        /**
-         * 绑定生成显示信息面板,现在土地信息
-         */
-        this.showLandInfo.on(cc.Node.EventType.TOUCH_START, this._showLandInfo, this);
         //如果是种植状态并且有返回种植信息
         if (1 === this.leaseLandInfo.isPlant && this.leaseLandInfo.seedInfo) {
             //种植信息
@@ -462,6 +450,19 @@ cc.Class({
             this.showPlantInfo.on(cc.Node.EventType.TOUCH_START, this._showPlantInfo, this);
         }
 
+        //显示剩余天数
+        this.upSliderNode.parent.active = bSelf;
+        this.multipleLabel.string = this.leaseLandInfo.leaseMultiple;
+        //  进去条按天算
+        let sliderProgressScript = this.upSliderNode.getComponent("slider_progress");
+        let _proccess = this.leaseLandInfo.leaseDays === 0 ? 0 : this.leaseLandInfo.leaseDaysRemaining / this.leaseLandInfo.leaseDays;
+        sliderProgressScript.onSetProcgress(_proccess);
+
+        /**
+         * 绑定生成显示信息面板,现在土地信息
+         */
+        this.showLandInfo.on(cc.Node.EventType.TOUCH_START, this._showLandInfo, this);
+
         let lastUpdateTime = Date.now();
         let elapsedTime = 0;
         let updateFrequency = 1; //ms
@@ -520,7 +521,10 @@ cc.Class({
                             if (bSelf) {
                                 this.onShowHarvest();
                             } else {
-                                this.onShowStealHarvest();
+                                //存在可偷的状态才设置这个图标
+                                if (1 === this.leaseLandInfo.canSteal) {
+                                    this.onShowStealHarvest();
+                                }
                             }
                         } else {
                             let _maturityHour = this.leaseLandInfo.seedInfo.maturity * 24
@@ -635,39 +639,42 @@ cc.Class({
         this.stealHarvestNode.active = true;
     },
 
+    onHideStealHarvest() {
+        this.stealHarvestNode.active = false;
+    },
+
     /**
      * 设置总体信息面板显示
      * @param {boolean} bActive 
      */
     onSetInfoBoxActive(bActive) {
-        if(!this.bSelfLand){
+        if (!this.bSelfLand) {
             // console.log("其他用户的不用显示面板");
             return;
         }
-        if (this.leaseLandInfo){
+        if (this.leaseLandInfo) {
             this.infoBox.active = bActive;
-            if(bActive)
-            {
-                if(this.showTimeOut){
+            if (bActive) {
+                if (this.showTimeOut) {
                     clearTimeout(this.showTimeOut);
                     this.showTimeOut = null;
                 }
                 //自动隐藏面板
-                this.showTimeOut = setTimeout(()=>{
+                this.showTimeOut = setTimeout(() => {
                     this.infoBox.active = false;
-                },5000)
+                }, 5000)
             }
         }
-            
+
     },
 
-    
+
     onDestroy() {
         if (this.timeInterval) {
             clearInterval(this.timeInterval);
             this.timeInterval = null;
         }
-        if(this.showTimeOut){
+        if (this.showTimeOut) {
             clearTimeout(this.showTimeOut);
             this.showTimeOut = null;
         }

+ 10 - 4
assets/Script/public/GameData.js

@@ -1084,7 +1084,7 @@ cc.Class({
     //获取用户全部租赁土地
     getOtherUserLandList(otherUserId, callback) {
         this.showToast(cc.find("Canvas/UICamera"), "载入玩家数据中..", 5);
-        utils.get(utils.api.userLandList, { otherUserId: otherUserId }, (flag, value) => {
+        utils.get(utils.api.userLandAndCanStealList, { otherUserId: otherUserId }, (flag, value) => {
             console.log(otherUserId + ",获取其他用户土地数据:", value);
             if (flag && 0 === value.code) {
                 GlobalD.OtherLeaseland = value.data;
@@ -1209,9 +1209,15 @@ cc.Class({
         utils.post(utils.api.stealAllFruit, data, (flag, value) => {
             this.isOnAddFruit = false;
             this.hideToast();
-            GlobalD.PlayerAttribute = value.data.playerAttribute;
-            //这里需要更新体力值
-            this.SetStrength(GlobalD.PlayerAttribute.currentStrength);
+            if (0 === value.code) {
+                //如果返回一个体力信息,更新对应的新的用户信息。
+                if (value.data.playerAttribute) {
+                    GlobalD.PlayerAttribute = value.data.playerAttribute;
+                    //这里需要更新体力值
+                    this.SetStrength(GlobalD.PlayerAttribute.currentStrength);
+                }
+            }
+
             if (flag)
                 callback(value);
         })

+ 32 - 11
assets/Script/public/ManageUI.js

@@ -1220,26 +1220,47 @@ cc.Class({
    */
   onStealAllFruit() {
     //todo 偷取之前本地判断下体力值
-    if (GlobalD.PlayerAttribute.currentStrength <= 0) 
-    {
+    if (GlobalD.PlayerAttribute.currentStrength <= 0) {
       GlobalD.GameData.showToast(cc.find("Canvas/UICamera"), "体力不足,无法收取作物!", 1);
       return;
     }
 
     GlobalD.GameData.onStealAllFruit({ otherUserId: GlobalD.OtherUserInfo.userId }, (value) => {
       console.log(value);
-      if (this.StealViewSuccessPrefab) {
-        let _TipView = cc.instantiate(this.StealViewSuccessPrefab)
-        _TipView.parent = this.TipView
-        _TipView.setPosition(cc.v2(0, 0))
-        _TipView
-          .getComponent('StealViewSuccess')
-          .setInfo({ amount: value.data.stealSum });
-
-     
+
+      if (0 === value.code) {
+        if (this.StealViewSuccessPrefab) {
+          let _TipView = cc.instantiate(this.StealViewSuccessPrefab)
+          _TipView.parent = this.TipView
+          _TipView.setPosition(cc.v2(0, 0))
+          _TipView
+            .getComponent('StealViewSuccess')
+            .setInfo({ amount: value.data.stealSum });
+        }
+
         let BuildingView = cc.find('Canvas/UICamera/BuildingContainer/BuildingView').getComponent('BuildingView');
         BuildingView.onUpdateList();
+
+        //偷取成功后,关闭对应土地的提示图标
+        let _landBuildingsInfo = cc.find("Canvas/MyMapNode").children;
+        let _stealList = value.data.steals;
+        for (let j = 0; j < _stealList.length; j++) {
+          for (let i = _landBuildingsInfo.length - 1; i >= 0; i--) {
+            let resetLandInfo = _landBuildingsInfo[i];
+            if (resetLandInfo.name == "Labour_205_Holy_Farmland") {
+              let leaseFarmlandInfoScript = resetLandInfo.getComponent("LeaseFarmlandInfo");
+              if (leaseFarmlandInfoScript.leaseLandInfo && leaseFarmlandInfoScript.leaseLandInfo.configLandId == _stealList[j].landId) {
+                leaseFarmlandInfoScript.onHideStealHarvest();
+              }
+            }
+
+          }
+        }
+
+      } else {
+        GlobalD.GameData.showToast(cc.find("Canvas/UICamera"), value.msg, 1);
       }
+
     });
   },
   //体力值