diff --git a/assets/Script/GameManager.ts b/assets/Script/GameManager.ts index 8eef396..a4a2184 100644 --- a/assets/Script/GameManager.ts +++ b/assets/Script/GameManager.ts @@ -256,10 +256,10 @@ export default class GameManager extends cc.Component { cc.fx.GameConfig.GM_INFO.allOutTradeNo = data.data.outTradeNo; console.log("______________________________有未发放奖励", cc.fx.GameConfig.GM_INFO.allOutTradeNo); } - if (data.data.shareLvl) { + if (data.data.shareLv) { if (data.data.shareLvl.length > 0) { - console.log("设置分享等级", data.data.shareLvl); - cc.fx.GameConfig.GM_INFO.helpLevel = data.data.shareLvl; + console.log("设置分享等级", data.data.shareLv); + cc.fx.GameConfig.GM_INFO.helpLevel = data.data.shareLv; } } this.setUserPower(data); @@ -365,10 +365,13 @@ export default class GameManager extends cc.Component { cc.fx.GameConfig.GM_INFO.level = levelInfo.level; if (cc.fx.GameConfig.GM_INFO.helpLevel == (cc.fx.GameConfig.GM_INFO.level + 1)) { cc.fx.GameConfig.GM_INFO.level += 1; + console.log("好友帮助通过第" + cc.fx.GameConfig.GM_INFO.helpLevel + "关"); } } this.load4 = true; - cc.fx.StorageMessage.setStorage("level", cc.fx.GameConfig.GM_INFO.level); + levelInfo.level = cc.fx.GameConfig.GM_INFO.level; + levelInfo.timestamp = timestamp; + cc.fx.StorageMessage.setStorage("level", levelInfo); console.log("关卡等级成功时间耗时:", Date.now() - this.nowTime); cc.fx.GameTool.setUserLevel((data) => { }); @@ -384,8 +387,11 @@ export default class GameManager extends cc.Component { cc.fx.GameConfig.GM_INFO.level = levelInfo.level; if (cc.fx.GameConfig.GM_INFO.helpLevel == (cc.fx.GameConfig.GM_INFO.level + 1)) { cc.fx.GameConfig.GM_INFO.level += 1; + console.log("好友帮助通过第" + cc.fx.GameConfig.GM_INFO.helpLevel + "关"); } - cc.fx.StorageMessage.setStorage("level", cc.fx.GameConfig.GM_INFO.level); + levelInfo.level = cc.fx.GameConfig.GM_INFO.level; + levelInfo.timestamp = timestamp; + cc.fx.StorageMessage.setStorage("level", levelInfo); // console.log("等级为:",cc.fx.GameConfig.GM_INFO.level); cc.fx.GameTool.setUserLevel((data) => { }); @@ -823,6 +829,7 @@ export default class GameManager extends cc.Component { cc.fx.GameConfig.GM_INFO.level = data.result.data; if (cc.fx.GameConfig.GM_INFO.helpLevel == (cc.fx.GameConfig.GM_INFO.level + 1)) { cc.fx.GameConfig.GM_INFO.level += 1; + console.log("好友帮助通过第" + cc.fx.GameConfig.GM_INFO.helpLevel + "关"); } let levelInfo = { "level": cc.fx.GameConfig.GM_INFO.level, "timestamp": timestamp }; // console.log("444444存储关卡信息:",levelInfo); diff --git a/assets/Script/JiaZai.ts b/assets/Script/JiaZai.ts index 2916136..349d74d 100644 --- a/assets/Script/JiaZai.ts +++ b/assets/Script/JiaZai.ts @@ -80,6 +80,7 @@ export default class JiaZai extends cc.Component { // LIFE-CYCLE CALLBACKS: onLoad() { + this.checkShare(); console.log("进入首页获取的share", cc.fx.GameConfig.GM_INFO.otherUid, cc.fx.GameConfig.GM_INFO.otherLevel); if (cc.fx.GameConfig.GM_INFO.otherUid != "") { this.getShareInfo(); @@ -973,5 +974,48 @@ export default class JiaZai extends cc.Component { cc.fx.GameTool.shushu_Track("resource_get", dataTemp); } + //检测当日是否有分享行为,用不用主动获取分享关卡信息 + checkShare() { + const otherInfo = cc.fx.StorageMessage.getStorage("otherLevel"); + if (otherInfo && otherInfo.timeStamp && otherInfo.otherLevel) { + const currentTime = Date.now(); + const timeDifference = currentTime - otherInfo.timeStamp; + const oneDayInMilliseconds = 24 * 60 * 60 * 1000; + + if (timeDifference > oneDayInMilliseconds || cc.fx.GameConfig.GM_INFO.level >= otherInfo.otherLevel) { + console.log("检查分享信息过期或已获取过,清除存储信息"); + cc.fx.StorageMessage.setStorage("otherLevel", null); + } + else { + if ((cc.fx.GameConfig.GM_INFO.level + 1) == otherInfo.otherLevel) { + console.log("有分享信息,并且符合条件"); + Utils.getShareLevel((res) => { + if (res.code == 1) { + + let title = "好友帮助通过第" + otherInfo.otherLevel + "关"; + console.log(title); + MiniGameSdk.API.showToast(title); + cc.fx.GameConfig.GM_INFO.level = otherInfo.otherLevel; + const timestamp = Date.now(); + const levelInfo = { + level: cc.fx.GameConfig.GM_INFO.level, // 关卡 + timestamp: timestamp, // 时间戳 + }; + cc.fx.StorageMessage.setStorage("level", levelInfo); + NumberToImage.numberToImageNodes((cc.fx.GameConfig.GM_INFO.level + 1), 43, 15, "level_", this.level, true); + cc.fx.GameTool.setUserLevel((data) => { + }); + } + + }) + + } + } + } + else { + console.log("没有分享信息"); + } + } + // update (dt) {} } diff --git a/assets/Script/Map.ts b/assets/Script/Map.ts index 4b71f3c..4ad179a 100644 --- a/assets/Script/Map.ts +++ b/assets/Script/Map.ts @@ -1581,7 +1581,10 @@ export default class MapConroler extends cc.Component { cc.fx.GameTool.shushu_Track("resource_get", data); let overTime = Date.now(); this.count_Time = overTime - this.count_Time; - cc.fx.GameTool.addLevel(this.count_Time, this.add_Time); + if (cc.fx.GameConfig.GM_INFO.otherLevel > 0) { + + } + else cc.fx.GameTool.addLevel(this.count_Time, this.add_Time); const winCOIN = cc.find("Canvas"); // 假设 Canvas 节点 if (winCOIN) { const wincoin = winCOIN.getComponent(SceneManager); diff --git a/assets/Script/SceneManager.ts b/assets/Script/SceneManager.ts index 47c2e1d..926ea61 100644 --- a/assets/Script/SceneManager.ts +++ b/assets/Script/SceneManager.ts @@ -142,8 +142,11 @@ export default class SceneManager extends cc.Component { } this.node.getChildByName("Game").getChildByName("bg").getComponent(cc.Sprite).spriteFrame = spriteFrame; }) - - NumberToImage.numberToImageNodes((cc.fx.GameConfig.GM_INFO.level + 1), 43, 15, "level_", this.level, true); + let levelName = (cc.fx.GameConfig.GM_INFO.level + 1); + if (cc.fx.GameConfig.GM_INFO.otherLevel > 0) { + levelName = cc.fx.GameConfig.GM_INFO.otherLevel; + } + NumberToImage.numberToImageNodes(levelName, 43, 15, "level_", this.level, true); //time金币数量 NumberToImage.numberToImageNodes(1000, 25, 15, "button_", this.timeCoin, false); } @@ -433,6 +436,12 @@ export default class SceneManager extends cc.Component { shareFriend() { console.log("设置分享链接"); + let timeStamp = Date.now(); + let otherInfo = { + timeStamp: timeStamp, + otherLevel: cc.fx.GameConfig.GM_INFO.otherLevel, + } + cc.fx.StorageMessage.setStorage("otherLevel", otherInfo); MiniGameSdk.API.shareGame(); } diff --git a/assets/Script/module/Pay/Utils.ts b/assets/Script/module/Pay/Utils.ts index 62608d6..ad084ec 100644 --- a/assets/Script/module/Pay/Utils.ts +++ b/assets/Script/module/Pay/Utils.ts @@ -959,6 +959,7 @@ export default class Utils { } } + //设置分享成功信息,帮别人成功 static shareLevel(otherLevel, uid, callBack) { let otheruid = uid || ""; let level = otherLevel || 0; @@ -999,6 +1000,24 @@ export default class Utils { poll(); } + + //获取分享信息 + static getShareLevel(callBack) { + let data = { + uid: cc.fx.GameConfig.GM_INFO.uid + }; + if (typeof wx !== 'undefined' && wx !== null) { + Utils.POST("getShareLv", data, res => { + console.log("获得shareLvSuccess数据:", res); + if (res.code === 1) { + console.log("服务器:分享帮助通过关卡数据成功", res); + if (callBack) callBack(res); + } else { + if (callBack) callBack(res); + } + }); + } + } // const propName={ //   gold_1: "金币包1", //   gold_2: "金币包2",