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

    properties: {
        tagHero : 0,
        cameraNodeTag : false
    },

    start: function () {

    },


    onCollisionEnter: function (other,self) {
        // cc.log("上车",other,self);
        CustomLog("镜头准备移动吗",other.node.parent.parent.name,this.cameraNodeTag);
        if(other.node.name === 'PlayerCollisionLine') {
            var Hero = cc.find(other.node.parent.parent.name);
            //下面
            if (other.node.parent.parent.name == "Hero") {

                if (!this.cameraNodeTag) {
                    return;
                }
                // console.log("镜头准备移动吗 成功的案例是",other.node.parent.parent.name,this.cameraNodeTag);
                var Hero =  cc.find("Hero");
                var HeroControl = Hero.getComponent("HeroControl");
                // HeroControl.SetCurrentSpeed_noRestrictions(600);
                //
                // var Hero =  cc.find("Hero");
                // var NetworkSocket = Hero.getComponent('NetworkSocket');
                // var  data = {FunctionName:'upJavelinend',Speed:600};
                // NetworkSocket.sendSyncData(JSON.stringify(data));
                //     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") {
                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);
    },
});
