| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149 |
- cc.Class({
- extends: require("BasePlayerController"),
- properties: {
- TouchNode: cc.Node,
- charactor: cc.Node,
- AiController: 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; //被连击
- //注册回调事件
- 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');
- this.stateScp = this.states.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') {
- if (this.stateScp._endurance >= this.stateScp._block_minus_endurance) {
- this._Defence = true;
- this.AiControScp._Statepassivity = false;
- this.ctorScp.block();
- } else {
- this._Defence = false;
- this.AiControScp._Statepassivity = true;
- }
- }
- },
- update(dt) {
- },
- });
|