const PlayerState = require('PlayerState');
//todo 上车没时间解释了
var BarrierSuperClass = require("BarrierSuper");
const GameStatesStatic = require('GameStates');
cc.Class({
    extends:BarrierSuperClass,

    properties: {
        Javelin1: {
            default: null,
                    type: cc.Node
            },
        Javelin2: {
            default: null,
                    type: cc.Node
            },
    },

    start: function () {

    },
    onLoad : function () {
        if (this.node.name == "Javelin1") {
            var Hero = cc.find('Hero');
            var HeroPlayerState = Hero.getComponent("PlayerState");
            var data = {
                px : this.node.convertToWorldSpaceAR(cc.Vec2.ZERO).x,
                node : this.node
            }
            HeroPlayerState.JavePositionArray_Hero.push(data);
            // cc.log("创建出来的标枪 Hero",HeroPlayerState.JavePositionArray_Hero);
        }else if (this.node.name == "Javelin2") {
            var Rivel = cc.find('Rivel');
            var RivelPlayerState = Rivel.getComponent("PlayerState");
            var data = {
                px : this.node.convertToWorldSpaceAR(cc.Vec2.ZERO).x,
                node : this.node
            }
            RivelPlayerState.JavePositionArray_Rivel.push(data);
            // cc.log("创建出来的标枪 Rivel",RivelPlayerState.JavePositionArray_Rivel);
        }
    },

    onCollisionEnter: function (other,self) {
        // cc.log("上车",other,self);

        // cc.log("碰到标枪",other.node.parent.parent.name);

        if(other.node.name === 'PlayerCollisionLine') {
            //获取场景
            var Level = this.node.parent.parent;
            var Canvas = Level.getComponent('LevelControl').Canvas;
            var GameStates = Canvas.getComponent('GameStates');
            GameStates.CurrentProgress = GameStatesStatic.GameProgress.Javelin;


            // return;
            //下面
            if (other.node.parent.parent.name == "Hero") {
                CustomLog("下面的 碰到了",other.node);
                var HeroControl = cc.find("Hero").getComponent("HeroControl");
                if (HeroControl != null) {
                    HeroControl.playAudioByName("JavelinPickUp");//播放标枪捡起的音效
                    HeroControl.upJavelin();

                    // cc.find("Hero").getComponent("HeroControl").SetCurrentSpeed(0);
                    // cc.find("Hero").getComponent("HeroControl").SetCurrentSpeed(PlayerState.SpeedRangeForAnimation.SlowSpeed[1]);
                }
                //捡起来标枪
                var Hero =  cc.find("Hero");
                var NetworkSocket = Hero.getComponent('NetworkSocket');
                var  data = {FunctionName:'upJavelinHeroAnimation',ParentName:this.Javelin2.parent.name,ObjName:this.Javelin2.name,PositionX:this.Javelin2.convertToWorldSpaceAR(cc.Vec2.ZERO).x};
                NetworkSocket.sendSyncData(JSON.stringify(data));
                // this.Javelin1.destroy();

            }
            if (other.node.parent.parent.name == "Rivel") {
                CustomLog("上面的 碰到了",other.node);
                var HeroControl = cc.find("Rivel").getComponent("HeroControl");
                if (HeroControl != null) {
                    HeroControl.upJavelin();
                    // cc.find("Rivel").getComponent("HeroControl").SetCurrentSpeed(0);
                    // cc.find("Rivel").getComponent("HeroControl").SetCurrentSpeed(PlayerState.SpeedRangeForAnimation.SlowSpeed[1]);

                }
                var Hero =  cc.find("Hero");
                var NetworkSocket = Hero.getComponent('NetworkSocket');
                var  data = {Name:'upJavelinRivelAnimation',ParentName:this.Javelin1.parent.name,ObjName:this.Javelin1.name,PositionX:this.Javelin1.convertToWorldSpaceAR(cc.Vec2.ZERO).x};
                NetworkSocket.sendSyncData(JSON.stringify(data));
                // this.Javelin2.destroy();
            }

            //不删除
            this.node.active = false;

            // cc.log("父亲",scene);





                // scene.getChildByName("Hero").getComponent("HeroControl").setSeeds(0);

            // charactor.setInterruptListener(function (name) {
            //     cc.log("有么 播放了吗",name);
            //     // if (name == "bybike_redy_boy") {
            //     //     charactor.spine.timeScale = 1;
            //     //     scene.getChildByName("Hero").getComponent("HeroControl").PlayerStateScript.CurrentSpeed = PlayerState.SpeedRangeForAnimation.SlowSpeed[1];
            //     //     // scene.getChildByName("Hero").getComponent("HeroControl").setSeeds(0);
            //     //     this.node.destroy();
            //     //     charactor.setInterruptListener(null);
            //     // }
            //
            //
            //
            //
            //
            // }.bind(this));
        }else if (other.node.name == "PlayerCollisionLine_end") {
            if (other.node.parent.parent.name == "Rivel") {
                CustomLog("上面的 碰到了",other.node);
                var HeroControl = cc.find("Rivel").getComponent("HeroControl");
                if (HeroControl != null) {
                    HeroControl.upJavelin();
                    // cc.find("Rivel").getComponent("HeroControl").SetCurrentSpeed(0);
                    // cc.find("Rivel").getComponent("HeroControl").SetCurrentSpeed(PlayerState.SpeedRangeForAnimation.SlowSpeed[1]);

                }
                cc.find('Canvas').getComponent('GameStates').CurrentProgress = GameStatesStatic.GameProgress.Javelin;
                // this.Javelin2.destroy();
            }
            this.node.active = false;
        }
        // this.node.getComponent("HurdleBandCharactor").collode();
        // console.log('预制撞倒栏杆',other,self);
        // if(other.node.name === 'PlayerCollisionLine')
        // {
        //     var PlayerCollisionLine = other.getComponent("PlayerCollisionLine");
        //     var PlayerStateScript = PlayerCollisionLine.Hero.getComponent("PlayerState");
        //     PlayerStateScript.CurrentInZoneType = 'PerfectHurdleBand';
        //
        //     // cc.log(PlayerStateScript.CurrentInZoneType );
        // }
    },
    onCollisionStay: function (other,self) {
        // console.log('on collision stay');
    },
    onCollisionExit: function (other,self)
    {
    //     if(other.node.name === 'PlayerCollisionLine') {
    //         var PlayerCollisionLine = other.getComponent("PlayerCollisionLine");
    //         var HeroControlScript = PlayerCollisionLine.Hero.getComponent("HeroControl");
    //         var PlayerStateScript = PlayerCollisionLine.Hero.getComponent("PlayerState");
    //         if(!PlayerStateScript.BTouchedScreenInTheZone)
    //         {
    //             HeroControlScript.Stagger();
    //         }
    //         PlayerStateScript.CurrentInZoneType = 'None';
    //         PlayerStateScript.BTouchedScreenInTheZone = false;
    //     }
    }
});
