|
|
@@ -45,7 +45,18 @@ cc.Class({
|
|
|
visible: false,
|
|
|
},
|
|
|
|
|
|
-
|
|
|
+ /**
|
|
|
+ * 接口
|
|
|
+ * todo cnt和snb 由钱包读取
|
|
|
+ */
|
|
|
+ CNT: {
|
|
|
+ default: 0,
|
|
|
+ visible: false,
|
|
|
+ },
|
|
|
+ SNB: {
|
|
|
+ default: 0,
|
|
|
+ visible: false,
|
|
|
+ },
|
|
|
|
|
|
},
|
|
|
onLoad() {
|
|
|
@@ -76,14 +87,18 @@ cc.Class({
|
|
|
//读取网络数据
|
|
|
try {
|
|
|
GlobalD.dapp.cntBalance().then((cntBalance) => {
|
|
|
- console.log(cntBalance) // string, 精度18,需要自行处理省略几位小数
|
|
|
+ //会延迟返回
|
|
|
+ console.log("获取cnt:" + cntBalance) // string, 精度18,需要自行处理省略几位小数
|
|
|
GlobalD.GameData.SetCNT(cntBalance);
|
|
|
});
|
|
|
} catch (err) {
|
|
|
console.error(err) // 初始化失败,运行环境不是钱包环境
|
|
|
}
|
|
|
+ //登录时候已经初始化好snb了
|
|
|
+ this.SNB = GlobalD.UserInfo.snb;
|
|
|
+
|
|
|
this.readData = userData.readData;
|
|
|
- cc.log('playerPullInfo 读取到数据?:', this.readData)
|
|
|
+ // cc.log('playerPullInfo 读取到数据?:', this.readData)
|
|
|
this.InitNextworkData();
|
|
|
this.InitSceneInfo();
|
|
|
|
|
|
@@ -92,7 +107,7 @@ cc.Class({
|
|
|
* todo 如果退出游戏,触发一次存储。
|
|
|
*/
|
|
|
this.AutoSaveData = function () {
|
|
|
- this.pushData();
|
|
|
+ this.pushData(true);
|
|
|
};
|
|
|
this.schedule(this.AutoSaveData, 20);
|
|
|
} else {
|
|
|
@@ -101,6 +116,10 @@ cc.Class({
|
|
|
// this.onClearAllData();
|
|
|
this.Init();
|
|
|
this.InitSceneInfo();
|
|
|
+ this.AutoSaveData = function () {
|
|
|
+ this.pushData(false);
|
|
|
+ };
|
|
|
+ this.schedule(this.AutoSaveData, 20);
|
|
|
}
|
|
|
},
|
|
|
|
|
|
@@ -129,12 +148,14 @@ cc.Class({
|
|
|
this.onSpawnHighway();
|
|
|
//初始化时间ui
|
|
|
cc.find("GameNode/ManageTimer").getComponent('ManageTimer').Init();
|
|
|
- //初始化金钱ui
|
|
|
+ //初始化金钱ui,gold,diamond, cnt,snb,
|
|
|
cc.find("GameNode/ManageGolden").getComponent('ManageGolden').InitManageGlodenUI();
|
|
|
// //初始化地图物件
|
|
|
// cc.find("GameNode/ManageMap").getComponent('ManageMap').InitManageMap();
|
|
|
GlobalD.TiledMap.onInitSolid();
|
|
|
|
|
|
+ //tudo 初始化DApp固定土地
|
|
|
+
|
|
|
//初始化生成房屋
|
|
|
this.ManageUI.getComponent('ManageBuildings').InitBuildings();
|
|
|
//初始化生成人物
|
|
|
@@ -164,12 +185,6 @@ cc.Class({
|
|
|
this.GameYear = this.readData.GameYear;
|
|
|
this.GameMonth = this.readData.GameMonth;
|
|
|
this.GameDay = this.readData.GameDay;
|
|
|
- /**
|
|
|
- * 接口
|
|
|
- * todo cnt和snb 由钱包读取
|
|
|
- */
|
|
|
- this.CNT = 0;
|
|
|
- this.SNB = 0;
|
|
|
|
|
|
//读取金币
|
|
|
this.Golden = this.readData.Golden;
|
|
|
@@ -499,14 +514,14 @@ cc.Class({
|
|
|
* 游戏里面的cnt 和神农呗
|
|
|
*/
|
|
|
GetCNT: function () {
|
|
|
- return this.CNT;
|
|
|
+ return parseFloat(this.CNT);
|
|
|
},
|
|
|
SetCNT: function (Num) {
|
|
|
this.CNT = Num;
|
|
|
this.ManageUI.getComponent('ManageUI').CNTChangeCallBack(this.CNT);
|
|
|
},
|
|
|
GetSNB: function () {
|
|
|
- return this.SNB;
|
|
|
+ return parseFloat(this.SNB);
|
|
|
},
|
|
|
SetSNB: function (Num) {
|
|
|
this.SNB = Num;
|
|
|
@@ -791,8 +806,10 @@ cc.Class({
|
|
|
* 现在转服务器存储,原本所有相关操作通过服务器计算。
|
|
|
* 一、目前涉及到的是 SNT 和 SNB 两个货币相关,和买田地操作 (可以理解为租聘,三种类型)
|
|
|
*
|
|
|
+ * isNetwork:true,上传到网络
|
|
|
+ *
|
|
|
*/
|
|
|
- pushData: function () {
|
|
|
+ pushData: function (isNetwork) {
|
|
|
// cc.log(this.EveryDayRewardsArray);
|
|
|
// console.log(this.readData.BFirstLoadGame);
|
|
|
var datas = {
|
|
|
@@ -857,18 +874,168 @@ cc.Class({
|
|
|
//任务
|
|
|
TaskIconCountClick: task.TaskIconCountClick
|
|
|
}
|
|
|
- var data = [];
|
|
|
- // data["openid"] = userData.openId;
|
|
|
- // data["userdata"] = JSON.stringify(datas);
|
|
|
- data["playerData"] = JSON.stringify(datas);
|
|
|
-
|
|
|
- /** 推送信息 */
|
|
|
- utils.post(utils.api.playerPushInfo, data, (res, playerPushInfoTemp) => {
|
|
|
- // console.log('playerPushInfoTemp', playerPushInfoTemp);
|
|
|
+
|
|
|
+ if (isNetwork) {
|
|
|
+ var data = [];
|
|
|
+ // data["openid"] = userData.openId;
|
|
|
+ // data["userdata"] = JSON.stringify(datas);
|
|
|
+ data["playerData"] = JSON.stringify(datas);
|
|
|
+
|
|
|
+ /** 推送信息 */
|
|
|
+ utils.post(utils.api.playerPushInfo, data, (res, playerPushInfoTemp) => {
|
|
|
+ // console.log('playerPushInfoTemp', playerPushInfoTemp);
|
|
|
+ })
|
|
|
+ } else {
|
|
|
+ console.log("存储本地:" + isNetwork);
|
|
|
+ //保存用户数据到本地
|
|
|
+ cc.sys.localStorage.setItem('userdata', JSON.stringify(datas));
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ },
|
|
|
+
|
|
|
+
|
|
|
+ getLandConfig() {
|
|
|
+ // "data": [
|
|
|
+ // {
|
|
|
+ // "id": 1,
|
|
|
+ // "configLandId": 1,
|
|
|
+ // "userId": "4",
|
|
|
+ // "name": "1",
|
|
|
+ // "isLease": 1,
|
|
|
+ // "leaseTime": "2022-01-10 21:25:17",
|
|
|
+ // "leaseMultiple": null,
|
|
|
+ // "isPlant": 1,
|
|
|
+ // "plantStart": "2022-01-10 21:25:22",
|
|
|
+ // "plantMature": 1,
|
|
|
+ // "landDescribe": "1",
|
|
|
+ // "createTime": "2022-01-10 21:25:30",
|
|
|
+ // "updateTime": "2022-01-10 21:25:33"
|
|
|
+ // }
|
|
|
+ // ],
|
|
|
+ utils.get(utils.api.landConfig, {}, (res, vaule) => {
|
|
|
+
|
|
|
})
|
|
|
- return;
|
|
|
- //保存用户数据到本地
|
|
|
- cc.sys.localStorage.setItem('userdata', JSON.stringify(datas));
|
|
|
},
|
|
|
+ //获取用户全部租赁土地
|
|
|
+ getUserLandList() {
|
|
|
+ // "data": [
|
|
|
+ // {
|
|
|
+ // "id": 1,
|
|
|
+ // "configLandId": 1,
|
|
|
+ // "userId": "4",
|
|
|
+ // "name": "1",
|
|
|
+ // "isLease": 1,
|
|
|
+ // "leaseTime": "2022-01-10 21:25:17",
|
|
|
+ // "leaseMultiple": null,
|
|
|
+ // "isPlant": 1,
|
|
|
+ // "plantStart": "2022-01-10 21:25:22",
|
|
|
+ // "plantMature": 1,
|
|
|
+ // "landDescribe": "1",
|
|
|
+ // "createTime": "2022-01-10 21:25:30",
|
|
|
+ // "updateTime": "2022-01-10 21:25:33"
|
|
|
+ // }
|
|
|
+ // ],
|
|
|
+ utils.get(utils.api.userLandList, {}, (res, vaule) => {
|
|
|
|
|
|
+ })
|
|
|
+ },
|
|
|
+ //获取用户已租赁土地的状态
|
|
|
+ getLandState() {
|
|
|
+ // {
|
|
|
+ // "id": 1,
|
|
|
+ // "configLandId": 1,
|
|
|
+ // "userId": "4",
|
|
|
+ // "name": "1",
|
|
|
+ // "isLease": 1,
|
|
|
+ // "leaseTime": "2022-01-10 21:25:17",
|
|
|
+ // "leaseMultiple": null,
|
|
|
+ // "isPlant": 1,
|
|
|
+ // "plantStart": "2022-01-10 21:25:22",
|
|
|
+ // "plantMature": 1,
|
|
|
+ // "landDescribe": "1",
|
|
|
+ // "createTime": "2022-01-10 21:25:30",
|
|
|
+ // "updateTime": "2022-01-10 21:25:33"
|
|
|
+ // }
|
|
|
+ utils.get(utils.api.landState, { landId: 1 }, (res, vaule) => {
|
|
|
+
|
|
|
+ })
|
|
|
+ },
|
|
|
+ //获取商城种子
|
|
|
+ getMallSeed() {
|
|
|
+ // "data": [
|
|
|
+ // {
|
|
|
+ // "id": 1,
|
|
|
+ // "mallType": "0",
|
|
|
+ // "picture": null,
|
|
|
+ // "name": "白菜种子",
|
|
|
+ // "maturity": 100,
|
|
|
+ // "planting": 100,
|
|
|
+ // "harvestQuantity": 2500,
|
|
|
+ // "harvestCount": 2500,
|
|
|
+ // "harvestName": "大白菜",
|
|
|
+ // "price": 99,
|
|
|
+ // "amount": 0,
|
|
|
+ // "withered": 200,
|
|
|
+ // "createTime": "2022-01-10 16:45:18",
|
|
|
+ // "updateTime": "2022-01-10 16:45:26"
|
|
|
+ // },
|
|
|
+ // {
|
|
|
+ // "id": 2,
|
|
|
+ // "mallType": "0",
|
|
|
+ // "picture": null,
|
|
|
+ // "name": "辣椒种子",
|
|
|
+ // "maturity": 100,
|
|
|
+ // "planting": 100,
|
|
|
+ // "harvestQuantity": 2500,
|
|
|
+ // "harvestCount": 2500,
|
|
|
+ // "harvestName": "辣椒",
|
|
|
+ // "price": 99,
|
|
|
+ // "amount": 0,
|
|
|
+ // "withered": 200,
|
|
|
+ // "createTime": "2022-01-10 16:45:23",
|
|
|
+ // "updateTime": "2022-01-10 16:45:28"
|
|
|
+ // }
|
|
|
+ // ],
|
|
|
+ utils.get(utils.api.mallSeed, {}, (res, vaule) => {
|
|
|
+
|
|
|
+ })
|
|
|
+ },
|
|
|
+
|
|
|
+ getWarehouseSeedAndFruit(){
|
|
|
+ // "data": {
|
|
|
+ // "seed": [
|
|
|
+ // {
|
|
|
+ // "id": 1,
|
|
|
+ // "mallType": "0",
|
|
|
+ // "picture": null,
|
|
|
+ // "name": "白菜种子",
|
|
|
+ // "maturity": 100,
|
|
|
+ // "planting": 100,
|
|
|
+ // "harvestQuantity": 2500,
|
|
|
+ // "harvestCount": 2500,
|
|
|
+ // "harvestName": "大白菜",
|
|
|
+ // "price": 99,
|
|
|
+ // "amount": 0,
|
|
|
+ // "withered": 200,
|
|
|
+ // "createTime": "2022-01-10 16:45:18",
|
|
|
+ // "updateTime": "2022-01-10 16:45:26"
|
|
|
+ // }
|
|
|
+ // ],
|
|
|
+ // "fruit": [
|
|
|
+ // {
|
|
|
+ // "id": 1,
|
|
|
+ // "picture": null,
|
|
|
+ // "name": "白菜",
|
|
|
+ // "priceSnb": 99,
|
|
|
+ // "priceCnt": 9.9,
|
|
|
+ // "createTime": "2022-01-10 16:45:18",
|
|
|
+ // "updateTime": "2022-01-10 16:45:26"
|
|
|
+ // }
|
|
|
+ // ]
|
|
|
+ // },
|
|
|
+ utils.get(utils.api.getSeedAndFruit, {}, (res, vaule) => {
|
|
|
+
|
|
|
+ })
|
|
|
+ }
|
|
|
});
|