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/MechanismParatroopsSchedule.ts

136 lines
4.7 KiB

3 weeks ago
/**
* 空降兵
*/
import { _decorator, Component, isValid, tween, Vec3, Tween, UITransform } from 'cc';
import { BossWarnType } from '../BossWarnSpine';
import { IParatroopsProperty } from '../../../game/ChapterPlayTypes';
import { GEvent } from 'db://assets/mx/module/event/GEvent';
const { ccclass, property } = _decorator;
@ccclass('MechanismParatroopsSchedule')
export class MechanismParatroopsSchedule extends Component {
_dt: number = 0
paratroopsInfo: IParatroopsProperty = null
paratroopsInfo2: IParatroopsProperty = null
monsterIds: number[] = [];
private getPlaneStartEndX() {
const tf = this.node.parent?.getComponent(UITransform);
const halfW = tf ? tf.width / 2 : 700;
const margin = 100;
return {
startX: halfW + margin,
endX: -halfW - margin
};
}
start() {
}
protected update(dt: number): void {
if (!gg.game.CurentBattle.canUpdateFrame()) return;
this._dt += dt * gg.game.CurentBattle.TimeScale;
if (this._dt >= 1) {
this._dt = 0
this.checkParatroopsLaunchTime()
}
}
init(paratroopsInfo: IParatroopsProperty) {
this.paratroopsInfo = paratroopsInfo
}
/**检查是否到了攻击时间 */
checkParatroopsLaunchTime() {
if (this.paratroopsInfo && this.paratroopsInfo.timeArr && this.paratroopsInfo.timeArr.length > 0 && gg.game.CurentBattle.BattleTime >= this.paratroopsInfo.timeArr[0]) {
this.paratroopsInfo.timeArr.shift()
this.launchParatroops()
}
if (this.paratroopsInfo2 && this.paratroopsInfo2.timeArr && this.paratroopsInfo2.timeArr.length > 0 && gg.game.CurentBattle.BattleTime >= this.paratroopsInfo2.timeArr[0]) {
this.paratroopsInfo2.timeArr.shift()
this.launchParatroops2()
}
}
/**释放空降兵 */
launchParatroops() {
// gg.game.CurentBattle.IsLaunchParatroops = true
let plane = this.node.getChildByName('飞机影子')
const { startX, endX } = this.getPlaneStartEndX();
plane.active = true
tween(plane)
.set({ position: new Vec3(startX, 50, 0) })
.to(2, { position: new Vec3(endX, 50, 0) })
.call(() => {
plane.active = false
})
.start()
this.scheduleOnce(() => {
GEvent.Ins.emit(BossWarnType.Paratroops)
//释放数量
let num = this.paratroopsInfo.numArr.shift()
let grids = gg.game.CurentBattle.Map.getRandomCanPutObstacleMapGrids(num);
for (let i = 0; i < num; i++) {
let grid = null;
if (i < grids.length) {
grid = grids[i];
} else {
grid = grids.random();
}
// gg.game.CurentBattle.spawnSentryMonster(this.paratroopsInfo.monsterId, grid);
}
this.scheduleOnce(() => {
// gg.game.CurentBattle.IsLaunchParatroops = false
}, 3.5)
}, 2)
}
/**释放空降兵 */
launchParatroops2() {
// gg.game.CurentBattle.IsLaunchParatroops = true
let plane = this.node.getChildByName('飞机影子2')
const { startX, endX } = this.getPlaneStartEndX();
plane.active = true
tween(plane)
.set({ position: new Vec3(startX, 50, 0) })
.to(2, { position: new Vec3(endX, 50, 0) })
.call(() => {
plane.active = false
})
.start()
this.scheduleOnce(() => {
GEvent.Ins.emit(BossWarnType.Paratroops)
//释放数量
let num = this.paratroopsInfo2.numArr.shift()
let monsterId = this.monsterIds.shift();
let grids = gg.game.CurentBattle.Map.getRandomCanPutObstacleMapGrids(num);
for (let i = 0; i < num; i++) {
let grid = null;
if (i < grids.length) {
grid = grids[i];
} else {
grid = grids.random();
}
// gg.game.CurentBattle.spawnSentryMonster(monsterId, grid);
}
this.scheduleOnce(() => {
// gg.game.CurentBattle.IsLaunchParatroops = false
}, 3.5)
}, 2)
}
protected onDisable(): void {
// 组件失活后,取消 scheduleOnce,避免闭包持有引用
this.unscheduleAllCallbacks();
// 同时停止当前节点相关 tween(plane 节点会被放在子树里)
Tween.stopAllByTarget(this.node);
}
protected onDestroy(): void {
this.unscheduleAllCallbacks();
Tween.stopAllByTarget(this.node);
}
}