AiPlayerController.js 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. cc.Class({
  2. extends: require("BasePlayerController"),
  3. properties: {
  4. charactor: cc.Node,
  5. PlayerController: cc.Node,
  6. PlayerctorScp: cc.Node,
  7. states: cc.Node,
  8. },
  9. onLoad() {
  10. this._super();
  11. this._Statepassivity = this.Statepassivity; //被动状态
  12. this._RightJayShow = this.RightJayShow; //出右拳
  13. this._LeftJayShow = this.LeftJayShow; //出左拳
  14. this._RightDodge = this.RightDodge; //右躲闪
  15. this._LeftDodg = this.LeftDodg; //左躲闪
  16. this._Defence = this.Defence; //防御
  17. this._Hurt = this.Hurt;
  18. this._CriticalStrike = this.CriticalStrike; //暴击
  19. this._DoubleHit = this.DoubleHit; //连击
  20. this._BeCriticalStrike = this.BeCriticalStrike; //被暴击
  21. this._BeDoubleHit = this.BeDoubleHit; //被连击
  22. },
  23. start() {
  24. this.init();
  25. // this.scheduleOnce(function() {
  26. this.schedule(function() {
  27. this.onAttck_Ai();
  28. }, 1);
  29. //}, 5.5);
  30. },
  31. init() {
  32. //角色脚本
  33. this.ctorScp = this.charactor.getComponent('AiCharactor');
  34. this.PlayerControScp = this.PlayerController.getComponent('PlayerController');
  35. //角色脚本
  36. this.playerctorScp = this.PlayerctorScp.getComponent('Charactor');
  37. this.stateScp = this.states.getComponent('AiPlayerStates');
  38. },
  39. update(dt) {
  40. },
  41. //Ai防守
  42. ondefense_Ai(direction, type) { //左右拳,击打类型
  43. this._Statepassivity = true;
  44. let random = parseInt(Math.round(Math.random() * 10 + 1))
  45. if (random < 5) {
  46. //半概率不躲避 被击中
  47. if (direction == 1) {
  48. this.ctorScp.hurt(1, type);
  49. }
  50. if (direction == -1) {
  51. this.ctorScp.hurt(0, type);
  52. }
  53. // this.armature_Ai.node.scaleX = direction;
  54. //this.armature_Ai.playAnimation(GameConfig.AnimationName_Hurt, 1);
  55. this._Hurt = true;
  56. } else {
  57. if (random < 7) {
  58. //左躲闪
  59. if (this.PlayerControScp._LeftJayShow) {
  60. this.ctorScp.hurt(0, type);
  61. this._Hurt = true;
  62. } else {
  63. this.ctorScp.dodge(0);
  64. this._LeftDodg = true;
  65. }
  66. } else if (random < 9) {
  67. //右躲闪
  68. if (this.PlayerControScp._RightJayShow) {
  69. this.ctorScp.hurt(1, type);
  70. this._Hurt = true;
  71. } else {
  72. this.ctorScp.dodge(1);
  73. this._RightDodge = true;
  74. }
  75. } else {
  76. //防御
  77. if (this.stateScp._endurance >= this.stateScp._block_minus_endurance) {
  78. this.ctorScp.block();
  79. this._Defence = true;
  80. } else {
  81. this._Defence = false;
  82. }
  83. }
  84. }
  85. }, //Ai攻击
  86. onAttck_Ai(direction) {
  87. if (this._Statepassivity) return;
  88. let random = Math.random();
  89. var randomnum_1 = parseInt(Math.round(Math.random() * 98 + 1)); //(0-100]
  90. var randomnum_2 = parseInt(Math.round(Math.random() + 1)); //[1-2]
  91. if (random < 0.5) {
  92. direction = 1;
  93. this._LeftJayShow = true;
  94. this._RightJayShow = false;
  95. if (randomnum_1 >= 1 && randomnum_1 <= 10) {
  96. //出现暴击或者连击
  97. if (randomnum_2 == 1) {
  98. //暴击
  99. this._CriticalStrike = true;
  100. this.ctorScp.attack(2);
  101. // this.AiControScp.ondefense_Ai(1, 1); //左右拳,击打类型
  102. if (!this.PlayerControScp._RightDodge && !this.PlayerControScp._Defence) {
  103. this.PlayerControScp._BeCriticalStrike = true;
  104. this.playerctorScp.hurt(0, 1); //左暴击
  105. }
  106. }
  107. if (randomnum_2 == 2) {
  108. //连击
  109. this._DoubleHit = true;
  110. this.ctorScp.attack(4);
  111. //this.AiControScp.ondefense_Ai(1, 2); //左右拳,击打类型
  112. if (!this.PlayerControScp._RightDodge && !this.PlayerControScp._Defence) {
  113. this.PlayerControScp._BeDoubleHit = true;
  114. this.playerctorScp.hurt(0, 2); //左连击
  115. }
  116. }
  117. } else { //普攻状态 普攻动作
  118. this._RightJayShow = true;
  119. this.ctorScp.attack(0);
  120. //this.AiControScp.ondefense_Ai(1, 0); //左右拳,击打类型
  121. if (!this.PlayerControScp._RightDodge && !this.PlayerControScp._Defence) {
  122. this.PlayerControScp._Hurt = true;
  123. this.playerctorScp.hurt(0, 0); //左击
  124. }
  125. }
  126. } else {
  127. direction = -1;
  128. this._RightJayShow = true;
  129. this._LeftJayShow = false;
  130. if (randomnum_1 >= 1 && randomnum_1 <= 10) {
  131. //出现暴击或者连击
  132. if (randomnum_2 == 1) {
  133. //暴击
  134. this._CriticalStrike = true;
  135. this.ctorScp.attack(2);
  136. //this.AiControScp.ondefense_Ai(1, 1); //左右拳,击打类型
  137. this.playerctorScp.hurt(1, 1); //右暴击
  138. }
  139. if (randomnum_2 == 2) {
  140. //连击
  141. this._DoubleHit = true;
  142. this.ctorScp.attack(4);
  143. //this.AiControScp.ondefense_Ai(1, 2); //左右拳,击打类型
  144. this.playerctorScp.hurt(1, 2); //右连击
  145. }
  146. } else { //普攻状态 普攻动作
  147. this._RightJayShow = true;
  148. this.ctorScp.attack(1);
  149. //this.AiControScp.ondefense_Ai(1, 0); //左右拳,击打类型
  150. if (!this.PlayerControScp._LeftDodg && !this.PlayerControScp._Defence) {
  151. this.PlayerControScp._Hurt = true;
  152. this.playerctorScp.hurt(1, 0); //右击
  153. }
  154. }
  155. }
  156. //this.ctorScp.attack(direction);
  157. // this.armature_Ai.node.scaleX = direction;
  158. // this.armature_Ai.playAnimation(GameConfig.AnimationName_Attack, 1);
  159. },
  160. });