PlayerController.js 5.2 KB

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