cc.Class({
    extends: require("BasePlayerController"),

    properties: {
        TouchNode: cc.Node,
        charactor: cc.Node,
        AiController: cc.Node,
    },
    onLoad() {
        this._super();
        this._Statepassivity = this.Statepassivity;
        this._RightJayShow = this.RightJayShow; //出右拳
        this._LeftJayShow = this.LeftJayShow; //出左拳

        this._RightDodge = this.RightDodge; //右躲闪
        this._LeftDodg = this.LeftDodg; //左躲闪

        this._Defence = this.Defence; //防御

        this._Hurt = this.Hurt;
        this._CriticalStrike = this.CriticalStrike; //暴击
        this._DoubleHit = this.DoubleHit; //连击
        this._BeCriticalStrike = this.BeCriticalStrike; //被暴击
        this._BeDoubleHit = this.BeDoubleHit; //被连击
        //注册回调事件
        let Self = this;

        this.TouchNode.on('gesture', function(event) {
            console.log(event.name);
            Self.Gesture(event.name);
        });
    },
    start() {
        this.init();
    },
    init() {
        //角色脚本
        this.ctorScp = this.charactor.getComponent('Charactor');
        this.AiControScp = this.AiController.getComponent('AiPlayerController');
        //this.statesScp = this.charactor.getComponent('PlayerStates');
    },
    Gesture(name) {
        var randomnum_1 = parseInt(Math.round(Math.random() * 98 + 1)); //(0-100]
        var randomnum_2 = parseInt(Math.round(Math.random() + 1)); //[1-2]
        console.log(randomnum_1, randomnum_2);
        if (name == 'right_top') {
            if (randomnum_1 >= 1 && randomnum_1 <= 10) {
                //出现暴击或者连击
                if (randomnum_2 == 1) {
                    //暴击
                    this._CriticalStrike = true;
                    this.ctorScp.attack(2);
                    this.AiControScp.ondefense_Ai(1, 1); //左右拳，击打类型
                }
                if (randomnum_2 == 2) {
                    //连击
                    this._DoubleHit = true;
                    this.ctorScp.attack(4);
                    this.AiControScp.ondefense_Ai(1, 2); //左右拳，击打类型
                }
            } else { //普攻状态 普攻动作
                this._RightJayShow = true;
                this.ctorScp.attack(0);
                this.AiControScp.ondefense_Ai(1, 0); //左右拳，击打类型
            }


        } else if (name == 'left_top') {
            if (randomnum_1 >= 1 && randomnum_1 <= 10) {
                //出现暴击或者连击
                if (randomnum_2 == 1) {
                    //暴击
                    this._CriticalStrike = true;
                    this.ctorScp.attack(3);
                    this.AiControScp.ondefense_Ai(-1, 1); //左右拳，击打类型
                }
                if (randomnum_2 == 2) {
                    //连击
                    this._DoubleHit = true;
                    this.ctorScp.attack(5);
                    this.AiControScp.ondefense_Ai(-1, 2); //左右拳，击打类型
                }
            } else { //普攻状态 普攻动作
                this._LeftJayShow = true;
                this.ctorScp.attack(1);
                this.AiControScp.ondefense_Ai(-1, 0); //左右拳，击打类型
            }

        } else if (name == 'right_down') {

            this.AiControScp._Statepassivity = false;
            if (this.AiControScp._RightJayShow) {
                //被右拳打中
                if (this.AiControScp._CriticalStrike) {
                    //被右拳打中 暴击
                    this.ctorScp.hurt(1, 1);
                    return;
                }
                if (this.AiControScp._DoubleHit) {
                    //被右拳打中 连击
                    this.ctorScp.hurt(1, 2);
                    return;
                }
                this.ctorScp.hurt(1, 0);
                return;
            }

            this._RightDodge = true;
            this.ctorScp.dodge(0);
        } else if (name == 'left_down') {
            this.AiControScp._Statepassivity = false;
            if (this.AiControScp._LeftJayShow) {
                //被左拳打中
                if (this.AiControScp._CriticalStrike) {
                    //被左拳打中 暴击
                    this.ctorScp.hurt(0, 1);
                    return;
                }
                if (this.AiControScp._DoubleHit) {
                    //被左拳打中 连击
                    this.ctorScp.hurt(0, 2);
                    return;
                }
                this.ctorScp.hurt(0, 0);
                return;
            }
            this._LeftDodg = true;
            this.ctorScp.dodge(1);
        } else if (name == 'down') {
            this._Defence = true;
            this.AiControScp._Statepassivity = false;
            this.ctorScp.block();
        }
    },

    update(dt) {

    },
});