PlayerStates.js 5.5 KB

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