AiPlayerStates.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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("attack", () => {
  35. //console.log("检测到攻击2");
  36. cc.audioEngine.playEffect(this.UiController.audioArr[3]);
  37. });
  38. this.Charactor.on("attack_critical_strike", () => {
  39. //console.log("检测到暴击2");
  40. cc.audioEngine.playEffect(this.UiController.audioArr[3]);
  41. });
  42. this.Charactor.on("attack_double-hit", () => {
  43. //console.log("检测到连击2");
  44. cc.audioEngine.playEffect(this.UiController.audioArr[3]);
  45. cc.audioEngine.playEffect(this.UiController.audioArr[3]);
  46. });
  47. this.Charactor.on("dodge", () => {
  48. //console.log("检测到躲闪2");
  49. this.addendurance(this._maxendurance, this._endurance, 1); //闪避回蓝
  50. this.progressBar_endur.getComponent(cc.Sprite).fillRange = this._endurance / this._maxendurance;
  51. });
  52. this.Charactor.on("block", () => {
  53. // console.log("检测到防御2");
  54. cc.audioEngine.playEffect(this.UiController.audioArr[1]);
  55. this._endurance = this.minusendurance(this._endurance); //减蓝
  56. this._hp = this.addblood(this._maxhp, this._hp, 1); //回血
  57. this.progressBar_hp.getComponent(cc.Sprite).fillRange = this._hp / this._maxhp;
  58. this.progressBar_endur.getComponent(cc.Sprite).fillRange = this._endurance / this._maxendurance;
  59. });
  60. this.Charactor.on("hurt_ord", () => {
  61. // console.log("检测到受普攻");
  62. cc.audioEngine.playEffect(this.UiController.audioArr[4]);
  63. this._hp = this.minusblood(this._hp);
  64. this.progressBar_hp.getComponent(cc.Sprite).fillRange = this._hp / this._maxhp;
  65. });
  66. this.Charactor.on("hurt_critical", () => {
  67. //console.log("检测到受暴击");
  68. cc.audioEngine.playEffect(this.UiController.audioArr[4]);
  69. this._hp = this.minusblood_critical(this._hp);
  70. //console.log("暴击后的血量:", this._hp);
  71. this.progressBar_hp.getComponent(cc.Sprite).fillRange = this._hp / this._maxhp;
  72. });
  73. this.Charactor.on("hurt_double", () => {
  74. cc.audioEngine.playEffect(this.UiController.audioArr[4]);
  75. cc.audioEngine.playEffect(this.UiController.audioArr[4]);
  76. //console.log("检测到受连攻");
  77. this._hp = this.minusblood(this._hp);
  78. this.progressBar_hp.getComponent(cc.Sprite).fillRange = this._hp / this._maxhp;
  79. this._hp = this.minusblood(this._hp);
  80. this.progressBar_hp.getComponent(cc.Sprite).fillRange = this._hp / this._maxhp;
  81. });
  82. this.init();
  83. },
  84. update(dt) {
  85. if (this._hp <= 0 || this._hp <= this.playerStateScp._hp && this.gamestate._game_time == 0) {
  86. cc.audioEngine.playEffect(this.UiController.audioArr[2]);
  87. this.game.removeAllChildren();
  88. var self = this;
  89. cc.loader.loadRes("prefab/Result/interface_Win", cc.Prefab, (err, ResultArr) => {
  90. // ...
  91. self.PanelResult.addChild(cc.instantiate(ResultArr));
  92. });
  93. }
  94. },
  95. init() {
  96. this.gamestate = cc.find("Canvas/Game/Interface_Game").getComponent('Interface_game');
  97. // //角色脚本
  98. // this.controScp = this.playerController.getComponent('PlayerController');
  99. // this.charactortroScp = this.Charactor.getComponent('Charactor');
  100. //this.playerStateScp = this.PlayerState.getComponent('PlayerStates');
  101. this.playerStateScp = this.PlayerState.getComponent('PlayerStates');
  102. this.UiController = cc.find("Canvas/UiController").getComponent('UiController');
  103. },
  104. });