// Learn TypeScript: // - https://docs.cocos.com/creator/manual/en/scripting/typescript.html // Learn Attribute: // - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html // Learn life-cycle callbacks: // - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html import GameManager from "./GameManager"; import MapConroler from "./Map"; import NumberToImage from "./NumberToImage"; import { MiniGameManager } from "./Sdk/MiniGameManager"; import { MiniGameSdk } from "./Sdk/MiniGameSdk"; import { LQCollideSystem } from "./lq_collide_system/lq_collide_system"; import AudioManager from "./module/Music/AudioManager"; import Utils from "./module/Pay/Utils"; const { ccclass, property } = cc._decorator; @ccclass export default class JiaZai extends cc.Component { // 缓存 shop 预制体 删除 // private static cachedShopPrefab: cc.Prefab | null = null; // 缓存 shop 节点 删除 // private shopNode: cc.Node | null = null; // 缓存 reward 预制体 private static cachedRewardPrefab: cc.Prefab | null = null; // 缓存 reward 奖励窗口 节点 private RewardNode: cc.Node | null = null; //缓存月卡 //// private static cachedMonthlyCardPrefab: cc.Prefab | null = null; // 缓存月卡节点 //// private monthlyCardNode: cc.Node | null = null; // 缓存 预制体 private static cachedActionPrefab: cc.Prefab | null = null; // 缓存 新手活动节点 节点 //// private actionpNode: cc.Node | null = null; private static cachedAvatarPrefab: cc.Prefab | null = null; private AvatarNode: cc.Node | null = null; //// private static cachedDailyQuestsPrefab: cc.Prefab | null = null; //// private dailyQuestsNode: cc.Node | null = null; //// private static cachedWinStreakPrefab: cc.Prefab | null = null; //// private winStreakNode: cc.Node | null = null; @property(cc.EditBox) custom: cc.EditBox = null; @property({ type: [cc.SpriteAtlas], tooltip: "方块颜色" }) Block_Color: Array = []; @property(cc.SpriteAtlas) liuGuang: cc.SpriteAtlas = null; @property(cc.SpriteAtlas) avatarUI: cc.SpriteAtlas = null; @property(cc.Node) level: cc.Node = null; // @property(cc.Node) // coin: cc.Node = null; // 健康值 @property(cc.Prefab) health: cc.Prefab = null; @property(cc.Node) Stamina: cc.Node = null; scheduleCallback: any; private heath: any; // 用于存储heath预制体 private lastPauseClickTime: number = 0; // 用于记录上次点击的时间戳 // 弹窗倒计时调度器 private heathScheduleCallback: Function = null; @property(cc.Node) setUi: cc.Node = null; scheduleCallback2: any; scheduleCallback3: any; private isFirstLaunch: boolean = true; // 添加首次启动标志 dailyQuestsShow: boolean = false; // 每日任务加载 winStreakShow: boolean = false; // 连胜活动是否展示 @property(cc.Node) cardTime: cc.Node = null; // LIFE-CYCLE CALLBACKS: private onShowListener: () => void; private onHideListener: () => void; // LIFE-CYCLE CALLBACKS: onLoad() { if (cc.fx.GameConfig.GM_INFO.otherUid != "") { this.getShareInfo(); } this.node.getChildByName("zhuanchang").zIndex = 1000; this.closeLoad(); this.checkShare(); this.closeAvatar(); this.setShareInfo(); //// this.checkTasks(); // this.checkDailyQuests(); //console.log("进入首页获取的share", cc.fx.GameConfig.GM_INFO.otherUid, cc.fx.GameConfig.GM_INFO.otherLevel); cc.game.setFrameRate(63); LQCollideSystem.is_enable = true; this.winStreakShow = false; //每日任务 this.dailyQuestsShow = false; GameManager._instance.Block_Color = this.Block_Color; let version = cc.fx.GameTool.getWechatGameVersion(); if (version == "开发版" || version == "体验版") { this.node.getChildByName("Load").getChildByName("New EditBox").active = true; } else if (version == "正式版") { this.node.getChildByName("Load").getChildByName("New EditBox").active = false; if (cc.fx.GameConfig.GM_INFO.openid) { if (cc.fx.GameConfig.GM_INFO.openid == "orm8I7N10NSQdAhN4LP04n8UP56I") { this.node.getChildByName("Load").getChildByName("New EditBox").active = true; // cc.fx.GameTool.changeCoin(99999); } } } else { this.node.getChildByName("Load").getChildByName("New EditBox").active = true; } // 预加载 活动 预制体 if (!JiaZai.cachedActionPrefab) { cc.assetManager.loadBundle('action_bundle', (err: Error, bundle: cc.AssetManager.Bundle) => { if (err) { cc.error(err.message || err); return; } bundle.load('prefab/Avatar', cc.Prefab, (err: Error, prefab: cc.Prefab) => { if (err) { cc.error(err.message || err); return; } JiaZai.cachedAvatarPrefab = prefab; console.log("头像预制体已经准备好"); }); //// bundle.load('prefab/dailyQuests', cc.Prefab, (err: Error, prefab: cc.Prefab) => { // if (err) { // cc.error(err.message || err); // return; // } // JiaZai.cachedDailyQuestsPrefab = prefab; // console.log("每日任务预制体已经准备好"); // }); //// bundle.load('prefab/winStreak', cc.Prefab, (err: Error, prefab: cc.Prefab) => { // if (err) { // cc.error(err.message || err); // return; // } // JiaZai.cachedWinStreakPrefab = prefab; // console.log("连胜活动预制体已经准备好"); // }); }); } // 预加载 shop 预制体 删除 // if (!JiaZai.cachedShopPrefab) { cc.assetManager.loadBundle('shop', (err: Error, bundle: cc.AssetManager.Bundle) => { if (err) { cc.error(err.message || err); return; } }); if (cc.fx.GameConfig.GM_INFO.otherLevel > 0) { if (cc.fx.GameConfig.GM_INFO.first) { this.setFirstInfo(); cc.fx.GameConfig.GM_INFO.first = false; } let power = cc.fx.GameTool.getUserPowerTime(); if (cc.fx.GameConfig.GM_INFO.hp < 1 && power == false) { MiniGameSdk.API.showToast("体力值不足,无法进入好友关卡"); setTimeout(() => { this.openHeath(); }, 1000); return; } else { // this.closeLoad(); cc.fx.GameConfig.LEVEL_INFO_init(true, 1000, true); } } else { if (cc.fx.GameConfig.GM_INFO.first) { //console.log("————————准备注册事件", cc.fx.GameConfig.GM_INFO.openid); this.setFirstInfo(); cc.fx.AudioManager._instance.playEffect("zhuan1", null); this.node.getChildByName("zhuanchang").active = true; this.node.getChildByName("zhuanchang").getComponent(sp.Skeleton).setAnimation(1, "up", false); setTimeout(() => { cc.fx.GameConfig.GM_INFO.first = false; cc.director.loadScene("GameScene"); }, 1000); } } //console.log("音乐开关", cc.fx.GameConfig.GM_INFO.musicOpen); AudioManager._instance.playMusicGame(); this.onGames(); if (cc.fx.GameConfig.GM_INFO.openHeath) { cc.fx.GameConfig.GM_INFO.openHeath = false setTimeout(() => { console.log("打开体力界面"); this.openHeath(); }, 100); } } //监听后台 onGames() { //@ts-ignore if (typeof wx !== 'undefined') { this.onShowListener = null; this.onHideListener = null; // 定义监听函数 this.onShowListener = () => { this.onGameShow(); }; this.onHideListener = () => { this.onGameHide(); }; //@ts-ignore wx.onShow(this.onShowListener); //@ts-ignore wx.onHide(this.onHideListener); } } onGameHide() { // console.log("执行onGameHide", cc.fx.GameConfig.GM_INFO.min_Time); if (this.isFirstLaunch != null && this.isFirstLaunch != undefined) this.isFirstLaunch = false; if (this) { if (this.node) { this.stopHeathTimeCutDown(); this.stopTimeCutDown(); this.stopPowerTime(); } } } onGameShow() { // console.log("执行开始游戏gameshow"); cc.fx.GameTool.getHealth((data) => { if (this.level) { NumberToImage.numberToImageNodes((cc.fx.GameConfig.GM_INFO.level + 1), 43, 15, "level_", this.level, true); } }); // console.log("执行on", cc.fx.GameConfig.GM_INFO.min_Time); if (this) { if (this.node) { if (this.node.getChildByName("heathpop")) { if (this.node.getChildByName("heathpop").active == true) { const heathComponent = this.node.getChildByName("heathpop").getComponent("heathnum"); if (heathComponent && heathComponent.timeNode && cc.fx.GameConfig.GM_INFO.hp < cc.fx.GameConfig.GM_INFO.hp_Max) { this.startHeathTimeCutDown(heathComponent.timeNode); } } } } } } start() { // //console.log("已经进入Home界面"); this.updatePower(); cc.fx.GameTool.getHealth((data) => { NumberToImage.numberToImageNodes((cc.fx.GameConfig.GM_INFO.level + 1), 43, 15, "level_", this.level, true); this.setHealthInfo(true); }); // cc.fx.GameConfig.LEVEL_INFO_init(false,0); if (cc.fx.GameConfig.GM_INFO.gameState) { this.node.getChildByName("zhuanchang").active = true; setTimeout(() => { cc.fx.AudioManager._instance.playEffect("zhuan2", null); this.node.getChildByName("zhuanchang").getComponent(sp.Skeleton).setAnimation(1, "down", false); this.node.getChildByName("zhuanchang").getComponent(sp.Skeleton).setCompleteListener((entry) => { if (entry.animation.name === "down" && !cc.fx.GameConfig.GM_INFO.first) { // 动画播放结束后执行的逻辑 this.node.getChildByName("zhuanchang").active = false; } }); }, 500); } else { if (!cc.fx.GameConfig.GM_INFO.first) { this.node.getChildByName("zhuanchang").active = false; } } this.uploadToCloud(cc.fx.GameConfig.GM_INFO.level + 1); // this.getMonthlyCardValidityDays(); // this.rewarded(); //判断过期 cc.fx.GameTool.checkExpiration(); let isExpired = cc.fx.GameTool.checkExpiration(); if (isExpired) { const validityTime = cc.fx.StorageMessage.getStorage("mCardDate"); // 后端返回的到期时间戳(毫秒) const today = new Date(); today.setHours(0, 0, 0, 0); const todayMidnight = today.getTime(); const expiryDate = new Date(validityTime); expiryDate.setHours(0, 0, 0, 0); const expiryMidnight = expiryDate.getTime(); const diffMs = expiryMidnight - todayMidnight; const days = Math.floor(diffMs / 86400000); const remainingDays = Math.max(0, days); cc.fx.GameConfig.GM_INFO.monthTime = remainingDays; } if (cc.fx.GameConfig.GM_INFO.level >= 17) { let top = this.node.getChildByName("Load").getChildByName("Top"); // top.getChildByName("hammer").active = true; } else { let top = this.node.getChildByName("Load").getChildByName("Top"); // top.getChildByName("hammer").active = false; } // 加载广告 cc.fx.GameTool.preloadRewardedVideoAd().then((success) => { if (success) { console.log("HomeScene广告预加载初始化成功"); } else { console.log("HomeScene广告预加载初始化失败"); } }); this.setAdaptation(); } setAdaptation() { const hmScale = cc.fx.GameTool.adaptation() if (hmScale == 1) return; console.log("HomeSceneScale", this.node.scale, hmScale); const loadNode = this.node.getChildByName("Load"); if (loadNode) { // 获取屏幕设计分辨率 const designSize = cc.view.getDesignResolutionSize(); // 获取实际屏幕尺寸 const frameSize = cc.view.getFrameSize(); // 计算缩放因子 const scaleX = frameSize.width / designSize.width; const scaleY = frameSize.height / designSize.height; // 取最小缩放因子保持比例 const scale = Math.min(scaleX, scaleY); // 计算黑边宽度 (如果有的话) let barWidth = 0; if (scaleX > scaleY) { // 左右有黑边 barWidth = (frameSize.width - designSize.width * scale) / 2; } loadNode.scale = hmScale; // 适配右边的元素,保持与右边框距离不变 const rightElements = [ "tiaodik", "shezhiBtn", "rank", "Pause", "topRank" ]; rightElements.forEach(elementName => { let element; if (elementName === "rank" || elementName === "Pause") { element = this.node.getChildByName(elementName); } else if (elementName === "topRank") { element = loadNode.getChildByName("rank"); } else { element = loadNode.getChildByName(elementName); } if (element) { // 保存原始x位置作为距离右边的距离参考 if (!element.originalRightOffset) { element.originalRightOffset = designSize.width / 2 - element.x; } // 根据屏幕适配调整位置,保持与右边框距离一致 element.x = designSize.width / 2 - element.originalRightOffset + barWidth / scale; element.scale = hmScale; } }); } } checkDailyQuests() { cc.fx.GameTool.getDailyQuestsInfo((data) => { }) } openAvatar() { if (!JiaZai.cachedAvatarPrefab) { console.log('Avatar prefab is not loaded yet.'); cc.assetManager.loadBundle('action_bundle', (err: Error, bundle: cc.AssetManager.Bundle) => { if (err) { cc.error(err.message || err); return; } bundle.load('prefab/Avatar', cc.Prefab, (err: Error, prefab: cc.Prefab) => { if (err) { cc.error(err.message || err); return; } JiaZai.cachedAvatarPrefab = prefab; if (!this.AvatarNode) { // 第一次使用,创建节点 this.AvatarNode = cc.instantiate(JiaZai.cachedAvatarPrefab); this.node.addChild(this.AvatarNode); this.AvatarNode.getComponent("Avatar").init(); } else { // 非第一次使用,直接激活节点 this.AvatarNode.active = true; this.AvatarNode.getComponent("Avatar").init(); } }); }); return; } if (!this.AvatarNode) { // 第一次使用,创建节点 this.AvatarNode = cc.instantiate(JiaZai.cachedAvatarPrefab); this.node.addChild(this.AvatarNode); this.AvatarNode.getComponent("Avatar").init(); } else { // 非第一次使用,直接激活节点 this.AvatarNode.active = true; this.AvatarNode.getComponent("Avatar").init(); } } closeAvatar() { console.log("最终头像:", cc.fx.GameConfig.GM_INFO.useravatarIcon); console.log("最终头像框:", cc.fx.GameConfig.GM_INFO.useravaterkuang); let top = this.node.getChildByName("Load").getChildByName("Top"); if (this.AvatarNode) this.AvatarNode.active = false; if (cc.fx.GameConfig.GM_INFO.useravatarIcon.length > 10) { console.log("获取头像链接:", cc.fx.GameConfig.GM_INFO.useravatarIcon); cc.assetManager.loadRemote(cc.fx.GameConfig.GM_INFO.useravatarIcon, { ext: '.png' }, (err, texture: cc.Texture2D) => { if (texture) { top.getChildByName("avatar").getComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(texture); } top.getChildByName("avatar").opacity = 255; }) } else { top.getChildByName("avatar").getComponent(cc.Sprite).spriteFrame = this.avatarUI.getSpriteFrame(cc.fx.GameConfig.GM_INFO.useravatarIcon); top.getChildByName("avatar").opacity = 255; } top.getChildByName("kuang").getComponent(cc.Sprite).spriteFrame = this.avatarUI.getSpriteFrame(cc.fx.GameConfig.GM_INFO.useravaterkuang); top.getChildByName("kuang").opacity = 255; cc.fx.GameTool.setUserAvatar(); } // 打开heath弹窗,创建预制体并启动自己的倒计时 openHeath() { let health = cc.instantiate(this.health); this.node.addChild(health); let heathPop = health.getComponent("heathnum").heatht; heathPop.scale = 2; this.heath = heathPop; // 保存heath预制体引用 let swichs = health.getComponent("heathnum").switchNode; let timeNode = health.getComponent("heathnum").timeNode; let switchButtons = health.getComponent("heathnum").switchButtons; // let coin = health.getComponent("heathnum").coin; let pauseNode = health.getChildByName("heath"); cc.fx.AudioManager._instance.playEffect("tanchuang", null); pauseNode.scale = 0.3; const hmScale = cc.fx.GameTool.adaptation() cc.tween(pauseNode) .to(0.2, { scale: 1.05 * hmScale }, { easing: 'backOut' }) .to(0.15, { scale: 1.0 * hmScale }, { easing: 'sineOut' }) .start(); // 启动弹窗自己的倒计时 if (cc.fx.GameConfig.GM_INFO.hp < cc.fx.GameConfig.GM_INFO.hp_Max) { this.startHeathTimeCutDown(timeNode); } if (cc.fx.GameConfig.GM_INFO.hp == 0) { if (cc.fx.GameConfig.GM_INFO.userPowerTime == 0) { // 体力为0,显示spriteFrames[1],只显示第二个按钮 if (switchButtons[0]) { switchButtons[0].active = false; swichs[0].active = false; } if (switchButtons[1]) { switchButtons[1].active = true; swichs[1].active = true; } } else { if (switchButtons[0]) { switchButtons[0].active = true; swichs[0].active = false; } if (switchButtons[1]) { switchButtons[1].active = false; swichs[1].active = true; } } } else if (cc.fx.GameConfig.GM_INFO.hp < cc.fx.GameConfig.GM_INFO.hp_Max && cc.fx.GameConfig.GM_INFO.hp > 0) { // 体力小于5但大于0,显示spriteFrames[1],只显示第一个按钮 if (switchButtons[0]) { switchButtons[0].active = true; swichs[0].active = false; } if (switchButtons[1]) { switchButtons[1].active = false; swichs[1].active = true; } } else if (cc.fx.GameConfig.GM_INFO.hp >= cc.fx.GameConfig.GM_INFO.hp_Max) { // 体力为5,显示spriteFrames[0],只显示第一个按钮 if (switchButtons[0]) { switchButtons[0].active = true; swichs[0].active = true; } if (switchButtons[1]) { switchButtons[1].active = false; swichs[1].active = false; } } NumberToImage.numberToImageNodes(cc.fx.GameConfig.GM_INFO.hp, 40, 20, "time_", heathPop, true); // 设置金币花费数 // NumberToImage.numberToImageNodes(1000, 35, 15, "button_", coin, true); } // 弹窗倒计时 startHeathTimeCutDown(timeLabelNode?: cc.Node) { this.stopHeathTimeCutDown(); this.heathScheduleCallback = function () { if (cc.fx.GameConfig.GM_INFO.min_Time <= 0) { this.stopHeathTimeCutDown(); let timeTemp = cc.fx.GameTool.getTimeMargin2(cc.fx.GameConfig.GM_INFO.min_Time); //console.log("健康值倒计时结束,当前时间:", timeTemp, cc.fx.GameConfig.GM_INFO.min_Time); if (timeLabelNode) { timeLabelNode.getComponent(cc.Label).string = timeTemp; // NumberToImage.getTimeMargin(cc.fx.GameConfig.GM_INFO.min_Time, 50, "month_", timeLabelNode); } NumberToImage.numberToImageNodes(cc.fx.GameConfig.GM_INFO.hp, 40, 20, "month_", this.heath, true); } else { let timeTemp = cc.fx.GameTool.getTimeMargin2(cc.fx.GameConfig.GM_INFO.min_Time); if (timeLabelNode) { timeLabelNode.getComponent(cc.Label).string = timeTemp; // NumberToImage.getTimeMargin(cc.fx.GameConfig.GM_INFO.min_Time, 50, "month_", timeLabelNode); } } }.bind(this); this.heathScheduleCallback(); this.schedule(this.heathScheduleCallback, 1); } stopHeathTimeCutDown() { if (this.heathScheduleCallback) { this.unschedule(this.heathScheduleCallback); this.heathScheduleCallback = null; } } //开始倒计时 恢复体力 startTimeCutDown() { this.stopTimeCutDown(); this.scheduleCallback = function () { if (cc.fx.GameConfig.GM_INFO.min_Time <= 0) { this.stopTimeCutDown(); var timeTemp = cc.fx.GameTool.getTimeMargin2(cc.fx.GameConfig.GM_INFO.min_Time); // 同步显示 if (this.Stamina && this.Stamina.getChildByName("time")) { this.Stamina.getChildByName("time").getComponent(cc.Label).string = timeTemp; } if (cc.fx.GameConfig.GM_INFO.hp < cc.fx.GameConfig.GM_INFO.hp_Max) { // MiniGameSdk.API.showToast("恢复一点体力"); cc.fx.GameTool.setUserHealth(1, (data) => { cc.fx.GameTool.getHealth((data) => { this.setHealthInfo(true); }); }, true) } } else { cc.fx.GameConfig.GM_INFO.min_Time -= 1; var timeTemp = cc.fx.GameTool.getTimeMargin2(cc.fx.GameConfig.GM_INFO.min_Time); // 同步显示 if (this.Stamina && this.Stamina.getChildByName("time")) { let power = cc.fx.GameTool.getUserPowerTime(); if (!power) this.Stamina.getChildByName("time").opacity = 255; else this.Stamina.getChildByName("time").opacity = 0; this.Stamina.getChildByName("time").getComponent(cc.Label).string = timeTemp; } } // console.log(cc.fx.GameConfig.GM_INFO.hp, cc.fx.GameConfig.GM_INFO.hp_Max, "月卡体力"); }.bind(this); this.schedule(this.scheduleCallback, 1); } // 停止倒计时 恢复体力 stopTimeCutDown() { if (this.scheduleCallback) { this.unschedule(this.scheduleCallback); this.scheduleCallback = null; } } startPowerTime() { this.stopPowerTime(); if (this.scheduleCallback2) { this.unschedule(this.scheduleCallback2); } this.scheduleCallback2 = function () { let nowTime = Math.floor(Date.now() / 1000); if (cc.fx.GameConfig.GM_INFO.userPowerTime < nowTime) { this.Stamina.getChildByName("skyLine").active = false; this.stopPowerTime(); this.setHealthInfo(true); return; } else { this.Stamina.getChildByName("skyLine").active = true; this.Stamina.getChildByName("time").opacity = 0; this.Stamina.getChildByName("man").active = false; } let time = cc.fx.GameConfig.GM_INFO.userPowerTime - nowTime; if (time <= 0) { time = 0; this.Stamina.getChildByName("skyLine").active = false; this.stopPowerTime(); this.setHealthInfo(true); var timeTemp = cc.fx.GameTool.getTimeMargin2(time); // 同步显示 if (this.Stamina && this.Stamina.getChildByName("skyLine").getChildByName("skyTime")) { this.Stamina.getChildByName("skyLine").getChildByName("skyTime").getComponent(cc.Label).string = timeTemp; } } else { var timeTemp = cc.fx.GameTool.getTimeMargin2(time); // 同步显示 if (this.Stamina && this.Stamina.getChildByName("skyLine").getChildByName("skyTime")) { this.Stamina.getChildByName("skyLine").getChildByName("skyTime").getComponent(cc.Label).string = timeTemp; } } }.bind(this); this.schedule(this.scheduleCallback2, 1); } stopPowerTime() { cc.fx.GameTool.getUserPowerTime(); if (this.scheduleCallback2) { this.unschedule(this.scheduleCallback2); this.scheduleCallback2 = null; } } uploadToCloud(level: number) { //@ts-ignore if (typeof wx !== 'undefined') { //@ts-ignore wx.setUserCloudStorage({ KVDataList: [ { key: 'level', value: String(level) } ], success: () => console.log('✅ 数据上传成功'), fail: (err) => console.error('❌ 上传失败', err) }); } } setHealthInfo(type) { if (cc.fx.GameConfig.GM_INFO.hp >= cc.fx.GameConfig.GM_INFO.hp_Max) { if (cc.fx.GameConfig.GM_INFO.userPowerTime != 0) { let nowTime = Math.floor(Date.now() / 1000); if (cc.fx.GameConfig.GM_INFO.userPowerTime > nowTime) { this.stopPowerTime(); this.startPowerTime(); //console.log("还有无限体力时间_____________", (cc.fx.GameConfig.GM_INFO.userPowerTime - nowTime)); this.Stamina.getChildByName("skyLine").active = true; this.Stamina.getChildByName("time").opacity = 0; this.Stamina.getChildByName("man").active = false; } else { this.Stamina.getChildByName("skyLine").active = false; //console.log("无限体力时间已过期"); this.Stamina.getChildByName("man").active = true; } } else { this.Stamina.getChildByName("man").active = true; } this.Stamina.getChildByName("health").active = true; NumberToImage.numberToImageNodes(cc.fx.GameConfig.GM_INFO.hp, 25, 15, "hp_", this.Stamina.getChildByName("health"), false); this.Stamina.getChildByName("time").active = false; } else { this.Stamina.getChildByName("man").active = false; this.Stamina.getChildByName("health").active = true; NumberToImage.numberToImageNodes(cc.fx.GameConfig.GM_INFO.hp, 25, 15, "hp_", this.Stamina.getChildByName("health"), false); this.Stamina.getChildByName("time").active = true; if (cc.fx.GameConfig.GM_INFO.min_Time != 0) { let time = cc.fx.GameTool.getTimeMargin2(cc.fx.GameConfig.GM_INFO.min_Time); this.Stamina.getChildByName("time").getComponent(cc.Label).string = time; let power = cc.fx.GameTool.getUserPowerTime(); if (!power) this.Stamina.getChildByName("time").opacity = 255; else this.Stamina.getChildByName("time").opacity = 0; // console.log("______________________启动计时器"); this.stopTimeCutDown(); this.startTimeCutDown(); } } } startGame() { cc.fx.AudioManager._instance.playEffect("anniu_Big", null); let version = cc.fx.GameTool.getWechatGameVersion(); if (cc.fx.GameTool.maxLevel()) { if (version != "开发版" && version != "体验版") { MiniGameSdk.API.showToast("关卡每周更新,敬请期待!"); return; } } let power = cc.fx.GameTool.getUserPowerTime(); if (cc.fx.GameConfig.GM_INFO.hp < 1 && power == false) { MiniGameSdk.API.showToast("体力值不足"); setTimeout(() => { this.openHeath(); }, 500); return; } //@ts-ignore if (typeof wx !== 'undefined') { //@ts-ignore wx.offShow(this.onShowListener); //@ts-ignore wx.offHide(this.onHideListener); } if (this.node.getChildByName("Load").getChildByName("startBtn").getComponent("btnControl")._touch) { this.node.getChildByName("Load").getChildByName("startBtn").getComponent("btnControl").setTouch(false); let version = cc.fx.GameTool.getWechatGameVersion(); if (version == "开发版" || version == "体验版") { if (this.custom.string != "") { cc.fx.GameConfig.GM_INFO.level = parseInt(this.custom.string) - 1; // cc.fx.StorageMessage.setStorage("level",cc.fx.GameConfig.GM_INFO.level.toString()); if (cc.fx.GameTool.maxLevel()) { MiniGameSdk.API.showToast("关卡每周更新,敬请期待!"); return; } cc.fx.GameConfig.LEVEL_INFO_init(true, 0, false); } else { cc.fx.AudioManager._instance.playEffect("zhuan1", null); this.node.getChildByName("zhuanchang").active = true; this.node.getChildByName("zhuanchang").getComponent(sp.Skeleton).setAnimation(1, "up", false); if (cc.fx.GameTool.maxLevel()) { MiniGameSdk.API.showToast("关卡每周更新,敬请期待!"); return; } cc.fx.GameConfig.LEVEL_INFO_init(true, 1000, false); } } else if (version == "正式版") { if (cc.fx.GameTool.maxLevel()) { MiniGameSdk.API.showToast("关卡每周更新,敬请期待!"); return; } cc.fx.AudioManager._instance.playEffect("zhuan1", null); this.node.getChildByName("zhuanchang").active = true; this.node.getChildByName("zhuanchang").getComponent(sp.Skeleton).setAnimation(1, "up", false); cc.fx.GameConfig.LEVEL_INFO_init(true, 1000, false); } else { if (this.custom.string != "") { cc.fx.GameConfig.GM_INFO.level = parseInt(this.custom.string) - 1; // cc.fx.StorageMessage.setStorage("level",cc.fx.GameConfig.GM_INFO.level.toString()); if (cc.fx.GameTool.maxLevel()) { MiniGameSdk.API.showToast("关卡每周更新,敬请期待!"); return; } cc.fx.GameConfig.LEVEL_INFO_init(true, 0, false); } else { cc.fx.AudioManager._instance.playEffect("zhuan1", null); this.node.getChildByName("zhuanchang").active = true; this.node.getChildByName("zhuanchang").getComponent(sp.Skeleton).setAnimation(1, "up", false); if (cc.fx.GameTool.maxLevel()) { MiniGameSdk.API.showToast("关卡每周更新,敬请期待!"); return; } cc.fx.GameConfig.LEVEL_INFO_init(true, 1000, false); } } } } openRewardWindow(data, month?: number) { if (!JiaZai.cachedRewardPrefab) { cc.error('Reward prefab is not loaded yet.'); return; } if (!this.RewardNode) { // 第一次使用,创建节点 this.RewardNode = cc.instantiate(JiaZai.cachedRewardPrefab); this.node.addChild(this.RewardNode); this.RewardNode.getComponent("Reward").init(data); } else { this.RewardNode.destroy(); this.RewardNode = null; this.RewardNode = cc.instantiate(JiaZai.cachedRewardPrefab); this.node.addChild(this.RewardNode); this.RewardNode.getComponent("Reward").init(data); } this.RewardNode.zIndex = 1001; this.updatePower(); } // openDailyQuests() { // this.dailyQuestsNode = null; // this.openLoad2(); // this.dailyQuestsShow = true; // cc.fx.GameTool.getDailyQuestsInfo((data) => { // this.dailyQuestsShow = false; // console.log("处理结果:", data); // this.closeLoad(); // if (data.code != 1) { // MiniGameSdk.API.showToast("网络异常,请稍后重试!") // return; // } // if (!JiaZai.cachedDailyQuestsPrefab) { // // cc.error('Action prefab is not loaded yet.'); // cc.assetManager.loadBundle('action_bundle', (err: Error, bundle: cc.AssetManager.Bundle) => { // if (err) { // cc.error(err.message || err); // return; // } // bundle.load('prefab/dailyQuests', cc.Prefab, (err: Error, prefab: cc.Prefab) => { // if (err) { // cc.error(err.message || err); // return; // } // JiaZai.cachedDailyQuestsPrefab = prefab; // if (!this.dailyQuestsNode) { // // 第一次使用,创建节点 // this.dailyQuestsNode = cc.instantiate(JiaZai.cachedDailyQuestsPrefab); // this.node.addChild(this.dailyQuestsNode); // this.dailyQuestsNode.getComponent("DailyQuests").init(data.data.task); // } else { // // 非第一次使用,直接激活节点 // this.dailyQuestsNode.active = true; // this.dailyQuestsNode.getComponent("DailyQuests").init(data.data.task); // } // }); // }); // return; // } // if (!this.dailyQuestsNode) { // // 第一次使用,创建节点 // this.dailyQuestsNode = cc.instantiate(JiaZai.cachedDailyQuestsPrefab); // this.node.addChild(this.dailyQuestsNode); // this.dailyQuestsNode.active = true; // this.dailyQuestsNode.getComponent("DailyQuests").init(data.data.task); // } else { // // 非第一次使用,直接激活节点 // this.dailyQuestsNode.active = true; // this.dailyQuestsNode.getComponent("DailyQuests").init(data.data.task); // } // }) // } closeRank() { this.node.getChildByName("Rank").active = false; } openRank() { this.node.getChildByName("Rank").active = true; } openReward() { this.node.getChildByName("Reward").active = true; } clickShop() { // 假设已经获取到了 userId 和 productId } openPause() { cc.fx.AudioManager._instance.playEffect("anniu_little", null); //console.log(cc.fx.GameConfig.GM_INFO); if (cc.fx.GameConfig.GM_INFO.openid == undefined) { //console.log(cc.fx.GameConfig.GM_INFO.openid); cc.fx.GameConfig.GM_INFO.openid = ""; } this.node.getChildByName("Pause").active = true; this.node.getChildByName("Pause").getChildByName("openID").getComponent(cc.Label).string = cc.fx.GameConfig.GM_INFO.openid; } closePause() { cc.fx.AudioManager._instance.playEffect("anniu_little", null); this.node.getChildByName("Pause").active = false; } openSet() { const now = Date.now(); if (now - this.lastPauseClickTime < 300) { // 0.3秒内禁止再次点击 return; } this.lastPauseClickTime = now; cc.fx.AudioManager._instance.playEffect("anniu_little", null); if (cc.fx.GameConfig.GM_INFO.openid == undefined) { cc.fx.GameConfig.GM_INFO.openid = ""; } if (!this.setUi.active) { // 第一次点击,打开并播放动画 this.setUi.active = true; this.setUi.getComponent(cc.Animation).play(); } else { // 再次点击,关闭节点 this.setUi.active = false; } } closeReward() { this.node.getChildByName("Reward").active = false; } openStamina() { this.node.getChildByName("Stamina").active = true; } closeStamina() { this.node.getChildByName("Stamina").active = false; } openLoad() { this.node.getChildByName("Loading").active = true; this.node.getChildByName("Loading").getChildByName("load").stopAllActions(); this.node.getChildByName("Loading").getChildByName("load").runAction(cc.rotateTo(2, 1080).repeatForever()); } openLoad2() { this.node.getChildByName("Loading").active = true; this.node.getChildByName("Loading").getChildByName("load").stopAllActions(); this.node.getChildByName("Loading").getChildByName("load").runAction(cc.rotateTo(2, 1080).repeatForever()); setTimeout(() => { if (this.dailyQuestsShow == true) { MiniGameSdk.API.showToast("网络异常,请稍后重试!") this.closeLoad(); } }, 5000); } closeLoad() { this.node.getChildByName("Loading").active = false; } updatePower() { if (cc.fx.GameConfig.GM_INFO.userPowerTime != 0) { let nowTime = Math.floor(Date.now() / 1000); if (cc.fx.GameConfig.GM_INFO.userPowerTime > nowTime) { this.stopPowerTime(); this.startPowerTime(); //("还有无限体力时间_____________", (cc.fx.GameConfig.GM_INFO.userPowerTime - nowTime)); this.Stamina.getChildByName("skyLine").active = true; this.Stamina.getChildByName("time").opacity = 0; this.Stamina.getChildByName("man").active = false; } else { this.Stamina.getChildByName("skyLine").active = false; //console.log("无限体力时间已过期"); this.setHealthInfo(true); } } else { this.Stamina.getChildByName("skyLine").active = false; this.Stamina.getChildByName("time").opacity = 255; this.Stamina.getChildByName("man").active = true; //console.log("没有无限体力时间"); this.setHealthInfo(true); } } stopStarter_pack() { if (this.scheduleCallback3) { this.unschedule(this.scheduleCallback3); this.scheduleCallback3 = null; } } //获取有没有分享信息 getShareInfo() { // 检查微信小游戏启动参数 if (cc.sys.platform === cc.sys.WECHAT_GAME) { //@ts-ignore const launchOptions = wx.getLaunchOptionsSync(); const query = launchOptions.query; if (query.level && query.uid) { const level = parseInt(query.level, 10); const uid = query.uid.toString(); if (uid != cc.fx.GameConfig.GM_INFO.uid) { cc.fx.GameConfig.GM_INFO.otherUid = uid; cc.fx.GameConfig.GM_INFO.otherLevel = level; // console.log('从分享链接获取到的关卡信息:', level); // console.log('从分享链接获取到的 UID:', uid); // console.log("自己的UID", cc.fx.GameConfig.GM_INFO.uid) let eventData = { identity: "helper", //发起者为helped 帮助者为helper helpedId: cc.fx.GameConfig.GM_INFO.otherUid, //被帮助者UID level: level //被帮助关卡等级 } cc.fx.GameTool.shushu_Track("stage_help", eventData); //帮助通关 this.openLoad(); } else { cc.fx.GameConfig.GM_INFO.otherLevel = 0; } // 可以在这里处理关卡信息和 UID } } } //第一次进游戏用户处理信息 setFirstInfo() { const group = cc.fx.GameTool.setWechatGameGroup(2); if (group == 0) { cc.fx.GameConfig.GM_INFO.musicOpen = true; } else if (group == 1) { cc.fx.GameConfig.GM_INFO.musicOpen = false; } const audioInfo = { "musicOpen": cc.fx.GameConfig.GM_INFO.musicOpen, //音乐 "effectOpen": cc.fx.GameConfig.GM_INFO.effectOpen, //音效 "vibrateOpen": cc.fx.GameConfig.GM_INFO.vibrateOpen, //震动 } cc.fx.StorageMessage.setStorage("music", audioInfo); if (cc.fx.GameConfig.GM_INFO.openid != "") { // console.log("————————发送注册事件"); const time = cc.fx.GameTool.formatDate(new Date()); let data = { register_time: time, // 注册时间 } // console.log("注册时间:", time); cc.fx.GameTool.shushu_Track("register", data); MiniGameSdk.API.shushu_SetSuperProperties(time); } } //检测当日是否有分享行为,用不用主动获取分享关卡信息 checkShare() { const otherInfo = cc.fx.StorageMessage.getStorage("otherLevel"); // console.log("分享信息:", otherInfo); if (otherInfo != null && otherInfo != undefined && otherInfo != "") { const currentTime = Date.now(); const timeDifference = currentTime - otherInfo.timeStamp; const oneDayInMilliseconds = 24 * 60 * 60 * 1000; // console.log("计入时间计算"); 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) { if ((cc.fx.GameConfig.GM_INFO.level + 1) == res.data[0].lv) { let title = "好友帮助通过第" + otherInfo.otherLevel + "关"; MiniGameSdk.API.showToast(title); cc.fx.GameConfig.GM_INFO.level = otherInfo.otherLevel; cc.fx.GameTool.maxLevel(); 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("没有分享信息"); } } setShareInfo() { console.log("设置分享信息"); MiniGameSdk.API.shareAppToFriends(); } //检查任务列表 // checkTasks() { // let top = this.node.getChildByName("Load").getChildByName("Top"); // top.getChildByName("day").getChildByName("red").active = false; // if (cc.fx.GameConfig.GM_INFO.tasks.levelPass.target == 0) { // console.log("没有获取任务列表从服务器拿"); // cc.fx.GameTool.getDailyQuestsInfo((data) => { // if (data.code == 1) { // let res = data.data.task; // cc.fx.GameConfig.GM_INFO.tasks.levelPass = res["levelPass"]; // cc.fx.GameConfig.GM_INFO.tasks.share = res["share"]; // cc.fx.GameConfig.GM_INFO.tasks.useEnergy = res["useEnergy"]; // cc.fx.GameConfig.GM_INFO.tasks.useProp = res["useProp"]; // } // else { // //以备不时之需 // cc.fx.GameConfig.GM_INFO.tasks.levelPass.target = 3; // cc.fx.GameConfig.GM_INFO.tasks.share.target = 1; // cc.fx.GameConfig.GM_INFO.tasks.useEnergy.target = 10; // cc.fx.GameConfig.GM_INFO.tasks.useProp.target = 3; // } // if (cc.fx.GameConfig.GM_INFO.tasks.levelPass.state == 1 || cc.fx.GameConfig.GM_INFO.tasks.share.state == 1 || // cc.fx.GameConfig.GM_INFO.tasks.useEnergy.state == 1 || cc.fx.GameConfig.GM_INFO.tasks.useProp.state == 1 // ) { // top.getChildByName("day").getChildByName("red").active = true; // } // }) // } // else { // console.log("有任务列表判断红点", cc.fx.GameConfig.GM_INFO.tasks); // if (cc.fx.GameConfig.GM_INFO.tasks.levelPass.state == 1 || cc.fx.GameConfig.GM_INFO.tasks.share.state == 1 || // cc.fx.GameConfig.GM_INFO.tasks.useEnergy.state == 1 || cc.fx.GameConfig.GM_INFO.tasks.useProp.state == 1 // ) { // top.getChildByName("day").getChildByName("red").active = true; // } // } // } openWin() { if (this.winStreakShow == false || cc.fx.GameConfig.GM_INFO.level < 17) { return; } else { let date = new Date(); let day = date.getDate(); // 当前日期(1-31) let month = date.getMonth() + 1; // 当前月份(1-12) let year = date.getFullYear(); // 当前年份 let dateStr = `${year}-${String(month).padStart(2, '0')}-${String(day).padStart(2, '0')}`; // 格式化为 YYYY-MM-DD // 从缓存中获取上次弹窗的日期 let cachedDateStr = cc.fx.StorageMessage.getStorage("winStreakTime"); // 如果缓存中的日期和当前日期不一致 if (cachedDateStr !== dateStr) { // 更新缓存 cc.fx.StorageMessage.setStorage("winStreakTime", dateStr); } else { return; } } //// this.openWinStreak(); } //打开连胜活动 update(dt) { //// if (this.newbieGift && this.monthlyCardNode) { // if (this.monthlyCardNode.active == true) { // this.monthlyCardNode.active = false; // } // } } }