forked from phenom/healer-man
Update Healer Man server
This commit is contained in:
1 parent
6cc1b9217f
commit
6114a2295f
67 files changed
+6241
-347
No files matched your search
@@ -1,79 +1,145 @@
|
||||
import { NodeIO } from "@gltf-transform/core";
|
||||
import { BufferGeometry, Float32BufferAttribute, Matrix4, Vector3 } from "three";
|
||||
import { requireDungeonDefinition } from "../src/game/dungeonRegistry";
|
||||
import { ALL_EXTENSIONS } from "@gltf-transform/extensions";
|
||||
import { createRequire } from "node:module";
|
||||
import { existsSync, readFileSync } from "node:fs";
|
||||
import { resolve } from "node:path";
|
||||
import { MeshoptDecoder } from "meshoptimizer";
|
||||
import { BufferAttribute, BufferGeometry, Group, Mesh } from "three";
|
||||
import {
|
||||
buildPartyNavigationGraph,
|
||||
findNearestPartyNavigationSurface,
|
||||
findPartyNavigationPath,
|
||||
} from "../src/game/partyNavigation";
|
||||
import { preparePartyNavigationGraph } from "../src/game/partyNavigationAssetCache";
|
||||
import type { DungeonDefinition } from "../src/game/dungeonTypes";
|
||||
import { withWowDungeonEnvironment } from "../src/game/wowDungeonEnvironment";
|
||||
|
||||
const dungeonIds = process.argv.slice(2).filter((argument) => !argument.startsWith("--"));
|
||||
if (!dungeonIds.length) throw new Error("Pass at least one dungeon id.");
|
||||
const require = createRequire(import.meta.url);
|
||||
const { DEFAULT_TEST_DUNGEON_ID } = require("./playtest-defaults.cjs") as {
|
||||
DEFAULT_TEST_DUNGEON_ID: string;
|
||||
};
|
||||
type Position = readonly [number, number, number];
|
||||
type ProbeDungeon = {
|
||||
id: string;
|
||||
title: string;
|
||||
entrance: { footPosition: Position };
|
||||
assets: { navigation?: { fileName: string; url: string } | null };
|
||||
navigationLinks?: readonly { start: Position; end: Position; bidirectional: boolean }[];
|
||||
traversalRamps?: DungeonDefinition["traversalRamps"];
|
||||
bosses: readonly { id: string; name: string; position: Position; eventOnly?: boolean }[];
|
||||
};
|
||||
const campaignCatalogPath = resolve(process.cwd(), "src", "game", "generated", "dungeonCampaignCatalog.json");
|
||||
const campaignCatalog = JSON.parse(readFileSync(campaignCatalogPath, "utf8")) as { definitions: ProbeDungeon[] };
|
||||
function requireGeneratedDungeonDefinition(dungeonId: string): ProbeDungeon {
|
||||
const dungeon = campaignCatalog.definitions.find((candidate) => candidate.id === dungeonId);
|
||||
if (!dungeon) throw new Error(`Generated campaign catalog has no dungeon ${dungeonId}.`);
|
||||
return dungeon;
|
||||
}
|
||||
const navigationIo = new NodeIO()
|
||||
.registerExtensions(ALL_EXTENSIONS)
|
||||
.registerDependencies({ "meshopt.decoder": MeshoptDecoder });
|
||||
const requestedDungeonIds = process.argv.slice(2).filter((argument) => !argument.startsWith("--"));
|
||||
const dungeonIds = requestedDungeonIds.length ? requestedDungeonIds : [DEFAULT_TEST_DUNGEON_ID];
|
||||
|
||||
async function navigationGraph(dungeonId: string) {
|
||||
const dungeon = requireDungeonDefinition(dungeonId);
|
||||
const dungeon = requireGeneratedDungeonDefinition(dungeonId);
|
||||
const navigation = dungeon.assets.navigation;
|
||||
if (!navigation) throw new Error(`${dungeonId} has no navigation asset.`);
|
||||
const file = `src/assets/game/dungeons/${dungeonId}/${navigation.fileName}`;
|
||||
const document = await new NodeIO().read(file);
|
||||
const positions: number[] = [];
|
||||
const vertex = new Vector3();
|
||||
const publicAssetPath = navigation.url.startsWith("/")
|
||||
? resolve(process.cwd(), "public", navigation.url.slice(1))
|
||||
: resolve(process.cwd(), "public", "assets", "game", "dungeons", dungeonId, navigation.fileName);
|
||||
const sourceAssetPath = resolve(process.cwd(), "src", "assets", "game", "dungeons", dungeonId, navigation.fileName);
|
||||
const file = [publicAssetPath, sourceAssetPath].find(existsSync);
|
||||
if (!file) throw new Error(`${dungeonId} navigation asset is missing at ${publicAssetPath} and ${sourceAssetPath}.`);
|
||||
await MeshoptDecoder.ready;
|
||||
const document = await navigationIo.read(file);
|
||||
const scene = new Group();
|
||||
for (const node of document.getRoot().listNodes()) {
|
||||
const mesh = node.getMesh();
|
||||
if (!mesh) continue;
|
||||
const world = new Matrix4().fromArray(node.getWorldMatrix());
|
||||
for (const primitive of mesh.listPrimitives()) {
|
||||
const source = primitive.getAttribute("POSITION")?.getArray();
|
||||
if (!source) continue;
|
||||
const indices = primitive.getIndices()?.getArray()
|
||||
?? Array.from({ length: source.length / 3 }, (_, index) => index);
|
||||
for (const index of indices) {
|
||||
vertex.fromArray(source, Number(index) * 3).applyMatrix4(world);
|
||||
positions.push(vertex.x, vertex.y, vertex.z);
|
||||
}
|
||||
const accessor = primitive.getAttribute("POSITION");
|
||||
const source = accessor?.getArray();
|
||||
if (!source || !accessor) continue;
|
||||
const geometry = new BufferGeometry();
|
||||
geometry.setAttribute("position", new BufferAttribute(source, 3, accessor.getNormalized()));
|
||||
const sourceIndices = primitive.getIndices()?.getArray();
|
||||
if (sourceIndices) geometry.setIndex(Array.from(sourceIndices));
|
||||
const navigationMesh = new Mesh(geometry);
|
||||
navigationMesh.matrixAutoUpdate = false;
|
||||
navigationMesh.matrix.fromArray(node.getWorldMatrix());
|
||||
scene.add(navigationMesh);
|
||||
}
|
||||
}
|
||||
const geometry = new BufferGeometry();
|
||||
geometry.setAttribute("position", new Float32BufferAttribute(positions, 3));
|
||||
const definition = withWowDungeonEnvironment(dungeon as unknown as DungeonDefinition);
|
||||
try {
|
||||
return buildPartyNavigationGraph(geometry);
|
||||
return preparePartyNavigationGraph(navigation.url, scene, definition.navigationLinks ?? [], definition.traversalRamps ?? []);
|
||||
} finally {
|
||||
geometry.dispose();
|
||||
scene.traverse((node) => {
|
||||
if ((node as Mesh).isMesh) (node as Mesh).geometry.dispose();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
for (const dungeonId of dungeonIds) {
|
||||
const dungeon = requireDungeonDefinition(dungeonId);
|
||||
const boss = dungeon.bosses.find((candidate) => !candidate.eventOnly);
|
||||
if (!boss) throw new Error(`${dungeonId} has no normal campaign boss.`);
|
||||
const dungeon = requireGeneratedDungeonDefinition(dungeonId);
|
||||
const eligibleBosses = dungeon.bosses.filter((candidate) => !candidate.eventOnly);
|
||||
const bosses = dungeonId === DEFAULT_TEST_DUNGEON_ID ? eligibleBosses : eligibleBosses.slice(0, 1);
|
||||
if (!bosses.length) throw new Error(`${dungeonId} has no normal campaign bosses.`);
|
||||
const graph = await navigationGraph(dungeonId);
|
||||
const start = findNearestPartyNavigationSurface(graph, dungeon.entrance.footPosition, 3);
|
||||
const end = findNearestPartyNavigationSurface(graph, boss.position, 6);
|
||||
if (!start || !end) throw new Error(`${dungeonId} entrance or ${boss.name} does not snap to navigation.`);
|
||||
const path = findPartyNavigationPath(graph, start.position, end.position, {
|
||||
maxStartSnapDistance: 3,
|
||||
maxEndSnapDistance: 6,
|
||||
simplifyTolerance: 0.01,
|
||||
});
|
||||
if (!path?.length) throw new Error(`${dungeonId} has no navigation path to ${boss.name}.`);
|
||||
if (!start) throw new Error(`${dungeonId} entrance does not snap to navigation.`);
|
||||
const waypoints: number[][] = [[...start.position]];
|
||||
const objectives: Array<{ id: string; name: string; position: readonly number[]; navigationPosition: readonly number[];
|
||||
waypointIndex: number; expectedNavigationDistance: number; snapDistance: number }> = [];
|
||||
let segmentStart = start.position;
|
||||
let expectedDistance = 0;
|
||||
for (let index = 1; index < path.length; index += 1) {
|
||||
expectedDistance += Math.hypot(
|
||||
path[index][0] - path[index - 1][0],
|
||||
path[index][1] - path[index - 1][1],
|
||||
path[index][2] - path[index - 1][2],
|
||||
);
|
||||
for (const boss of bosses) {
|
||||
const end = findNearestPartyNavigationSurface(graph, boss.position, 6);
|
||||
if (!end) throw new Error(`${dungeonId} ${boss.name} does not snap to navigation.`);
|
||||
const path = findPartyNavigationPath(graph, segmentStart, end.position, {
|
||||
maxStartSnapDistance: 3,
|
||||
maxEndSnapDistance: 6,
|
||||
simplifyTolerance: 0.01,
|
||||
});
|
||||
if (!path?.length) throw new Error(`${dungeonId} has no navigation path to ${boss.name}.`);
|
||||
const startIndex = waypoints.length - 1;
|
||||
let segmentDistance = 0;
|
||||
for (let index = 1; index < path.length; index += 1) {
|
||||
const segmentLength = Math.hypot(
|
||||
path[index][0] - path[index - 1][0],
|
||||
path[index][1] - path[index - 1][1],
|
||||
path[index][2] - path[index - 1][2],
|
||||
);
|
||||
segmentDistance += segmentLength;
|
||||
expectedDistance += segmentLength;
|
||||
waypoints.push([...path[index]]);
|
||||
}
|
||||
objectives.push({
|
||||
id: boss.id,
|
||||
name: boss.name,
|
||||
position: boss.position,
|
||||
navigationPosition: end.position,
|
||||
waypointIndex: waypoints.length - 1,
|
||||
expectedNavigationDistance: Number(segmentDistance.toFixed(2)),
|
||||
snapDistance: end.distance,
|
||||
});
|
||||
if (waypoints.length - 1 <= startIndex) {
|
||||
throw new Error(`${dungeonId} navigation path to ${boss.name} has no traversable segment.`);
|
||||
}
|
||||
segmentStart = end.position;
|
||||
}
|
||||
process.stdout.write(`${JSON.stringify({
|
||||
dungeonId,
|
||||
status: "navigation-guidance-only; live UI traversal required",
|
||||
objective: boss.name,
|
||||
objective: bosses.at(-1)!.name,
|
||||
objectiveId: bosses.at(-1)!.id,
|
||||
objectives,
|
||||
entrance: start.position,
|
||||
objectivePosition: end.position,
|
||||
objectivePosition: bosses.at(-1)!.position,
|
||||
startSnapDistance: start.distance,
|
||||
objectiveSnapDistance: end.distance,
|
||||
waypointCount: path.length,
|
||||
objectiveSnapDistance: objectives.at(-1)!.snapDistance,
|
||||
waypointCount: waypoints.length,
|
||||
expectedNavigationDistance: Number(expectedDistance.toFixed(2)),
|
||||
waypoints: path,
|
||||
waypoints,
|
||||
})}\n`);
|
||||
}
|
||||
Reference in new issue
Block a user