Files
Genarrative/src/data/itemPresentation.ts
kdletters cbc27bad4a
Some checks failed
CI / verify (push) Has been cancelled
init with react+axum+spacetimedb
2026-04-26 18:06:23 +08:00

106 lines
3.4 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import type {InventoryItem} from '../types';
import {getBuildTagDefinition} from './buildTags';
import type {InventoryUseEffect} from './inventoryEffects';
const STRUCTURAL_TAG_LABELS: Record<string, string> = {
weapon: '武器',
armor: '护甲',
relic: '遗物',
material: '材料',
consumable: '消耗品',
healing: '疗伤',
mana: '法力',
rare: '稀有',
wuxia: '边城模板',
xianxia: '灵潮模板',
neutral: '中性',
};
function dedupeStrings(values: Array<string | null | undefined>) {
return [...new Set(values.map(value => value?.trim() ?? '').filter(Boolean))];
}
function buildEffectSummaryParts(
item: InventoryItem,
useEffect: InventoryUseEffect | null,
) {
if (useEffect) {
return [
useEffect.hpRestore > 0 ? `恢复 ${useEffect.hpRestore} 点气血` : null,
useEffect.manaRestore > 0 ? `恢复 ${useEffect.manaRestore} 点灵力` : null,
useEffect.cooldownReduction > 0
? `额外推进 ${useEffect.cooldownReduction} 回合冷却`
: null,
useEffect.buildBuffs.length > 0
? `获得 ${useEffect.buildBuffs.map(buff => buff.name).join('、')}`
: null,
];
}
return [
item.tags.includes('healing') ? '在冒险中恢复生命值' : null,
item.tags.includes('mana') ? '帮助回转灵力与技能节奏' : null,
item.tags.includes('weapon') ? '适合进攻型构筑' : null,
item.tags.includes('armor') ? '适合防御型构筑' : null,
item.tags.includes('relic') ? '可作为稀有遗物长期携带' : null,
item.tags.includes('material') ? '可用于制作、锻造或交换' : null,
];
}
export function getInventoryTagLabel(tag: string) {
const normalized = tag.trim();
if (!normalized) return '';
const buildTag = getBuildTagDefinition(normalized);
if (buildTag) {
return buildTag.label;
}
return STRUCTURAL_TAG_LABELS[normalized.toLowerCase()] ?? normalized;
}
export function getInventoryTagLabels(tags: string[]) {
return dedupeStrings(tags.map(getInventoryTagLabel));
}
export function buildInventoryItemDescription(
item: InventoryItem,
useEffect: InventoryUseEffect | null = null,
) {
if (item.description?.trim()) return item.description.trim();
const storyFingerprint = item.runtimeMetadata?.storyFingerprint;
if (storyFingerprint) {
return [
storyFingerprint.visibleClue,
`${storyFingerprint.witnessMark} ${storyFingerprint.unresolvedQuestion}`,
`它会在此刻出现,是因为${storyFingerprint.currentAppearanceReason}`,
].join(' ');
}
const parts = buildEffectSummaryParts(item, useEffect).filter(
(part): part is string => Boolean(part),
);
if (parts.length > 0) {
return `${item.name} 当前可提供这些作用:${parts.join('')}`;
}
switch (item.category) {
case '武器':
return `${item.name} 更适合作为当前战利品中的主战装备,后续可用于替换现有武器或继续锻造。`;
case '护甲':
return `${item.name} 适合用来补足防护与承伤能力,也可留作后续重铸素材。`;
case '饰品':
case '稀有品':
case '专属品':
case '专属物':
case '专属物品':
return `${item.name} 更偏向长期携带与构筑补强,也可能牵出额外线索。`;
case '材料':
return `${item.name} 可用于制作、锻造、交易,或为后续掉落组合做准备。`;
default:
return `${item.name} 可用于后续路线规划、交易或构筑调整。`;
}
}