const PlayerStateStatic = require('PlayerState');
var BarrierSuperClass = require("BarrierSuper");
cc.Class({
    extends:BarrierSuperClass,

    properties: {
        Barrier: {
            default: null,
            type: cc.Node
        },
        Railing: {
            default: null,
            type: cc.Node
        },
    },
    start () {

    },
    onCollisionEnter: function (other) {
        if(other.node.name === 'PlayerCollisionLine') {
            var PlayerCollisionLine = other.getComponent("PlayerCollisionLine");
            var PlayerStateScript = PlayerCollisionLine.Hero.getComponent("PlayerState");
            PlayerStateScript.CurrentInZoneType = PlayerStateStatic.ZoneType.PerfectHurdleBand;

            // cc.log(PlayerStateScript.CurrentInZoneType );
            if (other.node.parent.parent.name == "Hero") {

                var PlayerState = other.node.parent.parent.getComponent("PlayerState");
                PlayerState.TouchControlEnableTouch = true;

            }
        }
        if(other.node.name === 'LocationLine')
        {
            //perfect完美提示
            cc.find('UIControl').getComponent('GameUI').hideTimerPerfect(3);
            cc.find('Hero').getComponent('HeroControl').addPerfectGradeAndPlay();
            // this.node.destroy();
            this.node.opacity = 0;
        }
    },
    onCollisionStay: function (other) {
        // console.log('on collision stay');
    },
    onCollisionExit: function (other)
    {
        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();
                // CustomLog("撞到了 栏杆",other.node);
                //下面
                if (other.node.parent.parent.name == "Hero") {

                    var PlayerState = other.node.parent.parent.getComponent("PlayerState");
                    PlayerState.TouchControlEnableTouch = true;

                    //卧倒
                    this.Barrier.getComponent("Barrier").FallingDown();
                    this.Railing.getComponent("Barrier");
                    var Hero =  cc.find("Hero");
                    var NetworkSocket = Hero.getComponent('NetworkSocket');
                    // CustomLog("撞到了 栏杆 具体",this.Barrier);

                    var  data = {FunctionName:'PerfectHurdleBandRailing',ParentName:this.Railing.parent.name,ObjName:this.Railing.name,PositionX:this.Railing.convertToWorldSpaceAR(cc.Vec2.ZERO).x};
                    NetworkSocket.sendSyncData(JSON.stringify(data));
                }
                if (other.node.parent.parent.name == "Rivel") {
                    this.Railing.getComponent("Barrier").FallingDown();
                    this.Barrier.getComponent("Barrier");
                    var Hero =  cc.find("Hero");
                    var NetworkSocket = Hero.getComponent('NetworkSocket');

                    var  data = {FunctionName:'PerfectHurdleBandBarrier',ParentName:this.Barrier.parent.name,ObjName:this.Barrier.name,PositionX:this.Barrier.convertToWorldSpaceAR(cc.Vec2.ZERO).x};
                    NetworkSocket.sendSyncData(JSON.stringify(data));

                }

            }
            PlayerStateScript.CurrentInZoneType = PlayerStateStatic.ZoneType.None;
            PlayerStateScript.BTouchedScreenInTheZone = false;
        }
    }
});
