PlayerStates.js 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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. cc.audioEngine.playEffect(this.UiController.audioArr[4]);
  65. this._hp = this.minusblood(this._hp);
  66. this.progressBar_hp.getComponent(cc.Sprite).fillRange = this._hp / this._maxhp;
  67. });
  68. this.Charactor.on("hurt_critical", () => {
  69. cc.audioEngine.playEffect(this.UiController.audioArr[4]);
  70. this._hp = this.minusblood_critical(this._hp);
  71. //console.log("暴击后的血量:", this._hp);
  72. this.progressBar_hp.getComponent(cc.Sprite).fillRange = this._hp / this._maxhp;
  73. });
  74. this.Charactor.on("hurt_double", () => {
  75. cc.audioEngine.playEffect(this.UiController.audioArr[4]);
  76. this._hp = this.minusblood(this._hp);
  77. this.progressBar_hp.getComponent(cc.Sprite).fillRange = this._hp / this._maxhp;
  78. this._hp = this.minusblood(this._hp);
  79. this.progressBar_hp.getComponent(cc.Sprite).fillRange = this._hp / this._maxhp;
  80. });
  81. //被动回血回蓝
  82. this.schedule(() => {
  83. this._hp = this.addblood(this._maxhp, this._hp, 0);
  84. this._endurance = this.addendurance(this._maxendurance, this._endurance, 0);
  85. }, 1);
  86. },
  87. start() {
  88. this.init();
  89. },
  90. init() {
  91. this.gamestate = cc.find("Canvas/Game/Interface_Game").getComponent('Interface_game');
  92. //角色脚本
  93. this.controScp = this.playerController.getComponent('PlayerController');
  94. this.charactortroScp = this.Charactor.getComponent('Charactor');
  95. //this.playerStateScp = this.PlayerState.getComponent('PlayerStates');
  96. this.aiplayerStateScp = this.AiPlayerState.getComponent('AiPlayerStates');
  97. this.UiController = cc.find("Canvas/UiController").getComponent('UiController');
  98. },
  99. update(dt) {
  100. if (this._hp <= 0 || this._hp <= this.aiplayerStateScp._hp && this.gamestate._game_time == 0) {
  101. cc.audioEngine.playEffect(this.UiController.audioArr[2]);
  102. this.game.removeAllChildren();
  103. var self = this;
  104. cc.loader.loadRes("prefab/Result/interface_Loser", cc.Prefab, (err, ResultArr) => {
  105. self.PanelResult.addChild(cc.instantiate(ResultArr))
  106. });
  107. // this.interface_game.active = false;
  108. }
  109. },
  110. });