Everything sat in packages/: two programs next to the small libraries
they use, and the patch data loose at the root. The programs now live in
apps/ and the shared libraries in packages/:
apps/server the local server (was packages/local-service),
package @wto/server
packages/patcher builds the game copy (was packages/build),
package @wto/patcher
patches/exe exe patch definitions (was exe-patches)
patches/gui GUI script patches (was gui-patches)
Inside the server, the network layer folder becomes transport/ so it is
not server/server/, the entry module is server.ts, and startLocalService
and its types become startServer, ServerOptions and RunningServer. The
health answer names the app wto-server, and the TLS files in the data
folder are server.key and server.crt (made again on the next start).
Comments, logs and tool texts say "local server".
The patcher no longer reaches into the server's folder. It read the
default tuning/store.jsonc by a relative path to register bundle GUIDs
for the multi-vehicle packs, which also ignored the player's overrides
in <data>/tuning/. It now takes the pack ids from its caller; the
server exports multiVehiclePackIds(dataFolder), which reads them the way
the running server does. rebuildGuiPack takes the patch folder from its
caller as well.
The development build moves out of the patcher to
scripts/build-game-copy.ts, since it uses both the server and the
patcher. It needs --data (the folder the server will run with) and
defaults the patch folders and the hook library to this repository.
Checked with the root typecheck, check-patches, check-gui,
check-offsets, the native build, a run of build-game-copy.ts into a
scratch folder (12 exe patches, 35 GUI patches, 496 bundle GUIDs as
before) and a server start from apps/server answering wto-server.
BREAKING CHANGE: Use @wto/server and @wto/patcher from the new workspace paths. Run the development build with scripts/build-game-copy.ts and pass --data.
169 lines
6.8 KiB
TypeScript
169 lines
6.8 KiB
TypeScript
/**
|
|
* Classic-item `autoConsume` wrappers (`810001+`), recycled craft fragments and re-synthesis
|
|
* generators. The fragments are the distinct recycleItemResult
|
|
* values of config/items.blk; the recipes are tuning (tuning/recycling.jsonc).
|
|
*/
|
|
import type { ItemDefinition } from '../game-data/datasets/item-catalogue.ts';
|
|
import {
|
|
makeLocalizedItemDef,
|
|
type CouponAction,
|
|
type GeneratorDefinition,
|
|
type GeneratorDrop,
|
|
type GeneratorRecipe,
|
|
type LocalizedItemDef,
|
|
} from './itemdef-types.ts';
|
|
import type { RecyclingTuning } from './recycling-tuning.ts';
|
|
|
|
const RECYCLE_SINGLE_OFFSET = 20;
|
|
const RECYCLE_GENERIC_GENERATOR_ID = 299030;
|
|
const FIRST_WRAPPER_ID = 810001;
|
|
|
|
export interface RecyclingBuildResult {
|
|
readonly defs: readonly LocalizedItemDef[];
|
|
readonly coupons: ReadonlyArray<readonly [number, CouponAction]>;
|
|
readonly generators: readonly GeneratorDefinition[];
|
|
readonly wrappersByPart: ReadonlyMap<number, readonly number[]>;
|
|
}
|
|
|
|
export function buildRecyclingDefs(classicItems: readonly ItemDefinition[], tuning: RecyclingTuning): RecyclingBuildResult {
|
|
const defs: LocalizedItemDef[] = [];
|
|
const coupons: Array<readonly [number, CouponAction]> = [];
|
|
const generators: GeneratorDefinition[] = [];
|
|
|
|
const partIds = [...new Set(classicItems.flatMap((item) => (item.recycleItemResult === undefined ? [] : [item.recycleItemResult])))].sort((a, b) => a - b);
|
|
const wrappersByPart = buildClassicWrappers(classicItems, partIds, tuning, defs, coupons);
|
|
const allWrappers = [...new Set([...wrappersByPart.values()].flat())];
|
|
for (const partId of partIds) {
|
|
registerSinglePartSynthesizer(partId, wrappersByPart.get(partId) ?? allWrappers, tuning, defs, generators);
|
|
}
|
|
registerMixedSynthesizer(partIds, allWrappers, defs, generators);
|
|
return { defs, coupons, generators, wrappersByPart };
|
|
}
|
|
|
|
function registerSinglePartSynthesizer(
|
|
partId: number,
|
|
pool: readonly number[],
|
|
tuning: RecyclingTuning,
|
|
defs: LocalizedItemDef[],
|
|
generators: GeneratorDefinition[],
|
|
): void {
|
|
const singleGenId = partId + RECYCLE_SINGLE_OFFSET;
|
|
const title = tuning.partNames.get(partId) ?? { en: `Recycled Part #${partId}`, zh: `回收组件 #${partId}` };
|
|
const needed = tuning.partsPerItem;
|
|
defs.push(makeLocalizedItemDef(partId, {
|
|
type: 'item',
|
|
marketable: false,
|
|
item_quality: 1,
|
|
used_to_create: `${singleGenId}x1;${RECYCLE_GENERIC_GENERATOR_ID}x1`,
|
|
tags: 'type:craft_part;hideMarketablePropDesc:yes',
|
|
icon_url: '!#ui/gameuiskin#item_type_craftpart.svg',
|
|
}, title, {
|
|
en: `Obtained by recycling classic items; ${needed} fragments craft a new random item.`,
|
|
zh: `回收经典道具所得;每 ${needed} 个组件可重新合成 1 件随机道具。`,
|
|
}));
|
|
defs.push(makeLocalizedItemDef(singleGenId, {
|
|
type: 'generator',
|
|
marketable: false,
|
|
item_quality: 1,
|
|
exchange: `${partId}x${needed}`,
|
|
bundle: pool.map((id) => `${id}x1`).join(';'),
|
|
tags: 'devItem:yes',
|
|
icon_url: '!#ui/gameuiskin#item_type_craftpart.svg',
|
|
}, { en: 'Item Synthesizer', zh: '道具合成器' }, { en: '', zh: '' }));
|
|
generators.push({
|
|
itemdefId: singleGenId,
|
|
isChestGenerator: false,
|
|
recipes: [{ components: [{ itemdefId: partId, quantity: needed }] }],
|
|
drops: pool.map((id): GeneratorDrop => ({ itemdefId: id, weight: 10 })),
|
|
});
|
|
}
|
|
|
|
function registerMixedSynthesizer(
|
|
partIds: readonly number[],
|
|
allWrappers: readonly number[],
|
|
defs: LocalizedItemDef[],
|
|
generators: GeneratorDefinition[],
|
|
): void {
|
|
const { pairRecipes, pairStrings } = buildPairRecipes(partIds);
|
|
defs.push(makeLocalizedItemDef(RECYCLE_GENERIC_GENERATOR_ID, {
|
|
type: 'generator',
|
|
marketable: false,
|
|
item_quality: 1,
|
|
exchange: pairStrings.join(';'),
|
|
bundle: allWrappers.map((id) => `${id}x1`).join(';'),
|
|
tags: 'devItem:yes',
|
|
icon_url: '!#ui/gameuiskin#item_type_craftpart.svg',
|
|
}, { en: 'Mixed Item Synthesizer', zh: '混搭道具合成器' }, { en: '', zh: '' }));
|
|
generators.push({
|
|
itemdefId: RECYCLE_GENERIC_GENERATOR_ID,
|
|
isChestGenerator: false,
|
|
recipes: pairRecipes,
|
|
drops: allWrappers.map((id): GeneratorDrop => ({ itemdefId: id, weight: 10 })),
|
|
});
|
|
}
|
|
|
|
function buildClassicWrappers(
|
|
classicItems: readonly ItemDefinition[],
|
|
partIds: readonly number[],
|
|
tuning: RecyclingTuning,
|
|
defs: LocalizedItemDef[],
|
|
coupons: Array<readonly [number, CouponAction]>,
|
|
): ReadonlyMap<number, readonly number[]> {
|
|
const byRecyclePart = new Map<number, number[]>();
|
|
for (const partId of partIds) byRecyclePart.set(partId, []);
|
|
|
|
// Sort deterministically by item id so wrapper IDs and drop pools do not depend on BLK order.
|
|
const sortedPermanent = classicItems
|
|
.filter((item) => item.expiresAt === undefined && item.type !== 'personalDiscounts')
|
|
.sort((a, b) => a.name.localeCompare(b.name));
|
|
|
|
const preferredByPart = new Map<number, ItemDefinition[]>();
|
|
for (const item of sortedPermanent) {
|
|
const partId = item.recycleItemResult;
|
|
if (partId === undefined) continue;
|
|
let bucket = preferredByPart.get(partId);
|
|
if (!bucket) preferredByPart.set(partId, bucket = []);
|
|
if (bucket.length < tuning.itemsPerPart) bucket.push(item);
|
|
}
|
|
|
|
let nextWrapperId = FIRST_WRAPPER_ID;
|
|
for (const partId of partIds) {
|
|
const targetList = byRecyclePart.get(partId) ?? [];
|
|
for (const def of preferredByPart.get(partId) ?? []) {
|
|
const wrapperId = nextWrapperId++;
|
|
const count = tuning.piecesPerItem.get(def.name) ?? 1;
|
|
defs.push(makeLocalizedItemDef(wrapperId, {
|
|
type: 'item',
|
|
marketable: false,
|
|
item_quality: 1,
|
|
tags: 'type:internal_item;autoConsume:yes;showAsContentItem:yes;hideMarketablePropDesc:yes',
|
|
meta: `item:t="${def.name}"\ncount:i=${count}`,
|
|
icon_url: '!#ui/gameuiskin#item_type_trophies.svg',
|
|
}, { en: def.name, zh: def.name }, { en: '', zh: '' }));
|
|
coupons.push([wrapperId, { kind: 'classic-item', itemName: def.name, count }]);
|
|
targetList.push(wrapperId);
|
|
}
|
|
byRecyclePart.set(partId, targetList);
|
|
}
|
|
|
|
const fallbackPool = tuning.fallbackParts.flatMap((partId) => byRecyclePart.get(partId) ?? []);
|
|
for (const partId of partIds) {
|
|
if ((byRecyclePart.get(partId)?.length ?? 0) === 0) byRecyclePart.set(partId, fallbackPool);
|
|
}
|
|
return byRecyclePart;
|
|
}
|
|
|
|
function buildPairRecipes(partIds: readonly number[]): { readonly pairRecipes: readonly GeneratorRecipe[]; readonly pairStrings: readonly string[] } {
|
|
const pairRecipes: GeneratorRecipe[] = [];
|
|
const pairStrings: string[] = [];
|
|
for (let i = 0; i < partIds.length; i += 1) {
|
|
for (let j = i + 1; j < partIds.length; j += 1) {
|
|
const a = partIds[i]!;
|
|
const b = partIds[j]!;
|
|
pairRecipes.push({ components: [{ itemdefId: a, quantity: 1 }, { itemdefId: b, quantity: 1 }] });
|
|
pairStrings.push(`${a}x1,${b}x1`);
|
|
}
|
|
}
|
|
return { pairRecipes, pairStrings };
|
|
}
|