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

    properties: {
        NumOfCameIn:0,

    },
    onLoad: function () {
    },
    onCollisionEnter: function (other) {
        // return;
        if (other.node.name === 'PlayerCollisionLine')
        {
            cc.find('Hero').getComponent('HeroControl').StopPlayerAllSchedule();
            cc.find('Rivel').getComponent('HeroControl').StopPlayerAllSchedule();
            if(this.NumOfCameIn == 0){
                this.NumOfCameIn++;
                this.ResetPerfectGradeAndAddScore(other);
                // cc.log("进了StartLine"+this.NumOfCameIn);
            }
            // var CurrentPlayerNode = other.node.parent.parent;
            // var CurrentPlayerScript = CurrentPlayerNode.getComponent('HeroControl');
            // console.log("减速区域结束。");
            //停止减速
            // CurrentPlayerScript.ResetSpeed_noType_lerp_Stop();
            this.scheduleOnce(function() {
                this.GameMode = cc.find('Canvas').getComponent('GameMode');
                this.GameMode.bHasAddScore = false;
            }, 3);
            this.OneGameInit();
        }
    },
    ResetPerfectGradeAndAddScore:function(other)//项目开始前重置perfectGrade，及显示比分
    {
        if (other.node.parent.parent.name == "Hero") {
            cc.find('Hero').getComponent('HeroControl').resetPerfectGrade();
        }
        // var Level = cc.find('Level');
        // Level.getComponent('LevelControl').hidePKScore(other.node.parent.parent);
    },
    GetOtherPlayer:function(CurrentPlayerNode)
    {
        var OtherPlayerNode = null;
        if (CurrentPlayerNode.name == 'Hero') {
            OtherPlayerNode = cc.find('Rivel');
        }
        else
        {
            OtherPlayerNode = cc.find('Hero');
        }

        return OtherPlayerNode;
    },
    OneGameInit:function () {
        var Hero = cc.find('Hero');
        var HeroControl = Hero.getComponent("HeroControl");
        var NodeTouch = cc.find("TouchLayout").getComponent("NodeTouch");
        var HeroPlayerState = Hero.getComponent('PlayerState');
        var GameStates = cc.find('Canvas').getComponent('GameStates');

        GameStates.uploadValue = 0;//重置项目结束时上传的距离值

        HeroPlayerState.unscheduleAllCallbacks();
        HeroPlayerState.StayInFrontLongAccelerationBand=null;
        NodeTouch.TOUCH_END();
        NodeTouch.CanCreateYellowArea = false;

        HeroControl.PlayerStateScript.BStagger = false;
        // HeroPlayerState.unschedule(HeroPlayerState.StayInFrontLongAccelerationBand);
        HeroPlayerState.TouchControlEnableTouch = false;
        HeroPlayerState.enableTouch = false;
        HeroPlayerState.CurrentInZoneType = PlayerStateStatic.ZoneType.None;
    }
});
