//限时活动脚本
//1.万圣节活动
var TableReader =require("TableReader");

cc.Class({
    extends: cc.Component,

    properties: {
        xuanyao: cc.Node,
        knifeIcon: cc.Sprite,  //主界面上飞刀皮肤图片
    },

    // LIFE-CYCLE CALLBACKS:

    // onLoad () {},

    start () {
    },

    //限时活动奖励领取按钮
    onLingqu: function(){
        console.log("万圣节奖励领取");
        if(this.xuanyao.getChildByName("gouxuan_on").active == true){
            //分享
            sdk.shareAppMessage({type:11,query:""});
            //埋点
            sdk.setSceneEvent("万圣节","点击","领取按钮-已勾选炫耀一下",{},null);
        }else{
            //埋点
            sdk.setSceneEvent("万圣节","点击","领取按钮-未勾选炫耀一下",{},null);
        }

        sdk.setToServer("timeActiveKey","timeActiveData",1,86400);

        let arr =cc.HQ.GameMgr.getKnife();   //用户已拥有的飞刀
        arr =cc.HQ.GameMgr.onChangeData(arr);
        if(arr.indexOf(65) ==-1){
            arr.push(65);
            cc.HQ.GameMgr.setKnife(arr);
            //当前装备的飞刀皮肤
            cc.HQ.GameMgr.setCurKnife(65);
            let skin =null;
            let userCurWeapan =cc.HQ.GameMgr.getCurKnife();  //当前装备的飞刀
            skin =TableReader.getTableRowByNum("knifeItems",Number(userCurWeapan));
            //更换飞刀图片
            cc.HQ.GameMgr.onReplaceKnife(this.knifeIcon,skin);
            cc.HQ.Global.showTips(2,"恭喜获得万圣节奖励!",1);
        }else{
            cc.HQ.Global.showTips(2,"你已拥有此飞镖!",1);
        }
        this.node.active =false;
    },

    //关闭按钮
    onClose: function(){
        console.log("万圣节奖励关闭"); 
        sdk.setToServer("timeActiveKey","timeActiveData",1,86400);
        this.node.active =false;
    },

    //关闭签到面板
    onClose: function(){
        this.node.active = false;
        //显示投诉按钮
        cc.HQ.GameMgr.feedbackButtonShow();
    },
    
    //炫耀一下是否勾选
    onGouxuan: function(){
        if(this.xuanyao.getChildByName("gouxuan_off").active == true){
            this.xuanyao.getChildByName("gouxuan_off").active = false;
            this.xuanyao.getChildByName("gouxuan_on").active = true;
        }else{
            this.xuanyao.getChildByName("gouxuan_on").active = false;
            this.xuanyao.getChildByName("gouxuan_off").active = true;
        }
    }

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