PlayerStates.js 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  1. cc.Class({
  2. extends: cc.Component,
  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.init();
  19. this.game = cc.find("Canvas/Game");
  20. this.PanelResult = cc.find("Canvas/PanelResult");
  21. this._hp = this.Interface_Info.hp;
  22. this._maxhp = this.Interface_Info.maxhp; //血量
  23. this._endurance = this.Interface_Info.endurance;
  24. this._maxendurance = this.Interface_Info.maxendurance; //蓝量
  25. this._damage = this.Interface_Info.damage; //攻击力
  26. this._defense = this.Interface_Info.defense; //防御
  27. this._combo_rate = this.Interface_Info.combo_rate; //连击率
  28. this._crit_rate = this.Interface_Info.crit_rate; //暴击率
  29. this._dodge_endurance = this.Interface_Info.dodge_endurance; //闪避回蓝
  30. this._defense_hp = this.Interface_Info.defense_hp; //格挡回血
  31. this._recover_hp = this.Interface_Info.recover_hp; //被动回血1/s
  32. this._recover_endurance = this.Interface_Info.recover_endurance; //被动回蓝1/s
  33. this._block_minus_endurance = this.Interface_Info.block_minus_endurance; //格挡减蓝量
  34. //回复状态
  35. //this.oligemia();//继承BasePlayerStates函数
  36. this.Charactor.on("attack", () => {
  37. //console.log("检测到攻击1");
  38. cc.audioEngine.playEffect(this.UiController.audioArr[3]);
  39. });
  40. this.Charactor.on("attack_critical_strike", () => {
  41. //console.log("检测到暴击1");
  42. cc.audioEngine.playEffect(this.UiController.audioArr[3]);
  43. });
  44. this.Charactor.on("attack_double-hit", () => {
  45. //console.log("检测到连击1");
  46. cc.audioEngine.playEffect(this.UiController.audioArr[3]);
  47. cc.audioEngine.playEffect(this.UiController.audioArr[3]);
  48. });
  49. this.Charactor.on("dodge", () => {
  50. //console.log("检测到躲闪");
  51. this.addendurance(this._maxendurance, this._endurance, 1); //闪避回蓝
  52. this.progressBar_endur.getComponent(cc.Sprite).fillRange = this._endurance / this._maxendurance;
  53. });
  54. this.Charactor.on("block", () => {
  55. //console.log("检测到防御");
  56. cc.audioEngine.playEffect(this.UiController.audioArr[1]);
  57. this._endurance = this.Interface_Info.minusendurance(this._endurance); //减蓝
  58. this._hp = this.Interface_Info.addblood(this._maxhp, this._hp, 1); //回血
  59. this.progressBar_hp.getComponent(cc.Sprite).fillRange = this._hp / this._maxhp;
  60. this.progressBar_endur.getComponent(cc.Sprite).fillRange = this._endurance / this._maxendurance;
  61. });
  62. this.Charactor.on("hurt_ord", () => {
  63. cc.audioEngine.playEffect(this.UiController.audioArr[4]);
  64. this._hp = this.Interface_Info.minusblood(this._hp);
  65. this.progressBar_hp.getComponent(cc.Sprite).fillRange = this._hp / this._maxhp;
  66. });
  67. this.Charactor.on("hurt_critical", () => {
  68. cc.audioEngine.playEffect(this.UiController.audioArr[4]);
  69. this._hp = this.Interface_Info.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. this._hp = this.Interface_Info.minusblood(this._hp);
  76. this.progressBar_hp.getComponent(cc.Sprite).fillRange = this._hp / this._maxhp;
  77. this._hp = this.Interface_Info.minusblood(this._hp);
  78. this.progressBar_hp.getComponent(cc.Sprite).fillRange = this._hp / this._maxhp;
  79. });
  80. //被动回血回蓝
  81. this.schedule(() => {
  82. this._hp = this.Interface_Info.addblood(this._maxhp, this._hp, 0);
  83. this._endurance = this.Interface_Info.addendurance(this._maxendurance, this._endurance, 0);
  84. }, 1);
  85. },
  86. start() {
  87. console.log("角色血量", this._hp);
  88. console.log("角色伤害", this._damage);
  89. console.log("角色防御", this._defense);
  90. console.log("角色连击", this._combo_rate);
  91. },
  92. init() {
  93. this._GameState = cc.find("GameStates").getComponent("GameStates");
  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. this.Interface_Info = cc.find("Canvas/Interface_Info").getComponent("Interface_Info"); //角色数据界面脚本
  102. },
  103. update(dt) {
  104. if (this._hp <= 0 || this._hp <= this.aiplayerStateScp._hp && this.gamestate._game_time == 0) {
  105. cc.audioEngine.playEffect(this.UiController.audioArr[2]);
  106. // console.log("失败", this._GameState.gameresult);
  107. this.game.removeAllChildren();
  108. var self = this;
  109. cc.loader.loadRes("prefab/Result/interface_Loser", cc.Prefab, (err, ResultArr) => {
  110. self.PanelResult.addChild(cc.instantiate(ResultArr))
  111. });
  112. // this.interface_game.active = false;
  113. }
  114. if (this._hp <= this._damage) {
  115. this.UiController.Ui_Shake(4); //气血不足
  116. }
  117. if (this._endurance <= this._block_minus_endurance) {
  118. this.UiController.Ui_Shake(5); //能量不足不足
  119. }
  120. },
  121. });