Jelajahi Sumber

添加果实

slambb 3 tahun lalu
induk
melakukan
2a2f3cc48e

+ 20 - 8
assets/Prefabs/UI/lease/SalePanel.prefab

@@ -28,11 +28,11 @@
     "_level": 1,
     "_components": [
       {
-        "__id__": 78
+        "__id__": 79
       }
     ],
     "_prefab": {
-      "__id__": 79
+      "__id__": 80
     },
     "_opacity": 255,
     "_color": {
@@ -220,11 +220,11 @@
     "_level": 6,
     "_components": [
       {
-        "__id__": 76
+        "__id__": 77
       }
     ],
     "_prefab": {
-      "__id__": 77
+      "__id__": 78
     },
     "_opacity": 255,
     "_color": {
@@ -2020,8 +2020,8 @@
       }
     ],
     "_useOriginalSize": true,
-    "_string": "被赠予用户账号地址",
-    "_N$string": "被赠予用户账号地址",
+    "_string": "输入出售的数量",
+    "_N$string": "输入出售的数量",
     "_fontSize": 20,
     "_lineHeight": 25,
     "_enableWrapText": false,
@@ -2209,7 +2209,7 @@
       }
     ],
     "_prefab": {
-      "__id__": 75
+      "__id__": 76
     },
     "_opacity": 255,
     "_color": {
@@ -2502,7 +2502,9 @@
     "duration": 0.1,
     "zoomScale": 1.2,
     "clickEvents": [
-      null
+      {
+        "__id__": 75
+      }
     ],
     "_N$interactable": true,
     "_N$enableAutoGrayEffect": false,
@@ -2573,6 +2575,16 @@
     },
     "_id": ""
   },
