AiPlayerStates.js 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. cc.Class({
  2. extends: require("BasePlayerStates"),
  3. properties: {
  4. playerController: cc.Node,
  5. Charactor: cc.Node,
  6. PlayerState: cc.Node,
  7. progressBar_hp: cc.Node,
  8. progressBar_endur: cc.Node,
  9. },
  10. onLoad() {
  11. this.game = cc.find("Canvas/Game");
  12. this.PanelResult = cc.find("Canvas/PanelResult");
  13. this._super();
  14. this._hp = this.hp;
  15. this._maxhp = this.maxhp; //血量
  16. this._endurance = this.endurance;
  17. this._maxendurance = this.maxendurance; //蓝量
  18. this._damage = this.damage; //攻击力
  19. this._defense = this.defense; //防御
  20. this._combo_rate = this.combo_rate; //连击率
  21. this._crit_rate = this.crit_rate; //暴击率
  22. this._dodge_endurance = this.dodge_endurance; //闪避回蓝
  23. this._defense_hp = this.defense_hp; //格挡回血
  24. this._recover_hp = this.recover_hp; //被动回血1/s
  25. this._recover_endurance = this.recover_endurance; //被动回蓝1/s
  26. this._block_minus_endurance = this.block_minus_endurance; //格挡减蓝量
  27. //被动回血回蓝
  28. this.schedule(() => {
  29. this._hp = this.addblood(this._maxhp, this._hp, 0);
  30. this._endurance = this.addendurance(this._maxendurance, this._endurance, 0);
  31. }, 1);
  32. },
  33. start() {
  34. this.Charactor.on("attack1", () => {
  35. //console.log("检测到攻击2 右");
  36. this.UiController.Ui_Shake(2);
  37. cc.audioEngine.playEffect(this.UiController.audioArr[3]);
  38. });
  39. this.Charactor.on("attack2", () => {
  40. //console.log("检测到攻击2 左");
  41. this.UiController.Ui_Shake(1);
  42. cc.audioEngine.playEffect(this.UiController.audioArr[3]);
  43. });
  44. this.Charactor.on("attack_critical_strike1", () => {
  45. //console.log("检测到暴击2右");
  46. this.UiController.Ui_Shake(2);
  47. cc.audioEngine.playEffect(this.UiController.audioArr[3]);
  48. });
  49. this.Charactor.on("attack_critical_strike2", () => {
  50. //console.log("检测到暴击2左");
  51. this.UiController.Ui_Shake(1);
  52. cc.audioEngine.playEffect(this.UiController.audioArr[3]);
  53. });
  54. this.Charactor.on("attack_double-hit1", () => {
  55. //console.log("检测到连击2右");
  56. this.UiController.Ui_Shake(2);
  57. cc.audioEngine.playEffect(this.UiController.audioArr[3]);
  58. cc.audioEngine.playEffect(this.UiController.audioArr[3]);
  59. });
  60. this.Charactor.on("attack_double-hit2", () => {
  61. //console.log("检测到连击2左");
  62. this.UiController.Ui_Shake(1);
  63. cc.audioEngine.playEffect(this.UiController.audioArr[3]);
  64. cc.audioEngine.playEffect(this.UiController.audioArr[3]);
  65. });
  66. this.Charactor.on("dodge", () => {
  67. //console.log("检测到躲闪2");
  68. this.addendurance(this._maxendurance, this._endurance, 1); //闪避回蓝
  69. this.progressBar_endur.getComponent(cc.Sprite).fillRange = this._endurance / this._maxendurance;
  70. });
  71. this.Charactor.on("block", () => {
  72. // console.log("检测到防御2");
  73. cc.audioEngine.playEffect(this.UiController.audioArr[1]);
  74. this._endurance = this.minusendurance(this._endurance); //减蓝
  75. this._hp = this.addblood(this._maxhp, this._hp, 1); //回血
  76. this.progressBar_hp.getComponent(cc.Sprite).fillRange = this._hp / this._maxhp;
  77. this.progressBar_endur.getComponent(cc.Sprite).fillRange = this._endurance / this._maxendurance;
  78. });
  79. this.Charactor.on("hurt_ord", () => {
  80. // console.log("检测到受普攻");
  81. this.UiController.Shake(this.Charactor, 1);
  82. cc.audioEngine.playEffect(this.UiController.audioArr[4]);
  83. this._hp = this.minusblood(this._hp);
  84. this.progressBar_hp.getComponent(cc.Sprite).fillRange = this._hp / this._maxhp;
  85. });
  86. this.Charactor.on("hurt_critical", () => {
  87. //console.log("检测到受暴击");
  88. this.UiController.Shake(this.Charactor, 1);
  89. cc.audioEngine.playEffect(this.UiController.audioArr[4]);
  90. this._hp = this.minusblood_critical(this._hp);
  91. //console.log("暴击后的血量:", this._hp);
  92. this.progressBar_hp.getComponent(cc.Sprite).fillRange = this._hp / this._maxhp;
  93. });
  94. this.Charactor.on("hurt_double", () => {
  95. this.UiController.Shake(this.Charactor, 1);
  96. this.UiController.Shake(this.Charactor, 1);
  97. cc.audioEngine.playEffect(this.UiController.audioArr[4]);
  98. cc.audioEngine.playEffect(this.UiController.audioArr[4]);
  99. //console.log("检测到受连攻");
  100. this._hp = this.minusblood(this._hp);
  101. this.progressBar_hp.getComponent(cc.Sprite).fillRange = this._hp / this._maxhp;
  102. this._hp = this.minusblood(this._hp);
  103. this.progressBar_hp.getComponent(cc.Sprite).fillRange = this._hp / this._maxhp;
  104. });
  105. this.init();
  106. },
  107. update(dt) {
  108. if (this._hp <= 0 || this._hp <= this.playerStateScp._hp && this.gamestate._game_time == 0) {
  109. cc.audioEngine.playEffect(this.UiController.audioArr[2]);
  110. this.game.removeAllChildren();
  111. var self = this;
  112. cc.loader.loadRes("prefab/Result/interface_Win", cc.Prefab, (err, ResultArr) => {
  113. // ...
  114. self.PanelResult.addChild(cc.instantiate(ResultArr));
  115. });
  116. }
  117. if (this._hp <= this._damage) {
  118. this.UiController.Ui_Shake(4); //气血不足
  119. }
  120. if (this._endurance <= this._block_minus_endurance) {
  121. this.UiController.Ui_Shake(5); //能量不足不足
  122. }
  123. },
  124. init() {
  125. this.gamestate = cc.find("Canvas/Game/Interface_Game").getComponent('Interface_game');
  126. // //角色脚本
  127. // this.controScp = this.playerController.getComponent('PlayerController');
  128. // this.charactortroScp = this.Charactor.getComponent('Charactor');
  129. //this.playerStateScp = this.PlayerState.getComponent('PlayerStates');
  130. this.playerStateScp = this.PlayerState.getComponent('PlayerStates');
  131. this.UiController = cc.find("Canvas/UiController").getComponent('UiController');
  132. },
  133. });