AiPlayerController.js 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  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._rate = this.stateScp._combo_rate + this.stateScp._crit_rate;
  27. this.schedule(function() {
  28. if (this.GameMode._gamestart) { this.onAttck_Ai(); }
  29. }, 1);
  30. //}, 5.5);
  31. },
  32. init() {
  33. this.GameMode = cc.find("GameMode").getComponent("GameMode");
  34. //角色脚本
  35. this.ctorScp = this.charactor.getComponent('AiCharactor');
  36. this.PlayerControScp = this.PlayerController.getComponent('PlayerController');
  37. //角色脚本
  38. this.playerctorScp = this.PlayerctorScp.getComponent('Charactor');
  39. this.stateScp = this.states.getComponent('AiPlayerStates');
  40. this.UiController = cc.find("Canvas/UiController").getComponent('UiController');
  41. },
  42. update(dt) {
  43. },
  44. //Ai防守
  45. ondefense_Ai(direction, type) { //左右拳,击打类型
  46. this._Statepassivity = true;
  47. let random = parseInt(Math.round(Math.random() * 10 + 1))
  48. if (random < 5) {
  49. //半概率不躲避 被击中
  50. if (direction == 1) {
  51. this.ctorScp.hurt(1, type);
  52. }
  53. if (direction == -1) {
  54. this.ctorScp.hurt(0, type);
  55. }
  56. // this.armature_Ai.node.scaleX = direction;
  57. //this.armature_Ai.playAnimation(GameConfig.AnimationName_Hurt, 1);
  58. this._Hurt = true;
  59. } else {
  60. if (random < 7) {
  61. //左躲闪
  62. if (this.PlayerControScp._LeftJayShow) {
  63. this.ctorScp.hurt(0, type);
  64. this._Hurt = true;
  65. } else {
  66. this.ctorScp.dodge(0);
  67. this._LeftDodg = true;
  68. }
  69. } else if (random < 9) {
  70. //右躲闪
  71. if (this.PlayerControScp._RightJayShow) {
  72. this.ctorScp.hurt(1, type);
  73. this._Hurt = true;
  74. } else {
  75. this.ctorScp.dodge(1);
  76. this._RightDodge = true;
  77. }
  78. } else {
  79. //防御
  80. if (this.stateScp._endurance >= this.stateScp._block_minus_endurance) {
  81. this.ctorScp.block();
  82. this._Defence = true;
  83. } else {
  84. this._Defence = false;
  85. }
  86. }
  87. }
  88. }, //Ai攻击
  89. onAttck_Ai(direction) {
  90. if (this._Statepassivity) return;
  91. let random = Math.random();
  92. var randomnum_1 = parseInt(Math.round(Math.random() * 98 + 1)); //(0-100]
  93. var randomnum_2 = parseInt(Math.round(Math.random() + 1)); //[1-2]
  94. if (random < 0.5) {
  95. direction = 1;
  96. this._LeftJayShow = true;
  97. this._RightJayShow = false;
  98. if (randomnum_1 >= 1 && randomnum_1 <= this._rate) {
  99. //出现暴击或者连击
  100. if (randomnum_2 == 1) {
  101. //暴击
  102. this._CriticalStrike = true;
  103. this.UiController.Ui_Shake(1);
  104. this.scheduleOnce(function() {
  105. this.ctorScp.attack(2);
  106. }, 1.8);
  107. // this.AiControScp.ondefense_Ai(1, 1); //左右拳,击打类型
  108. if (!this.PlayerControScp._RightDodge && !this.PlayerControScp._Defence) {
  109. this.PlayerControScp._BeCriticalStrike = true;
  110. this.playerctorScp.hurt(0, 1); //左暴击
  111. }
  112. }
  113. if (randomnum_2 == 2) {
  114. //连击
  115. this._DoubleHit = true;
  116. this.UiController.Ui_Shake(1);
  117. this.scheduleOnce(function() {
  118. this.ctorScp.attack(4);
  119. }, 1.8);
  120. //this.AiControScp.ondefense_Ai(1, 2); //左右拳,击打类型
  121. if (!this.PlayerControScp._RightDodge && !this.PlayerControScp._Defence) {
  122. this.PlayerControScp._BeDoubleHit = true;
  123. this.playerctorScp.hurt(0, 2); //左连击
  124. }
  125. }
  126. } else { //普攻状态 普攻动作
  127. this._RightJayShow = true;
  128. this.UiController.Ui_Shake(1);
  129. this.scheduleOnce(function() {
  130. this.ctorScp.attack(0);
  131. }, 1.8);
  132. //this.AiControScp.ondefense_Ai(1, 0); //左右拳,击打类型
  133. if (!this.PlayerControScp._RightDodge && !this.PlayerControScp._Defence) {
  134. this.PlayerControScp._Hurt = true;
  135. this.playerctorScp.hurt(0, 0); //左击
  136. }
  137. }
  138. } else {
  139. direction = -1;
  140. this._RightJayShow = true;
  141. this._LeftJayShow = false;
  142. if (randomnum_1 >= 1 && randomnum_1 <= this._rate) {
  143. //出现暴击或者连击
  144. if (randomnum_2 == 1) {
  145. //暴击
  146. this._CriticalStrike = true;
  147. this.UiController.Ui_Shake(2);
  148. this.scheduleOnce(function() {
  149. this.ctorScp.attack(2);
  150. }, 1.8);
  151. //this.AiControScp.ondefense_Ai(1, 1); //左右拳,击打类型
  152. this.playerctorScp.hurt(1, 1); //右暴击
  153. }
  154. if (randomnum_2 == 2) {
  155. //连击
  156. this._DoubleHit = true;
  157. this.UiController.Ui_Shake(2);
  158. this.scheduleOnce(function() {
  159. this.ctorScp.attack(4);
  160. }, 1.8);
  161. //this.AiControScp.ondefense_Ai(1, 2); //左右拳,击打类型
  162. this.playerctorScp.hurt(1, 2); //右连击
  163. }
  164. } else { //普攻状态 普攻动作
  165. this._RightJayShow = true;
  166. this.UiController.Ui_Shake(2);
  167. this.scheduleOnce(function() {
  168. this.ctorScp.attack(1);
  169. }, 1.8);
  170. //this.AiControScp.ondefense_Ai(1, 0); //左右拳,击打类型
  171. if (!this.PlayerControScp._LeftDodg && !this.PlayerControScp._Defence) {
  172. this.PlayerControScp._Hurt = true;
  173. this.playerctorScp.hurt(1, 0); //右击
  174. }
  175. }
  176. }
  177. //this.ctorScp.attack(direction);
  178. // this.armature_Ai.node.scaleX = direction;
  179. // this.armature_Ai.playAnimation(GameConfig.AnimationName_Attack, 1);
  180. },
  181. });