You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
AdLike2048/assets/script/ui/BattleGame/NewMechanism/MechanismMagicEyeSchedule.ts

178 lines
5.9 KiB

/**
* 魔眼机制-定时加盾全体怪物
*/
import { _decorator, Component, sp, Vec3, Node, tween } from 'cc';
import { ChapterNewPlayTypeEnum, IMagicEyeProperty } from '../../../game/ChapterPlayTypes';
import { Monster } from '../Monster';
import { BattleSpinePlayback } from 'db://assets/script/battle/presentation/BattleSpinePlayback';
const { ccclass, property } = _decorator;
@ccclass('MechanismMagicEyeSchedule')
export class MechanismMagicEyeSchedule extends Component {
anim: sp.Skeleton = null;
eff: Node = null;
title: Node = null;
buff: sp.Skeleton = 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.buff = this.node.getChildByName('buff').getComponent(sp.Skeleton);
this.guangdun = this.node.getChildByName('魔眼抗盾').getComponent(sp.Skeleton);
this.anim.node.active = false;
this.eff.active = false;
this.title.active = false;
this.buff.node.active = false;
this.guangdun.node.active = false;
}
protected onDisable(): void {
this.unscheduleAllCallbacks();
}
/**开启CD时间 */
private enableCDTime: number = 0;
/**持续时间 */
private existTime: number = 0;
/**触发时间 */
private triggerTime: number = 0;
/**触发CD时间 */
private triggerCDTime: number = 0;
private _pendingShieldMonsters: Monster[] = [];
private _pendingShieldIndex: number = 0;
private _pendingShieldCoefficient: number = 0;
private _magicEyeBatchSize: number = 12;
magicEyeInfo: IMagicEyeProperty = null;
start() {
this.magicEyeInfo = gg.data.project.getChapterNewPlayInfo(ChapterNewPlayTypeEnum.MagicEye);
this.enableCDTime = this.magicEyeInfo.startTime;
}
protected update(dt: number): void {
if (!gg.game.CurentBattle.canUpdateFrame()) return;
this.processShieldQueue();
const scaledDt = dt * gg.game.CurentBattle.TimeScale;
this.enableCDTime -= scaledDt;
this.existTime -= scaledDt;
this.triggerTime -= scaledDt;
// if (this.triggerTime <= 0 && gg.game.CurentBattle.IsOpenMagicEye) {
// this.trigger();
// }
// if (this.existTime <= 0 && gg.game.CurentBattle.IsOpenMagicEye) {
// this.close();
// }
// if (this.enableCDTime <= 0 && !gg.game.CurentBattle.IsOpenMagicEye) {
// this.open();
// }
}
open() {
//gg.game.CurentBattle.IsOpenMagicEye = true;
this.enableCDTime = this.magicEyeInfo.intervalTime + this.magicEyeInfo.existTime;
this.existTime = this.magicEyeInfo.existTime;
this.triggerCDTime = Math.random() * (this.magicEyeInfo.effectTimeUpperLimit - this.magicEyeInfo.effectTimeLowerLimit) + this.magicEyeInfo.effectTimeLowerLimit;
this.triggerTime = this.triggerCDTime;
this.playMagicEyeEffect(() => {
this.trigger();
});
}
close() {
//gg.game.CurentBattle.IsOpenMagicEye = false;
this.exitMagicEyeEffect();
}
playMagicEyeEffect(callback?: Function) {
this.anim.node.active = true;
this.eff.active = true;
BattleSpinePlayback.play(this.anim, '出现(90帧)', {
loop: false,
onComplete: () => {
BattleSpinePlayback.play(this.anim, '待机(45帧)', { loop: true });
if (callback) callback();
},
});
this.showTitle();
}
exitMagicEyeEffect(callback?: Function) {
if (this.anim.node.active) {
BattleSpinePlayback.play(this.anim, '消失(90帧)', {
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();
}
trigger() {
this.triggerTime = this.triggerCDTime;
this.buff.node.active = true;
BattleSpinePlayback.play(this.buff, '释放', {
loop: false,
onComplete: () => {
this.buff.node.active = false;
this.guangdun.node.active = false;
},
});
}
private enqueueAddShield(shieldHpCoefficient: number) {
const all = gg.game.CurentBattle.MonsterSpawner.getAllMonster();
this._pendingShieldMonsters = all
.map(x => x?.getComponent(Monster))
.filter(x => !!x && x.node && x.node.isValid);
this._pendingShieldIndex = 0;
this._pendingShieldCoefficient = shieldHpCoefficient;
}
private processShieldQueue() {
if (this._pendingShieldMonsters.length <= 0) return;
const left = this._pendingShieldMonsters.length - this._pendingShieldIndex;
if (left <= 0) {
this._pendingShieldMonsters = [];
this._pendingShieldIndex = 0;
return;
}
const count = Math.min(this._magicEyeBatchSize, left);
for (let i = 0; i < count; i++) {
const m = this._pendingShieldMonsters[this._pendingShieldIndex++];
// if (m && m.node && m.node.isValid) {
// m.addShieldHp(this._pendingShieldCoefficient);
// }
}
if (this._pendingShieldIndex >= this._pendingShieldMonsters.length) {
this._pendingShieldMonsters = [];
this._pendingShieldIndex = 0;
}
}
}