AiPlayerController.js 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  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. },
  41. update(dt) {
  42. },
  43. //Ai防守
  44. ondefense_Ai(direction, type) { //左右拳,击打类型
  45. this._Statepassivity = true;
  46. let random = parseInt(Math.round(Math.random() * 10 + 1))
  47. if (random < 5) {
  48. //半概率不躲避 被击中
  49. if (direction == 1) {
  50. this.ctorScp.hurt(1, type);
  51. }
  52. if (direction == -1) {
  53. this.ctorScp.hurt(0, type);
  54. }
  55. // this.armature_Ai.node.scaleX = direction;
  56. //this.armature_Ai.playAnimation(GameConfig.AnimationName_Hurt, 1);
  57. this._Hurt = true;
  58. } else {
  59. if (random < 7) {
  60. //左躲闪
  61. if (this.PlayerControScp._LeftJayShow) {
  62. this.ctorScp.hurt(0, type);
  63. this._Hurt = true;
  64. } else {
  65. this.ctorScp.dodge(0);
  66. this._LeftDodg = true;
  67. }
  68. } else if (random < 9) {
  69. //右躲闪
  70. if (this.PlayerControScp._RightJayShow) {
  71. this.ctorScp.hurt(1, type);
  72. this._Hurt = true;
  73. } else {
  74. this.ctorScp.dodge(1);
  75. this._RightDodge = true;
  76. }
  77. } else {
  78. //防御
  79. if (this.stateScp._endurance >= this.stateScp._block_minus_endurance) {
  80. this.ctorScp.block();
  81. this._Defence = true;
  82. } else {
  83. this._Defence = false;
  84. }
  85. }
  86. }
  87. }, //Ai攻击
  88. onAttck_Ai(direction) {
  89. if (this._Statepassivity) return;
  90. let random = Math.random();
  91. var randomnum_1 = parseInt(Math.round(Math.random() * 98 + 1)); //(0-100]
  92. var randomnum_2 = parseInt(Math.round(Math.random() + 1)); //[1-2]
  93. if (random < 0.5) {
  94. direction = 1;
  95. this._LeftJayShow = true;
  96. this._RightJayShow = false;
  97. if (randomnum_1 >= 1 && randomnum_1 <= this._rate) {
  98. //出现暴击或者连击
  99. if (randomnum_2 == 1) {
  100. //暴击
  101. this._CriticalStrike = true;
  102. this.ctorScp.attack(2);
  103. // this.AiControScp.ondefense_Ai(1, 1); //左右拳,击打类型
  104. if (!this.PlayerControScp._RightDodge && !this.PlayerControScp._Defence) {
  105. this.PlayerControScp._BeCriticalStrike = true;
  106. this.playerctorScp.hurt(0, 1); //左暴击
  107. }
  108. }
  109. if (randomnum_2 == 2) {
  110. //连击
  111. this._DoubleHit = true;
  112. this.ctorScp.attack(4);
  113. //this.AiControScp.ondefense_Ai(1, 2); //左右拳,击打类型
  114. if (!this.PlayerControScp._RightDodge && !this.PlayerControScp._Defence) {
  115. this.PlayerControScp._BeDoubleHit = true;
  116. this.playerctorScp.hurt(0, 2); //左连击
  117. }
  118. }
  119. } else { //普攻状态 普攻动作
  120. this._RightJayShow = true;
  121. this.ctorScp.attack(0);
  122. //this.AiControScp.ondefense_Ai(1, 0); //左右拳,击打类型
  123. if (!this.PlayerControScp._RightDodge && !this.PlayerControScp._Defence) {
  124. this.PlayerControScp._Hurt = true;
  125. this.playerctorScp.hurt(0, 0); //左击
  126. }
  127. }
  128. } else {
  129. direction = -1;
  130. this._RightJayShow = true;
  131. this._LeftJayShow = false;
  132. if (randomnum_1 >= 1 && randomnum_1 <= this._rate) {
  133. //出现暴击或者连击
  134. if (randomnum_2 == 1) {
  135. //暴击
  136. this._CriticalStrike = true;
  137. this.ctorScp.attack(2);
  138. //this.AiControScp.ondefense_Ai(1, 1); //左右拳,击打类型
  139. this.playerctorScp.hurt(1, 1); //右暴击
  140. }
  141. if (randomnum_2 == 2) {
  142. //连击
  143. this._DoubleHit = true;
  144. this.ctorScp.attack(4);
  145. //this.AiControScp.ondefense_Ai(1, 2); //左右拳,击打类型
  146. this.playerctorScp.hurt(1, 2); //右连击
  147. }
  148. } else { //普攻状态 普攻动作
  149. this._RightJayShow = true;
  150. this.ctorScp.attack(1);
  151. //this.AiControScp.ondefense_Ai(1, 0); //左右拳,击打类型
  152. if (!this.PlayerControScp._LeftDodg && !this.PlayerControScp._Defence) {
  153. this.PlayerControScp._Hurt = true;
  154. this.playerctorScp.hurt(1, 0); //右击
  155. }
  156. }
  157. }
  158. //this.ctorScp.attack(direction);
  159. // this.armature_Ai.node.scaleX = direction;
  160. // this.armature_Ai.playAnimation(GameConfig.AnimationName_Attack, 1);
  161. },
  162. });