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

    properties: {
        Bike1: {
            default: null,
            type: cc.Node
        },
        Bike2: {
            default: null,
            type: cc.Node
        },
    },
    onCollisionEnter: function (other,self) {
        var Level = this.node.parent.parent;
        var Canvas = Level.getComponent('LevelControl').Canvas;
        var GameStates = Canvas.getComponent('GameStates');
        GameStates.CurrentProgress = GameStatesStatic.GameProgress.RideBike;
        //下面
        if (other.node.parent.parent.name == "Hero") {
            var HeroControl = cc.find("Hero").getComponent("HeroControl");
            var charactor = cc.find("Hero").getChildByName("Player").getComponent("Charactor");
            if (charactor != null) {
                this.scheduleOnce(function() {
                    HeroControl.playAudioByName("Ringtone");//播放自行车铃声
                }, 0.5);
                charactor.upBike();
                // cc.log("上车 本地",other.node.parent.parent.name);
                var Hero =  cc.find("Hero");
                var NetworkSocket = Hero.getComponent('NetworkSocket');
                // CustomLog("撞到了 栏杆 具体",this.Barrier);
                var  data = {FunctionName:'upBike'};
                NetworkSocket.sendSyncData(JSON.stringify(data));
                cc.find("Hero").getComponent("HeroControl").SetCurrentSpeed(0);
                setTimeout(function () {
                    charactor.spine.timeScale = 1;
                    if (other.node.parent.parent.name == "Hero") {
                        cc.find("Hero").getComponent("HeroControl").SetCurrentSpeed(PlayerState.SpeedRangeForAnimation.SlowSpeed[1]);
                        this.node.active = false;
                    }

                }.bind(this),600);
            }
            //卧倒
            var Hero =  cc.find("Hero");
            var NetworkSocket = Hero.getComponent('NetworkSocket');
            var  data = {Name:'upBikeHeroAnimation',ParentName:this.Bike1.parent.name,ObjName:this.Bike1.name,PositionX:this.Bike1.convertToWorldSpaceAR(cc.Vec2.ZERO).x};
            NetworkSocket.sendSyncData(JSON.stringify(data));
        }
        if (other.node.parent.parent.name == "Rivel") {
            var HeroControl = cc.find("Rivel").getComponent("HeroControl");
            var charactor = cc.find("Rivel").getChildByName("Player").getComponent("Charactor");
            if (charactor != null) {
                charactor.upBike();
                cc.find("Rivel").getComponent("HeroControl").SetCurrentSpeed(0);
                setTimeout(function () {
                    charactor.spine.timeScale = 1;
                        charactor.spine.timeScale = 1;
                        if (other.node.parent.parent.name == "Rivel")
                        {

                            cc.find("Rivel").getComponent("HeroControl").SetCurrentSpeed(PlayerState.SpeedRangeForAnimation.SlowSpeed[1]);
                            this.node.active = false;
                        }
                }.bind(this),600);
            }
            var Hero =  cc.find("Hero");
            var NetworkSocket = Hero.getComponent('NetworkSocket');
            var  data = {Name:'upBikeRivelAnimation',ParentName:this.Bike2.parent.name,ObjName:this.Bike2.name,PositionX:this.Bike2.convertToWorldSpaceAR(cc.Vec2.ZERO).x};
            NetworkSocket.sendSyncData(JSON.stringify(data));
        }
    },
});
