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

74 lines
2.9 KiB

3 weeks ago
import { Node, sp } from 'cc';
import type { BattleSession } from 'db://assets/mx/module/battle';
import type { MapManager } from '../map/legacy/MapManager';
import type { MapGrid } from '../map/legacy/MapGrid';
/** 芭蕉扇:单阵营攻击站立格(阵营区域 + 站立格) */
export interface BajiaoCampStand {
campAreaId: number;
standGrid: MapGrid;
}
/** 受击闪白:取攻击点节点下首个可见 Spine(唐僧 / 江流儿等) */
export function resolveWallHitFlashSpine(hitTarget: Node | null | undefined): sp.Skeleton | null {
if (!hitTarget?.isValid) return null;
for (const sk of hitTarget.getComponentsInChildren(sp.Skeleton)) {
if (sk?.isValid && sk.node.activeInHierarchy) return sk;
}
return null;
}
/** wallTarget1 攻击站立格(与寻路 attackTargets 一致,勿用唐僧当前 worldPosition) */
export function resolveWallTarget1StandGrid(map: MapManager): MapGrid | null {
const wallNode = map.mapTargetParent?.getChildByName('wallTarget1');
if (!wallNode) return null;
for (const [grid, node] of map.allAttackPointGrids) {
if (node === wallNode) return grid;
}
return map.findNearestWalkableGridForTarget(wallNode.worldPosition);
}
/** 指定阵营区域的攻击站立格(多目标地图按 campAreaId 区分) */
export function resolveAttackStandGridForCamp(
map: MapManager,
session: BattleSession,
campAreaId: number,
): MapGrid | null {
const targets = session.topology.getAttackTargetsForCampArea(campAreaId);
if (targets.length > 0) {
const grid = map.getMapGrid(targets[0].row, targets[0].col);
if (grid) return grid;
}
return resolveWallTarget1StandGrid(map);
}
/**
* 收集芭蕉扇各阵营图标锚点。
* 单阵营仍用 wallTarget1;多阵营每营一个攻击站立格。
*/
export function collectBajiaoCampStands(map: MapManager, session: BattleSession): BajiaoCampStand[] {
const topo = session.topology;
if (!topo.attackTargets.length) {
const stand = resolveWallTarget1StandGrid(map);
if (!stand) return [];
const campId = topo.attackTargetCampArea[0] ?? topo.getSpawnPortCampArea(1) ?? 1;
return [{ campAreaId: campId, standGrid: stand }];
}
if (!topo.hasMultipleCampAreas()) {
const stand = resolveWallTarget1StandGrid(map);
if (!stand) return [];
const campId = topo.attackTargetCampArea[0] ?? topo.getSpawnPortCampArea(1) ?? 1;
return [{ campAreaId: campId, standGrid: stand }];
}
const out: BajiaoCampStand[] = [];
for (const campId of topo.getDistinctCampAreaIds()) {
const stand = resolveAttackStandGridForCamp(map, session, campId);
if (stand) out.push({ campAreaId: campId, standGrid: stand });
}
return out;
}
/** @deprecated 新产品无唐僧求救 */
export function syncTangSengAudioCell(_map: MapManager | null | undefined): void {
}