AiCharactor.js 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  1. cc.Class({
  2. extends: require("BaseCharactor"),
  3. properties: {
  4. PlayerController: cc.Node,
  5. AiPlayerController: cc.Node,
  6. },
  7. onLoad() {
  8. this._super();
  9. this.armatureDisplay = this.node.getComponent(dragonBones.ArmatureDisplay);
  10. this.armature = this.armatureDisplay.armature();
  11. //添加动画事件监听
  12. this.armatureDisplay.addEventListener(dragonBones.EventObject.COMPLETE, this.animationEventHandler, this);
  13. this.armatureDisplay.addEventListener(dragonBones.EventObject.FRAME_EVENT, this.animationEventHandler_Enter, this);
  14. },
  15. start() {
  16. this.init();
  17. },
  18. // update (dt) {},
  19. attack(bLeft) {
  20. //发射攻击事件 // 普攻
  21. if (bLeft == 0) {
  22. //右拳
  23. this.armatureDisplay.node.scaleX = 1;
  24. this.armature.animation.play("attack", 1);
  25. this.node.emit("attack");
  26. } else if (bLeft == 1) {
  27. //左拳
  28. this.armatureDisplay.node.scaleX = -1;
  29. this.armature.animation.play("attack", 1);
  30. this.node.emit("attack");
  31. }
  32. //暴击右
  33. else if (bLeft == 2) {
  34. this.armatureDisplay.node.scaleX = -1;
  35. this.armature.animation.play("critical_strike", 1);
  36. this.node.emit("attack_critical_strike");
  37. }
  38. //暴击左
  39. else if (bLeft == 3) {
  40. this.armatureDisplay.node.scaleX = 1;
  41. this.armature.animation.play("critical_strike", 1);
  42. this.node.emit("attack_critical_strike");
  43. }
  44. //连击
  45. else if (bLeft == 4) {
  46. this.armatureDisplay.node.scaleX = -1;
  47. this.armature.animation.play("double-hit", 1);
  48. this.node.emit("attack_double-hit");
  49. }
  50. //连击
  51. else if (bLeft == 5) {
  52. this.armatureDisplay.node.scaleX = 1;
  53. this.armature.animation.play("double-hit", 1);
  54. this.node.emit("attack_double-hit");
  55. }
  56. },
  57. dodge(bLeft) { //躲闪
  58. console.log("Ai躲闪");
  59. //发射躲闪事件
  60. if (bLeft == 0) {
  61. //左躲闪
  62. this.armatureDisplay.node.scaleX = 1;
  63. this.armature.animation.play("dodge", 1);
  64. } else if (bLeft == 1) {
  65. //右躲闪
  66. this.armatureDisplay.node.scaleX = -1;
  67. this.armature.animation.play("dodge", 1);
  68. }
  69. this.node.emit("dodge");
  70. },
  71. hurt(bLeft, type) { //挨打 左右拳,击打类型
  72. //发射挨打事件
  73. if (type == 0) {
  74. //普通挨打
  75. if (bLeft == 0) {
  76. //左挨打
  77. console.log("Ai挨右打");
  78. this.armatureDisplay.node.scaleX = -1;
  79. this.armature.animation.play("be_beaten", 1);
  80. } else if (bLeft == 1) {
  81. //右挨打
  82. console.log("Ai挨左打");
  83. this.armatureDisplay.node.scaleX = 1;
  84. this.armature.animation.play("be_beaten", 1);
  85. }
  86. this.node.emit("hurt_ord");
  87. }
  88. if (type == 1) {
  89. console.log("Ai挨暴打");
  90. if (bLeft == 0) {
  91. //左挨打
  92. //被暴打
  93. this.armatureDisplay.node.scaleX = -1;
  94. this.armature.animation.play("be_critical_strike", 1);
  95. } else if (bLeft == 1) {
  96. //被暴打
  97. //右挨打
  98. this.armatureDisplay.node.scaleX = 1;
  99. this.armature.animation.play("be_critical_strike", 1);
  100. }
  101. this.node.emit("hurt_critical");
  102. }
  103. if (type == 2) {
  104. console.log("Ai挨连打");
  105. if (bLeft == 0) {
  106. //被连击打
  107. //左挨打
  108. this.armatureDisplay.node.scaleX = -1;
  109. this.armature.animation.play("be_double_hit", 1);
  110. } else if (bLeft == 1) {
  111. //被连击打
  112. //右挨打
  113. this.armatureDisplay.node.scaleX = 1;
  114. this.armature.animation.play("be_double_hit", 1);
  115. }
  116. this.node.emit("hurt_double");
  117. }
  118. },
  119. block() { //防御
  120. this.armature.animation.play("block", 1);
  121. this.node.emit("block");
  122. },
  123. animationEventHandler(event) {
  124. if (event.type === dragonBones.EventObject.COMPLETE) {
  125. //主角
  126. if (event.animationState.name === "attack") {
  127. console.log("attack 动作播放完毕!!!");
  128. //TODO:
  129. //this.armatureDisplay.node.scaleX = 0.39;
  130. this.armature.animation.play("idle", 0);
  131. this.aicontroScp._RightJayShow = false;
  132. this.aicontroScp._LeftJayShow = false;
  133. this.aicontroScp._Statepassivity = false;
  134. }
  135. if (event.animationState.name === "be_beaten") {
  136. console.log("critical_strike 动作播放完毕!!!");
  137. //TODO:
  138. this.armatureDisplay.node.scaleX = 1;
  139. this.armature.animation.play("idle", 0);
  140. this.aicontroScp._Hurt = false;
  141. this.aicontroScp._Statepassivity = false;
  142. }
  143. if (event.animationState.name === "critical_strike") {
  144. console.log("critical_strike 动作播放完毕!!!");
  145. //TODO:
  146. //this.armatureDisplay.node.scaleX = 0.39;
  147. this.armature.animation.play("idle", 0);
  148. this.aicontroScp._CriticalStrike = false;
  149. this.aicontroScp._Statepassivity = false;
  150. }
  151. if (event.animationState.name === "double-hit") {
  152. console.log("double-hit 动作播放完毕!!!");
  153. //TODO:
  154. //this.armatureDisplay.node.scaleX = 0.39;
  155. this.armature.animation.play("idle", 0);
  156. this.aicontroScp._DoubleHit = false;
  157. this.aicontroScp._Statepassivity = false;
  158. }
  159. if (event.animationState.name === "dodge") {
  160. console.log("dodge 动作播放完毕!!!");
  161. //TODO:
  162. //this.armatureDisplay.node.scaleX = 0.39;
  163. this.armature.animation.play("idle", 0);
  164. this.aicontroScp._RightDodge = false;
  165. this.aicontroScp._LeftDodg = false;
  166. this.aicontroScp._Statepassivity = false;
  167. }
  168. if (event.animationState.name === "block") {
  169. console.log("block 动作播放完毕!!!");
  170. //TODO:
  171. // this.armatureDisplay.node.scaleX = 0.39;
  172. this.armature.animation.play("idle", 0);
  173. this.aicontroScp._Defence = false;
  174. this.aicontroScp._Statepassivity = false;
  175. }
  176. }
  177. },
  178. animationEventHandler_Enter(event) {
  179. },
  180. init() {
  181. //角色脚本
  182. this.controScp = this.PlayerController.getComponent('PlayerController');
  183. //Ai脚本
  184. this.aicontroScp = this.AiPlayerController.getComponent('AiPlayerController');
  185. },
  186. });