@@ -1,6 +1,7 @@
|
||||
import type {
|
||||
RuntimeStoryEncounterViewModel,
|
||||
RuntimeStoryChoicePayload,
|
||||
RuntimeStoryEncounterViewModel,
|
||||
RuntimeStoryOptionInteraction,
|
||||
RuntimeStoryOptionView,
|
||||
RuntimeStoryViewModel,
|
||||
Task5RuntimeOptionScope,
|
||||
@@ -180,8 +181,7 @@ const TASK6_RUNTIME_FUNCTION_ID_SET = new Set<string>(
|
||||
TASK6_RUNTIME_FUNCTION_IDS,
|
||||
);
|
||||
|
||||
export const TASK6_DEFERRED_FUNCTION_IDS = new Set<string>([
|
||||
]);
|
||||
export const TASK6_DEFERRED_FUNCTION_IDS = new Set<string>([]);
|
||||
|
||||
const FUNCTION_DEFINITIONS: Record<string, FunctionDefinition> = {
|
||||
story_continue_adventure: {
|
||||
@@ -406,13 +406,16 @@ function normalizeNpcState(value: unknown): RuntimeNpcState {
|
||||
? cloneJson(rawState.stanceProfile)
|
||||
: null,
|
||||
revealedFacts: readArray(rawState.revealedFacts).filter(
|
||||
(item): item is string => typeof item === 'string' && item.trim().length > 0,
|
||||
(item): item is string =>
|
||||
typeof item === 'string' && item.trim().length > 0,
|
||||
),
|
||||
knownAttributeRumors: readArray(rawState.knownAttributeRumors).filter(
|
||||
(item): item is string => typeof item === 'string' && item.trim().length > 0,
|
||||
(item): item is string =>
|
||||
typeof item === 'string' && item.trim().length > 0,
|
||||
),
|
||||
seenBackstoryChapterIds: readArray(rawState.seenBackstoryChapterIds).filter(
|
||||
(item): item is string => typeof item === 'string' && item.trim().length > 0,
|
||||
(item): item is string =>
|
||||
typeof item === 'string' && item.trim().length > 0,
|
||||
),
|
||||
};
|
||||
}
|
||||
@@ -456,7 +459,10 @@ function normalizeHostileNpc(value: unknown): RuntimeHostileNpc | null {
|
||||
}
|
||||
|
||||
const maxHp = Math.max(1, Math.round(readNumber(rawNpc.maxHp, 1)));
|
||||
const hp = Math.max(0, Math.min(maxHp, Math.round(readNumber(rawNpc.hp, maxHp))));
|
||||
const hp = Math.max(
|
||||
0,
|
||||
Math.min(maxHp, Math.round(readNumber(rawNpc.hp, maxHp))),
|
||||
);
|
||||
|
||||
return {
|
||||
id,
|
||||
@@ -489,7 +495,10 @@ function normalizeNpcStates(value: unknown) {
|
||||
const rawStates = isObject(value) ? value : {};
|
||||
|
||||
return Object.fromEntries(
|
||||
Object.entries(rawStates).map(([key, state]) => [key, normalizeNpcState(state)]),
|
||||
Object.entries(rawStates).map(([key, state]) => [
|
||||
key,
|
||||
normalizeNpcState(state),
|
||||
]),
|
||||
) as Record<string, RuntimeNpcState>;
|
||||
}
|
||||
|
||||
@@ -672,13 +681,14 @@ function buildBasicAttackBaseDamage(character: RuntimePlayerCharacter) {
|
||||
}
|
||||
|
||||
function buildBattleDisabledOption(params: {
|
||||
session: RuntimeSession;
|
||||
functionId: string;
|
||||
actionText?: string;
|
||||
detailText?: string;
|
||||
reason: string;
|
||||
payload?: RuntimeStoryChoicePayload;
|
||||
}) {
|
||||
return buildOptionView(params.functionId, {
|
||||
return buildOptionView(params.session, params.functionId, {
|
||||
actionText: params.actionText,
|
||||
detailText: params.detailText,
|
||||
payload: params.payload,
|
||||
@@ -687,6 +697,44 @@ function buildBattleDisabledOption(params: {
|
||||
});
|
||||
}
|
||||
|
||||
function buildOptionInteraction(
|
||||
session: RuntimeSession,
|
||||
functionId: string,
|
||||
): RuntimeStoryOptionInteraction | undefined {
|
||||
const encounter = session.currentEncounter;
|
||||
|
||||
if (encounter?.kind === 'npc') {
|
||||
const npcId = getEncounterKey(encounter);
|
||||
const npcActionMap: Record<string, RuntimeStoryOptionInteraction> = {
|
||||
npc_chat: { kind: 'npc', npcId, action: 'chat' },
|
||||
npc_fight: { kind: 'npc', npcId, action: 'fight' },
|
||||
npc_help: { kind: 'npc', npcId, action: 'help' },
|
||||
npc_leave: { kind: 'npc', npcId, action: 'leave' },
|
||||
npc_preview_talk: { kind: 'npc', npcId, action: 'chat' },
|
||||
npc_recruit: { kind: 'npc', npcId, action: 'recruit' },
|
||||
npc_spar: { kind: 'npc', npcId, action: 'spar' },
|
||||
npc_trade: { kind: 'npc', npcId, action: 'trade' },
|
||||
npc_gift: { kind: 'npc', npcId, action: 'gift' },
|
||||
npc_quest_accept: { kind: 'npc', npcId, action: 'quest_accept' },
|
||||
npc_quest_turn_in: { kind: 'npc', npcId, action: 'quest_turn_in' },
|
||||
};
|
||||
|
||||
return npcActionMap[functionId];
|
||||
}
|
||||
|
||||
if (encounter?.kind === 'treasure') {
|
||||
const treasureActionMap: Record<string, RuntimeStoryOptionInteraction> = {
|
||||
treasure_secure: { kind: 'treasure', action: 'secure' },
|
||||
treasure_inspect: { kind: 'treasure', action: 'inspect' },
|
||||
treasure_leave: { kind: 'treasure', action: 'leave' },
|
||||
};
|
||||
|
||||
return treasureActionMap[functionId];
|
||||
}
|
||||
|
||||
return undefined;
|
||||
}
|
||||
|
||||
function buildBattleItemSummary(
|
||||
effect: NonNullable<ReturnType<typeof resolveInventoryItemUseEffect>>,
|
||||
) {
|
||||
@@ -711,44 +759,47 @@ function pickPreferredBattleItem(session: RuntimeSession) {
|
||||
const cooldowns = getPlayerSkillCooldowns(session);
|
||||
const hasCoolingSkill = Object.values(cooldowns).some((turns) => turns > 0);
|
||||
const playerHpRatio = session.playerHp / Math.max(session.playerMaxHp, 1);
|
||||
const playerManaRatio = session.playerMana / Math.max(session.playerMaxMana, 1);
|
||||
const playerManaRatio =
|
||||
session.playerMana / Math.max(session.playerMaxMana, 1);
|
||||
|
||||
return getBattleInventoryItems(session)
|
||||
.filter((item) => item.quantity > 0 && isInventoryItemUsable(item))
|
||||
.map((item) => {
|
||||
const effect = resolveInventoryItemUseEffect(item, character);
|
||||
if (!effect) {
|
||||
return null;
|
||||
}
|
||||
return (
|
||||
getBattleInventoryItems(session)
|
||||
.filter((item) => item.quantity > 0 && isInventoryItemUsable(item))
|
||||
.map((item) => {
|
||||
const effect = resolveInventoryItemUseEffect(item, character);
|
||||
if (!effect) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const score =
|
||||
effect.hpRestore * (playerHpRatio <= 0.45 ? 2.6 : 1.2) +
|
||||
effect.manaRestore * (playerManaRatio <= 0.45 ? 2.2 : 0.9) +
|
||||
effect.cooldownReduction * (hasCoolingSkill ? 18 : 6) +
|
||||
effect.buildBuffs.length * 8;
|
||||
const score =
|
||||
effect.hpRestore * (playerHpRatio <= 0.45 ? 2.6 : 1.2) +
|
||||
effect.manaRestore * (playerManaRatio <= 0.45 ? 2.2 : 0.9) +
|
||||
effect.cooldownReduction * (hasCoolingSkill ? 18 : 6) +
|
||||
effect.buildBuffs.length * 8;
|
||||
|
||||
return {
|
||||
item,
|
||||
effect,
|
||||
score,
|
||||
};
|
||||
})
|
||||
.filter(
|
||||
(
|
||||
candidate,
|
||||
): candidate is {
|
||||
item: RuntimeBattleInventoryItem;
|
||||
effect: NonNullable<ReturnType<typeof resolveInventoryItemUseEffect>>;
|
||||
score: number;
|
||||
} => Boolean(candidate),
|
||||
)
|
||||
.sort(
|
||||
(left, right) =>
|
||||
right.score - left.score ||
|
||||
right.effect.hpRestore - left.effect.hpRestore ||
|
||||
right.effect.manaRestore - left.effect.manaRestore ||
|
||||
left.item.name.localeCompare(right.item.name, 'zh-CN'),
|
||||
)[0] ?? null;
|
||||
return {
|
||||
item,
|
||||
effect,
|
||||
score,
|
||||
};
|
||||
})
|
||||
.filter(
|
||||
(
|
||||
candidate,
|
||||
): candidate is {
|
||||
item: RuntimeBattleInventoryItem;
|
||||
effect: NonNullable<ReturnType<typeof resolveInventoryItemUseEffect>>;
|
||||
score: number;
|
||||
} => Boolean(candidate),
|
||||
)
|
||||
.sort(
|
||||
(left, right) =>
|
||||
right.score - left.score ||
|
||||
right.effect.hpRestore - left.effect.hpRestore ||
|
||||
right.effect.manaRestore - left.effect.manaRestore ||
|
||||
left.item.name.localeCompare(right.item.name, 'zh-CN'),
|
||||
)[0] ?? null
|
||||
);
|
||||
}
|
||||
|
||||
function buildBattleSkillOptions(session: RuntimeSession) {
|
||||
@@ -762,7 +813,9 @@ function buildBattleSkillOptions(session: RuntimeSession) {
|
||||
return character.skills.map((skill) => {
|
||||
const remainingCooldown = cooldowns[skill.id] ?? 0;
|
||||
const damage = resolvePlayerOutgoingDamageResult(
|
||||
session.rawGameState as Parameters<typeof resolvePlayerOutgoingDamageResult>[0],
|
||||
session.rawGameState as Parameters<
|
||||
typeof resolvePlayerOutgoingDamageResult
|
||||
>[0],
|
||||
character,
|
||||
skill.damage,
|
||||
1,
|
||||
@@ -776,6 +829,7 @@ function buildBattleSkillOptions(session: RuntimeSession) {
|
||||
|
||||
if (remainingCooldown > 0) {
|
||||
return buildBattleDisabledOption({
|
||||
session,
|
||||
functionId: 'battle_use_skill',
|
||||
actionText: skill.name,
|
||||
detailText,
|
||||
@@ -786,6 +840,7 @@ function buildBattleSkillOptions(session: RuntimeSession) {
|
||||
|
||||
if (skill.manaCost > session.playerMana) {
|
||||
return buildBattleDisabledOption({
|
||||
session,
|
||||
functionId: 'battle_use_skill',
|
||||
actionText: skill.name,
|
||||
detailText,
|
||||
@@ -794,7 +849,7 @@ function buildBattleSkillOptions(session: RuntimeSession) {
|
||||
});
|
||||
}
|
||||
|
||||
return buildOptionView('battle_use_skill', {
|
||||
return buildOptionView(session, 'battle_use_skill', {
|
||||
actionText: skill.name,
|
||||
detailText,
|
||||
payload: { skillId: skill.id },
|
||||
@@ -807,7 +862,9 @@ function buildBattleActionOptions(session: RuntimeSession) {
|
||||
const itemCandidate = pickPreferredBattleItem(session);
|
||||
const basicAttackDamage = character
|
||||
? resolvePlayerOutgoingDamageResult(
|
||||
session.rawGameState as Parameters<typeof resolvePlayerOutgoingDamageResult>[0],
|
||||
session.rawGameState as Parameters<
|
||||
typeof resolvePlayerOutgoingDamageResult
|
||||
>[0],
|
||||
character,
|
||||
buildBasicAttackBaseDamage(character),
|
||||
1,
|
||||
@@ -816,30 +873,31 @@ function buildBattleActionOptions(session: RuntimeSession) {
|
||||
: 0;
|
||||
|
||||
return [
|
||||
buildOptionView('battle_attack_basic', {
|
||||
buildOptionView(session, 'battle_attack_basic', {
|
||||
detailText:
|
||||
basicAttackDamage > 0
|
||||
? `不耗蓝 / 伤害 ${basicAttackDamage}`
|
||||
: '不耗蓝的基础攻击',
|
||||
}),
|
||||
buildOptionView('battle_recover_breath', {
|
||||
buildOptionView(session, 'battle_recover_breath', {
|
||||
actionText: '恢复',
|
||||
detailText: '回血 12 / 回蓝 9 / 冷却 -1',
|
||||
}),
|
||||
itemCandidate
|
||||
? buildOptionView('inventory_use', {
|
||||
? buildOptionView(session, 'inventory_use', {
|
||||
actionText: `使用物品:${itemCandidate.item.name}`,
|
||||
detailText: buildBattleItemSummary(itemCandidate.effect),
|
||||
payload: { itemId: itemCandidate.item.id },
|
||||
})
|
||||
: buildBattleDisabledOption({
|
||||
session,
|
||||
functionId: 'inventory_use',
|
||||
actionText: '使用物品',
|
||||
detailText: '当前没有可直接结算的战斗消耗品',
|
||||
reason: '暂无可用物品',
|
||||
}),
|
||||
...buildBattleSkillOptions(session),
|
||||
buildOptionView('battle_escape_breakout'),
|
||||
buildOptionView(session, 'battle_escape_breakout'),
|
||||
] satisfies RuntimeStoryOptionView[];
|
||||
}
|
||||
|
||||
@@ -875,7 +933,10 @@ export function loadRuntimeSession(
|
||||
sceneHostileNpcs,
|
||||
inBattle,
|
||||
playerHp: Math.max(0, Math.round(readNumber(rawGameState.playerHp, 0))),
|
||||
playerMaxHp: Math.max(1, Math.round(readNumber(rawGameState.playerMaxHp, 1))),
|
||||
playerMaxHp: Math.max(
|
||||
1,
|
||||
Math.round(readNumber(rawGameState.playerMaxHp, 1)),
|
||||
),
|
||||
playerMana: Math.max(0, Math.round(readNumber(rawGameState.playerMana, 0))),
|
||||
playerMaxMana: Math.max(
|
||||
1,
|
||||
@@ -953,6 +1014,7 @@ export function setEncounterNpcState(
|
||||
}
|
||||
|
||||
function buildOptionView(
|
||||
session: RuntimeSession,
|
||||
functionId: string,
|
||||
overrides: Partial<RuntimeStoryOptionView> = {},
|
||||
): RuntimeStoryOptionView {
|
||||
@@ -963,6 +1025,7 @@ function buildOptionView(
|
||||
actionText: functionId,
|
||||
detailText: '',
|
||||
scope: 'story',
|
||||
interaction: buildOptionInteraction(session, functionId),
|
||||
...overrides,
|
||||
};
|
||||
}
|
||||
@@ -972,6 +1035,7 @@ function buildOptionView(
|
||||
actionText: definition.actionText,
|
||||
detailText: definition.detailText,
|
||||
scope: definition.scope,
|
||||
interaction: buildOptionInteraction(session, functionId),
|
||||
...overrides,
|
||||
};
|
||||
}
|
||||
@@ -1033,38 +1097,42 @@ export function buildAvailableOptions(session: RuntimeSession) {
|
||||
const npcState = getEncounterNpcState(session);
|
||||
if (session.currentEncounter.hostile) {
|
||||
return [
|
||||
buildOptionView('npc_fight'),
|
||||
buildOptionView('npc_leave'),
|
||||
buildOptionView(session, 'npc_fight'),
|
||||
buildOptionView(session, 'npc_leave'),
|
||||
];
|
||||
}
|
||||
|
||||
if (!session.npcInteractionActive) {
|
||||
return [
|
||||
buildOptionView('npc_preview_talk'),
|
||||
buildOptionView('npc_fight'),
|
||||
buildOptionView('npc_leave'),
|
||||
buildOptionView(session, 'npc_preview_talk'),
|
||||
buildOptionView(session, 'npc_fight'),
|
||||
buildOptionView(session, 'npc_leave'),
|
||||
];
|
||||
}
|
||||
|
||||
const activeQuest = getActiveEncounterQuest(session);
|
||||
const options = [
|
||||
buildOptionView('npc_chat'),
|
||||
buildOptionView('npc_help', npcState?.helpUsed
|
||||
? {
|
||||
disabled: true,
|
||||
reason: '当前 NPC 的一次性援手已经用完了。',
|
||||
}
|
||||
: {}),
|
||||
buildOptionView('npc_spar'),
|
||||
buildOptionView('npc_fight'),
|
||||
buildOptionView(session, 'npc_chat'),
|
||||
buildOptionView(
|
||||
session,
|
||||
'npc_help',
|
||||
npcState?.helpUsed
|
||||
? {
|
||||
disabled: true,
|
||||
reason: '当前 NPC 的一次性援手已经用完了。',
|
||||
}
|
||||
: {},
|
||||
),
|
||||
buildOptionView(session, 'npc_spar'),
|
||||
buildOptionView(session, 'npc_fight'),
|
||||
];
|
||||
|
||||
if ((npcState?.inventory?.length ?? 0) > 0) {
|
||||
options.push(buildOptionView('npc_trade'));
|
||||
options.push(buildOptionView(session, 'npc_trade'));
|
||||
}
|
||||
|
||||
if (hasGiftablePlayerInventory(session)) {
|
||||
options.push(buildOptionView('npc_gift'));
|
||||
options.push(buildOptionView(session, 'npc_gift'));
|
||||
}
|
||||
|
||||
if (
|
||||
@@ -1072,14 +1140,15 @@ export function buildAvailableOptions(session: RuntimeSession) {
|
||||
(activeQuest.status === 'completed' ||
|
||||
activeQuest.status === 'ready_to_turn_in')
|
||||
) {
|
||||
options.push(buildOptionView('npc_quest_turn_in'));
|
||||
options.push(buildOptionView(session, 'npc_quest_turn_in'));
|
||||
} else if (!activeQuest) {
|
||||
options.push(buildOptionView('npc_quest_accept'));
|
||||
options.push(buildOptionView(session, 'npc_quest_accept'));
|
||||
}
|
||||
|
||||
if (npcState && !npcState.recruited && npcState.affinity >= 60) {
|
||||
options.push(
|
||||
buildOptionView(
|
||||
session,
|
||||
'npc_recruit',
|
||||
session.companions.length >= MAX_TASK5_COMPANIONS
|
||||
? {
|
||||
@@ -1091,15 +1160,15 @@ export function buildAvailableOptions(session: RuntimeSession) {
|
||||
);
|
||||
}
|
||||
|
||||
options.push(buildOptionView('npc_leave'));
|
||||
options.push(buildOptionView(session, 'npc_leave'));
|
||||
return options;
|
||||
}
|
||||
|
||||
if (session.currentEncounter?.kind === 'treasure') {
|
||||
return [
|
||||
buildOptionView('treasure_secure'),
|
||||
buildOptionView('treasure_inspect'),
|
||||
buildOptionView('treasure_leave'),
|
||||
buildOptionView(session, 'treasure_secure'),
|
||||
buildOptionView(session, 'treasure_inspect'),
|
||||
buildOptionView(session, 'treasure_leave'),
|
||||
];
|
||||
}
|
||||
|
||||
@@ -1110,7 +1179,7 @@ export function buildAvailableOptions(session: RuntimeSession) {
|
||||
'idle_explore_forward',
|
||||
'idle_travel_next_scene',
|
||||
'story_continue_adventure',
|
||||
].map((functionId) => buildOptionView(functionId));
|
||||
].map((functionId) => buildOptionView(session, functionId));
|
||||
}
|
||||
|
||||
function buildEncounterViewModel(
|
||||
@@ -1189,6 +1258,7 @@ export function buildLegacyCurrentStory(
|
||||
text: option.actionText,
|
||||
detailText: option.detailText,
|
||||
priority: option.scope === 'npc' ? 3 : option.scope === 'combat' ? 2 : 1,
|
||||
interaction: option.interaction,
|
||||
runtimePayload: option.payload,
|
||||
disabled: option.disabled,
|
||||
disabledReason: option.reason,
|
||||
@@ -1221,8 +1291,10 @@ export function syncRawGameState(session: RuntimeSession) {
|
||||
session.rawGameState.npcStates = cloneJson(session.npcStates);
|
||||
session.rawGameState.companions = cloneJson(session.companions);
|
||||
session.rawGameState.currentNpcBattleMode = session.currentNpcBattleMode;
|
||||
session.rawGameState.currentNpcBattleOutcome = session.currentNpcBattleOutcome;
|
||||
session.rawGameState.currentBattleNpcId = session.currentEncounter?.id ?? null;
|
||||
session.rawGameState.currentNpcBattleOutcome =
|
||||
session.currentNpcBattleOutcome;
|
||||
session.rawGameState.currentBattleNpcId =
|
||||
session.currentEncounter?.id ?? null;
|
||||
session.rawGameState.activeCombatEffects = [];
|
||||
session.rawGameState.playerActionMode = 'idle';
|
||||
session.rawGameState.scrollWorld = false;
|
||||
|
||||
Reference in New Issue
Block a user