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/battle/view/CocosTowerPositiveBuffPrese...

59 lines
2.3 KiB

import { createMembershipSet, membershipAdd } from '../../../mx/tools/MembershipSet';
import type { BattleSession } from 'db://assets/mx/module/battle';
import type { Player } from '../../game/Player';
import {
entityHasActivePositiveBuff,
forEachGridIndexForEntity,
} from '../combat/TowerPositiveBuffState';
import type { MapManager } from '../map/legacy/MapManager';
import type { TextGrid } from './TextGrid';
/** 地图字块正面 buff 特效(怪_攻击buff):按实体同步到全部占格 */
export class CocosTowerPositiveBuffPresenter {
private _activeGridIndices = createMembershipSet<number>();
/** 复用 MembershipSet,sync 末尾与 _activeGridIndices 交换,避免每帧分配 */
private _nextActiveScratch = createMembershipSet<number>();
sync(
session: BattleSession,
map: MapManager,
player: Player | null,
mapGrids: ReadonlyMap<number, TextGrid>,
): void {
const nextActive = this._nextActiveScratch;
nextActive.clear();
if (player) {
for (const entityId of player.deployedUnits) {
if (!entityHasActivePositiveBuff(session, entityId)) continue;
forEachGridIndexForEntity(entityId, session, map, player, (gridIndex) => {
membershipAdd(nextActive, gridIndex);
});
}
}
// 按当前 mapGrids 清扫:拆组合后字块可能换格复用,旧 gridIndex 清不到节点上的特效
for (const [gridIndex, grid] of mapGrids) {
if (!nextActive.has(gridIndex)) {
grid?.clearPositiveBuffFx?.();
}
}
for (const gridIndex of nextActive.keys()) {
mapGrids.get(gridIndex)?.showPositiveBuffFx?.();
}
this._nextActiveScratch = this._activeGridIndices;
this._activeGridIndices = nextActive;
}
clearAll(mapGrids: ReadonlyMap<number, TextGrid>): void {
for (const gridIndex of this._activeGridIndices.keys()) {
mapGrids.get(gridIndex)?.clearPositiveBuffFx?.();
}
this._activeGridIndices.clear();
}
unbind(mapGrids?: ReadonlyMap<number, TextGrid> | null): void {
if (mapGrids) this.clearAll(mapGrids);
this._activeGridIndices.clear();
this._nextActiveScratch.clear();
}
}