PlayerController.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. cc.Class({
  2. extends: require("BasePlayerController"),
  3. properties: {
  4. TouchNode: cc.Node,
  5. charactor: cc.Node,
  6. AiController: 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. let Self = this;
  24. this.TouchNode.on('gesture', function(event) {
  25. //console.log(event.name);
  26. Self.Gesture(event.name);
  27. });
  28. },
  29. start() {
  30. this.init();
  31. },
  32. init() {
  33. //角色脚本
  34. this.ctorScp = this.charactor.getComponent('Charactor');
  35. this.AiControScp = this.AiController.getComponent('AiPlayerController');
  36. //this.statesScp = this.charactor.getComponent('PlayerStates');
  37. this.stateScp = this.states.getComponent('PlayerStates');
  38. },
  39. Gesture(name) {
  40. var randomnum_1 = parseInt(Math.round(Math.random() * 98 + 1)); //(0-100]
  41. var randomnum_2 = parseInt(Math.round(Math.random() + 1)); //[1-2]
  42. //console.log(randomnum_1, randomnum_2);
  43. if (name == 'right_top') {
  44. if (randomnum_1 >= 1 && randomnum_1 <= 10) {
  45. //出现暴击或者连击
  46. if (randomnum_2 == 1) {
  47. //暴击
  48. this._CriticalStrike = true;
  49. this.ctorScp.attack(2);
  50. this.AiControScp.ondefense_Ai(1, 1); //左右拳,击打类型
  51. }
  52. if (randomnum_2 == 2) {
  53. //连击
  54. this._DoubleHit = true;
  55. this.ctorScp.attack(4);
  56. this.AiControScp.ondefense_Ai(1, 2); //左右拳,击打类型
  57. }
  58. } else { //普攻状态 普攻动作
  59. this._RightJayShow = true;
  60. this.ctorScp.attack(0);
  61. this.AiControScp.ondefense_Ai(1, 0); //左右拳,击打类型
  62. }
  63. } else if (name == 'left_top') {
  64. if (randomnum_1 >= 1 && randomnum_1 <= 10) {
  65. //出现暴击或者连击
  66. if (randomnum_2 == 1) {
  67. //暴击
  68. this._CriticalStrike = true;
  69. this.ctorScp.attack(3);
  70. this.AiControScp.ondefense_Ai(-1, 1); //左右拳,击打类型
  71. }
  72. if (randomnum_2 == 2) {
  73. //连击
  74. this._DoubleHit = true;
  75. this.ctorScp.attack(5);
  76. this.AiControScp.ondefense_Ai(-1, 2); //左右拳,击打类型
  77. }
  78. } else { //普攻状态 普攻动作
  79. this._LeftJayShow = true;
  80. this.ctorScp.attack(1);
  81. this.AiControScp.ondefense_Ai(-1, 0); //左右拳,击打类型
  82. }
  83. } else if (name == 'right_down') {
  84. this.AiControScp._Statepassivity = false;
  85. if (this.AiControScp._RightJayShow) {
  86. //被右拳打中
  87. if (this.AiControScp._CriticalStrike) {
  88. //被右拳打中 暴击
  89. this.ctorScp.hurt(1, 1);
  90. return;
  91. }
  92. if (this.AiControScp._DoubleHit) {
  93. //被右拳打中 连击
  94. this.ctorScp.hurt(1, 2);
  95. return;
  96. }
  97. this.ctorScp.hurt(1, 0);
  98. return;
  99. }
  100. this._RightDodge = true;
  101. this.ctorScp.dodge(0);
  102. } else if (name == 'left_down') {
  103. this.AiControScp._Statepassivity = false;
  104. if (this.AiControScp._LeftJayShow) {
  105. //被左拳打中
  106. if (this.AiControScp._CriticalStrike) {
  107. //被左拳打中 暴击
  108. this.ctorScp.hurt(0, 1);
  109. return;
  110. }
  111. if (this.AiControScp._DoubleHit) {
  112. //被左拳打中 连击
  113. this.ctorScp.hurt(0, 2);
  114. return;
  115. }
  116. this.ctorScp.hurt(0, 0);
  117. return;
  118. }
  119. this._LeftDodg = true;
  120. this.ctorScp.dodge(1);
  121. } else if (name == 'down') {
  122. if (this.stateScp._endurance >= this.stateScp._block_minus_endurance) {
  123. this._Defence = true;
  124. this.AiControScp._Statepassivity = false;
  125. this.ctorScp.block();
  126. } else {
  127. this._Defence = false;
  128. this.AiControScp._Statepassivity = true;
  129. }
  130. }
  131. },
  132. update(dt) {
  133. },
  134. });