//商城脚本
var TableReader =require("TableReader");

cc.Class({
    extends: cc.Component,

    properties: {
        scrollViewNode: cc.Node, //滚动区节点
        scrollViewContentNode: cc.Node, //滚动区内容节点
        storeKnifePre: cc.Prefab,  //商店中飞镖预制
        pointNode: [cc.Node], //下点显示节点
        selectKnifeIcon: cc.Sprite,  //显示飞刀的信息
        labPrice: cc.Label, //随机价格
        labGold: cc.Label,  //用户金币
        randomBtn: cc.Node,  //随机按钮节点
        mianfeiBtn: cc.Node,  //免费抽奖按钮节点
        labTitle: cc.Node,  //转盘获得文字节点
        homePageUI: cc.Node,  //首页界面节点
        moreGameUI: cc.Node, //更多游戏界面节点
        noClickNode: cc.Node,  //屏蔽层
        labNum: cc.Label,  //每天免费抽奖次数
        xinwuqi: cc.Node,  //新武器节点提示
        videoIcon: cc.Node,  //看视频图标
        lauchNodeUI: cc.Node,  //游戏中界面节点
        choujiangBtn: cc.Node,  //商城中宝刀抽奖按钮
        labNumber: cc.Label,  //看视频次数，看了3次才允许随机获得一把宝刀
        labShuoming: cc.Node,  //特效武器获得说明
        _pageCount: 0, //界面数量
        _currentPageIndex: 0, //当前滚动页序号
        _first: true, //第1次
        _only1: true, //只一次
        _only2: true,
        _only3: true,
        _direction: 0, //滚动方向(0默认，1左，2右)
        _startOffset: 0, //开始滚动时第1帧
        _endOffset: 0, //开始滚动时第2帧
        _shopKnifeArray: [],  //存储当前界面的飞刀节点
        _shopKnifeId: [],  //存储当前界面的飞刀的id
        _lotteryState:false,  //是否显示免费抽奖按钮节点
        _state: null,  //商城返回后，要不是显示主界面节点
    },

    // LIFE-CYCLE CALLBACKS:

    onLoad () {
        this._currentPageIndex = 0; //当前滚动页序号
        // console.log("商城当前页面1111111111",this._currentPageIndex);
    },

    initBegin: function(state){
        this._state =state;
    },

    onEnable: function(){
        //要不要显示宝刀抽奖按钮 
        if(!sdk.getConfig4().ipLimit){  //ip限制
            if(sdk.getConfig1().hz){
                if(cc.HQ.GameMgr.oniSshowBtn()){
                    this.choujiangBtn.active =false;
                }else{
                    this.choujiangBtn.active =true;
                }
                let fuhuoka =cc.HQ.GameMgr.getChoujiangNum();
                this.labNumber.string = fuhuoka+"/"+3;
            }
        }

        //免费抽奖按钮上，要不要显示视频图片
        let state =cc.HQ.GameMgr.onShareVideoState(sdk.getConfig2().model.v3);
        console.log("显不显示视频图片2",state);
        if(state){
            this.videoIcon.active =true;
        }else{
            this.videoIcon.active =false;
        }
        if(!sdk.getConfig4().ipLimit){  //ip限制
            if(sdk.getConfig1().hz){
                this.moreGameUI.active =false;  //隐藏更多游戏面板
            }
        }
        let func =function(d){
            console.log("是否可以显示抽奖",d);
            if(!d || d==1 || d==2){  //可以抽奖一次   (每天有三次机会)
                if(!sdk.getConfig4().ipLimit){  //ip限制
                    if(sdk.getConfig1().sns){
                        if(!d){
                            this.labNum.string =3;
                        }else if(d ==1){
                            this.labNum.string =2;
                        }else{
                            this.labNum.string =1;    
                        }
                        if(this._currentPageIndex==4 || this._currentPageIndex ==5){
                            this.mianfeiBtn.active =false;
                        }else{
                            this.mianfeiBtn.active =true;
                        }
                        this._lotteryState =true;
                    }
                }
            }else{   //抽奖
                this.mianfeiBtn.active =false;
                this._lotteryState =false;
            }
        }.bind(this);
        var time = sdk.formatTime(new Date(),"date","");
        sdk.getFromServer("LotteryKey"+time,"LotteryData",null,func);
       
        this.init();
        console.log("商城当前页面",this._currentPageIndex);
    },

    init: function(){
        this._first = true; //第1次
        this._only1 = true; //只一次
        this._only2 = true;
        this._only3 = true;
        // this._currentPageIndex = 0; //当前滚动页序号
        this._direction = 0; //滚动方向(0默认，1左，2右)
        this._startOffset = 0; //开始滚动时第1帧
        this._endOffset = 0; //开始滚动时第2帧
        this.labGold.string =cc.HQ.GameMgr.getGold(); //显示用户金币数  金币存入本地

        //添加不同的飞刀物品
        var pos =[[127,255],[277,255],[426,255],[579,255],[127,100],[277,100],[426,100],[579,100],[127,-55],[277,-55],[426,-55],[579,-55],[127,-211],[277,-211],[426,-211],[579,-211]];
        let arr =cc.HQ.GameMgr.getKnife();    //用户已拥有的飞刀
        arr =cc.HQ.GameMgr.onChangeData(arr);
        console.log("商城中用户拥有的飞刀数",arr);
        let baodaoTime =cc.HQ.GameMgr.getBaodaoTime();
        let curDate =Date.now();   //当天的当前时间
        if(Number(curDate -Number(baodaoTime)) > 60000){   //屠龙刀使用时间就算用完了
            if(arr.indexOf(82) != -1){
                arr.splice(arr.indexOf(82),1);
                //屠龙刀使用时间到后,(去掉屠龙皮肤)
                cc.HQ.GameMgr.setKnife(arr);
            }   
            console.log("过后过后飞刀数",arr);
        }

        let num =TableReader.getTableLength("knifeItems");
        // console.log("商城中飞刀物品数量",num,arr);
       
        if(!this.scrollViewContentNode.children.length){
            //根据飞刀物品数设置滚动区大小
            this._pageCount = Math.ceil(num / 16);
            this.scrollViewContentNode.width = 700 * this._pageCount;
            
            for(var i = 0; i < num; i++){
                var knifeNode = cc.instantiate(this.storeKnifePre);
                this.scrollViewContentNode.addChild(knifeNode);
                knifeNode.setPosition(pos[i % 16][0] + 700 * Math.floor(i / 16), pos[i % 16][1]);
                let data =TableReader.getTableRow("knifeItems",i+1);
                // console.log("飞刀数量",data);
                if(arr.indexOf(data.goodsId) != -1){    //用户已拥有的飞刀
                    knifeNode.getComponent("storeKnife").init(0,this,data);
                }else{
                    if(data.price>0){  //用户未拥有的飞刀
                        knifeNode.getComponent("storeKnife").init(1,this,data);
                    }else{    //宝箱获得的飞刀
                        knifeNode.getComponent("storeKnife").init(2,this,data);
                    }
                }
            }
        }else{
            let child =this.scrollViewContentNode.children;
            for(var i = 0; i < num; i++){
                child[i].setPosition(pos[i % 16][0] + 700 * Math.floor(i / 16), pos[i % 16][1]);
                let data =TableReader.getTableRow("knifeItems",i+1);
                if(arr.indexOf(data.goodsId) != -1){    //用户已拥有的飞刀
                    child[i].getComponent("storeKnife").init(0,this,data);
                }else{
                    if(data.price>0){  //用户未拥有的飞刀
                        child[i].getComponent("storeKnife").init(1,this,data);
                        
                    }else{    //宝箱获得的飞刀
                        child[i].getComponent("storeKnife").init(2,this,data);
                    }
                }
            }
            
        }
        //设置点位置(目前只添加了4个点，以后根据需要再添加)
        for(var i = 0; i < this.pointNode.length; i++){
            this.pointNode[i].active = i < this._pageCount ? true : false;
        }
        var isEvenNumber = this._pageCount % 2 == 0 ? true : false;
        if(isEvenNumber){ //偶数
            var half = Math.floor(this._pageCount / 2);
            for(var i = 0; i < this._pageCount; i++){
                this.pointNode[i].x = -(half - i - 1) * 40 - 20;
            }
        }else{ //奇数
            var half = Math.ceil(this._pageCount / 2);
            for(var i = 0; i < this._pageCount; i++){
                this.pointNode[i].x = -(half - i - 1) * 40;
            }
        }

        // //设置滚动区为当前关按钮所在页面
        // for(var i = 0; i < this._pageCount; i++){
        //     if(0 >= i * 16 && 0 <= (i + 1) * 16 - 1){
        //         this._currentPageIndex = i;
        //         break;
        //     }  
        // }
        this.scheduleOnce(function(){
            this.scrollToPage(this._currentPageIndex); //滚动到指定百分比位置
        }, 0.1); //延迟到滚动区设置完毕(不延迟会出现页面一直在第1页)

        this.scrollViewNode.on("scrolling", function(){ //滚动中事件
            if(this._only3 && !this._first){
                this._only3 = false;
                this._startOffset = this.scrollViewContentNode.x;
            }
        }, this);
        this.scrollViewNode.on("scroll-ended", function(){ //滚动结束事件
            if(this._only2 && !this._first){
                this._only2 = false;
                this.scrollToTarget();
            }
        }, this);
    },


    scrollToTarget: function(){
        this._endOffset = this.scrollViewContentNode.x;
        var t = Math.ceil(Math.abs(this._endOffset)) % 700;
        if(t >= 0 && t <= 10){ //太小的滚动，直接忽略
            this._only2 = true;
            this._only3 = true;
            return;
        }
        this._direction = this._endOffset - this._startOffset < 0 ? 1 : 2;
        if(this._direction == 1){ //向左
            this._currentPageIndex = this._currentPageIndex + 1 <= (this._pageCount - 1) ? (this._currentPageIndex + 1) : this._pageCount - 1; 
        }else if(this._direction == 2){ //向右
            this._currentPageIndex = this._currentPageIndex - 1 >= 0 ? (this._currentPageIndex - 1) : 0;
        } 
        this.scrollToPage(this._currentPageIndex); //滚动到指定百分比位置 
    },

    scrollToPage: function(pageIndex){
        this._only2 = this._only3 = false;
        var percent = 0;
        if(this._pageCount == 1){ //滚动区只有1页
            return;
        }else if(this._pageCount == 2){ //滚动区只有2页
            percent = pageIndex;
        }else if(this._pageCount >= 3){ //滚动区有超过3页
            if(pageIndex == 0){ //第1页
                percent = 0;
            }else if(pageIndex == this._pageCount - 1){ //最后一页
                percent = 1;
            }else{
                percent = pageIndex / (this._pageCount - 1);
            }
        }
        //console.log("percent=" + percent);
        this.scrollViewNode.getComponent(cc.ScrollView).scrollToPercentHorizontal(percent, 0.2); //滚动到指定百分比位置 
        for(var i = 0; i < this._pageCount; i++){ 
            this.pointNode[i].getChildByName("weixuanzhongState").active = pageIndex == i ? false : true; //灰色点
        }
        this.scheduleOnce(function(){ //初始化
            this._only2 = this._only3 = true;
            this._direction = 0;
            this._first = false;
        }, 0.2);

        // console.log("页数",pageIndex);
        //每页面显示的价格不同
        switch(pageIndex){
            case 0:
                this.randomBtn.active =true;
                if(this._lotteryState){
                    this.mianfeiBtn.active =true;
                }
                this.labTitle.active =false;
                this.labPrice.string =1500;
                this.xinwuqi.active =true; //新武器提示箭头
                this.choujiangBtn.active =false;
                this.labShuoming.active =false;
                this.onWeaponNum(0);
            break; 
            case 1:
                this.randomBtn.active =true;
                if(this._lotteryState){
                    this.mianfeiBtn.active =true;
                }
                this.labTitle.active =false;
                this.labPrice.string =3000;
                this.xinwuqi.active =true; //新武器提示箭头
                this.choujiangBtn.active =false;
                this.labShuoming.active =false;
                this.onWeaponNum(1);
            break; 
            case 2:
                this.randomBtn.active =true;
                if(this._lotteryState){
                    this.mianfeiBtn.active =true;
                }
                this.labTitle.active =false;
                this.labPrice.string =6000;
                this.xinwuqi.active =true; //新武器提示箭头
                this.choujiangBtn.active =false;
                this.labShuoming.active =false;
                this.onWeaponNum(2);
            break; 
            case 3:
                this.randomBtn.active =true;
                if(this._lotteryState){
                    this.mianfeiBtn.active =true;
                }
                this.labTitle.active =false;
                this.labPrice.string =12000;
                this.xinwuqi.active =true; //新武器提示箭头
                this.choujiangBtn.active =false;
                this.labShuoming.active =false;
                this.onWeaponNum(3);    
            break;
            case 4:
                this.randomBtn.active =false;
                this.mianfeiBtn.active =false;
                this.labTitle.getComponent(cc.Label).string ="转盘获得";
                this.labTitle.active =true;   
                this.xinwuqi.active =true; //新武器提示箭头
                this.choujiangBtn.active =false;
                this.labShuoming.active =false;
            break;
            case 5:
                this.randomBtn.active =false;
                this.mianfeiBtn.active =false;
                // this.labTitle.getComponent(cc.Label).string ="活动获得";
                this.labTitle.active =false;
                this.xinwuqi.active =true; //新武器提示箭头
                //要不要显示宝刀抽奖按钮 
                if(!sdk.getConfig4().ipLimit){  //ip限制
                    if(sdk.getConfig1().hz){
                        if(cc.HQ.GameMgr.oniSshowBtn()){
                            this.choujiangBtn.active =false;
                        }else{
                            this.choujiangBtn.active =true;
                        }
                    }
                }
                this.labShuoming.active =true;
                //抽宝刀按钮
                this.onWeaponNum(4);
            break;    
            case 6:
                this.randomBtn.active =false;
                this.mianfeiBtn.active =false;
                this.labTitle.getComponent(cc.Label).string ="通关奖励";
                this.labTitle.active =true;   
                this.xinwuqi.active =false; //新武器提示箭头
                this.choujiangBtn.active =false;
                this.labShuoming.active =false;    
            break;
        }
    },

    onWeaponNum: function(num){
        this._shopKnifeArray.length =0;
        this._shopKnifeId.length =0;
        let child =this.scrollViewContentNode.children;
        switch(num){
            case 0:
                for(let i=0;i<16;i++){
                    this._shopKnifeArray.push(child[i]);
                    this._shopKnifeId.push(i+1);
                }
            break;
            case 1:
                for(let i=16;i<32;i++){
                    this._shopKnifeArray.push(child[i]);
                    this._shopKnifeId.push(i+1);
                }
            break;
            case 2:
                for(let i=32;i<48;i++){
                    this._shopKnifeArray.push(child[i]);
                    this._shopKnifeId.push(i+1);
                }
            break;
            case 3:
                for(let i=48;i<64;i++){
                    this._shopKnifeArray.push(child[i]);
                }
                for(let i=65;i<81;i++){
                    this._shopKnifeId.push(i+1);
                }
            break;
            case 4:
                this._shopKnifeArray.push(child[80]);
                for(let i=82;i<96;i++){
                    this._shopKnifeArray.push(child[i]);
                }
                this._shopKnifeId.push(65);
                for(let i=82;i<96;i++){
                    this._shopKnifeId.push(i+1);
                }
            break;
        }
    },

    //显示飞刀信息
    onDetailInfo: function(data){
        //飞镖图片显示
        cc.HQ.GameMgr.onReplaceKnife(this.selectKnifeIcon,data);
    },

    //将已拥有的飞刀数，用数组来表示下
    onMyselfShow: function(){
        let ownBall =cc.HQ.GameMgr.getKnife();
        ownBall =cc.HQ.GameMgr.onChangeData(ownBall);
        return ownBall;
    },

    //1500随机获得飞刀按钮
    onRandomGet: function(){
        if(Number(cc.HQ.GameMgr.getGold())< Number(this.labPrice.string)){
            cc.HQ.Global.showTips(2,"金币不足!",0.1);
            return;
        }
        this.onRandom(1,false); 
    },

    onRandom: function(type,state){
        this.noClickNode.active =true;  //开启屏蔽层
        let ownBall =this.onMyselfShow();
        console.log("OWN我拥有的",ownBall,this._shopKnifeArray.length,this._shopKnifeId);

        // for(let i=0;i<this._shopKnifeArray.length;i++){
        //     // console.log("商城此页面有的武器",this._shopKnifeArray[i]);
        // }
        for (let i = 0; i < ownBall.length; i++) {
            let tempNumber = ownBall[i];
            for (let j = 0; j < this._shopKnifeId.length; j++) {
                if(this._shopKnifeId[j] == tempNumber) { 
                    this._shopKnifeId.splice(j, 1);
                    this._shopKnifeArray.splice(j, 1);
                    break;
                }
            }
        }
        console.log("商城可抽武器去重",this._shopKnifeArray.length,this._shopKnifeId.length);
        if(!this._shopKnifeArray.length){
            cc.HQ.Global.showTips(2,"此页武器皮肤你均已拥有!",0.3);
            this.noClickNode.active =false;  //关闭屏蔽层
            return
        }else{
            if(type ==1){
                let curGold =Number(cc.HQ.GameMgr.getGold()) - Number(this.labPrice.string);
                this.labGold.string =curGold; //显示用户剩余金币数  金币存入本地
                cc.HQ.GameMgr.setGold(curGold);
            }
        }

        let ballShopArray = this._shopKnifeArray;
        let randomRange = this._shopKnifeId.length;
        for (let i = 0; i < 20; i++) {
            let randomNumber = Math.floor(Math.random() * randomRange);
            console.log("####randomNumber",randomNumber);
            let tempBall =null;
            tempBall = ballShopArray[randomNumber];
            if (tempBall) {
                if (i != 19) {
                    this.scheduleOnce(() => {
                        // tempBall.getChildByName("randomFlice").runAction(cc.sequence(
                        //     cc.fadeIn(0.075),
                        //     cc.fadeOut(0.075)
                        // ))
                        tempBall.runAction(cc.sequence(
                            cc.scaleTo(0.075, 1.2, 1.2),
                            cc.scaleTo(0.075, 1, 1)
                        ))
                    }, i * 0.15)
                }
                else {
                    this.scheduleOnce(() => {
                       
                        this.getBall(this._shopKnifeId[randomNumber],state);
                      
                        for (let j = 0; j < 10; j++) {
                            this.scheduleOnce(() => {
                                tempBall.getChildByName("maskNode").active =false;
                                tempBall.getChildByName("kuang0").active =true;
                                tempBall.getChildByName("kuang2").active =true;
                                
                                // tempBall.getChildByName("kuang2").runAction(cc.sequence(
                                //     cc.fadeIn(0.05),
                                //     cc.fadeOut(0.05)
                                // ))
                            }, j * 0.1)
                        }
                    }, i * 0.15)
                }
            }
        }
    },

    //选中的飞刀
    getBall: function(id,state){
        this.noClickNode.active =false;  //关闭屏蔽层
        //已获得的飞刀
        let arr =cc.HQ.GameMgr.getKnife();
        arr =cc.HQ.GameMgr.onChangeData(arr);
        console.log("选中的飞刀",id,arr);
        arr.push(id);
        cc.HQ.GameMgr.setKnife(arr);
        console.log("已购买嘤嘤嘤",arr);
        //当拥有了这些宝刀后，宝刀抽奖按钮就隐藏
        //要不要显示宝刀抽奖按钮
        if(!sdk.getConfig4().ipLimit){  //ip限制
            if(sdk.getConfig1().hz){
                if(state){
                    if(cc.HQ.GameMgr.oniSshowBtn()){
                        this.choujiangBtn.active =false;
                    }else{
                        this.choujiangBtn.active =true;
                    }
                }
            }
        }
        //当前装备的飞刀皮肤
        cc.HQ.GameMgr.setCurKnife(id);

        //在商城抽奖更换新武器后，体验皮肤次数清空
        cc.HQ.Local.weaponSkin =0;
        
        this.onEquipSkin(id);

        let data =TableReader.getTableRowByNum("knifeItems",id);
        this.onDetailInfo(data);
    },

    //将随机已获得的飞刀装备起来
    onEquipSkin: function(id){
        console.log("随机已获得id",id);
        let child =this.scrollViewContentNode.children;
        for(var j in child){
            if(child[j].getChildByName("kuang2").active){
                child[j].getChildByName("kuang0").active =true;
                child[j].getChildByName("kuang2").active =false;
                if(child[j].getChildByName("labTime").getComponent(cc.Label).string =="体验中"){   //"体验中"文本隐藏
                    child[j].getChildByName("labTime").active =false;
                    child[j].getChildByName("kuang0").active =false;
                }
            }
        }
    },


    //免费抽奖按钮
    onReward: function(){
        //分享或视频模式
        cc.HQ.GameMgr.shareOrVideo(sdk.getConfig2().model.v3,this.onVideo,this.onShare,2);
        //埋点
        sdk.setSceneEvent("商城","点击","免费领取抽奖按钮",{},null);
    },

    //看3次视频，抽宝刀按钮
    onChoujiangBtn: function(){
        //观看视频
        cc.HQ.GameMgr.onShopChoujiang(this.onVideo1);
        //埋点
        sdk.setSceneEvent("商城","点击","活动皮肤-免费领取按钮",{},null);
    },

    //退出商城界面
    onClose: function(){
        this.node.active =false;   //隐藏商城界面节点
        if(!this._state){
            this.homePageUI.active =true;
            if(!sdk.getConfig4().ipLimit){  //ip限制
                if(sdk.getConfig1().hz){
                    this.moreGameUI.active =true;  //显示更多游戏面板
                }
            }
            //显示投诉按钮
            cc.HQ.GameMgr.feedbackButtonShow();
        }else{
            //在商城中更换了皮肤，加到游戏中刷新皮肤
            this.lauchNodeUI.getComponent("lauchNodeUI").onCheckSkin();
        }
        //显示banner广告
        var bannerAd = sdk.createBannerAd({});
        bannerAd.show();
    },

    //调视频
    onVideo: function(data,type,isValue){
        sdk.videoSuccess = function(){
            //视频成功处理逻辑
            var storeJS =cc.find("Canvas").getChildByName("storeUI").getComponent("storeUI");
            console.log("免费抽奖%%%%%%",data);
            if(data ==3){
                storeJS.mianfeiBtn.active =false;
                storeJS._lotteryState =false;
            }else{
                storeJS.labNum.string =3-data;
            }
            storeJS.onRandom(0,false);

            if(type =="cycle1"){
                if(isValue){
                    cc.HQ.dConf.sv.type ="share";
                }
                storeJS.videoIcon.active =false;
            }else if(type =="cycle2"){
                if(isValue){
                    cc.HQ.dConf.sv.type ="video";
                }
                storeJS.videoIcon.active =true;
            }else if(type =="cycle3"){
                if(isValue){
                    cc.HQ.dConf.sv1.type ="video";
                }
                storeJS.videoIcon.active =true;
            }else if(type =="cycle4"){
                if(isValue){
                    cc.HQ.dConf.sv1.type ="share";
                }
                storeJS.videoIcon.active =false;
            }
            var time = sdk.formatTime(new Date(),"date","");
            sdk.setToServer("LotteryKey"+time,"LotteryData",data,86400);
        }.bind(this);
        sdk.videoFail = function(){
            //视频失败处理逻辑
            console.log("视频未看完");
        };
        var videoAd = sdk.createRewardedVideoAd(sdk.getConfig2().videoIdArr[0]);
        videoAd.load().then(() => videoAd.show());
    },

    onShare: function(data,type,isValue){
       
        sdk.shareAppMessage({type:5,query:""});
        let shareFun5 =function(){
            var storeJS =cc.find("Canvas").getChildByName("storeUI").getComponent("storeUI");
            console.log("免费抽奖%%%%%%",data);
            if(data ==3){
                storeJS.mianfeiBtn.active =false;
                storeJS._lotteryState =false;
            }else{
                storeJS.labNum.string =3-data;
            }
            storeJS.onRandom(0,false); 
    
            if(type =="cycle1"){
                if(isValue){
                    cc.HQ.dConf.sv.type ="share";
                }
                storeJS.videoIcon.active =false;
            }else if(type =="cycle2"){
                if(isValue){
                    cc.HQ.dConf.sv.type ="video";
                }
                storeJS.videoIcon.active =true;
            }else if(type =="cycle3"){
                if(isValue){
                    cc.HQ.dConf.sv1.type ="video";
                }
                storeJS.videoIcon.active =true;
            }else if(type =="cycle4"){
                if(isValue){
                    cc.HQ.dConf.sv1.type ="share";
                }
                storeJS.videoIcon.active =false;
            }
            var time = sdk.formatTime(new Date(),"date","");
            sdk.setToServer("LotteryKey"+time,"LotteryData",data,86400);
        }
        cc.HQ.GameMgr.clickShare =true;
        cc.HQ.GameMgr.shareNum7++;
        cc.HQ.GameMgr.onSimulateShareBack(shareFun5,7);
    },

    //调视频
    onVideo1: function(){
        sdk.videoSuccess = function(){
            //视频成功处理逻辑
            var storeJS =cc.find("Canvas").getChildByName("storeUI").getComponent("storeUI");
        
            let fuhuoka =cc.HQ.GameMgr.getChoujiangNum();
            fuhuoka =Number(fuhuoka)+1;
            console.log("宝刀抽奖次数",fuhuoka); 
            cc.HQ.GameMgr.setChoujiangNum(fuhuoka);
            if(fuhuoka ==3){
                //次数请空
                fuhuoka =0;
                cc.HQ.GameMgr.setChoujiangNum(fuhuoka);
                //视频3次已达到，随机抽取一把宝刀
                storeJS.onRandom(0,true);
            }
            storeJS.labNumber.string = fuhuoka+"/"+3;
            
        }.bind(this);
        sdk.videoFail = function(){
            //视频失败处理逻辑
            console.log("视频未看完");
        };
        var videoAd = sdk.createRewardedVideoAd(sdk.getConfig2().videoIdArr[0]);
        videoAd.load().then(() => videoAd.show());
    },

    //抽宝刀，只会看视频，这辈子都不可能进行分享获得 （策划说的）
    onShare1: function(data,type,isValue){

    },

    // update (dt) {},
});
