cc.Class({ extends: require("BasePlayerController"), properties: { charactor: cc.Node, PlayerController: cc.Node, PlayerctorScp: cc.Node, states: 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; //被连击 }, start() { this.init(); // this.scheduleOnce(function() { this.schedule(function() { this.onAttck_Ai(); }, 1); //}, 5.5); }, init() { //角色脚本 this.ctorScp = this.charactor.getComponent('AiCharactor'); this.PlayerControScp = this.PlayerController.getComponent('PlayerController'); //角色脚本 this.playerctorScp = this.PlayerctorScp.getComponent('Charactor'); this.stateScp = this.states.getComponent('AiPlayerStates'); }, update(dt) { }, //Ai防守 ondefense_Ai(direction, type) { //左右拳,击打类型 this._Statepassivity = true; let random = parseInt(Math.round(Math.random() * 10 + 1)) if (random < 5) { //半概率不躲避 被击中 if (direction == 1) { this.ctorScp.hurt(1, type); } if (direction == -1) { this.ctorScp.hurt(0, type); } // this.armature_Ai.node.scaleX = direction; //this.armature_Ai.playAnimation(GameConfig.AnimationName_Hurt, 1); this._Hurt = true; } else { if (random < 7) { //左躲闪 if (this.PlayerControScp._LeftJayShow) { this.ctorScp.hurt(0, type); this._Hurt = true; } else { this.ctorScp.dodge(0); this._LeftDodg = true; } } else if (random < 9) { //右躲闪 if (this.PlayerControScp._RightJayShow) { this.ctorScp.hurt(1, type); this._Hurt = true; } else { this.ctorScp.dodge(1); this._RightDodge = true; } } else { //防御 if (this.stateScp._endurance >= this.stateScp._block_minus_endurance) { this.ctorScp.block(); this._Defence = true; } else { this._Defence = false; } } } }, //Ai攻击 onAttck_Ai(direction) { if (this._Statepassivity) return; let random = Math.random(); var randomnum_1 = parseInt(Math.round(Math.random() * 98 + 1)); //(0-100] var randomnum_2 = parseInt(Math.round(Math.random() + 1)); //[1-2] if (random < 0.5) { direction = 1; this._LeftJayShow = true; this._RightJayShow = false; 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 (!this.PlayerControScp._RightDodge && !this.PlayerControScp._Defence) { this.PlayerControScp._BeCriticalStrike = true; this.playerctorScp.hurt(0, 1); //左暴击 } } if (randomnum_2 == 2) { //连击 this._DoubleHit = true; this.ctorScp.attack(4); //this.AiControScp.ondefense_Ai(1, 2); //左右拳,击打类型 if (!this.PlayerControScp._RightDodge && !this.PlayerControScp._Defence) { this.PlayerControScp._BeDoubleHit = true; this.playerctorScp.hurt(0, 2); //左连击 } } } else { //普攻状态 普攻动作 this._RightJayShow = true; this.ctorScp.attack(0); //this.AiControScp.ondefense_Ai(1, 0); //左右拳,击打类型 if (!this.PlayerControScp._RightDodge && !this.PlayerControScp._Defence) { this.PlayerControScp._Hurt = true; this.playerctorScp.hurt(0, 0); //左击 } } } else { direction = -1; this._RightJayShow = true; this._LeftJayShow = false; if (randomnum_1 >= 1 && randomnum_1 <= 10) { //出现暴击或者连击 if (randomnum_2 == 1) { //暴击 this._CriticalStrike = true; this.ctorScp.attack(2); //this.AiControScp.ondefense_Ai(1, 1); //左右拳,击打类型 this.playerctorScp.hurt(1, 1); //右暴击 } if (randomnum_2 == 2) { //连击 this._DoubleHit = true; this.ctorScp.attack(4); //this.AiControScp.ondefense_Ai(1, 2); //左右拳,击打类型 this.playerctorScp.hurt(1, 2); //右连击 } } else { //普攻状态 普攻动作 this._RightJayShow = true; this.ctorScp.attack(1); //this.AiControScp.ondefense_Ai(1, 0); //左右拳,击打类型 if (!this.PlayerControScp._LeftDodg && !this.PlayerControScp._Defence) { this.PlayerControScp._Hurt = true; this.playerctorScp.hurt(1, 0); //右击 } } } //this.ctorScp.attack(direction); // this.armature_Ai.node.scaleX = direction; // this.armature_Ai.playAnimation(GameConfig.AnimationName_Attack, 1); }, });