import { _decorator, Component, Node, instantiate, Prefab } from 'cc'; import { DataSystem } from '../core/data/DataSystem'; import { Sound } from '../core/sound/Sound'; import { ConfigData } from '../data/ConfigData'; import { BattleData, BattleState } from './BattleData'; import { BuffData } from './BuffData'; import { ComboNode } from './ComboNode'; import { MissionData } from './MissionData'; const { ccclass, property } = _decorator; @ccclass('Combination') export class Combination extends Component { @property({ type: Node, tooltip: "全屏特效层" }) effect: Node; @property({ type: Prefab, tooltip: "全屏特效预制体" }) prefab: Prefab; private missionConfig: any; private data: BattleData; /**是否可以使用组合技 */ private _canUseCombination: boolean = false; /**组合技计时器 */ public _combinationTimer = 0; /**音效组件 */ private sound: Sound; private useCount = 0; private nowCount = 0; start() { this.data = DataSystem.getData(BattleData); this.missionConfig = DataSystem.getData(ConfigData)["mission"]; this.sound = this.getComponent(Sound); } update(dt: number) { DataSystem.watch(BattleData, "mission") && this.changeMission(); this.combinationCountDown(dt); } private changeMission(): void { this._canUseCombination = false; this._combinationTimer = 0; let isBoss = this.missionConfig[this.data.mission]["type"] == "2"; if (!isBoss) { this.checkCombination(); } this.nowCount = this.useCount = 0; } /**检查组合技 */ private checkCombination(): void { let camp: Array = DataSystem.getData(ConfigData)["fetter"]["5"]["specificGroup"].split(";"); let heros: Array> = []; for (let i = 0; i < camp.length; i++) { heros.push(camp[i].split(",")); } let count = 0; for (let k = 0; k < heros.length; k++) { count = 0; for (let j = 1; j <= this.data.heros.size; j++) { if (heros[k].indexOf(this.data.heros.get(j).id + "") == -1) { this._canUseCombination = false; DataSystem.getData(BuffData).canUseCombination = false; break; } else { count++; } } if (count == 5) { this._canUseCombination = true; DataSystem.getData(BuffData).canUseCombination = true; return; } } this._canUseCombination = false; DataSystem.getData(BuffData).canUseCombination = false; } /**使用组合技 */ private async useCombination(time: number) { if (this.useCount > this.nowCount) { this.nowCount = time; let node = instantiate(this.prefab); node.setParent(this.effect); node.getComponent(ComboNode).setData(this.data._monsters, time); if (this.sound && !DataSystem.getData(MissionData).isInPvp) { this.sound.play(); } } } /**组合技使用计时 */ private combinationCountDown(dt: number): void { if (this._canUseCombination && this.data.battleState == BattleState.inBattle) { this._combinationTimer += dt; if (Math.floor(this._combinationTimer) != 0 && Math.floor(this._combinationTimer) % 5 == 0) { this.useCount = Math.floor(this._combinationTimer) / 5 this.useCombination(this.useCount); if (this.useCount == 3) { this._canUseCombination = false; } } } } }