diff --git a/assets/Script/GameManager.ts b/assets/Script/GameManager.ts index d04aaa6..326464a 100644 --- a/assets/Script/GameManager.ts +++ b/assets/Script/GameManager.ts @@ -215,7 +215,7 @@ export default class GameManager extends cc.Component { if (typeof wx !== 'undefined' && wx !== null) { MiniGameSdk.API.shushu_Init(); Utils.getUserInfo((data) => { - console.log("登陆成功", data); + console.log("登陆成功_____________", data); if (data.data._id) { cc.fx.GameConfig.GM_INFO.uid = data.data._id; cc.fx.StorageMessage.setStorage("uid", data.data._id); @@ -226,6 +226,8 @@ export default class GameManager extends cc.Component { cc.fx.GameConfig.GM_INFO.allOutTradeNo = data.data.outTradeNo; console.log("______________________________有未发放奖励", cc.fx.GameConfig.GM_INFO.allOutTradeNo); } + this.setUserPower(data); + let levelInfo = cc.fx.StorageMessage.getStorage("level"); //旧的读取数据设置数据方法,以强联网为主 if (levelInfo == undefined || levelInfo == "" || levelInfo == null) { @@ -405,20 +407,21 @@ export default class GameManager extends cc.Component { if (data.result.code == 404 && data.result.message == "未找到道具数据") { console.log("没有道具信息,从用户接口拿到数据", propInfo); if (propInfo.freezeAmount == undefined || propInfo.hammerAmount == undefined || propInfo.magicAmount == undefined) { - console.log("2222222道具数据异常"); - cc.fx.GameConfig.GM_INFO.freezeAmount = 0; - cc.fx.GameConfig.GM_INFO.hammerAmount = 0; - cc.fx.GameConfig.GM_INFO.magicAmoun = 0; + console.log("____________________道具数据异常"); + cc.fx.GameConfig.GM_INFO.freezeAmount = 3; + cc.fx.GameConfig.GM_INFO.hammerAmount = 3; + cc.fx.GameConfig.GM_INFO.magicAmoun = 3; let propInfoNew = { "freezeAmount": cc.fx.GameConfig.GM_INFO.freezeAmount, "hammerAmount": cc.fx.GameConfig.GM_INFO.hammerAmount, "magicAmount": cc.fx.GameConfig.GM_INFO.magicAmoun, "timestamp": timestamp } - console.log("1111111上传道具信息:", propInfoNew); + console.log("_______________上传道具信息:", propInfoNew); cc.fx.StorageMessage.setStorage("prop", propInfoNew); } else { + console.log("_______________________道具数据正常", propInfo); // cc.fx.GameConfig.GM_INFO.freezeAmount = data.result.data.freeze; // cc.fx.GameConfig.GM_INFO.hammerAmount = data.result.data.hammer; // cc.fx.GameConfig.GM_INFO.magicAmount = data.result.data.magic_wand; @@ -426,16 +429,11 @@ export default class GameManager extends cc.Component { cc.fx.GameConfig.GM_INFO.hammerAmount = propInfo.hammerAmount; cc.fx.GameConfig.GM_INFO.magicAmount = propInfo.magicAmount; } - - - // cc.fx.GameConfig.GM_INFO.freezeAmount = propInfo.freezeAmount; - // cc.fx.GameConfig.GM_INFO.hammerAmount = propInfo.hammerAmount; - // cc.fx.GameConfig.GM_INFO.magicAmount = propInfo.magicAmount; cc.fx.GameTool.setUserProp(0, 0, (data) => { }); } else if (data.result.code == 200) { - // console.log("本地时间戳",propInfo.timestamp,"服务器时间戳",data.result.timestamp); + console.log("本地时间戳", propInfo.timestamp, "服务器时间戳", data.result.timestamp); if ((data.result.timestamp - propInfo.timestamp) < 10000) { console.log("以前端道具为主:", propInfo); if (propInfo.freezeAmount == undefined || propInfo.hammerAmount == undefined || propInfo.magicAmount == undefined) { @@ -547,12 +545,13 @@ export default class GameManager extends cc.Component { cc.fx.GameTool.setUserLevel((data) => { }); setTimeout(() => { - cc.fx.GameConfig.GM_INFO.freezeAmount = 0; - cc.fx.GameConfig.GM_INFO.hammerAmount = 0; - cc.fx.GameConfig.GM_INFO.magicAmount = 0; + cc.fx.GameConfig.GM_INFO.freezeAmount = 3; + cc.fx.GameConfig.GM_INFO.hammerAmount = 3; + cc.fx.GameConfig.GM_INFO.magicAmount = 3; + cc.fx.GameTool.setUserProp(0, 0, (data) => { if (data.result.code == 200) { - console.log("上传道具信息成功", data); + console.log("1111111上传道具信息成功", data); } else { MiniGameSdk.API.showToast("网络异常,正在努力加载"); @@ -627,32 +626,32 @@ export default class GameManager extends cc.Component { cc.fx.GameTool.getUserProp((data) => { if (data.result.code == 404 && data.result.message == "未找到道具数据") { console.log("没有道具信息,从用户接口拿到数据"); - cc.fx.GameConfig.GM_INFO.freezeAmount = 0; - cc.fx.GameConfig.GM_INFO.hammerAmount = 0; - cc.fx.GameConfig.GM_INFO.magicAmount = 0; + cc.fx.GameConfig.GM_INFO.freezeAmount = 3; + cc.fx.GameConfig.GM_INFO.hammerAmount = 3; + cc.fx.GameConfig.GM_INFO.magicAmount = 3; let propInfo = { - "freezeAmount": 0, - "hammerAmount": 0, - "magicAmount": 0, + "freezeAmount": 3, + "hammerAmount": 3, + "magicAmount": 3, "timestamp": timestamp, } - console.log("上传道具信息:", propInfo); + console.log("上传道具信息44444444:", propInfo); cc.fx.StorageMessage.setStorage("prop", propInfo); cc.fx.GameTool.setUserProp(0, 0, (data) => { }); } else if (data.result.code == 200) { console.log("有道具信息,从道具接口拿到数据", data.result.data); - cc.fx.GameConfig.GM_INFO.freezeAmount = data.result.data.freeze || 0; - cc.fx.GameConfig.GM_INFO.hammerAmount = data.result.data.hammer || 0; - cc.fx.GameConfig.GM_INFO.magicAmount = data.result.data.magic_wand || 0; + cc.fx.GameConfig.GM_INFO.freezeAmount = data.result.data.freeze || 3; + cc.fx.GameConfig.GM_INFO.hammerAmount = data.result.data.hammer || 3; + cc.fx.GameConfig.GM_INFO.magicAmount = data.result.data.magic_wand || 3; let propInfo = { "freezeAmount": cc.fx.GameConfig.GM_INFO.freezeAmount, "hammerAmount": cc.fx.GameConfig.GM_INFO.hammerAmount, "magicAmount": cc.fx.GameConfig.GM_INFO.magicAmount, "timestamp": timestamp, } - console.log("上传道具信息:", propInfo); + console.log("上传道具信息6666666:", propInfo); cc.fx.StorageMessage.setStorage("prop", propInfo); } @@ -707,6 +706,72 @@ export default class GameManager extends cc.Component { } } + setUserPower(data) { + let nowTime = Math.floor(Date.now() / 1000); + let powerTime = cc.fx.StorageMessage.getStorage("userPowerTime"); + //本地没缓存 + if (powerTime == "undifend" || powerTime == null || powerTime == "" || powerTime == 0) { + //本地没缓存,但是服务器有缓存,判断服务器的无限体力时间是否过期 + if (data.data.userPowerTime && data.data.userPowerTime != 0) { + powerTime = data.data.userPowerTime; + if (powerTime > nowTime) { + cc.fx.GameConfig.GM_INFO.userPowerTime = powerTime; + cc.fx.StorageMessage.setStorage("userPowerTime", powerTime); + } + else { + cc.fx.GameConfig.GM_INFO.userPowerTime = 0; + cc.fx.StorageMessage.setStorage("userPowerTime", 0); + } + } + //本地没缓存,服务器也没缓存 + else { + powerTime = 0; + cc.fx.GameConfig.GM_INFO.userPowerTime = 0; + cc.fx.StorageMessage.setStorage("userPowerTime", 0); + } + } + //本地有缓存 + else { + //本地有缓存,且服务器有缓存 + if (data.data.userPowerTime && data.data.userPowerTime != 0) { + //服务器缓存大于本地缓存,以服务器缓存为主 + if (data.data.userPowerTime > powerTime) { + powerTime = data.data.userPowerTime; + if (powerTime > nowTime) { + cc.fx.GameConfig.GM_INFO.userPowerTime = powerTime; + cc.fx.StorageMessage.setStorage("userPowerTime", powerTime); + } + else { + cc.fx.GameConfig.GM_INFO.userPowerTime = 0; + cc.fx.StorageMessage.setStorage("userPowerTime", 0); + } + } + //服务器缓存小于本地缓存,以本地缓存为主 + else { + if (powerTime > nowTime) { + cc.fx.GameConfig.GM_INFO.userPowerTime = powerTime; + cc.fx.StorageMessage.setStorage("userPowerTime", powerTime); + } + else { + cc.fx.GameConfig.GM_INFO.userPowerTime = 0; + cc.fx.StorageMessage.setStorage("userPowerTime", 0); + } + } + } + //本地有缓存,服务器没缓存 + else { + if (powerTime > nowTime) { + cc.fx.GameConfig.GM_INFO.userPowerTime = powerTime; + cc.fx.StorageMessage.setStorage("userPowerTime", powerTime); + } + else { + cc.fx.GameConfig.GM_INFO.userPowerTime = 0; + cc.fx.StorageMessage.setStorage("userPowerTime", 0); + } + } + } + } + update(dt) { //console.log("加载1:", this.load1, "加载2:", this.load2, "加载3:", this.load3, "加载4:", this.load4, "加载5:", this.load5, "加载6:", this.load6, "时间:", this.timeNumber); if (this.load1 && this.load2 && this.load3 && this.load4 && this.load5 && this.load6 == true && this.timeNumber <= 0) { diff --git a/assets/Script/JiaZai.ts b/assets/Script/JiaZai.ts index 6fec5ec..05add35 100644 --- a/assets/Script/JiaZai.ts +++ b/assets/Script/JiaZai.ts @@ -158,7 +158,18 @@ export default class JiaZai extends cc.Component { // //console.log("已经进入Home界面"); // //console.log("金币",cc.fx.GameConfig.GM_INFO.coin); // //console.log("关卡",cc.fx.GameConfig.GM_INFO.level+1); - + if (cc.fx.GameConfig.GM_INFO.userPowerTime != 0) { + let nowTime = Math.floor(Date.now() / 1000); + if (cc.fx.GameConfig.GM_INFO.userPowerTime > nowTime) { + console.log("还有无限体力时间_____________", (cc.fx.GameConfig.GM_INFO.userPowerTime - nowTime)); + } + else { + console.log("无限体力时间已过期"); + } + } + else { + console.log("没有无限体力时间"); + } cc.fx.GameTool.getHealth(null); // cc.fx.GameConfig.LEVEL_INFO_init(false,0); setTimeout(() => { diff --git a/assets/Script/Map.ts b/assets/Script/Map.ts index 4436dfe..d40b55e 100644 --- a/assets/Script/Map.ts +++ b/assets/Script/Map.ts @@ -1878,7 +1878,7 @@ export default class MapConroler extends cc.Component { else if (data == "hammerAmount") hammerBtn.getComponent("btnControl").setTouch(true); else if (data == "magicAmount") magicBtn.getComponent("btnControl").setTouch(true); if (data == "freezeAmount") { - cc.fx.GameConfig.GM_INFO.freezeAmount += 3; + // cc.fx.GameConfig.GM_INFO.freezeAmount += 3; let propInfo = cc.fx.StorageMessage.getStorage("prop"); propInfo.freezeAmount = cc.fx.GameConfig.GM_INFO.freezeAmount; propInfo.timestamp = timestamp; @@ -1893,7 +1893,7 @@ export default class MapConroler extends cc.Component { } else if (data == "magicAmount") { - cc.fx.GameConfig.GM_INFO.magicAmount += 3; + // cc.fx.GameConfig.GM_INFO.magicAmount += 3; let propInfo = cc.fx.StorageMessage.getStorage("prop"); propInfo.magicAmount = cc.fx.GameConfig.GM_INFO.magicAmount; propInfo.timestamp = timestamp; @@ -1907,7 +1907,7 @@ export default class MapConroler extends cc.Component { } else if (data == "hammerAmount") { - cc.fx.GameConfig.GM_INFO.hammerAmount += 1; + // cc.fx.GameConfig.GM_INFO.hammerAmount += 1; let propInfo = cc.fx.StorageMessage.getStorage("prop"); propInfo.hammerAmount = cc.fx.GameConfig.GM_INFO.hammerAmount; propInfo.timestamp = timestamp; diff --git a/assets/Script/module/Config/GameConfig.ts b/assets/Script/module/Config/GameConfig.ts index be5d5c0..e4581ce 100644 --- a/assets/Script/module/Config/GameConfig.ts +++ b/assets/Script/module/Config/GameConfig.ts @@ -97,12 +97,14 @@ export class GameConfig { version: number; //版本号 shushu_DistinctId: string; //数数访客ID shushu_AccountId: string; //数数账号ID - uid: string; + uid: string; //用户和后端唯一id + userPowerTime: number; }; + //游戏内信息 static get Instance() { @@ -227,9 +229,9 @@ export class GameConfig { iosOutTradeNo: "", //ios订单号 allOutTradeNo: [], //订单号数组 min_Time: 0, //体力恢复的剩余时间 - freezeAmount: 0, //冻结道具次数 - hammerAmount: 0, //锤子道具次数 - magicAmount: 0, //魔法棒道具次数 + freezeAmount: 3, //冻结道具次数 + hammerAmount: 3, //锤子道具次数 + magicAmount: 3, //魔法棒道具次数 musicOpen: true, //音乐 effectOpen: true, //音效 vibrateOpen: true, //震动 @@ -239,6 +241,7 @@ export class GameConfig { shushu_DistinctId: "", //数数访客ID shushu_AccountId: "", //数数账号ID uid: "", //用户和后端唯一id + userPowerTime: 0, //用户体力恢复时间 }; // this.setCode(this.getKey("scode")); // this.GM_INFO.level = 0; diff --git a/assets/Script/module/Pay/Utils.ts b/assets/Script/module/Pay/Utils.ts index 4789188..239c12a 100644 --- a/assets/Script/module/Pay/Utils.ts +++ b/assets/Script/module/Pay/Utils.ts @@ -484,6 +484,7 @@ export default class Utils { uid: cc.fx.GameConfig.GM_INFO.uid, action: 'read', } + Utils.POST("userData", data, res => { console.log("获得userData数据:", res); if (res.code === 1) { @@ -562,7 +563,7 @@ export default class Utils { let setData = { uid: cc.fx.GameConfig.GM_INFO.uid, action: 'save', - coinAmount: cc.fx.GameConfig.GM_INFO.coin + coinAmount: parseInt(cc.fx.GameConfig.GM_INFO.coin) } Utils.POST("userCoin", setData, res => { console.log("获得userCoin数据:", res); @@ -615,7 +616,7 @@ export default class Utils { let setData = { uid: cc.fx.GameConfig.GM_INFO.uid, action: 'save', - levelAmount: cc.fx.GameConfig.GM_INFO.level + levelAmount: parseInt(cc.fx.GameConfig.GM_INFO.level) } Utils.POST("userLevel", setData, res => { console.log("获得userLevel数据:", res); @@ -671,11 +672,7 @@ export default class Utils { uid: cc.fx.GameConfig.GM_INFO.uid, action: 'save', propType: propid, - propData: { - freeze: cc.fx.GameConfig.GM_INFO.freezeAmount, - hammer: cc.fx.GameConfig.GM_INFO.hammerAmount, - magic_wand: cc.fx.GameConfig.GM_INFO.wandAmount, - }, + propData: JSON.stringify(amount), } } else { @@ -756,6 +753,60 @@ export default class Utils { } } + + //获得关卡等级信息 + static getUserPowerTime(callBack) { + if (typeof wx !== 'undefined' && wx !== null) { + let uid = cc.fx.StorageMessage.getStorage("uid"); + //旧的读取数据设置数据方法,以强联网为主 + if (uid != undefined && uid != "" && uid != null) { + cc.fx.GameConfig.GM_INFO.uid = uid; + } + let setData = { + uid: cc.fx.GameConfig.GM_INFO.uid, + action: 'read', + } + Utils.POST("userPower", setData, res => { + console.log("获得userPower数据:", res); + if (res.code === 1) { + console.log("服务器:获得无限体力成功", res); + if (callBack) callBack(res); + } else { + console.log("服务器:获得无限体力失败", res); + if (callBack) callBack(res); + } + }); + } + + } + + //上传关卡等级信息 + static setUserPowerTime(userPowerTime, callBack) { + if (typeof wx !== 'undefined' && wx !== null) { + let uid = cc.fx.StorageMessage.getStorage("uid"); + //旧的读取数据设置数据方法,以强联网为主 + if (uid != undefined && uid != "" && uid != null) { + cc.fx.GameConfig.GM_INFO.uid = uid; + } + let setData = { + uid: cc.fx.GameConfig.GM_INFO.uid, + action: 'save', + userPowerTime: userPowerTime + } + + Utils.POST("userPower", setData, res => { + console.log("获得userPower数据:", res); + if (res.code === 1) { + console.log("服务器:上传无限体力成功", res); + if (callBack) callBack(res); + } else { + console.log("服务器:上传无限体力失败", res); + if (callBack) callBack(res); + } + }); + } + } + // const propName={ //   gold_1: "金币包1", //   gold_2: "金币包2", diff --git a/assets/Script/module/Tool/GameTool.ts b/assets/Script/module/Tool/GameTool.ts index fb31c54..9446805 100644 --- a/assets/Script/module/Tool/GameTool.ts +++ b/assets/Script/module/Tool/GameTool.ts @@ -684,23 +684,41 @@ var GameTool = { num: -cost } cc.fx.GameTool.shushu_Track("resource_cost", dataTemp); - cc.fx.GameTool.setUserProp(propid, num, (data) => { - }) + let _id = ""; - if (propid == 2001) _id = "freeze_in_game"; - else if (propid == 2002) _id = "hammer_in_game"; - else if (propid == 2003) _id = "wand_in_game"; + let propNumber = 0; + if (propid == 2001) { + _id = "freeze_in_game"; + cc.fx.GameConfig.GM_INFO.freezeAmount += num; + propNumber = cc.fx.GameConfig.GM_INFO.freezeAmount; + } + else if (propid == 2002) { + _id = "hammer_in_game"; + cc.fx.GameConfig.GM_INFO.hammerAmount += num; + propNumber = cc.fx.GameConfig.GM_INFO.hammerAmount; + } + else if (propid == 2003) { + _id = "wand_in_game"; + cc.fx.GameConfig.GM_INFO.magicAmount += num; + propNumber = cc.fx.GameConfig.GM_INFO.magicAmount; + } + + console.log("购买道具:", num); + cc.fx.GameTool.setUserProp(propid, propNumber, (data) => { + }) + + const data = { change_reason: "game", id: propid, - num: 3 + num: num } cc.fx.GameTool.shushu_Track("resource_get", data); const buyData = { item_id: _id, - item_num: 3, + item_num: num, item_price: cost, cost_type: "gold" } @@ -927,6 +945,7 @@ var GameTool = { cc.fx.GameTool.changeCoin(5000); coin = 5000; price = 1800; + this.setUserPowerTime(60); MiniGameSdk.API.showToast("获得无限体力小组合包"); break; case "unlimited_health_bundle_2": @@ -940,6 +959,7 @@ var GameTool = { "price": price } this.getShopProp(propData, null); + this.setUserPowerTime(120); MiniGameSdk.API.showToast("获得无限体力大组合包"); break; case "unlimited_health_bundle_3": @@ -953,6 +973,7 @@ var GameTool = { "price": price } this.getShopProp(propData2, null); + this.setUserPowerTime(180); MiniGameSdk.API.showToast("获得无限体力超组合包"); break; } @@ -1199,5 +1220,31 @@ var GameTool = { } }, + + //购买无限体力 + setUserPowerTime(time) { + //@ts-ignore + if (typeof wx !== 'undefined' && wx !== null) { + let nowTime = Math.floor(Date.now() / 1000); + let powerTime = cc.fx.StorageMessage.getStorage("userPowerTime"); + if (powerTime == "undifend" || powerTime == null || powerTime == "" || powerTime == 0) { + powerTime = Math.floor(Date.now() / 1000) + time; + } else { + if (nowTime >= powerTime) { + powerTime = nowTime + time; + } + else { + powerTime = powerTime + time; + } + } + cc.fx.GameConfig.GM_INFO.userPowerTime = powerTime; + cc.fx.StorageMessage.setStorage("userPowerTime", powerTime); + Utils.setUserPowerTime(powerTime, (data) => { + console.log("购买无限体力同步:", data); + }) + } + + } + }; export { GameTool }; \ No newline at end of file