AiCharactor.js 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  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("right_fit", 1);
  25. this.node.emit("attack1");
  26. } else if (bLeft == 1) {
  27. //左拳
  28. //this.armatureDisplay.node.scaleX = -1;
  29. this.armature.animation.play("left_fit", 1);
  30. this.node.emit("attack2");
  31. }
  32. //暴击右
  33. else if (bLeft == 2) {
  34. this.armatureDisplay.node.scaleX = 1;
  35. this.armature.animation.play("double_hit", 1);
  36. this.node.emit("attack_critical_strike1");
  37. }
  38. //暴击左
  39. else if (bLeft == 3) {
  40. this.armatureDisplay.node.scaleX = -1;
  41. this.armature.animation.play("double_hit", 1);
  42. this.node.emit("attack_critical_strike2");
  43. }
  44. //连击
  45. else if (bLeft == 4) {
  46. this.armatureDisplay.node.scaleX = 1;
  47. this.armature.animation.play("critical_strike", 1);
  48. this.node.emit("attack_double_hit1");
  49. }
  50. //连击
  51. else if (bLeft == 5) {
  52. this.armatureDisplay.node.scaleX = -1;
  53. this.armature.animation.play("critical_strike", 1);
  54. this.node.emit("attack_double_hit2");
  55. }
  56. },
  57. dodge(bLeft) { //躲闪
  58. //发射躲闪事件
  59. if (bLeft == 0) {
  60. //左躲闪
  61. this.armatureDisplay.node.scaleX = 1;
  62. this.armature.animation.play("dodge", 1);
  63. } else if (bLeft == 1) {
  64. //右躲闪
  65. this.armatureDisplay.node.scaleX = -1;
  66. this.armature.animation.play("dodge", 1);
  67. }
  68. this.node.emit("dodge");
  69. },
  70. hurt(bLeft, type) { //挨打 左右拳,击打类型
  71. //发射挨打事件
  72. if (type == 0) {
  73. //普通挨打
  74. if (bLeft == 0) {
  75. //左挨打
  76. //this.armatureDisplay.node.scaleX = -1;
  77. this.armature.animation.play("be_beaten_left", 1);
  78. } else if (bLeft == 1) {
  79. //右挨打
  80. //this.armatureDisplay.node.scaleX = 1;
  81. this.armature.animation.play("be_beaten_right", 1);
  82. }
  83. this.node.emit("hurt_ord");
  84. }
  85. if (type == 1) {
  86. if (bLeft == 0) {
  87. //左挨打
  88. //被暴打
  89. this.armatureDisplay.node.scaleX = -1;
  90. this.armature.animation.play("be_double_hit", 1);
  91. } else if (bLeft == 1) {
  92. //被暴打
  93. //右挨打
  94. this.armatureDisplay.node.scaleX = 1;
  95. this.armature.animation.play("be_double_hit", 1);
  96. }
  97. this.node.emit("hurt_critical");
  98. }
  99. if (type == 2) {
  100. if (bLeft == 0) {
  101. //被连击打
  102. //左挨打
  103. this.armatureDisplay.node.scaleX = -1;
  104. this.armature.animation.play("be_critical_strike", 1);
  105. } else if (bLeft == 1) {
  106. //被连击打
  107. //右挨打
  108. this.armatureDisplay.node.scaleX = 1;
  109. this.armature.animation.play("be_critical_strike", 1);
  110. }
  111. this.node.emit("hurt_double");
  112. }
  113. },
  114. block() { //防御
  115. this.armature.animation.play("block", 1);
  116. this.node.emit("block");
  117. },
  118. animationEventHandler(event) {
  119. if (event.type === dragonBones.EventObject.COMPLETE) {
  120. //主角
  121. if (event.animationState.name === "right_fit" || event.animationState.name === "left_fit") {
  122. //console.log("attack 动作播放完毕!!!");
  123. //TODO:
  124. this.armatureDisplay.node.scaleX = 1;
  125. this.armature.animation.play("idle", 0);
  126. this.aicontroScp._RightJayShow = false;
  127. this.aicontroScp._LeftJayShow = false;
  128. this.aicontroScp._Statepassivity = false;
  129. if (this.controScp._Hurt) {
  130. this.UiController.Ui_Shake(3);
  131. }
  132. }
  133. if (event.animationState.name === "be_beaten_left" || event.animationState.name === "be_beaten_right") {
  134. // console.log("critical_strike 动作播放完毕!!!");
  135. //TODO:
  136. this.armatureDisplay.node.scaleX = 1;
  137. this.armature.animation.play("idle", 0);
  138. this.aicontroScp._Hurt = false;
  139. this.aicontroScp._Statepassivity = false;
  140. }
  141. if (event.animationState.name === "double_hit") {
  142. // console.log("critical_strike 动作播放完毕!!!");
  143. //TODO:
  144. this.armatureDisplay.node.scaleX = 1;
  145. this.armature.animation.play("idle", 0);
  146. this.aicontroScp._CriticalStrike = false;
  147. this.aicontroScp._Statepassivity = false;
  148. if (this.controScp._BeDoubleHit) {
  149. this.UiController.Ui_Shake(3);
  150. }
  151. }
  152. if (event.animationState.name === "critical_strike") {
  153. //console.log("double-hit 动作播放完毕!!!");
  154. //TODO:
  155. this.armatureDisplay.node.scaleX = 1;
  156. this.armature.animation.play("idle", 0);
  157. this.aicontroScp._DoubleHit = false;
  158. this.aicontroScp._Statepassivity = false;
  159. if (this.controScp._BeCriticalStrike) {
  160. this.UiController.Ui_Shake(3);
  161. }
  162. }
  163. if (event.animationState.name === "dodge") {
  164. // console.log("dodge 动作播放完毕!!!");
  165. //TODO:
  166. this.armatureDisplay.node.scaleX = 1;
  167. this.armature.animation.play("idle", 0);
  168. this.aicontroScp._RightDodge = false;
  169. this.aicontroScp._LeftDodg = false;
  170. this.aicontroScp._Statepassivity = false;
  171. }
  172. if (event.animationState.name === "block") {
  173. // console.log("block 动作播放完毕!!!");
  174. //TODO:
  175. this.armatureDisplay.node.scaleX = 1;
  176. this.armature.animation.play("idle", 0);
  177. this.aicontroScp._Defence = false;
  178. this.aicontroScp._Statepassivity = false;
  179. }
  180. if (event.animationState.name === "be_beaten_left" || event.animationState.name === "be_critical_strike" ||
  181. event.animationState.name === "be_double_hit" || event.animationState.name === "be_beaten_right") {
  182. // console.log("be_beaten 动作播放完毕!!!");
  183. //TODO:
  184. this.armatureDisplay.node.scaleX = 1;
  185. this.armature.animation.play("idle", 0);
  186. this.aicontroScp._Defence = false;
  187. this.aicontroScp._Statepassivity = false;
  188. }
  189. }
  190. },
  191. animationEventHandler_Enter(event) {
  192. },
  193. init() {
  194. //角色脚本
  195. this.controScp = this.PlayerController.getComponent('PlayerController');
  196. //Ai脚本
  197. this.aicontroScp = this.AiPlayerController.getComponent('AiPlayerController');
  198. this.UiController = cc.find("Canvas/UiController").getComponent('UiController');
  199. },
  200. });