/** * 血月机制-定时加速全体怪物 */ import { _decorator, Component, sp, Vec3, Node, tween } from 'cc'; import { ChapterNewPlayTypeEnum, IBloodMoonProperty } from '../../../game/ChapterPlayTypes'; import { Monster } from '../Monster'; import { BattleSpinePlayback } from 'db://assets/script/battle/presentation/BattleSpinePlayback'; const { ccclass, property } = _decorator; @ccclass('MechanismBloodMoonSchedule') export class MechanismBloodMoonSchedule extends Component { anim: sp.Skeleton = null; eff: Node = null; title: Node = null; guangdun:sp.Skeleton = null; onLoad(): void { this.anim = this.node.getChildByName('anim').getComponent(sp.Skeleton); this.eff = this.node.getChildByName('eff'); this.title = this.node.getChildByName('title'); this.guangdun = this.node.getChildByName('魔眼抗盾').getComponent(sp.Skeleton); this.anim.node.active = false; this.eff.active = false; this.title.active = false; this.guangdun.node.active = false; } protected onDisable(): void { this.unscheduleAllCallbacks(); } _dt: number = 0 private _pendingBloodMoonMonsters: Monster[] = []; private _pendingBloodMoonIndex: number = 0; private _pendingBloodMoonState: boolean | null = null; private _bloodMoonBatchSize: number = 12; bloodMoonInfo: IBloodMoonProperty = null; start() { this.bloodMoonInfo = gg.data.project.getChapterNewPlayInfo(ChapterNewPlayTypeEnum.BloodMoon); // gg.game.CurentBattle.RedMoonMultiplier = this.bloodMoonInfo.accelerateSpeed; } protected update(dt: number): void { if (!gg.game.CurentBattle.canUpdateFrame()) return; this.processBloodMoonQueue(); this._dt += dt * gg.game.CurentBattle.TimeScale; if (this._dt >= 1) { this._dt = 0 this.checkBloodMoonTime() } } checkBloodMoonTime() { if (this.bloodMoonInfo && this.bloodMoonInfo.openTimeArr && this.bloodMoonInfo.openTimeArr.length > 0 && gg.game.CurentBattle.BattleTime >= this.bloodMoonInfo.openTimeArr[0]) { this.bloodMoonInfo.openTimeArr.shift() this.playBloodMoonEffect(() => { // gg.game.CurentBattle.IsOpenRedMoon = true; // if(!gg.game.CurentBattle.IsOpenProtectiveCrystal){ // this.enqueueSetBloodMoon(true); // } }); } if (this.bloodMoonInfo && this.bloodMoonInfo.closeTimeArr && this.bloodMoonInfo.closeTimeArr.length > 0 && gg.game.CurentBattle.BattleTime >= this.bloodMoonInfo.closeTimeArr[0]) { this.bloodMoonInfo.closeTimeArr.shift(); this.exitBloodMoonEffect(() => { // gg.game.CurentBattle.IsOpenRedMoon = false; // if(!gg.game.CurentBattle.IsOpenProtectiveCrystal){ // this.enqueueSetBloodMoon(false); // } }); } } private enqueueSetBloodMoon(show: boolean) { const all = gg.game.CurentBattle.MonsterSpawner.getAllMonster(); this._pendingBloodMoonMonsters = all .map(x => x?.getComponent(Monster)) .filter(x => !!x && x.node && x.node.isValid); this._pendingBloodMoonIndex = 0; this._pendingBloodMoonState = show; } private processBloodMoonQueue() { if (this._pendingBloodMoonState === null || this._pendingBloodMoonMonsters.length <= 0) return; const show = this._pendingBloodMoonState; const left = this._pendingBloodMoonMonsters.length - this._pendingBloodMoonIndex; if (left <= 0) { this._pendingBloodMoonMonsters = []; this._pendingBloodMoonIndex = 0; this._pendingBloodMoonState = null; return; } const count = Math.min(this._bloodMoonBatchSize, left); for (let i = 0; i < count; i++) { const m = this._pendingBloodMoonMonsters[this._pendingBloodMoonIndex++]; if (m && m.node && m.node.isValid) { // m.setBloodMoon(show); } } if (this._pendingBloodMoonIndex >= this._pendingBloodMoonMonsters.length) { this._pendingBloodMoonMonsters = []; this._pendingBloodMoonIndex = 0; this._pendingBloodMoonState = null; } } playBloodMoonEffect(callback?: Function) { this.anim.node.active = true; this.eff.active = true; BattleSpinePlayback.play(this.anim, '出现', { loop: false, onComplete: () => { BattleSpinePlayback.play(this.anim, '待机', { loop: true }); this.guangdun.setAnimation(0, '持续', true); if (callback) callback(); }, }); this.showTitle(); } exitBloodMoonEffect(callback?: Function) { if (this.anim.node.active) { this.guangdun.node.active = false; BattleSpinePlayback.play(this.anim, '消失', { loop: false, onComplete: () => { this.anim.node.active = false; this.eff.active = false; if (callback) callback(); }, }); } } showTitle(callback?: Function) { this.title.active = true; tween(this.title) .set({ opacity: 0 }) .to(0.5, { opacity: 255 }) .delay(2) .to(0.5, { opacity: 0 }) .call(() => { if (callback) callback(); }) .start(); } }