Combination.ts 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. import { _decorator, Component, Node, instantiate, Prefab } from 'cc';
  2. import { DataSystem } from '../core/data/DataSystem';
  3. import { Sound } from '../core/sound/Sound';
  4. import { ConfigData } from '../data/ConfigData';
  5. import { BattleData, BattleState } from './BattleData';
  6. import { BuffData } from './BuffData';
  7. import { ComboNode } from './ComboNode';
  8. import { MissionData } from './MissionData';
  9. const { ccclass, property } = _decorator;
  10. @ccclass('Combination')
  11. export class Combination extends Component {
  12. @property({ type: Node, tooltip: "全屏特效层" }) effect: Node;
  13. @property({ type: Prefab, tooltip: "全屏特效预制体" }) prefab: Prefab;
  14. private missionConfig: any;
  15. private data: BattleData;
  16. /**是否可以使用组合技 */
  17. private _canUseCombination: boolean = false;
  18. /**组合技计时器 */
  19. public _combinationTimer = 0;
  20. /**音效组件 */
  21. private sound: Sound;
  22. private useCount = 0;
  23. private nowCount = 0;
  24. start() {
  25. this.data = DataSystem.getData(BattleData);
  26. this.missionConfig = DataSystem.getData(ConfigData)["mission"];
  27. this.sound = this.getComponent(Sound);
  28. }
  29. update(dt: number) {
  30. DataSystem.watch(BattleData, "mission") && this.changeMission();
  31. this.combinationCountDown(dt);
  32. }
  33. private changeMission(): void {
  34. this._canUseCombination = false;
  35. this._combinationTimer = 0;
  36. let isBoss = this.missionConfig[this.data.mission]["type"] == "2";
  37. if (!isBoss) {
  38. this.checkCombination();
  39. }
  40. this.nowCount = this.useCount = 0;
  41. }
  42. /**检查组合技 */
  43. private checkCombination(): void {
  44. let camp: Array<string> = DataSystem.getData(ConfigData)["fetter"]["5"]["specificGroup"].split(";");
  45. let heros: Array<Array<string>> = [];
  46. for (let i = 0; i < camp.length; i++) {
  47. heros.push(camp[i].split(","));
  48. }
  49. let count = 0;
  50. for (let k = 0; k < heros.length; k++) {
  51. count = 0;
  52. for (let j = 1; j <= this.data.heros.size; j++) {
  53. if (heros[k].indexOf(this.data.heros.get(j).id + "") == -1) {
  54. this._canUseCombination = false;
  55. DataSystem.getData(BuffData).canUseCombination = false;
  56. break;
  57. } else {
  58. count++;
  59. }
  60. }
  61. if (count == 5) {
  62. this._canUseCombination = true;
  63. DataSystem.getData(BuffData).canUseCombination = true;
  64. return;
  65. }
  66. }
  67. this._canUseCombination = false;
  68. DataSystem.getData(BuffData).canUseCombination = false;
  69. }
  70. /**使用组合技 */
  71. private async useCombination(time: number) {
  72. if (this.useCount > this.nowCount) {
  73. this.nowCount = time;
  74. let node = instantiate(this.prefab);
  75. node.setParent(this.effect);
  76. node.getComponent(ComboNode).setData(this.data._monsters, time);
  77. if (this.sound && !DataSystem.getData(MissionData).isInPvp) {
  78. this.sound.play();
  79. }
  80. }
  81. }
  82. /**组合技使用计时 */
  83. private combinationCountDown(dt: number): void {
  84. if (this._canUseCombination && this.data.battleState == BattleState.inBattle) {
  85. this._combinationTimer += dt;
  86. if (Math.floor(this._combinationTimer) != 0 && Math.floor(this._combinationTimer) % 5 == 0) {
  87. this.useCount = Math.floor(this._combinationTimer) / 5
  88. this.useCombination(this.useCount);
  89. if (this.useCount == 3) {
  90. this._canUseCombination = false;
  91. }
  92. }
  93. }
  94. }
  95. }