AiPlayerStates.js 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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. cc.audioEngine.playEffect(this.UiController.audioArr[3]);
  37. });
  38. this.Charactor.on("attack2", () => {
  39. //console.log("检测到攻击2 左");
  40. cc.audioEngine.playEffect(this.UiController.audioArr[3]);
  41. });
  42. this.Charactor.on("attack_critical_strike1", () => {
  43. //console.log("检测到暴击2右");
  44. //this.UiController.Ui_Shake(2);
  45. cc.audioEngine.playEffect(this.UiController.audioArr[3]);
  46. });
  47. this.Charactor.on("attack_critical_strike2", () => {
  48. //console.log("检测到暴击2左");
  49. // this.UiController.Ui_Shake(1);
  50. cc.audioEngine.playEffect(this.UiController.audioArr[3]);
  51. });
  52. this.Charactor.on("attack_double_hit1", () => {
  53. //console.log("检测到连击2右");
  54. // this.UiController.Ui_Shake(2);
  55. cc.audioEngine.playEffect(this.UiController.audioArr[3]);
  56. cc.audioEngine.playEffect(this.UiController.audioArr[3]);
  57. });
  58. this.Charactor.on("attack_double_hit2", () => {
  59. //console.log("检测到连击2左");
  60. // this.UiController.Ui_Shake(1);
  61. cc.audioEngine.playEffect(this.UiController.audioArr[3]);
  62. cc.audioEngine.playEffect(this.UiController.audioArr[3]);
  63. });
  64. this.Charactor.on("dodge", () => {
  65. //console.log("检测到躲闪2");
  66. this.addendurance(this._maxendurance, this._endurance, 1); //闪避回蓝
  67. this.progressBar_endur.getComponent(cc.Sprite).fillRange = this._endurance / this._maxendurance;
  68. });
  69. this.Charactor.on("block", () => {
  70. // console.log("检测到防御2");
  71. cc.audioEngine.playEffect(this.UiController.audioArr[1]);
  72. this._endurance = this.minusendurance(this._endurance); //减蓝
  73. this._hp = this.addblood(this._maxhp, this._hp, 1); //回血
  74. this.progressBar_hp.getComponent(cc.Sprite).fillRange = this._hp / this._maxhp;
  75. this.progressBar_endur.getComponent(cc.Sprite).fillRange = this._endurance / this._maxendurance;
  76. });
  77. this.Charactor.on("hurt_ord", () => {
  78. // console.log("检测到受普攻");
  79. this.UiController.Shake(this.Charactor, 2);
  80. cc.audioEngine.playEffect(this.UiController.audioArr[4]);
  81. this._hp = this.minusblood(this._hp);
  82. this.progressBar_hp.getComponent(cc.Sprite).fillRange = this._hp / this._maxhp;
  83. });
  84. this.Charactor.on("hurt_critical", () => {
  85. //console.log("检测到受暴击");
  86. this.UiController.Shake(this.Charactor, 2);
  87. cc.audioEngine.playEffect(this.UiController.audioArr[4]);
  88. this._hp = this.minusblood_critical(this._hp);
  89. //console.log("暴击后的血量:", this._hp);
  90. this.progressBar_hp.getComponent(cc.Sprite).fillRange = this._hp / this._maxhp;
  91. });
  92. this.Charactor.on("hurt_double", () => {
  93. this.UiController.Shake(this.Charactor, 2);
  94. cc.audioEngine.playEffect(this.UiController.audioArr[4]);
  95. cc.audioEngine.playEffect(this.UiController.audioArr[4]);
  96. //console.log("检测到受连攻");
  97. this._hp = this.minusblood(this._hp);
  98. this.progressBar_hp.getComponent(cc.Sprite).fillRange = this._hp / this._maxhp;
  99. this._hp = this.minusblood(this._hp);
  100. this.progressBar_hp.getComponent(cc.Sprite).fillRange = this._hp / this._maxhp;
  101. });
  102. this.init();
  103. },
  104. update(dt) {
  105. if (this._hp <= 0 || this._hp <= this.playerStateScp._hp && this.gamestate._game_time == 0) {
  106. this._GameState.gameresult = true;
  107. this._GameState._currPass++;
  108. if (this._GameState._currPass >= 3) {
  109. this._GameState._currPass = 3;
  110. }
  111. // console.log("胜利", this._GameState.gameresult);
  112. cc.audioEngine.playEffect(this.UiController.audioArr[2]);
  113. this.game.removeAllChildren();
  114. var self = this;
  115. cc.loader.loadRes("prefab/Result/interface_Win", cc.Prefab, (err, ResultArr) => {
  116. // ...
  117. self.PanelResult.addChild(cc.instantiate(ResultArr));
  118. });
  119. }
  120. },
  121. init() {
  122. this.gamestate = cc.find("Canvas/Game/Interface_Game").getComponent('Interface_game');
  123. // //角色脚本
  124. // this.controScp = this.playerController.getComponent('PlayerController');
  125. // this.charactortroScp = this.Charactor.getComponent('Charactor');
  126. //this.playerStateScp = this.PlayerState.getComponent('PlayerStates');
  127. this.playerStateScp = this.PlayerState.getComponent('PlayerStates');
  128. this.UiController = cc.find("Canvas/UiController").getComponent('UiController');
  129. this._GameState = cc.find("GameStates").getComponent("GameStates");
  130. },
  131. });