
const PlayerStateStatic = require('PlayerState');
cc.Class({
    extends: cc.Component,

    properties: {
        BotPerfectPercentage:40,

    },
    start : function () {
        this.NodeTouch = cc.find("TouchLayout").getComponent("NodeTouch");
        var randomNum = Math.floor(Math.random()*100);
        // cc.log(randomNum+'*************');
        if(randomNum<30){//低难度几率30%
            this.BotPerfectPercentage = 40;
        }else if(randomNum>=30 && randomNum<80){//中等难度几率50%
            this.BotPerfectPercentage = 70;
        }else if(randomNum>=80 && randomNum<=100){//高难度几率20%
            this.BotPerfectPercentage = 90;
        }
    },
    myRandom : function(num){
        if (num>Math.floor(Math.random()*100)) {
            return true;
        }else{
            return false;
        }
    },
    Enters :function (other,node) {

        var name = node.node.parent.parent.name;
        var PlayerStateScript = node.node.parent.parent.getComponent("PlayerState");
        var HeroControlScript =  node.node.parent.parent.getComponent("HeroControl");
        //完美加速
        if (PlayerStateScript.CurrentInZoneType==PlayerStateStatic.ZoneType.AccelerationBandCenter) {
            // cc.log("调用了 ai 完美加速");
            if (this.myRandom(this.BotPerfectPercentage)) {
                this.NodeTouch.TOUCH_START(true);
            }
        }
        //右面加速
        else if(PlayerStateScript.CurrentInZoneType===PlayerStateStatic.ZoneType.BehindAccelerationBand)
        {
            if (!PlayerStateScript.BTouchedScreenInTheZone) {
                if (this.myRandom(100)) {
                    this.NodeTouch.TOUCH_START(true);
                }
            }
        }
        //长加速带
        else if(PlayerStateScript.CurrentInZoneType===PlayerStateStatic.ZoneType.FrontLongAccelerationBand)
        {
            this.NodeTouch.TOUCH_START(true);
            setTimeout(function () {
                this.NodeTouch.TOUCH_END(true);
            }.bind(this),200);

        }
        //跳远
        else if(PlayerStateScript.CurrentInZoneType===PlayerStateStatic.ZoneType.FrontLongJumpBand)//Hurdle
        {
            // cc.log("现在动作","跳远");
            // CustomLog("现在跳远",bHero);
            if (!PlayerStateScript.BTouchedScreenInTheZone) {
                this.NodeTouch.TOUCH_START(true);
            }
        }
        else if(PlayerStateScript.CurrentInZoneType===PlayerStateStatic.ZoneType.PreHurdleBand)//Hurdle
        {
            // cc.log("跨栏",name);
            if (!PlayerStateScript.BTouchedScreenInTheZone) {
                if (this.myRandom(100)) {
                    this.NodeTouch.TOUCH_START(true);
                }
            }
        }
        else if(PlayerStateScript.CurrentInZoneType===PlayerStateStatic.ZoneType.PerfectHurdleBand)//Hurdle
        {

            if (!PlayerStateScript.BTouchedScreenInTheZone) {
                if (this.myRandom(this.BotPerfectPercentage)) {
                    this.NodeTouch.TOUCH_START(true);
                }
            }
        }
    }

});
