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

    properties: {
        tagHero : 0
    },
    onLoad : function () {
        this.tag = 0;
    },
    start: function () {
            // cc.log('x===='+this.node.convertToWorldSpaceAR(cc.Vec2.ZERO).x);




    },


    onCollisionEnter: function (other,self) {

            if(other.node.name === 'PlayerCollisionLine') {
                var Hero = cc.find(other.node.parent.parent.name);
                if (self.tag == 99) {
                    if (this.tag == 0) {
                        this.tag++;
                        return;
                    }
                //下面
                if (other.node.parent.parent.name == "Hero") {
                    return;
                    var Hero =  cc.find("Hero");
                    var HeroControl = Hero.getComponent("HeroControl");
                    HeroControl.SetCurrentSpeed_noRestrictions(600);

                    var networkUITest = Hero.getComponent('NetworkSocket');
                    // cc.log("发布的 111",'Herojavelin');
                    var data = { FunctionName: 'Restrictions', ParentName: Hero.parent.name, ObjName: Hero.name, PositionX: Hero.convertToWorldSpaceAR(cc.Vec2.ZERO).x };
                    networkUITest.sendSyncData(JSON.stringify(data));
                    // if (this.tagHero == 0) {
                    //     // HeroControl.SetCurrentSpeed_noRestrictions(300);
                    //     this.tagHero++;
                    // }else if (this.tagHero ==1) {
                    //     CustomLog("下面的1111 碰到了",other.node);
                    //     var tPrefab = cc.find("javetemp_Hero");
                    // var Herop = Hero.getBoundingBoxToWorld();
                    // var tPrefabp = tPrefab.getBoundingBoxToWorld();
                    // CustomLog("两个世界位置","hero",Herop,"标枪",tPrefabp);
                    // var datas = {
                    //     duration : 0.5,
                    //     position : Herop.x,
                    //     y : Herop.y
                    // };
                    // this.javelinmoveHero(datas,HeroControl.CameraNode,function () {
                    //
                    // }.bind(this),function () {
                    //     HeroControl.CameraNode.parent = Hero;
                    //     HeroControl.SetCurrentSpeed_noRestrictions(300);
                    // }.bind(this));
                    //

                    // HeroControl.CameraNode.parent = Hero;
                    // HeroControl.SetCurrentSpeed_noRestrictions(300);

                    // tPrefab.getComponent(cc.Camera).enabled = false;
                    // Hero.getComponent(cc.Camera).enabled = true;

                    // }

                    // tPrefab.active = false;


                }
                if (other.node.parent.parent.name == "Rivel") {
                    var HeroControl = Hero.getComponent("HeroControl");
                    HeroControl.SetCurrentSpeed_noRestrictions(600);
                    // CustomLog("上面的1111 碰到了",other.node);
                    // this.Javelin2.destroy();
                }
                // this.node.active = false;
                // cc.log("父亲",scene);




            }
        }





    },
    onCollisionStay: function (other,self) {

    },
    onCollisionExit: function (other,self)
    {

    },
    javelinmoveHero : function (data,view,starListener,endListener) {
        var actionBy = cc.moveTo(data.duration, data.position, data.y);

        var start = cc.callFunc(function () {
            if (starListener!=null) {
                starListener();
            }
        }.bind(this), this);

        var stop = cc.callFunc(function () {
            if (endListener!=null) {
                endListener();
            }
        }.bind(this), this);
        var myAction = cc.sequence(start,actionBy,stop);
        view.runAction(myAction);
    },
});
