import GamePlay from "../../../before/GamePlay"; import { AdFun } from "../../data/AdData"; import { GameProp, RewardType } from "../../data/GameData"; const { ccclass, property } = cc._decorator; /** * 盖子类型 */ enum LidType { /** 无盖子 */ none = 0, /** 幸运红包盖子 */ luck = 1, /** 通关红包盖子 */ mission = 2 } /** * 获取奖励界面-红包 * @author 薛鸿潇 */ @ccclass export default class Reward extends cc.Component { @property({ displayName: '红包类型', type: cc.Enum(LidType), tooltip: 'none无类型,luck幸运红包,mission通关红包' }) private lid_type: LidType = LidType.none; @property({ displayName: '幸运红包', type: cc.Node }) private node_luck: cc.Node = null; @property({ displayName: '通关红包', type: cc.Node }) private node_mission: cc.Node = null; @property({ displayName: '开红包动画', type: cc.Animation }) private anim_open_redbag: cc.Animation = null; @property({ displayName: '按钮看视频', type: cc.Button }) private btn_watch_video: cc.Button = null; @property({ displayName: '货币图标', type: cc.Sprite }) private node_coin: cc.Sprite = null; @property({ displayName: '奖励数量', type: cc.Label }) private lbl_reward_value: cc.Label = null; @property({ displayName: '星星闪闪效果', type: cc.Node }) private hb_star: cc.Node = null; // @property({ displayName: '关闭按钮', type: cc.Node }) // private btn_close: cc.Node = null; // @property({ displayName: '金猪币节点', type: cc.Node }) // private node_pig: cc.Node = null; // @property({ displayName: '货币图标', type: cc.Sprite }) // private node_coin1: cc.Sprite = null; // @property({ displayName: '奖励数量', type: cc.Label }) // private lbl_reward_value1: cc.Label = null; // // 底部提现相关 // @property({ displayName: 'spr提现进度', type: cc.Sprite }) // private spr_cash_out: cc.Sprite = null; // @property({ displayName: 'lbl提现进度', type: cc.Label }) // private lbl_cash_out: cc.Label = null; // @property({ displayName: '提现金额', type: cc.Label }) // private lbl_cash: cc.Label = null; // @property({ displayName: '提现按钮', type: cc.Animation }) // private node_cash: cc.Animation = null; @property({ displayName: '红包金额', type: cc.Label }) private lbl_reward_show: cc.Label = null; @property({ displayName: '奖励倍数', type: cc.Label }) private lbl_reward_times: cc.Label = null; /** 当前阶段 */ private cur_stage: number = LidType.none; /** 是否看广告 */ private hasWatchVideo = false; private curLevel = 0; onLoad() { this.hb_star.active = false; this.hasWatchVideo = false; this.lbl_reward_value.string = '0'; // gData.reward.data = [{ rewardType: 3, rewardNum: 100 }]// 测试数据 } start() { mk.ad.showNative(4); // mk.ad.showBanner(); // mk.ad.checkShowInterByChance(); /** 盖子 */ this.initLid(); // gData.gameData.gameData.redMoney = 1500;// 测试数据 // this.initCashOutStyle(gData.gameData.gameData.redMoney); } update(dt) { if (gData.reward.add_redbag_value) { // this.initCashOutStyle(gData.gameData.gameData.redMoney + gData.reward.add_redbag_value); } if (gData.reward.adData) { // 展示奖励 this.watchVideoCall(); this.hasWatchVideo = true; return; } } lateUpdate() { gData.reward.add_redbag_value = 0; gData.reward.adData = null; } /** * 初始化封面样式 */ private initLid() { if (this.lid_type === LidType.none) {// 无盖子样式 this.node_luck.active = false; this.node_mission.active = false; this.btn_watch_video.node.active = false; this.watchVideoCall(); } else if (this.lid_type === LidType.luck) { this.node_luck.active = true; this.node_mission.active = false; this.btn_watch_video.node.active = true; this.cur_stage = LidType.luck; mk.audio.playEffect("reward"); } else if (this.lid_type === LidType.mission) { this.node_luck.active = false; this.node_mission.active = true; this.btn_watch_video.node.active = true; this.cur_stage = LidType.mission; mk.audio.playEffect("reward"); this.lbl_reward_times.string = `${gData.gameData.configs.ServerConfig.DoubleCoefficient}倍奖励` this.curLevel = gData.gameData.getProp(GameProp.levelNum); if (this.curLevel <= 600) { this.lbl_reward_show.string = (gData.gameData.configs.LevelRedMoneyReward[this.curLevel - 1].redMoney * 0.0001).toFixed(2) + '元'; } else { this.lbl_reward_show.string = (gData.gameData.configs.ServerConfig.LevelRewardRedMoney * 0.0001).toFixed(2) + '元'; } } } // /** // * 底部提现相关样式 // */ // private initCashOutStyle(redMoney: number = 0) { // const cash_bar = gData.redBagCash.cash_bar; // let cash_data = gData.redBagCash.getItemDataByIndex(cash_bar); // if (!cash_data) return; // const newRedMoney = redMoney > cash_data.type_value ? cash_data.type_value : redMoney; // this.lbl_cash.string = cash_data.money / 100 + '元'; // this.lbl_cash_out.string = newRedMoney + '/' + cash_data.type_value; // const fillRange = newRedMoney / cash_data.type_value >= 1 ? 1 : newRedMoney / cash_data.type_value; // // this.spr_cash_out.fillRange = fillRange; // cc.tween(this.spr_cash_out).to(fillRange, { fillRange: fillRange }).start(); // if (redMoney >= cash_data.type_value) { // this.node_cash.play(); // } else { // this.node_cash.stop(); // } // } /** * 看广告 */ private async clickWatchVideo() { cc.log('看广告请求'); // if (gData.gameData.gameData.isFirstRedMoney) { // gData.gameData.gameData.isFirstRedMoney = 0; // // 用户第一次看此视频时,可不需要看直接领取奖励 // let response = await mk.http.sendData('getFreeRedMoney', {}); // if (response.errcode != 0) { // mk.tip.pop(response.errmsg); // return; // } // gData.reward.adData = {} // gData.reward.adData.videoRedMoney = {} // gData.reward.adData.videoRedMoney.videoRewardList = [{ rewardType: RewardType.redBag, rewardNum: response.data.freeRedMoney }] // return; // } if (this.lid_type === LidType.mission) { // 关卡结算红包 mk.ad.watchAd((success: boolean, request_id: string) => { mk.console.log("watchAD:" + success); if (success) { gData.adData.watchVideo(AdFun.settlement, request_id); // this.nextMission(); } }); } else { mk.ad.watchAd((success: boolean, request_id: string) => { mk.console.log("watchAD:" + success); if (success) { gData.adData.watchVideo(gData.reward.subType === 2 ? AdFun.checkpoint : AdFun.bubble, request_id); //FC:不需要置空 // gData.reward.subType = null; } }); } } /** * 看广告回调:开奖 */ private async watchVideoCall() { if (gData.reward.adData) { // 气泡视频奖励 通关视频奖励 // gData.reward.adData.videoRedMoney.videoRewardList = [{ rewardType: 3, rewardNum: 1000 }, { rewardType: 1, rewardNum: 1000 }]// 测试数据 gData.reward.data = gData.reward.adData.videoRedMoney.videoRewardList; } if (!gData.reward.data || !gData.reward.data.length) return; // this.btn_close && (this.btn_close.active = false); mk.audio.playEffect("rewardOpen"); this.hb_star.active = true; this.hb_star.getComponent(sp.Skeleton).animation = 'animation'; this.hb_star.getComponent(sp.Skeleton).loop = false; this.cur_stage = LidType.none; // 数据排序:多条奖励,只展示红包,把红包放在首位 const r_count = gData.reward.data.length; if (r_count >= 2) { for (let i = 0; i < r_count; i++) { if (gData.reward.data[i].rewardType === RewardType.redBag) { let new_data = gData.reward.data.splice(i, 1); gData.reward.data.unshift(new_data[0]); break; } } } // 图标展示 this.node_coin.spriteFrame = await mk.loader.load('game/texture/coin/' + gData.reward.data[0].rewardType, cc.SpriteFrame); let rewardNum: number = gData.reward.data[0].rewardNum || 0; this.lbl_reward_value.string = `${(rewardNum * 0.0001).toFixed(2)}元`; // 动画 this.anim_open_redbag.play(); this.node_luck.active = false; this.node_mission.active = false; this.btn_watch_video.node.active = false; // 底部进度动画 if (gData.reward.data[0].rewardType === RewardType.redBag) { gData.reward.add_redbag_value = gData.reward.data[0].rewardNum; } } /** * 点击获得奖励 */ private clickGetReward() { cc.log('获取奖励:', gData.reward.data); gData.reward.flyCoinAnim(); this.onClickClose(); if (gData.gameData.getProp(GameProp.videoTimes) == 0) { mk.data.sendXYEvent("guide_receive", "新手引导领取2500红包币"); } this.nextMission(); } /** * 提现操作 */ private clickCashOut() { gData.reward.addReward(); mk.ui.closePanel(this.node.name); let path = 'module/redBagCash/redBagCash'; mk.ui.openPanel(path); } /** 普通领取奖励 */ public async clickNormalGet() { let data = { "levelNum": this.curLevel } let response = await mk.http.sendData('redMoney/receiveLevelRedMoney', data); if (response.errcode != 0) { return; } gData.reward.adData = {} gData.reward.adData.videoRedMoney = {} gData.reward.adData.videoRedMoney.videoRewardList = [{ rewardType: RewardType.redBag, rewardNum: response.data.redMoney }] } /** * 下一关操作 */ public nextMission() { //如果是关卡消除红包 关闭之后则清除 this.checkIfClearLevelScore(); GamePlay.Inst.nextLevel(); // mk.ad.destoryBanner(); mk.ad.destroyNativeAd(); } /** 点击返回 */ public clickBack() { //如果是关卡消除红包 关闭之后则清除 this.checkIfClearLevelScore(); GamePlay.Inst.restart();//退出不扣体力 GamePlay.Inst.node.active = false; mk.ad.destoryBanner(); } onDestroy() { if (this.cur_stage === LidType.none) { mk.audio.playEffect("rewardClose"); } } onClickClose() { mk.ui.closePanel(this.node.name); //如果是关卡消除红包 关闭之后则清除 this.checkIfClearLevelScore(); // mk.ad.checkShowInterByChance(); // if (!this.hasWatchVideo) { // gData.adData.checkShowFullInter(2); // } mk.ad.destoryBanner(); } checkIfClearLevelScore() { if (gData.reward.subType == 2) { console.log("清除积分啦啦啦啦啦阿拉拉拉啦--------------------------------", GamePlay.Inst.ifPass) gData.gameData.setProp(GameProp.curTotalScore, 0); GamePlay.Inst.curProgressScore = 0; GamePlay.Inst.curGetScore = 0; GamePlay.Inst.finalGetScore = 0; GamePlay.Inst.initScore(); } } }