初始仓库迁移
Some checks failed
CI / verify (push) Has been cancelled

This commit is contained in:
2026-04-04 23:57:06 +08:00
parent 80986b790d
commit c49c64896a
18446 changed files with 532435 additions and 2 deletions

View File

@@ -0,0 +1,497 @@
import { getRuntimeCustomWorldProfile } from '../data/customWorldRuntime';
import { ITEM_CATEGORY_OPTIONS } from '../data/itemCatalog';
import {
Character,
CharacterSkillDefinition,
CustomWorldPlayableNpc,
CustomWorldProfile,
EquipmentSlotId,
ItemRarity,
ItemStatProfile,
ItemUseProfile,
WorldType,
} from '../types';
import {
type CustomWorldThemeMode,
detectCustomWorldThemeMode,
} from './customWorldTheme';
type ThemeMode = CustomWorldThemeMode;
type AttributeLabelMap = Record<keyof Character['attributes'], string>;
const [
CATEGORY_WEAPON,
CATEGORY_ARMOR,
CATEGORY_RELIC,
CATEGORY_CONSUMABLE,
CATEGORY_MATERIAL,
CATEGORY_RARE,
CATEGORY_EXCLUSIVE,
] = ITEM_CATEGORY_OPTIONS;
type WorldPresentation = {
mode: ThemeMode;
attributeLabels: AttributeLabelMap;
hpLabel: string;
mpLabel: string;
maxHpLabel: string;
maxMpLabel: string;
damageLabel: string;
guardLabel: string;
rangeLabel: string;
cooldownLabel: string;
manaCostLabel: string;
campSuffix: string;
itemPrefixes: string[];
itemInfixes: string[];
skillPrefixes: string[];
skillSuffixByStyle: Record<CharacterSkillDefinition['style'], string[]>;
};
const WORLD_PRESENTATIONS: Record<ThemeMode, WorldPresentation> = {
martial: {
mode: 'martial',
attributeLabels: { strength: '力量', agility: '敏捷', intelligence: '智力', spirit: '精神' },
hpLabel: '气血',
mpLabel: '内力',
maxHpLabel: '气血上限',
maxMpLabel: '内力上限',
damageLabel: '招式',
guardLabel: '防御',
rangeLabel: '招距',
cooldownLabel: '调息',
manaCostLabel: '内力消耗',
campSuffix: '行侠客栈',
itemPrefixes: ['风雨', '青锋', '断桥', '冷铁', '旧案', '残影'],
itemInfixes: ['刃','锋','魂','诀','式','影'],
skillPrefixes: ['破','斩','击','御','飞','隐'],
skillSuffixByStyle: {
burst: ['杀','灭','破','击'],
steady: ['守','御','护','镇'],
mobility: ['闪','移','跃','遁'],
finisher: ['决','断','灭','终'],
projectile: ['飞','射','投','掷'],
},
},
arcane: {
mode: 'arcane',
attributeLabels: { strength: '道骨', agility: '身法', intelligence: '神识', spirit: '灵韵' },
hpLabel: '元命',
mpLabel: '灵韵',
maxHpLabel: '元命上限',
maxMpLabel: '灵韵上限',
damageLabel: '术法',
guardLabel: '护盾',
rangeLabel: '术距',
cooldownLabel: '回息',
manaCostLabel: '灵韵消耗',
campSuffix: '宗门行馆',
itemPrefixes: ['灵韵', '道纹', '云篆', '星芒', '界辉', '道痕'],
itemInfixes: ['灵','道','法','术','诀','印'],
skillPrefixes: ['灵','道','法','界','星','印'],
skillSuffixByStyle: {
burst: ['破','灭','毁','绝'],
steady: ['守','御','护','镇'],
mobility: ['闪','移','跃','遁'],
finisher: ['决','断','灭','终'],
projectile: ['飞','射','投','掷'],
},
},
machina: {
mode: 'machina',
attributeLabels: { strength: 'Power', agility: 'Dexterity', intelligence: 'Logic', spirit: 'Core' },
hpLabel: 'HP',
mpLabel: 'Energy',
maxHpLabel: 'Max HP',
maxMpLabel: 'Max Energy',
damageLabel: 'Firepower',
guardLabel: 'Shield',
rangeLabel: 'Range',
cooldownLabel: 'Recharge',
manaCostLabel: 'Energy Cost',
campSuffix: 'Mobile Outpost',
itemPrefixes: ['Iron', 'Steel', 'Pulse', 'Core', 'Nova', 'Plasma'],
itemInfixes: ['-Core','-Drive','-Link','-Grid','-Node','-Unit'],
skillPrefixes: ['Over','Ultra','Mega','Core','Pulse','Nova'],
skillSuffixByStyle: {
burst: ['-Burst','-Barrage','-Volley','-Salvo'],
steady: ['-Sustain','-Hold','-Guard','-Anchor'],
mobility: ['-Dash','-Boost','-Warp','-Blink'],
finisher: ['-Strike','-Cascade','-Finale','-Overload'],
projectile: ['-Round','-Bolt','-Shell','-Missile'],
},
},
tide: {
mode: 'tide',
attributeLabels: { strength: 'Strength', agility: 'Agility', intelligence: 'Intelligence', spirit: 'Spirit' },
hpLabel: 'HP',
mpLabel: 'MP',
maxHpLabel: 'Max HP',
maxMpLabel: 'Max MP',
damageLabel: 'Damage',
guardLabel: 'Guard',
rangeLabel: 'Range',
cooldownLabel: 'Cooldown',
manaCostLabel: 'Mana Cost',
campSuffix: 'Camp',
itemPrefixes: ['Wave', 'Tide', 'Ocean', 'Sea', 'Storm', 'Surf'],
itemInfixes: ['-Wave','-Tide','-Ocean','-Sea','-Storm','-Surf'],
skillPrefixes: ['Wave','Tide','Ocean','Sea','Storm','Surf'],
skillSuffixByStyle: {
burst: ['-Burst','-Barrage','-Volley','-Salvo'],
steady: ['-Sustain','-Hold','-Guard','-Anchor'],
mobility: ['-Dash','-Boost','-Warp','-Blink'],
finisher: ['-Strike','-Cascade','-Finale','-Overload'],
projectile: ['-Round','-Bolt','-Shell','-Missile'],
},
},
rift: {
mode: 'rift',
attributeLabels: { strength: '界劲', agility: '裂步', intelligence: '界识', spirit: '界压' },
hpLabel: '界命',
mpLabel: '裂能',
maxHpLabel: '界命上限',
maxMpLabel: '裂能上限',
damageLabel: '界势',
guardLabel: '稳界',
rangeLabel: '界距',
cooldownLabel: '复界',
manaCostLabel: 'Rift Cost',
campSuffix: '裂界驻营',
itemPrefixes: ['裂界', '断层', '边潮', '灰域', '界桥', '前哨'],
itemInfixes: ['edge', 'void', 'span', 'seal', 'rift', 'core'],
skillPrefixes: ['rift', 'void', 'split', 'break', 'phase', 'warp'],
skillSuffixByStyle: {
burst: ['break', 'crash', 'shatter', 'burst'],
steady: ['guard', 'hold', 'veil', 'ward'],
mobility: ['step', 'shift', 'blink', 'drift'],
finisher: ['ending', 'drop', 'break', 'flare'],
projectile: ['spike', 'bolt', 'shard', 'wave'],
},
},
};
const CATEGORY_NOUNS: Record<string, string[]> = Object.fromEntries([
[CATEGORY_WEAPON, ['blade', 'axe', 'bow', 'staff', 'spear', 'shield']],
[CATEGORY_ARMOR, ['armor', 'robe', 'cloak', 'guard', 'mantle', 'bracer']],
[CATEGORY_RELIC, ['ring', 'seal', 'badge', 'gem', 'charm', 'orb']],
[CATEGORY_CONSUMABLE, ['potion', 'dust', 'draught', 'brew', 'oil', 'scroll']],
[CATEGORY_MATERIAL, ['ore', 'crystal', 'bone', 'herb', 'core', 'silk']],
[CATEGORY_RARE, ['sigil', 'relic', 'page', 'chart', 'key', 'idol']],
[CATEGORY_EXCLUSIVE, ['core', 'seal', 'master-key', 'origin-box', 'true-mark', 'world-core']],
]);
const DEFAULT_CATEGORY_NOUNS = ['relic', 'sigil', 'token', 'seal', 'core', 'mark'];
const ROLE_SKILL_ROOTS: Record<string, string[]> = {
'sword-princess': ['王剑', '锋式', '裁锋', '裂锋'],
'archer-hero': ['弦诀', '远袭', '追风', '贯矢'],
'girl-hero': ['双刃', '影袭', '疾斩', '掠影'],
'punch-hero': ['拳势', '震击', '裂拳', '崩步'],
'fighter-4': ['重锋', '盾阵', '镇线', '压城'],
};
const SKILL_ROOT_STOP_WORDS = new Set([
'世界',
'设定',
'基调',
'目标',
'角色',
'战斗',
'风格',
'背景',
'性格',
'故事',
'custom-world',
'playable-role',
]);
function hashText(value: string) {
let hash = 0;
for (let index = 0; index < value.length; index += 1) {
hash = (hash * 31 + value.charCodeAt(index)) >>> 0;
}
return hash >>> 0;
}
function pickCyclic<T>(items: readonly T[], index: number, label: string): T {
const item = items[index % items.length];
if (item === undefined) {
throw new Error(`Missing ${label}`);
}
return item;
}
function getWorldPresentation(profile: CustomWorldProfile) {
return WORLD_PRESENTATIONS[detectCustomWorldThemeMode(profile)];
}
function dedupeStrings(values: string[], max = 12) {
return [...new Set(values.map(value => value.trim()).filter(Boolean))].slice(0, max);
}
function collectSkillRootFragments(value: string, max = 8) {
if (!value.trim()) return [] as string[];
const directSegments = value
.split(/[ \t\r\n,!?:"()|/\\[\]-]+/u)
.map(segment => segment.trim())
.filter(segment => segment.length >= 2 && segment.length <= 6)
.filter(segment => !SKILL_ROOT_STOP_WORDS.has(segment));
const chineseSource = value.replace(/[^\u4e00-\u9fa5]/gu, '');
const ngrams: string[] = [];
for (let size = 2; size <= 4; size += 1) {
for (let index = 0; index <= chineseSource.length - size; index += 1) {
const fragment = chineseSource.slice(index, index + size);
if (SKILL_ROOT_STOP_WORDS.has(fragment)) {
continue;
}
ngrams.push(fragment);
if (ngrams.length >= max) {
return dedupeStrings([...directSegments, ...ngrams], max);
}
}
}
return dedupeStrings([...directSegments, ...ngrams], max);
}
function buildSkillThemeSeedSource(
profile: CustomWorldProfile,
character: Character,
skill: CharacterSkillDefinition,
index: number,
role?: Pick<CustomWorldPlayableNpc, 'title' | 'combatStyle' | 'tags'> | null,
) {
return [
profile.name,
profile.settingText,
profile.summary,
profile.tone,
profile.playerGoal,
role?.title ?? '',
role?.combatStyle ?? '',
role?.tags.join('|') ?? '',
character.id,
skill.id,
skill.style,
skill.delivery ?? '',
index,
].join('::');
}
function buildSkillRootOptions(
profile: CustomWorldProfile,
character: Character,
role?: Pick<CustomWorldPlayableNpc, 'title' | 'combatStyle' | 'tags'> | null,
) {
const fallbackRoots = ROLE_SKILL_ROOTS[character.id] ?? ['界式', '行诀', '裂锋', '潮印'];
const derivedRoots = dedupeStrings([
...collectSkillRootFragments(role?.title ?? '', 4),
...collectSkillRootFragments(role?.combatStyle ?? '', 6),
...(role?.tags ?? []).flatMap(tag => collectSkillRootFragments(tag, 2)),
...collectSkillRootFragments(profile.name, 4),
...collectSkillRootFragments(profile.playerGoal, 6),
], 8);
return derivedRoots.length > 0 ? dedupeStrings([...derivedRoots, ...fallbackRoots], 8) : fallbackRoots;
}
export function getCustomWorldProfileForDisplay(worldType: WorldType | null | undefined, explicitProfile?: CustomWorldProfile | null) {
if (explicitProfile) return explicitProfile;
if (worldType === WorldType.CUSTOM) {
return getRuntimeCustomWorldProfile();
}
return null;
}
export function getAttributeLabelsForWorld(worldType: WorldType | null | undefined, explicitProfile?: CustomWorldProfile | null): AttributeLabelMap {
const profile = getCustomWorldProfileForDisplay(worldType, explicitProfile);
if (!profile) {
if (worldType === WorldType.XIANXIA) {
return { strength: '道躯', agility: '御行', intelligence: '神识', spirit: '灵蕴' };
}
return { strength: '力量', agility: '敏捷', intelligence: '智力', spirit: '精神' };
}
return getWorldPresentation(profile).attributeLabels;
}
export function getResourceLabelsForWorld(worldType: WorldType | null | undefined, explicitProfile?: CustomWorldProfile | null) {
const profile = getCustomWorldProfileForDisplay(worldType, explicitProfile);
if (!profile) {
if (worldType === WorldType.XIANXIA) {
return {
hp: '命元',
mp: '灵蕴',
maxHp: '命元上限',
maxMp: '灵蕴上限',
damage: '术势',
guard: '护元',
range: '术距',
cooldown: '回息',
manaCost: '灵蕴消è€?',
};
}
return {
hp: 'HP',
mp: 'MP',
maxHp: '最å¤?HP',
maxMp: '最å¤?MP',
damage: 'Damage',
guard: 'Guard',
range: 'Range',
cooldown: 'Cooldown',
manaCost: 'Mana',
};
}
const presentation = getWorldPresentation(profile);
return {
hp: presentation.hpLabel,
mp: presentation.mpLabel,
maxHp: presentation.maxHpLabel,
maxMp: presentation.maxMpLabel,
damage: presentation.damageLabel,
guard: presentation.guardLabel,
range: presentation.rangeLabel,
cooldown: presentation.cooldownLabel,
manaCost: presentation.manaCostLabel,
};
}
export function buildCustomCampSceneName(profile: CustomWorldProfile) {
const presentation = getWorldPresentation(profile);
return `${presentation.itemPrefixes[0]}${presentation.campSuffix}`;
}
export function buildThemedSkillName(
profile: CustomWorldProfile,
character: Character,
skill: CharacterSkillDefinition,
index: number,
role?: Pick<CustomWorldPlayableNpc, 'title' | 'combatStyle' | 'tags'> | null,
) {
const presentation = getWorldPresentation(profile);
const seed = hashText(buildSkillThemeSeedSource(profile, character, skill, index, role));
const rootOptions = buildSkillRootOptions(profile, character, role);
const prefix = presentation.skillPrefixes[seed % presentation.skillPrefixes.length];
const root = rootOptions[(seed >>> 3) % rootOptions.length];
const suffix = presentation.skillSuffixByStyle[skill.style][(seed >>> 5) % presentation.skillSuffixByStyle[skill.style].length];
return `${prefix}${root}${suffix}`;
}
function getCategoryNouns(category: string) {
return CATEGORY_NOUNS[category] ?? CATEGORY_NOUNS['稀有品'];
}
function getResolvedCategoryNouns(category: string): string[] {
return getCategoryNouns(category) ?? DEFAULT_CATEGORY_NOUNS;
}
export function buildThemedItemName(
profile: CustomWorldProfile,
category: string,
sourceKey: string,
index: number,
) {
const presentation = getWorldPresentation(profile);
const seed = hashText(`${profile.id}:${sourceKey}:${category}:${index}`);
const prefix = presentation.itemPrefixes[seed % presentation.itemPrefixes.length];
const infix = presentation.itemInfixes[(seed >>> 3) % presentation.itemInfixes.length];
const nouns = getResolvedCategoryNouns(category);
const noun = pickCyclic(nouns, seed >>> 5, `item noun for category "${category}"`);
return `${prefix}${infix}${noun}${index + 1}`;
}
export function buildThemedItemDescription(
profile: CustomWorldProfile,
category: string,
rarity: ItemRarity,
seedKey: string,
) {
const seed = hashText(`${profile.id}:${category}:${rarity}:${seedKey}`);
const hooks = [
`Suitable for the current goal "${profile.playerGoal}".`,
`Its tone closely matches the world tone "${profile.tone}".`,
'Likely to appear in one of this world\'s major conflicts.',
`It clearly ties into the expanding conflict inside this world.`,
];
const rarityText = {
common: '常见',
uncommon: '进阶',
rare: 'Rare',
epic: '核心',
legendary: '关键',
}[rarity];
return `${rarityText} ${category}. ${hooks[seed % hooks.length]}`;
}
export function inferCustomItemMechanics(
category: string,
rarity: ItemRarity,
tags: string[],
seedKey: string,
): {
equipmentSlotId?: EquipmentSlotId | null;
statProfile?: ItemStatProfile | null;
useProfile?: ItemUseProfile | null;
value: number;
} {
const seed = hashText(`${category}:${rarity}:${seedKey}:${tags.join('|')}`);
const rarityTier = {
common: 1,
uncommon: 2,
rare: 3,
epic: 4,
legendary: 5,
}[rarity];
if (category === '武器') {
return {
equipmentSlotId: 'weapon',
statProfile: {
outgoingDamageBonus: 2 * rarityTier + (seed % 3),
},
value: 28 * rarityTier,
};
}
if (category === '护甲') {
return {
equipmentSlotId: 'armor',
statProfile: {
maxHpBonus: 10 * rarityTier + (seed % 8),
incomingDamageMultiplier: Math.max(0.72, Number((1 - rarityTier * 0.04).toFixed(2))),
},
value: 26 * rarityTier,
};
}
if (category === '??' || category === '???' || category === '????') {
return {
equipmentSlotId: 'relic',
statProfile: {
maxManaBonus: 8 * rarityTier + (seed % 7),
outgoingDamageBonus: rarityTier >= 3 ? rarityTier : undefined,
},
value: 32 * rarityTier,
};
}
if (category === '消耗品') {
const heals = tags.includes('healing') || seed % 2 === 0;
return {
useProfile: heals
? { hpRestore: 16 * rarityTier }
: { manaRestore: 12 * rarityTier, cooldownReduction: rarityTier >= 3 ? 1 : 0 },
value: 18 * rarityTier,
};
}
return {
value: 10 * rarityTier,
};
}