//处理游戏逻辑脚本

module.exports = {
    isInitGame: false,  //游戏是否初始化完成
    isGameOver: false,  //游戏是否结束
    fruitPointPool: null,   // 对象池
    fruitPool1: null,  //水果对象池
    fruitPool2: null,  //水果对象池
    fruitPool3: null,  //水果对象池
    fruitPool4: null,  //水果对象池
    fruitPool5: null,  //水果对象池
    fruitPool6: null,  //水果对象池
    fruitPool7: null,  //水果对象池
    fruitPool8: null,  //水果对象池
    fruitPool9: null,  //水果对象池
    fruitPool10: null,  //水果对象池 
    fruitPool11: null,  //金水果对象池
    FeedbackButton: null,  //
    shareTicket: null,  //群分享时的shareTicket
    isReward: false,
    recordStartTime: 0,  //调起分享记录的时间
    recordEndTime: 0,  //分享完成记录的时间
    clickShare: false,  //是否是分享点击
    shareNum: 0, //分享的次数
    shareNum1: 0, //分享的次数
    shareNum2: 0, //分享的次数
    shareNum3: 0, //分享的次数
    shareNum4: 0, //分享的次数
    shareNum5: 0, //分享的次数
    shareNum6: 0, //分享的次数
    shareNum7: 0, //分享的次数
    shareNum8: 0, //分享的次数
    clickShiwan: false, //是否是试玩点击
    shiwanGameSysid: null,  //试玩游戏id
    bdtips: true,//屠龙刀用完提示
    gzhAppid: null,  //公众号的appid

    navAppData: null,//可跳转的小程序列表数据
    curFloatApp: parseInt(Math.random() * 5),//当前浮动跳转小程序数据index
    curLikeApps: [0,1,2,3],//当前猜你喜欢的小程序数据index数组

    launchNum: 0, //每关发送的武器次数
    isACut: false,  //是否是一刀切
    // isShareSuccess: false,  //分享是否成功

    /**
     * 从res资源加载
     * 
     */
    loadRes(path, parent, position = cc.v2(0, 0)){
        return new Promise((resolve , reject) => {
            cc.loader.loadRes(path,function(err,prefab){
                if (err) {
                    console.error(err.message || err);
                    reject(err);
                    return;
                }
                var go = cc.instantiate(prefab)
                go.parent = parent
                go.position = position;
                resolve(go);
            })
        })
    },
    /**
     * 获取当前浮动跳转小程序数据
     */
    getCurFloadAppData(){
        if(this.navAppData){
            let result = this.navAppData[this.curFloatApp];
            this.curFloatApp = this.curFloatApp > this.navAppData.length-2 ? 0 : this.curFloatApp+1;
            return result;
        }else{
            return null;
        }
    },
    /**
     * 返回匹配appid的数据
     * @param {*} appId 
     */
    getAppDataByAppid(appId){
        let temp = this.navAppData.filter(item=>{
            return item.appId == appId;
        })
        return temp[0];
    },
    /**
     * 获取当前猜你喜欢的小程序数据
     */
    getCurLikeAppData(){
        if(this.navAppData){
            let result = this.curLikeApps.map(item=>{
                return this.navAppData[item];
            });
            let tempLen = this.curLikeApps.length;
            let tempArr = [];
            for (const iterator of this.curLikeApps) {
                let newIndex = iterator+tempLen;
                if(newIndex > this.navAppData.length-1){
                    tempArr.push(newIndex - this.navAppData.length)
                }else{
                    tempArr.push(newIndex);
                }
            }
            this.curLikeApps = tempArr;
            return result;
        }else{
            return null;
        }
    },
    /**
     * 可跳转的小程序列表数据
     */
    getNavAppData(){
        let self = this;
        return new Promise((resolve ,reject) => {
            if (cc.sys.platform === cc.sys.WECHAT_GAME) {
                sdk.Post(sdk.ip2+"/tuijian/box",{},function(data){
                    console.log("左边游戏",data);
                    if(!data){
                        reject('request fail or response null');
                        return;
                    }
                    self.navAppData =data.d;
                    resolve('ok');
                })
            }else{
                reject('not wechat');
            }
        })
    },

    //水果对象池
    createFruit: function () {
        this.fruitPointPool =new cc.NodePool("fruitPointPool");
        this.fruitPool1 =new cc.NodePool("fruitPool1");
        this.fruitPool2 =new cc.NodePool("fruitPool2");
        this.fruitPool3 =new cc.NodePool("fruitPool3");
        this.fruitPool4 =new cc.NodePool("fruitPool4");
        this.fruitPool5 =new cc.NodePool("fruitPool5");
        this.fruitPool6 =new cc.NodePool("fruitPool6");
        this.fruitPool7 =new cc.NodePool("fruitPool7");
        this.fruitPool8 =new cc.NodePool("fruitPool8");
        this.fruitPool9 =new cc.NodePool("fruitPool9");
        this.fruitPool10 =new cc.NodePool("fruitPool10");
        this.fruitPool11 =new cc.NodePool("fruitPool11");
    },

    //对应种类水果用对应的水果对象池存储
    recyleKindFruit: function(num){
        let fruitPre =null;
        switch(num){
            case 0:
                fruitPre =this.fruitPool1;
            break;
            case 1:
                fruitPre =this.fruitPool2;
            break;
            case 2:
                fruitPre =this.fruitPool3;
            break;
            case 3:
                fruitPre =this.fruitPool4;
            break;
            case 4:
                fruitPre =this.fruitPool5;
            break;
            case 5:
                fruitPre =this.fruitPool6;
            break;
            case 6:
                fruitPre =this.fruitPool7;
            break;
            case 7:
                fruitPre =this.fruitPool8;
            break;
            case 8:
                fruitPre =this.fruitPool9;
            break;
            case 9:
                fruitPre =this.fruitPool10;
            break;
        }
        return fruitPre;
    },

    //使手机发生振动
    shortPhoneShake: function(){  
        wx.vibrateShort({
            success:function(){//function 	否 	接口调用成功的回调函数 	
                console.log("调用手机振动功能成功");
            },
            fail:function(){  //function 	否 	接口调用失败的回调函数 	
                console.log("调用手机振动功能失败");
            },
            complete:function(){  //function 	否 	接口调用结束的回调函数（调用成功、失败都会执行）
                console.log("调用手机振动功能结束");
            }       
        });
    },

    //意见反馈页面createFeedbackButton
    createFeedbackButton: function(disLeft,disTop,banWidth,banHeight){
        let myleft = disLeft?disLeft:0;
        let mytop = disTop?disTop:0;
        let mywidth = banWidth?banWidth:0;
        let myheight = banHeight?banHeight:0;
        if(!this.FeedbackButton){
            this.FeedbackButton = wx.createFeedbackButton({
                type: 'image',
                image: "",
                style: {
                    left: myleft,
                    top: mytop,
                    width: mywidth,
                    height: myheight,
                    color: '#ffffff',
                    textAlign: 'center',
                }
            });
        }
    },

    //投诉意见按钮 显示
    feedbackButtonShow: function(){
        if(!sdk.getConfig4().ipLimit){  //ip限制
            if(sdk.getConfig1().sns){
                if (cc.sys.platform == cc.sys.WECHAT_GAME) {
                    if(this.FeedbackButton){
                        this.FeedbackButton.show();
                    }else{
                        var w  = wx.getSystemInfoSync().screenWidth;
                        var h  = wx.getSystemInfoSync().screenHeight;

                        let moni_w = parseInt(h/1334*750);
                        //  let realLeft = parseInt(((w*84)/320));
                        let realLeft = 0;
                        var diff_w = Math.abs(parseInt(moni_w - w)/2);
                        console.log("width:"+w+";height:"+h+"moni_w"+moni_w+"diff_w"+diff_w);
                        if(moni_w>=w){
                            realLeft = parseInt(((moni_w*140)/750)-diff_w);
                        }else{
                            realLeft = parseInt(((moni_w*140)/750)+diff_w);
                        }
                        
                        let realTop = parseInt(((h*903)/1334));
                        let realWidth = parseInt(((h*123)/1334));
                        let realHeight = parseInt(((h*123)/1334));
                        // console.log("w:"+w+",h:"+h+",rl:"+realLeft+",realTop:"+realTop+",rw:"+realWidth+";rh:"+realHeight);
                        this.createFeedbackButton(realLeft,realTop,realWidth,realHeight);
                        this.FeedbackButton.show();   
                    }
                }    
            }
        }
    },

    //投诉意见按钮 隐藏
    feedbackButtonHide: function(){
        if(!sdk.getConfig4().ipLimit){  //ip限制
            if(sdk.getConfig1().sns){
                this.FeedbackButton.hide();
            }   
        }        
    },

    //视频与分享切换(6种模式)
    onCheckModel: function(num){
        let state =null;
        switch(num){
            case 1:   //全视频
                state =1;
            break;
            case 2:   //全分享
                state =2;
            break;
            case 3:   //视频-分享-视频-分享……
                state =3;
            break;
            case 4:   //分享-视频-分享-视频……
                state =4;
            break;
            case 5:   //0点到10点，只视频，10点到24点“视频-分享-视频-分享（循环）
                // let start = new Date(new Date().toLocaleDateString()).getTime();   //当天0点
                // let middle = new Date(new Date().toLocaleDateString()).getTime() +10 * 60 * 60 * 1000;   //当天10点
                // // let end = new Date(new Date().toLocaleDateString()).getTime() +24 * 60 * 60 * 1000 -1000  //当天24点
                // let date =Date.now();   //当天的当前时间
                // if(date>=start && date<=middle){
                //     state =1;
                // }else{
                //     state =3;
                // }
                //---------视频-视频-视频...视频播放完，切换分享
                state =5;
            break;
            case 6:   //关闭
                state =6;
            break;
        }
        return {"stateNum":state};
    },

    //视频或分享模式切换
    shareOrVideo: function(modelNum,videoFun,shareFun,typeNum){
        let obj =this.onCheckModel(modelNum);
        if(obj.stateNum ==6){  //当state为5时，弹提示框
            this.systemTips(false);
            // this.isReward =false;
            return;
        }
        let func =function(d){
            console.log("模式切换-返回",d);
            let data =null;
            if(!d){   //为undefined时，表示没有数据
                data ={"shareTick":1};
            }else{
                data ={"shareTick":(Number(d)+1)};
            }

            console.log("模式切换-1",obj.stateNum);
            switch(obj.stateNum){
                case 1:  //视频
                    videoFun(data.shareTick,"nocycle");
                break; 
                case 2:  //分享
                    shareFun(data.shareTick,"nocycle");
                break; 
                case 3:  //视频-分享-视频-分享……
                    // console.log("模式切换-3",data.shareTick);
                    if(cc.HQ.dConf.sv.type =="video"){
                        if(data.shareTick-1 <cc.HQ.dConf.videoCount*2){
                            videoFun(data.shareTick,"cycle1",true);
                        }else{
                            shareFun(data.shareTick,"cycle1",true);    
                        }
                    }else{
                        if(data.shareTick-1 <cc.HQ.dConf.shareCount*2){
                            shareFun(data.shareTick,"cycle2",true);
                        }else{
                            videoFun(data.shareTick,"cycle2",true);
                        }
                    }
                break; 
                case 4:  //分享-视频-分享-视频……
                    // console.log("模式切换444444444444",data.shareTick,data.shareTick-1);
                    if(cc.HQ.dConf.sv1.type =="share"){
                            // console.log("视频次数用完111111111",cc.HQ.dConf.shareCount*2,data.shareTick);
                        if(data.shareTick-1 <cc.HQ.dConf.shareCount*2){
                            shareFun(data.shareTick,"cycle3",true);
                        }else{
                            videoFun(data.shareTick,"cycle3",true);
                        }
                    }else{
                        // console.log("视频次数用完666666666",cc.HQ.dConf.videoCount*2,data.shareTick);
                        if(data.shareTick-1 <cc.HQ.dConf.videoCount*2){
                            videoFun(data.shareTick,"cycle4",true);
                        }else{
                            shareFun(data.shareTick,"cycle4",true);
                        }
                    }
                break;    
                case 5:
                    // console.log("模式5555555555555555555555");
                    if(cc.HQ.dConf.sv2.type =="video"){
                        if(data.shareTick-1 <cc.HQ.dConf.videoCount*2){
                            videoFun(data.shareTick,"cycle1");
                        }else{
                            shareFun(data.shareTick,"cycle1");
                        }
                    }else{
                        if(data.shareTick-1 <cc.HQ.dConf.shareCount*2){
                            shareFun(data.shareTick,"cycle2");
                        }else{
                            videoFun(data.shareTick,"cycle2");
                        }
                    }
                break;
                    
            }
        }.bind(this);
        if(typeNum ==1){
            sdk.getFromServer("VideoOrShareKey1","VideoOrShareData1",null, (d) => {func(d)});
        }else{
            var time = sdk.formatTime(new Date(),"date","");
            sdk.getFromServer("LotteryKey"+time,"LotteryData",null,(d) => {func(d)});  
        }
    },

    //视频/分享，是视频时按钮上要显示视频图标
    onShareVideoState: function(modelNum,typeNum){
        let obj =this.onCheckModel(modelNum);
        let state =null;
        switch(obj.stateNum){
            case 1:  //视频
                state =true;
            break; 
            case 2:  //分享
                state =false;
            break; 
            case 3:
                if(cc.HQ.dConf.sv.type =="video"){
                    state =true;
                }else{
                    state =false; 
                }
            break;
            case 4:
                if(cc.HQ.dConf.sv1.type =="share"){
                    state =false;
                }else{
                    state =true;
                }
            break;
            case 5:
                if(cc.HQ.dConf.sv2.type =="video"){
                    state =true;
                }else{
                    state =false;
                }
            break;
        }  
        return state;
    },

    //弹系统默认弹窗
    systemTips: function(type){
        wx.showModal({
            title: type?"分享失败":"温馨提示",
            content: type?'1小时内不要分享到同一个群哦':'已达当日次数上限',
            success: function(res) {
              if (res.confirm) {
                console.log('用户点击确定');
              } else if (res.cancel) {
                console.log('用户点击取消');
              }
            }
        });
    },

    //获取群ID
    onGroupID: function(Tickets,succFun){
        wx.getShareInfo({
            shareTicket: Tickets,
            success: function(data) {
                console.log("群id成功",data);
                var func =function(d){
                    console.log("次次次次次",d);
                    if(d){   //为undefined时，表示没有数据,反之就是有数据
                        this.systemTips(true);
                        // this.isReward =false;
                        return;
                    }else{
                        sdk.setToServer("ShareGroupKey","ShareGroupData",data,3600);
                    }
                    //执行回调函数
                    succFun();
                }.bind(this);
                sdk.getFromServer("ShareGroupKey","ShareGroupData",data,func);
            }.bind(this),
            fail: function() {
                console.log('群id失败');
            },
            complete: function() {
                console.log('正在获取群id');
            }
        });    
    },

    //用户金币记录
    getGold: function() {
        var goldNum = cc.sys.localStorage.getItem('gold') || 0;
        return goldNum;
    },
    
    setGold: function(goldNum) {
        cc.sys.localStorage.setItem('gold', goldNum);
    },

    //用户拥有的飞刀数记录
    getKnife: function(){
        var knifeArr = cc.sys.localStorage.getItem('knife') || ["1"];
        console.log("用户拥有的飞刀",knifeArr);
        return knifeArr;
    },

    setKnife: function(knifeArr){
        cc.sys.localStorage.setItem('knife', knifeArr);
    },

    //用户装备的飞刀记录
    getCurKnife: function(){
        var curKnifeNum = cc.sys.localStorage.getItem('curKnife') || 1;
        console.log("用户当前装备的飞刀", curKnifeNum);
        return curKnifeNum;
    },

    setCurKnife: function(curKnifeNum){
        cc.sys.localStorage.setItem('curKnife', curKnifeNum);
    },

    //更换飞刀图片
    onReplaceKnife: function(sp,skin){
        if(skin){
            // console.log("skinskin",skin);
            cc.loader.loadRes(skin.icon ,cc.SpriteFrame, function (err, spriteFrame) {
            sp.spriteFrame = spriteFrame;
            }); 
        }   
    },

    //用户过的关卡数
    getPassNum: function(){
        var passNum = cc.sys.localStorage.getItem('pass') || 1;
        return passNum;
    },

    setPassNum: function(passNum){
        cc.sys.localStorage.setItem('pass', passNum);
    },

    //用户拥有的复活卡数
    getFuhuoNum: function(){
        var fuhuoNum = cc.sys.localStorage.getItem('fuhuo') || 0;
        return fuhuoNum;
    },

    setFuhuoNum: function(fuhuoNum){
        cc.sys.localStorage.setItem('fuhuo',fuhuoNum);
    },

    //用户是否点击看过公告
    getNotice: function(noticeId){
        var noticeNum = cc.sys.localStorage.getItem(noticeId) || 0;
        return noticeNum;
    },

    setNotice: function(noticeId){
        cc.sys.localStorage.setItem(noticeId,Number(noticeId));
    },

    //屠龙刀  使用时间还剩多久
    getBaodaoTime: function(){
        var baodaoTime = cc.sys.localStorage.getItem('baodaoTime') || 0;
        return baodaoTime;
    },

    setBaodaoTime: function(time){
        cc.sys.localStorage.setItem('baodaoTime',time);
    },

    //宝刀抽奖 （视频看的次数记录,满3次就可以抽一把随机宝刀）
    getChoujiangNum: function(){
        var choujiangNum = cc.sys.localStorage.getItem('choujiangNum') || 0;
        return choujiangNum;
    },

    setChoujiangNum: function(num){
        cc.sys.localStorage.setItem('choujiangNum',num);
    },

    //当前装备的飞刀皮肤 (屠龙刀皮肤与其他皮肤)
    onSetCurrSkin: function(){
        let baodaoTime =cc.HQ.GameMgr.getBaodaoTime();
        let curDate =Date.now();   //当天的当前时间
        let userCurWeapan =cc.HQ.GameMgr.getCurKnife();  //当前装备的飞刀
        let curSkin =null;
        // console.log("当前装备的飞刀皮肤",Number(curDate -Number(baodaoTime)));
        if(Number(curDate -Number(baodaoTime)) > 60000){   //屠龙刀使用时间就算用完了
            if(Number(userCurWeapan) ==82){
                curSkin =1;   //经典皮肤
            }else{
                curSkin =Number(userCurWeapan);   //当前是什么皮肤就显示对应皮肤
            }
        }else{
            curSkin =Number(userCurWeapan);
        }
        return curSkin;
    },


    //**************** 右上角分享  子域 ************************* */
    showShareMenu: function(){
        var tmp_data = wx.getLaunchOptionsSync();
        console.log('这是群分享进来的',tmp_data);
        if(tmp_data.referrerInfo){
            this.gzhAppid =tmp_data.referrerInfo.appId;
        }
        if( tmp_data.scene == 1007 || tmp_data.scene == 1008 || typeof(tmp_data.query)!="undefined" ){
            this.shareTicket =tmp_data.shareTicket?tmp_data.shareTicket:'';
            // WechatApi.query       =tmp_data.query;
        }
        //设置点转发时的提示内容
        sdk.onShareAppMessage({type:0,query:""});

        //获取手机的相关信息
        // this.getSystemInfo();    
    },

    //设置子域的信息openid和群分享的ticket  头像地址
    set_sub_info:function(){
        var data = {
            'type':'SaveUserInfo',
            'openid': sdk.getUser().openid,
            "imgUrl": sdk.getUser().avatarUrl,
            "name": sdk.getUser().nickName,
            'ticket':this.shareTicket
        };
        this.send_data_to_sub(data);
    },

    send_data_to_sub:function(mydata){
        var openDataContext = wx.getOpenDataContext();
        openDataContext.postMessage(mydata);
    },

    //主域向子域发送排行榜请求  (获取排行榜信息)
    //好友排行榜
    onFriendRankReq: function(typeNum,score){
        //好友排行榜
        var mydata = {
            type:'FriendCloud',
            data:'',
            key:['score'],
            num:typeNum,
            curLevel:score
        };
        this.send_data_to_sub(mydata);
    },

    //群排行榜
    onGroupRankReq: function(n,score){
        //群排行榜
        var mydata ={
            type:'GroupCloud',
            data: this.shareTicket? this.shareTicket:'',
            key:['score'],
            num:n,
            curScore:score
        };
        this.send_data_to_sub(mydata);
    },

    //本地上传要保存的数据  (上传给微信)
    setUserCloudStorage:function (levelNum) {
        console.log("上传",levelNum);
        if (cc.sys.platform == cc.sys.WECHAT_GAME) {
            var KVDataList = [{key: "score", value: String(levelNum)}];
            wx.setUserCloudStorage({
                KVDataList: KVDataList,
                success(res) {
                    // console.log("保存数据成功");
                    console.log("记录已保存",levelNum);
                },
                fail(res) {
                    console.log("上传失败");
                }
            });
            
        }
    },

    //按钮不可点击时，置灰按钮
    tureToashBtn: function(node,num){
        if(num ==1){
            node.color =new cc.Color(114,114,114,255);
        }else{
            node.color =new cc.Color(255,255,255,255);
        }
    },

    //从本地取用户已拥有的武器数据是字符器string, 然后将字符串转成数组，再将数组元素string类型变成number类型
    onChangeData: function(arr){
        if(typeof(arr)=="string"){
            arr =arr.split(",");
        }
        console.log("onChangeData",arr);
        for(var i=0;i<arr.length;i++){
            if(typeof(arr[i]) =="string"){
                arr[i] =Number(arr[i]);
            }
        } 
        return arr;
    },

    backFun : null,  
    tempNum: null,  
    //模拟分享回调
    onSimulateShareBack: function(shareFun,num){
        this.backFun = shareFun;
        this.tempNum = num;
        wx.onHide(() =>{
            this.hideBack();
        });

        wx.onShow(() => {
            this.showBack();
        });
    },

    hideBack(){
        //调起分享后触发一次小游戏onHide就开始打点记录
        let date =Date.now();   //获取当前打点的记录时间
        this.recordStartTime =date;
        // console.log("触发小游戏onHide",this.recordStartTime);    
    },

    showBack(){
        let date =Date.now();   //获取当前打点的记录时间
        this.recordEndTime =date;
        // console.log("触发小游戏onShow");
        if((this.recordEndTime-this.recordStartTime <sdk.getConfig2().successDiff) &&  cc.HQ.GameMgr.clickShare){
            // console.log("分享失败");
            cc.HQ.GameMgr.clickShare =false;
            this.recordEndTime =0;
            this.recordStartTime =0;
            //开启地区IP分享就领取
            if(sdk.getConfig4().cityLimit==1){
                //分享成功 调用api记录分享数据
                if(this.backFun){
                    this.backFun();
                }
                // console.log("sdk 限制城市分享成功回调");
            }else{
                //分享提示
                cc.HQ.Global.showTips(2,sdk.getConfig2().toast,0.8);
            }
        }else if((this.recordEndTime-this.recordStartTime >=sdk.getConfig2().successDiff) &&  cc.HQ.GameMgr.clickShare){
            // console.log("成功成功成功成功成功成功",this.tempNum);    
            cc.HQ.GameMgr.clickShare =false;
            this.recordEndTime =0;
            this.recordStartTime =0;
            
            if(sdk.getConfig2().isOpenProb){   //分享时开启概率判断
                if(this.onShareNumManage()){
                    let ran =Math.random();
                    // console.log("随机概率随机概率",ran,sdk.getConfig2().prob);
                    let isOpen = ran>=sdk.getConfig2().prob ? 1 :0;
                    if(isOpen){
                        if(this.backFun){
                            this.backFun();
                        }
                    }else{
                        cc.HQ.Global.showTips(2,sdk.getConfig2().toast,0.8);
                    }
                }else{
                    this.onShareNumReset();
                    if(this.backFun){
                        this.backFun();
                    }    
                }
            }else{
                if(this.backFun){
                    this.backFun();
                }       
            }
        }
        
        this.backFun =null;
        this.tempNum =null;

        // setTimeout(()=>{
        //     if(!cc.HQ.GameMgr.isShareSuccess){
        //         // console.error("分享成功!!!",cc.HQ.GameMgr.isShareSuccess);
        //         //分享成功 调用api记录分享数据
        //         if(this.backFun){
        //             this.backFun();
        //         }  
        //         // console.error("分享成功!!!3333",cc.HQ.GameMgr.isShareSuccess);
                
        //     }else{
        //         cc.HQ.GameMgr.isShareSuccess =false;
        //         // console.error("分享失败!!!222",cc.HQ.GameMgr.isShareSuccess);
                
        //     } 
            
        //     this.backFun =null;
        //     this.tempNum =null;
        // },100);

    },

    //分享次数记录处理
    onShareNumManage: function(){
        let state =null;
        switch(this.tempNum){
            case 0:
                state =this.shareNum ==1 ? true : false;
            break;
            case 1:
                state =this.shareNum1 ==1 ? true : false;
            break;
            case 2:
                state =this.shareNum2 ==1 ? true : false;
            break;
            case 3:
                state =this.shareNum3 ==1 ? true : false;
            break;
            case 4:
                state =this.shareNum4 ==1 ? true : false;
            break;
            case 5:
                state =this.shareNum5 ==1 ? true : false;
            break;
            case 6:
                state =this.shareNum6 ==1 ? true : false;
            break;
            case 7:
                state =this.shareNum7 ==1 ? true : false;
            break;
            case 8:
                state =this.shareNum8 ==1 ? true : false;
            break;
        }
        return state;
    },

    //当分享次数达到2次，重置为0
    onShareNumReset: function(){
        switch(this.tempNum){
            case 0:
                this.shareNum =this.shareNum ==2 ? 0 :this.shareNum;
            break;
            case 1:
                this.shareNum1 =this.shareNum1 ==2 ? 0 :this.shareNum1;
            break;
            case 2:
                this.shareNum2 =this.shareNum2 ==2 ? 0 :this.shareNum2;
            break;
            case 3:
                this.shareNum3 =this.shareNum3 ==2 ? 0 :this.shareNum3;
            break;
            case 4:
                this.shareNum4 =this.shareNum4 ==2 ? 0 :this.shareNum4;
            break;
            case 5:
                this.shareNum5 =this.shareNum5 ==2 ? 0 :this.shareNum5;
            break;
            case 6:
                this.shareNum6 =this.shareNum6 ==2 ? 0 :this.shareNum6;
            break;
            case 7:
                this.shareNum7 =this.shareNum7 ==2 ? 0 :this.shareNum7;
            break;
            case 8:
                this.shareNum8 =this.shareNum8 ==2 ? 0 :this.shareNum8;
            break;
        }
    },

    //试玩其他游戏  
    onPlayingOtherGame: function(gameAppId,gamePath){
        if (cc.sys.platform === cc.sys.WECHAT_GAME) {
            wx.navigateToMiniProgram({
                appId: gameAppId,   // 要打开的小程序appId
                path: gamePath,   //  打开的页面路径，如果为空则打开首页
                // extraData: '',  // 需要传递给目标小程序的数据
                // envVersion:'', //特殊情况下需要跳转到对应小程序的开发版本
                success: function(res){
                    console.log("小程序跳转成功",res);
                },
                fail: function(res){
                    console.log("小程序跳转失败",res);
                },
                complete: function(){
                },
            });  
        }
    },

    //宝刀看视频次数
    onShopChoujiang: function(videoFun){
        //回调
        videoFun();
    },

    //检查当前飞刀是否要显示特效
    onCheckStarand: function(userCurWeapan){
        if(userCurWeapan ==82 ||userCurWeapan ==65 ||userCurWeapan ==83 ||userCurWeapan ==84 ||userCurWeapan ==85 ||userCurWeapan ==86
        ||userCurWeapan ==87 ||userCurWeapan ==88 ||userCurWeapan ==89 ||userCurWeapan ==90 ||userCurWeapan ==91 ||userCurWeapan ==92
        ||userCurWeapan ==93 ||userCurWeapan ==94 ||userCurWeapan ==95 ||userCurWeapan ==96 ){
            return true;
        }else{
            return false;
        }
    },

    //要不要显示宝刀抽奖按钮 
    oniSshowBtn: function(){
        let arr =this.getKnife();    //用户已拥有的飞刀
        arr =this.onChangeData(arr);
        // console.log("拥有的宝刀",arr);
        if(arr.indexOf(65) != -1 &&arr.indexOf(83) != -1 &&arr.indexOf(84) != -1 &&arr.indexOf(85) != -1 &&arr.indexOf(86) != -1 &&arr.indexOf(87) != -1
        &&arr.indexOf(88) != -1&&arr.indexOf(89) != -1 &&arr.indexOf(90) != -1 &&arr.indexOf(91) != -1 &&arr.indexOf(92) != -1 &&arr.indexOf(93) != -1
        &&arr.indexOf(94) != -1 &&arr.indexOf(95) != -1 &&arr.indexOf(96) != -1){
            // console.log("真真真");
            return true;
        }else{
            // console.log("假假假");
            return false;
        }
    },

    /**
     * 主线通关送皮肤任务 (若完成，则送皮肤);
    */
    onCheckMainTask(){
        let currentLevels = cc.HQ.Local.CurrentLevels
        let isSucc =null;
        let mainSkinId =null;
        if(currentLevels>=1 && currentLevels<=10){
            isSucc = 11 - currentLevels;
            mainSkinId =97;
        }else if(currentLevels>=11 && currentLevels<=30){
            isSucc = 31 - currentLevels;
            mainSkinId =98;
        }else if(currentLevels>=31 && currentLevels<=60){
            isSucc = 61 - currentLevels; 
            mainSkinId =99;      
        }else if(currentLevels>=61 && currentLevels<=100){
            isSucc = 101 - currentLevels;   
            mainSkinId =100;   
        }else if(currentLevels>=101 && currentLevels<=150){
            isSucc = 151 - currentLevels; 
            mainSkinId =101; 
        }else if(currentLevels>=151 && currentLevels<=200){
            isSucc = 201 - currentLevels;  
            mainSkinId =102;
        }else if(currentLevels>=201 && currentLevels<=300){
            isSucc = 301 - currentLevels;  
            mainSkinId =103;
        }else if(currentLevels>=301 && currentLevels<=500){
            isSucc = 501 - currentLevels;  
            mainSkinId =104;
        }else if(currentLevels>=501 && currentLevels<=1000){
            isSucc = 1001 - currentLevels;
            mainSkinId =105;
        }else if(currentLevels>=1001){   //1001关过后，暂无主线通关任务
            isSucc = 0;
            mainSkinId =0; 
        }

        return {"isSucc":isSucc,"mainSkinId":mainSkinId};
    },

    //主线通关任务完成
    onCheckTaskSuccess(){  
        let state =null;
        let currentLevels = cc.HQ.Local.CurrentLevels;
        switch(currentLevels){
            case 11:
                state =97;
            break;
            case 31:
                state =98;
            break;
            case 61:
                state =99;
            break;
            case 101:
                state =100;
            break;
            case 151:
                state =101;
            break;
            case 201:
                state =102;
            break;
            case 301:
                state =103;
            break;
            case 501:
                state =104;
            break;
            case 1001:
                state =105;
            break;
        }
        
        return state;
    },
}