+  {
+    "__type__": "cc.ClickEvent",
+    "target": {
+      "__id__": 1
+    },
+    "component": "",
+    "_componentId": "2fbecbi51RFK5CVmi4gkU3e",
+    "handler": "onLeaseSaleFruit",
+    "customEventData": ""
+  },
   {
     "__type__": "cc.PrefabInfo",
     "root": {

+ 2 - 1
assets/Prefabs/UI/seed/HolyFarmlandFruit.prefab

@@ -13,7 +13,7 @@
   },
   {
     "__type__": "cc.Node",
-    "_name": "HolyFarmlandSeed",
+    "_name": "HolyFarmlandFruit",
     "_objFlags": 0,
     "_parent": null,
     "_children": [
@@ -1460,6 +1460,7 @@
     "saleInfoPrefabs": {
       "__uuid__": "c5974de4-05d0-443b-a59f-911cb68a6c1c"
     },
+    "fruitInfo": null,
     "_id": ""
   },
   {

+ 3 - 0
assets/Prefabs/UI/seed/HolyFarmlandSeed.prefab

@@ -779,6 +779,9 @@
     },
     "SpawnPoint": null,
     "seedType": 0,
+    "goodsSeedInfo": null,
+    "seedSpriteFrame": null,
+    "fruitSpriteFrame": null,
     "_id": ""
   },
   {

+ 12 - 0
assets/Script/Lease/LeaseGrantInfo.js

@@ -23,6 +23,18 @@ cc.Class({
             default: 1,
             visible: false
         },
+
+         //当前操作的果实信息
+         fruitInfo:{
+            default: null,
+            serializable: true, 
+            visible:false
+        },
+        upTarget: {
+            default: null,
+            type: cc.Node,
+            tooltip: "把当前操作的ui按钮传进来"
+        },
     },
 
     // LIFE-CYCLE CALLBACKS:

+ 57 - 12
assets/Script/Lease/LeaseSaleInfo.js

@@ -1,31 +1,42 @@
-
+import gameToast from "../Network/gameToast"
 cc.Class({
     extends: cc.Component,
 
     properties: {
-         saleName: {
-            default: null, 
-            type: cc.Label, 
-            serializable: true,   
+        saleName: {
+            default: null,
+            type: cc.Label,
+            serializable: true,
         },
         saleAmount: {
-            default: null, 
-            type: cc.Label, 
-            serializable: true,   
+            default: null,
+            type: cc.Label,
+            serializable: true,
         },
         inputInviteValue: {
             default: 1,
             visible: false
         },
+        //当前操作的果实信息
+        fruitInfo: {
+            default: null,
+            serializable: true,
+            visible: false
+        },
+        upTarget: {
+            default: null,
+            type: cc.Node,
+            tooltip: "把当前操作的ui按钮传进来"
+        },
 
     },
     inputValue(value, e) {
 
         var numberTemp = new RegExp("^[A-Za-z0-9]+$");
         if (numberTemp.test(value)) {
-            if(Number(value)>=1){
+            if (Number(value) >= 1) {
                 this.inputInviteValue = Number(value);
-            }else{
+            } else {
                 this.inputInviteValue = 1;
                 this.inputContainer.getComponent(cc.EditBox).string = this.inputInviteValue;
             }
@@ -38,11 +49,45 @@ cc.Class({
             // }, this);
         }
     },
-    setInfo(saleName,amount){
+    setInfo(saleName, amount) {
         this.saleName.string = saleName;
         this.saleAmount.string = amount;
     },
-    onclose(){
+    onclose() {
         this.node.destroy();
+    },
+
+    //确定销售果实
+    onLeaseSaleFruit() {
+        //todo 判断一下amount
+        console.log(this.inputInviteValue, Number(this.saleAmount.string));
+        if (this.inputInviteValue > Number(this.saleAmount.string)) {
+            gameToast.getInstance().show(cc.find('Canvas/UICamera'), "销售的果实数量过多!", 2, () => {
+                console.log("finish toast!");
+            }, this);
+            return;
+        }
+
+
+        GlobalD.GameData.onSaleFruit({ fruitId: this.fruitInfo.id, amount: this.inputInviteValue }, (res, value) => {
+            // console.log(value);
+            if (value.code === 0) {
+                let NumLabel = this.upTarget.getComponent("Content_Button").NumLabel.getComponent(cc.Label);
+                if (parseInt(NumLabel.string) <= 1) {
+                    //这里只隐藏
+                    this.upTarget.active = false;
+                } else {
+                    NumLabel.string = parseInt(NumLabel.string) - this.inputInviteValue;
+                    this.saleAmount.string = parseInt(this.saleAmount.string) - this.inputInviteValue;
+                }
+                gameToast.getInstance().show(cc.find('Canvas/UICamera'), "售卖成功!", 2, () => {
+                    console.log("finish toast!");
+                }, this);
+            } else {
+                gameToast.getInstance().show(cc.find('Canvas/UICamera'), value.msg, 2, () => {
+                    console.log("finish toast!");
+                }, this);
+            }
+        });
     }
 });

+ 43 - 43
assets/Script/Network/dapp.js

@@ -166,49 +166,49 @@ cc.Class({
             }
         }
         //初始化调用 dappInit;
-        dappInit();
-
-        // utils.get(utils.api.loginToken, { loginId: 4 }, (res, value) => {
-        //     console.log(res, value);
-        //     if (value.code == 0) {
-        //         /** 登录成功获取token */
-        //         utils.setToken(value.data.token);
-        //         /** 登录时候会获取一次游戏端的 userInfo ,后续可以通过userInfo接口获取 */
-        //         GlobalD.UserInfo = value.data.userInfo;
-        //         /** 推送信息 */
-        //         utils.get(utils.api.playerPullInfo, {}, (res, playerPullInfoTemp) => {
-        //             let _playerData = JSON.parse(playerPullInfoTemp.data.playerData);
-        //             //记录读取的数据到内存里面
-        //             // 正常游戏
-        //             userData.readData = _playerData;
-        //             //跳转游戏
-        //             cc.find("Canvas").getComponent("Login").loginButton();
-
-        //             // utils.init(4, (data) => {
-        //             //     console.log('utils ws:' + data);
-        //             // }, _self);
-        //         })
-        //         //需要提前拉取一下土地配置,用于初始化地图土地
-        //         utils.get(utils.api.landConfig, {}, (res, value) => {
-        //             if(0 === value.code){
-        //                 GlobalD.ConfigLand = value.data;
-        //             }else{
-        //                 console.warn("未能读取到config土地?");
-        //             }
-        //         })
-
-        //         utils.get(utils.api.userLandList, {}, (res, value) => {
-        //             if(0 === value.code){
-        //                 GlobalD.UserLeaseLand = value.data;
-        //             }else{
-        //                 console.warn("读取到用户的土地错误?");
-        //             }
-        //         })
-
-        //     } else {
-        //         console.log(res, value);
-        //     }
-        // })
+        // dappInit();
+
+        utils.get(utils.api.loginToken, { loginId: 4 }, (res, value) => {
+            console.log(res, value);
+            if (value.code == 0) {
+                /** 登录成功获取token */
+                utils.setToken(value.data.token);
+                /** 登录时候会获取一次游戏端的 userInfo ,后续可以通过userInfo接口获取 */
+                GlobalD.UserInfo = value.data.userInfo;
+                /** 推送信息 */
+                utils.get(utils.api.playerPullInfo, {}, (res, playerPullInfoTemp) => {
+                    let _playerData = JSON.parse(playerPullInfoTemp.data.playerData);
+                    //记录读取的数据到内存里面
+                    // 正常游戏
+                    userData.readData = _playerData;
+                    //跳转游戏
+                    cc.find("Canvas").getComponent("Login").loginButton();
+
+                    // utils.init(4, (data) => {
+                    //     console.log('utils ws:' + data);
+                    // }, _self);
+                })
+                //需要提前拉取一下土地配置,用于初始化地图土地
+                utils.get(utils.api.landConfig, {}, (res, value) => {
+                    if(0 === value.code){
+                        GlobalD.ConfigLand = value.data;
+                    }else{
+                        console.warn("未能读取到config土地?");
+                    }
+                })
+
+                utils.get(utils.api.userLandList, {}, (res, value) => {
+                    if(0 === value.code){
+                        GlobalD.UserLeaseLand = value.data;
+                    }else{
+                        console.warn("读取到用户的土地错误?");
+                    }
+                })
+
+            } else {
+                console.log(res, value);
+            }
+        })
     },
 
     start() {

+ 3 - 1
assets/Script/Network/netUtils.ts

@@ -43,7 +43,9 @@ var utils = {
         //仓库种子和果实
         getSeedAndFruit :'comPlayerGoods/getSeedAndFruit', 
         //收取果实
-        addFruit:'comPlayerGoods/addFruit'
+        addFruit:'comPlayerGoods/addFruit',
+        //出售果实
+        saleFruit:'comPlayerGoods/saleFruit'
 
     },
     /** 登录获取的token */

+ 6 - 2
assets/Script/UI/BuildingView.js

@@ -187,11 +187,15 @@ cc.Class({
                 _fruit.parent = this.Fruit;
                 _fruit.zIndex = 999;
                 let _fruitScript = _fruit.getComponent("Content_Button");
-                _fruitScript.NumLabel.string = 1;
+                _fruitScript.NumLabel.string = this.myFruitList[i].amount;
                 _fruitScript.NameLabel.string = this.myFruitList[i].name;
                 _fruitScript.Name = this.myFruitList[i].name;
                 _fruitScript.SNB = this.myFruitList[i].priceSnb;
-                _fruitScript.Synopsis = "出售SNB";
+                _fruitScript.Synopsis = this.myFruitList[i].fruitDescribe;
+
+                //设置果实信息
+                let _contentFruit = _fruit.getComponent("Content_fruit");
+                _contentFruit.fruitInfo = this.myFruitList[i];
 
                 switch (this.myFruitList[i].picture) {
                     case "Cabbage":

+ 31 - 18
assets/Script/UI/Content_fruit.js

@@ -4,49 +4,62 @@ cc.Class({
     extends: cc.Component,
 
     properties: {
- 
+
         grantnfoPrefabs: {
             default: null,
             type: cc.Prefab,
             serializable: true,
         },
-  
+
         saleInfoPrefabs: {
             default: null,
             type: cc.Prefab,
             serializable: true,
         },
+
+        //当前操作的果实信息
+        fruitInfo: {
+            default: null,
+            serializable: true,
+            visible: false
+        }
     },
 
     // LIFE-CYCLE CALLBACKS:
 
     // onLoad () {},
 
-    start () {
+    start() {
 
     },
 
-    onGrantInfo(){
+    onGrantInfo() {
         let leasePanel = cc.instantiate(this.grantnfoPrefabs);
-            let parent = cc.find('Canvas/UICamera');
-            leasePanel.parent = parent;
-            leasePanel.setPosition(0, 0);
-            leasePanel.zIndex = 999;
-            let LeaseGrantInfoScript = leasePanel.getComponent("LeaseGrantInfo");
-            
-            let _contentButton =  this.getComponent("Content_Button");
-            LeaseGrantInfoScript.setInfo(_contentButton.NameLabel.string,_contentButton.NumLabel.string);
+        let parent = cc.find('Canvas/UICamera');
+        leasePanel.parent = parent;
+        leasePanel.setPosition(0, 0);
+        // leasePanel.zIndex = 999;
+        let LeaseGrantInfoScript = leasePanel.getComponent("LeaseGrantInfo");
+        LeaseGrantInfoScript.fruitInfo = this.fruitInfo;
+        LeaseGrantInfoScript.upTarget = this.node;
+     
+
+        let _contentButton = this.getComponent("Content_Button");
+        LeaseGrantInfoScript.setInfo(_contentButton.NameLabel.string, _contentButton.NumLabel.string);
     },
 
-    onSaleInfo(){
+    onSaleInfo() {
         let leasePanel = cc.instantiate(this.saleInfoPrefabs);
         let parent = cc.find('Canvas/UICamera');
         leasePanel.parent = parent;
         leasePanel.setPosition(0, 0);
-        leasePanel.zIndex = 999;
-        let LeaseGrantInfoScript = leasePanel.getComponent("LeaseSaleInfo");
-        
-        let _contentButton =  this.getComponent("Content_Button");
-        LeaseGrantInfoScript.setInfo(_contentButton.NameLabel.string,_contentButton.NumLabel.string);
+        // leasePanel.zIndex = 999;
+        let leaseSaleInfoScript = leasePanel.getComponent("LeaseSaleInfo");
+        leaseSaleInfoScript.fruitInfo = this.fruitInfo;
+        leaseSaleInfoScript.upTarget = this.node;
+     
+
+        let _contentButton = this.getComponent("Content_Button");
+        leaseSaleInfoScript.setInfo(_contentButton.NameLabel.string, _contentButton.NumLabel.string);
     }
 });

+ 325 - 0
assets/Script/build/LeaseFarmlandInfo.js

@@ -0,0 +1,325 @@
+import date from "../Unit/date.js"
+import gameToast from "../Network/gameToast"
+/**
+ * 操作租赁土地的相关业务
+ */
+cc.Class({
+    extends: cc.Component,
+
+    properties: {
+        leasePanelPrefabs: {
+            default: null,
+            type: cc.Prefab,
+            serializable: true,
+        },
+
+        /**
+         * 显示天数部分
+         */
+        upSliderNode: {
+            default: null,
+            type: cc.Node,
+            serializable: true,
+        },
+        multipleLabel: {
+            default: null,
+            type: cc.Label,
+            serializable: true,
+            toolTip: "显示的倍数"
+        },
+        leaseDate: {
+            default: null,
+            type: cc.Label,
+            serializable: true,
+            toolTip: "剩余天数/总天数"
+        },
+
+
+        /**
+         * 成熟期部分
+         */
+        midSliderNode: {
+            default: null,
+            type: cc.Node,
+            serializable: true,
+        },
+        midDate: {
+            default: null,
+            type: cc.Label,
+            serializable: true,
+            toolTip: "剩余天数/总天数"
+        },
+
+        midSliderProgressNode: {
+            default: null,
+            type: cc.Node,
+            serializable: true,
+            toolTip: "进度条"
+        },
+
+
+        notLeased: {
+            default: null,
+            type: cc.Node,
+            serializable: true,
+        },
+
+        // configLandId: 1
+        // createTime: "2022-01-10 21:25:30"
+        // id: 1
+        // isLease: 1
+        // isPlant: 0
+        // landDescribe: "土地1xxx"
+        // leaseMultiple: 1
+        // leaseTime: "2022-01-10 21:25:17"
+        // name: "土地1"
+        // plantMature: 0
+        // plantStart: "2022-01-10 21:25:22"
+        // updateTime: "2022-01-10 21:25:33"
+        // userId: "4"
+        // 已经租赁的土地信息
+        leaseLandInfo: {
+            default: null,
+            visible: false
+        },
+
+        // createTime: "2022-01-10 21:25:30"
+        // id: 4
+        // initMultiple: 1
+        // isInit: 1
+        // isLease: 0
+        // isPlant: 0
+        // landDescribe: "一倍土地"
+        // leaseMultiple: 1
+        // leaseTime: "2022-01-10 21:25:17"
+        // name: "土地4"
+        // plantMature: 0
+        // plantStart: "2022-01-10 21:25:22"
+        // posX: 19
+        // posY: 10
+        // sizeX: 2
+        // sizeY: 2
+        // updateTime: "2022-01-10 21:25:33"
+        // 未初始化时候的土地信息
+        configLandInfo: {
+            default: null,
+            visible: false
+        },
+
+        showLandInfo: {
+            default: null,
+            type: cc.Node,
+            serializable: true,
+            toolTip: "显示土地信息"
+        },
+        landInfoPrefabs: {
+            default: null,
+            type: cc.Prefab,
+            serializable: true,
+        },
+
+        // 已经种植的作物信息
+        plantInfo: {
+            default: null,
+            visible: false
+        },
+        showPlantInfo: {
+            default: null,
+            type: cc.Node,
+            serializable: true,
+            toolTip: "显示种植信息"
+        },
+        plantInfoPrefabs: {
+            default: null,
+            type: cc.Prefab,
+            serializable: true,
+        },
+
+        //收获阶段
+
+        harvestNode: {
+            default: null,
+            type: cc.Node,
+            serializable: true,
+        }
+    },
+
+    // LIFE-CYCLE CALLBACKS:
+
+    // onLoad () {},
+
+    start() {
+
+    },
+
+    onSpawnLeasePanel() {
+
+        let leasePanel = cc.instantiate(this.leasePanelPrefabs);
+        let parent = cc.find('Canvas/UICamera/DAPPContainer');
+        leasePanel.parent = parent;
+        leasePanel.setPosition(0, 0);
+        // leasePanel.zIndex = 999;
+
+        //把操作对象传入
+        let leasePanelScript = leasePanel.getComponent("LeaseInfo");
+        leasePanelScript.leaseFarmlandInfoNode = this;
+        /**
+         * 初始化两个操作。一个是续约,续约的话,不给操作,只有续约按钮可点,相当于原来配置再购买一次
+         * 
+         * this.leaseLandInfo 如果购买了土地,这个参数不为空
+         */
+
+        if (this.leaseLandInfo) {
+            //续约时候拦截输入,固定倍数 
+            leasePanelScript.blockInput.active = true;
+            //传入当前计算倍数
+            leasePanelScript.onInitLeaseInfo(this.leaseLandInfo.leaseMultiple);
+        } else if (0 === this.configLandInfo.initMultiple) {
+            // 固定土地开启,限制输入,设置默认值是1
+            leasePanelScript.blockInput.active = true;
+            leasePanelScript.onInitLeaseInfo(1);
+        } else {
+            //多倍土地,可以自己输入
+            leasePanelScript.onInitLeaseInfo(this.configLandInfo.initMultiple);
+        }
+
+
+    },
+
+    /**
+     * 解锁土地操作
+     */
+    onUnlockLand() {
+        //直接删除此节点
+        if(this.notLeased){
+            this.notLeased.destroy();
+            this.notLeased = null;
+        }
+  
+    },
+    //设置config的土地信息
+    setConfigLandInfo(value) {
+        this.configLandInfo = value;
+    },
+    //设置已租赁参数
+    setLeaseLandInfo(value) {
+        this.leaseLandInfo = value;
+        //更新一下土地信息
+        this.updateLandState();
+    },
+
+    updateLandState() {
+        if (!this.leaseLandInfo) return;
+        if (1 === this.leaseLandInfo.isLease) {
+            //已解锁
+            //显示剩余天数
+            this.upSliderNode.parent.active = true;
+            this.multipleLabel.string = this.leaseLandInfo.leaseMultiple;
+            //计算天数
+            let day1 = date.datedifference(date.formatTime(new Date()), this.leaseLandInfo.leaseTime);
+            let allDay = date.datedifference(this.leaseLandInfo.createTime, this.leaseLandInfo.leaseTime);
+            this.leaseDate.string = "剩余" + day1 + "天数,共" + allDay + "天";
+            let sliderProgressScript = this.upSliderNode.getComponent("slider_progress");
+            sliderProgressScript.onSetProcgress(day1 / allDay);
+            //todo 到期处理
+
+            //删除解锁图标
+            this.onUnlockLand();
+
+            /**
+             * 绑定生成显示信息面板,现在土地信息
+             */
+
+            this.showLandInfo.on(cc.Node.EventType.TOUCH_START, () => {
+                let leasePanel = cc.instantiate(this.landInfoPrefabs);
+                let parent = cc.find('Canvas/UICamera/DAPPContainer');
+                leasePanel.parent = parent;
+                leasePanel.setPosition(0, 0);
+                // leasePanel.zIndex = 999;
+                let leasePanelScript = leasePanel.getComponent("LandInfo");
+                //price,date,start,end,multiple,describe
+                let _date = date.datedifference(this.leaseLandInfo.createTime, this.leaseLandInfo.leaseTime);
+                let { rentalExpenses, createTime, leaseTime, leaseMultiple, landDescribe } = this.leaseLandInfo;
+                leasePanelScript.setInfo(rentalExpenses, _date + "天", createTime, leaseTime, leaseMultiple + "倍", landDescribe);
+            })
+
+            if (this.leaseLandInfo.seedInfo) {
+                this.midSliderNode.active = true;
+                this.midSliderProgressNode.getComponent(cc.ProgressBar).progress = 0.5;
+                let _currentDay = date.dateAddDate(this.leaseLandInfo.plantStart, this.leaseLandInfo.seedInfo.maturity)
+
+                // console.log(_currentDay,date.formatTime(new Date()));
+                let [_remainingDay, _remainingHour] = date.dayAndHour(_currentDay, date.formatTime(new Date()));
+                this.midDate.string = "剩余" + _remainingDay + "天" + _remainingHour + "小时";
+                /**
+                  * 绑定生成显示信息面板,种植信息
+                  */
+                this.showPlantInfo.on(cc.Node.EventType.TOUCH_START, () => {
+                    let leasePanel = cc.instantiate(this.plantInfoPrefabs);
+                    let parent = cc.find('Canvas/UICamera/DAPPContainer');
+                    leasePanel.parent = parent;
+                    leasePanel.setPosition(0, 0);
+                    // leasePanel.zIndex = 999;
+                    let leasePanelScript = leasePanel.getComponent("PlantInfo");
+                    let _harvest = 0;
+                    if (this.leaseLandInfo.leaseDate === 1) {
+                        _harvest = this.leaseLandInfo.seedInfo.harvest1;
+                    } else if (this.leaseLandInfo.leaseDate === 2) {
+                        _harvest = this.leaseLandInfo.seedInfo.harvest2;
+                    } else if (this.leaseLandInfo.leaseDate === 3) {
+                        _harvest = this.leaseLandInfo.seedInfo.harvest3;
+                    }
+                    //price,maturity,plantStart,harvestQuantity,describe
+                    let { priceCnt, maturity, seedDescribe } = this.leaseLandInfo.seedInfo;
+                    leasePanelScript.setInfo(priceCnt, maturity + "天", this.leaseLandInfo.plantStart, _harvest, seedDescribe);
+                })
+            }
+
+
+        } else {
+
+        }
+    },
+
+
+
+
+    /**
+     * 点击之后,重置土地信息, 并且收入进仓库果实列表中去
+     */
+    onShowHarvest() {
+        this.harvestNode.active = true;
+
+        this.harvestNode.on(cc.Node.EventType.TOUCH_START, () => {
+            console.log("点击收获");
+
+            let data = { landId: this.leaseLandInfo.id };
+
+            //果实收入仓库,重置土地种植信息
+            GlobalD.GameData.onAddFruit(data, (res, value) => {
+                // console.log(value);
+                if (value.code === 0) {
+                    //收成后处理相关状态
+                    this.harvestNode.active = false;
+                    this.midSliderNode.active = false
+                    let _workingBuilding = this.node.getComponent("WorkingBuilding");
+                    _workingBuilding.onSetGrow(0, null);
+                    // "收获成功!"
+                    gameToast.getInstance().show(cc.find("Canvas/UICamera"), "收获成功!", 2, () => {
+                        console.log("finish toast!");
+                    }, this);
+                } else {
+                    gameToast.getInstance().show(cc.find("Canvas/UICamera"), value.msg, 2, () => {
+                        console.log("finish toast!");
+                    }, this);
+                }
+            });
+        })
+
+
+    },
+
+    onPayCnt() {
+        Global.game.payCNT();
+    }
+});

+ 9 - 0
assets/Script/build/LeaseFarmlandInfo.js.meta

@@ -0,0 +1,9 @@
+{
+  "ver": "1.0.5",
+  "uuid": "d7c14310-96e1-4f5a-923c-5181281d2a54",
+  "isPlugin": false,
+  "loadPluginInWeb": true,
+  "loadPluginInNative": true,
+  "loadPluginInEditor": false,
+  "subMetas": {}
+}

+ 62 - 0
assets/Script/public/GameData.js

@@ -1084,6 +1084,13 @@ cc.Class({
         })
     },
 
+    //出售果实
+    onSaleFruit(data, callback) {
+        utils.post(utils.api.saleFruit, data, (res, vaule) => {
+            callback(res, vaule);
+        })
+    },
+
 
     /**
      * 支付cnt操作
@@ -1113,9 +1120,64 @@ cc.Class({
                 console.log(err)
             }
 
+            if (callback) {
+                callback(data);
+            }
+        });
+    },
+
+    /**
+     * 神农呗转换CNT ,比例是5:1
+     * @param {*} snbAmount 
+     * @param {*} callback 
+     * @returns 
+     */
+    onSnbToCnt(snbAmount, callback) {
+        if (!GlobalD.dapp) {
+            console.warn("GlobalD.dapp未初始化,不能onSnbToCnt!");
+            return;
+        }
+        if (GlobalD.GameData.GetSNB() <= 0) {
+            console.log("神农呗数量GetSNB:", GlobalD.GameData.GetSNB(), "替换snbAmount:", snbAmount);
+            gameToast.getInstance().show(cc.find("Canvas/UICamera"), "神农呗数量不足!", 2, () => {
+                console.log("finish toast!");
+            }, this);
+            return;
+        }
+
+        GlobalD.dapp.snbToCnt(snbAmount).then((data) => {
+            const [err, tx] = data;
+            if (err === null) {
+                // TODO 成功, 兑换为链上操作,需要提供回调接口给这边服务端确认交易成功后修改扣除SNB数量
+                console.log(tx) // 交易hash,唯一标识符
+                //扣除对应的神农呗,本地修改显示
+                GlobalD.GameData.SetSNB(GlobalD.GameData.GetSNB() - snbAmount);
+
+            } else {
+                console.log(err)
+            }
+
+            if (callback) {
+                callback(data);
+            }
+        });
+    },
+    //获取 神农呗转 CNT 日志
+    onGetSnbToCntInfo(page,limit,callback) {
+        if (!GlobalD.dapp) {
+            console.warn("GlobalD.dapp未初始化,不能onGetSnbToCntInfo!");
+            return;
+        }
+        GlobalD.dapp.swapLog(page, limit).then((data) => {
+            const { err, res } = data;
+            if (err ===null) {
+                console.log(res) //
+            }
             if (callback) {
                 callback(data);
             }
         });
     }
+
+
 });