@@ -132,67 +132,16 @@ function createBattleOption(functionId = 'battle_all_in_crush'): StoryOption {
|
||||
};
|
||||
}
|
||||
|
||||
function createFallbackStory(text = 'fallback'): StoryMoment {
|
||||
function createFallbackStory(
|
||||
text = 'fallback',
|
||||
options: StoryOption[] = [],
|
||||
): StoryMoment {
|
||||
return {
|
||||
text,
|
||||
options: [],
|
||||
options,
|
||||
};
|
||||
}
|
||||
|
||||
function createCustomWorldProfileForSceneAct(sceneId: string) {
|
||||
return {
|
||||
id: 'custom-world-test',
|
||||
name: '场景幕重置测试',
|
||||
summary: '用于验证战败后回到首幕。',
|
||||
playableNpcs: [],
|
||||
storyNpcs: [],
|
||||
sceneChapterBlueprints: [
|
||||
{
|
||||
id: `${sceneId}-chapter`,
|
||||
sceneId,
|
||||
title: '测试章节',
|
||||
summary: '测试章节摘要',
|
||||
linkedThreadIds: [],
|
||||
linkedLandmarkIds: [],
|
||||
acts: [
|
||||
{
|
||||
id: `${sceneId}-act-1`,
|
||||
sceneId,
|
||||
title: '第一幕',
|
||||
summary: '开场第一幕',
|
||||
stageCoverage: ['opening'],
|
||||
backgroundImageSrc: '/act-1.png',
|
||||
encounterNpcIds: [],
|
||||
primaryNpcId: null,
|
||||
oppositeNpcId: null,
|
||||
eventDescription: '第一幕事件',
|
||||
linkedThreadIds: [],
|
||||
advanceRule: 'after_primary_contact',
|
||||
actGoal: '完成第一幕目标',
|
||||
transitionHook: '第一幕过渡',
|
||||
},
|
||||
{
|
||||
id: `${sceneId}-act-2`,
|
||||
sceneId,
|
||||
title: '第二幕',
|
||||
summary: '推进第二幕',
|
||||
stageCoverage: ['expansion'],
|
||||
backgroundImageSrc: '/act-2.png',
|
||||
encounterNpcIds: [],
|
||||
primaryNpcId: null,
|
||||
oppositeNpcId: null,
|
||||
eventDescription: '第二幕事件',
|
||||
linkedThreadIds: [],
|
||||
advanceRule: 'after_primary_contact',
|
||||
actGoal: '完成第二幕目标',
|
||||
transitionHook: '第二幕过渡',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
} as NonNullable<GameState['customWorldProfile']>;
|
||||
}
|
||||
|
||||
const neverNpcEncounter = (
|
||||
encounter: GameState['currentEncounter'],
|
||||
): encounter is Encounter => false;
|
||||
@@ -692,10 +641,8 @@ describe('createStoryChoiceActions', () => {
|
||||
it('keeps local npc defeat on the death revive chain and resets to the first scene act', async () => {
|
||||
vi.useFakeTimers();
|
||||
const firstScene = getScenePresetsByWorld(WorldType.WUXIA)[0]!;
|
||||
const customWorldProfile = createCustomWorldProfileForSceneAct(firstScene.id);
|
||||
const state = {
|
||||
...createBaseState(),
|
||||
customWorldProfile,
|
||||
currentScenePreset: firstScene,
|
||||
storyEngineMemory: {
|
||||
discoveredFactIds: [],
|
||||
@@ -735,7 +682,6 @@ describe('createStoryChoiceActions', () => {
|
||||
}));
|
||||
const setCurrentStory = vi.fn();
|
||||
const setGameState = vi.fn();
|
||||
|
||||
const { handleChoice } = createStoryChoiceActions({
|
||||
gameState: state,
|
||||
currentStory: createFallbackStory(),
|
||||
@@ -763,7 +709,7 @@ describe('createStoryChoiceActions', () => {
|
||||
skillCooldowns: {},
|
||||
})),
|
||||
buildStoryFromResponse: vi.fn((_, __, response) => response),
|
||||
buildFallbackStoryForState: vi.fn(() => createFallbackStory()),
|
||||
buildFallbackStoryForState: vi.fn(() => createFallbackStory('fallback')),
|
||||
generateStoryForState: vi.fn(),
|
||||
getAvailableOptionsForState: vi.fn(() => null),
|
||||
getStoryGenerationHostileNpcs: vi.fn(() => []),
|
||||
@@ -809,22 +755,24 @@ describe('createStoryChoiceActions', () => {
|
||||
id: firstScene.id,
|
||||
}),
|
||||
playerHp: 100,
|
||||
playerMana: 20,
|
||||
inBattle: false,
|
||||
currentNpcBattleOutcome: null,
|
||||
storyEngineMemory: expect.objectContaining({
|
||||
currentSceneActState: expect.objectContaining({
|
||||
sceneId: firstScene.id,
|
||||
currentActId: `${firstScene.id}-act-1`,
|
||||
currentActIndex: 0,
|
||||
}),
|
||||
}),
|
||||
}),
|
||||
);
|
||||
const revivedState = setGameState.mock.calls[1]?.[0] as GameState;
|
||||
expect(revivedState.currentBattleNpcId).toBeNull();
|
||||
expect(revivedState.currentNpcBattleMode).toBeNull();
|
||||
expect(revivedState.currentNpcBattleOutcome).toBeNull();
|
||||
expect(
|
||||
revivedState.currentEncounter !== null || revivedState.sceneHostileNpcs.length > 0,
|
||||
).toBe(true);
|
||||
expect(setCurrentStory).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
text: expect.stringContaining('重新醒来'),
|
||||
}),
|
||||
);
|
||||
vi.useRealTimers();
|
||||
});
|
||||
|
||||
it('settles escape locally without ai continuation', async () => {
|
||||
|
||||
@@ -721,6 +721,59 @@ describe('npcEncounterActions', () => {
|
||||
expect(result).toBeNull();
|
||||
});
|
||||
|
||||
it('restores the pre-battle encounter after fight_victory instead of using the battle encounter position', () => {
|
||||
const preBattleEncounter = {
|
||||
...createEncounter(),
|
||||
xMeters: 12,
|
||||
context: '断桥外侧',
|
||||
};
|
||||
const battleEncounter = {
|
||||
...createEncounter(),
|
||||
xMeters: 3.2,
|
||||
context: '战斗中心位',
|
||||
};
|
||||
const actions = createNpcEncounterActions({
|
||||
gameState: createState({
|
||||
currentEncounter: battleEncounter,
|
||||
inBattle: true,
|
||||
currentBattleNpcId: 'npc-rival',
|
||||
currentNpcBattleMode: 'fight',
|
||||
currentNpcBattleOutcome: 'fight_victory',
|
||||
sparReturnEncounter: preBattleEncounter,
|
||||
sceneHostileNpcs: [
|
||||
{
|
||||
id: 'npc-rival',
|
||||
name: '断桥客',
|
||||
action: '逼近',
|
||||
description: '拦路旧敌',
|
||||
animation: 'idle',
|
||||
xMeters: 3.2,
|
||||
yOffset: 0,
|
||||
facing: 'left',
|
||||
attackRange: 1.4,
|
||||
speed: 7,
|
||||
hp: 0,
|
||||
maxHp: 12,
|
||||
renderKind: 'npc',
|
||||
encounter: battleEncounter,
|
||||
},
|
||||
],
|
||||
}),
|
||||
});
|
||||
|
||||
const result = actions.finalizeNpcBattleResult(
|
||||
actions.gameState,
|
||||
actions.gameState.playerCharacter!,
|
||||
'fight',
|
||||
'fight_victory',
|
||||
);
|
||||
|
||||
expect(result).not.toBeNull();
|
||||
expect(result?.nextState.currentEncounter).toEqual(preBattleEncounter);
|
||||
expect(result?.nextState.currentEncounter?.xMeters).toBe(12);
|
||||
expect(result?.nextState.sparReturnEncounter).toBeNull();
|
||||
});
|
||||
|
||||
it('streams a model-driven npc-initiated opening on first meaningful contact', async () => {
|
||||
const encounter = createEncounter();
|
||||
streamNpcChatTurnMock.mockResolvedValueOnce({
|
||||
|
||||
327
src/hooks/rpg-runtime-story/postBattleFlow.test.ts
Normal file
327
src/hooks/rpg-runtime-story/postBattleFlow.test.ts
Normal file
@@ -0,0 +1,327 @@
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest';
|
||||
|
||||
const { ensureSceneEncounterPreviewMock } = vi.hoisted(() => ({
|
||||
ensureSceneEncounterPreviewMock: vi.fn(),
|
||||
}));
|
||||
|
||||
vi.mock('../../data/sceneEncounterPreviews', () => ({
|
||||
ensureSceneEncounterPreview: ensureSceneEncounterPreviewMock,
|
||||
}));
|
||||
|
||||
import { setRuntimeCustomWorldProfile } from '../../data/customWorldRuntime';
|
||||
import { getScenePresetsByWorld } from '../../data/scenePresets';
|
||||
import { AnimationState, type GameState, WorldType } from '../../types';
|
||||
import { buildRevivedFirstSceneState } from './postBattleFlow';
|
||||
|
||||
function createBackstoryReveal(label: string) {
|
||||
return {
|
||||
publicSummary: `${label}的公开背景`,
|
||||
chapters: [
|
||||
{
|
||||
id: `${label}-surface`,
|
||||
title: '表层来意',
|
||||
affinityRequired: 15,
|
||||
teaser: `${label}先收着话。`,
|
||||
content: `${label}把真正目的藏在后面。`,
|
||||
contextSnippet: `${label}表面上仍在试探。`,
|
||||
},
|
||||
{
|
||||
id: `${label}-scar`,
|
||||
title: '旧事裂痕',
|
||||
affinityRequired: 30,
|
||||
teaser: `${label}提到旧事会迟疑。`,
|
||||
content: `${label}背后压着旧伤。`,
|
||||
contextSnippet: `${label}仍被旧事牵制。`,
|
||||
},
|
||||
{
|
||||
id: `${label}-hidden`,
|
||||
title: '隐藏执念',
|
||||
affinityRequired: 60,
|
||||
teaser: `${label}真正执念并不在表面。`,
|
||||
content: `${label}真正想守住的是另一条暗线。`,
|
||||
contextSnippet: `${label}另有没说出口的理由。`,
|
||||
},
|
||||
{
|
||||
id: `${label}-final`,
|
||||
title: '最终底牌',
|
||||
affinityRequired: 90,
|
||||
teaser: `${label}手里还扣着底牌。`,
|
||||
content: `${label}掌握能改写局势的最后证据。`,
|
||||
contextSnippet: `${label}最后底牌还没翻出。`,
|
||||
},
|
||||
],
|
||||
};
|
||||
}
|
||||
|
||||
function createStoryRole(id: string, name: string, hostile = false) {
|
||||
return {
|
||||
id,
|
||||
name,
|
||||
title: `${name}的头衔`,
|
||||
role: hostile ? '敌对角色' : '同幕角色',
|
||||
description: `${name}的测试描述`,
|
||||
backstory: `${name}的测试背景`,
|
||||
personality: '冷静克制',
|
||||
motivation: hostile ? '阻拦玩家继续向前' : '观察局势变化',
|
||||
combatStyle: hostile ? '正面压制' : '后排支援',
|
||||
initialAffinity: hostile ? -20 : 12,
|
||||
relationshipHooks: [],
|
||||
tags: [],
|
||||
backstoryReveal: createBackstoryReveal(name),
|
||||
skills: [],
|
||||
initialItems: [],
|
||||
};
|
||||
}
|
||||
|
||||
function createReviveState(): GameState {
|
||||
const customWorldProfile = {
|
||||
id: 'custom-revive-test',
|
||||
name: '复活回场测试世界',
|
||||
subtitle: '首幕站位恢复',
|
||||
summary: '用于验证复活后第一幕 NPC 会按既有 encounter preview 恢复。',
|
||||
settingText: '围绕开局营地与第一幕对峙角色展开的自定义世界。',
|
||||
tone: '紧张、克制',
|
||||
playerGoal: '复活后重新回到第一幕并面对主交互角色。',
|
||||
templateWorldType: WorldType.WUXIA,
|
||||
majorFactions: [],
|
||||
coreConflicts: [],
|
||||
attributeSchema: {
|
||||
id: 'schema:test',
|
||||
worldId: 'CUSTOM',
|
||||
schemaVersion: 1,
|
||||
schemaName: '测试属性',
|
||||
generatedFrom: {
|
||||
worldType: WorldType.CUSTOM,
|
||||
worldName: '复活回场测试世界',
|
||||
settingSummary: '首幕站位恢复',
|
||||
tone: '紧张、克制',
|
||||
conflictCore: '复活后重新面对主交互角色',
|
||||
},
|
||||
slots: [],
|
||||
},
|
||||
playableNpcs: [],
|
||||
storyNpcs: [
|
||||
createStoryRole('npc-front', '正面对手', true),
|
||||
createStoryRole('npc-back-1', '后排甲'),
|
||||
createStoryRole('npc-back-2', '后排乙'),
|
||||
],
|
||||
items: [],
|
||||
landmarks: [],
|
||||
camp: {
|
||||
id: 'custom-scene-camp',
|
||||
name: '开局营地',
|
||||
description: '用于复活回场测试。',
|
||||
visualDescription: '营地火光映着即将重开的第一幕。',
|
||||
imageSrc: '/camp.png',
|
||||
sceneNpcIds: ['npc-front', 'npc-back-1', 'npc-back-2'],
|
||||
connections: [],
|
||||
narrativeResidues: null,
|
||||
},
|
||||
sceneChapterBlueprints: [
|
||||
{
|
||||
id: 'custom-scene-camp-chapter',
|
||||
sceneId: 'custom-scene-camp',
|
||||
title: '开局章节',
|
||||
summary: '复活后应回到这里的第一幕。',
|
||||
sceneTaskDescription: '',
|
||||
linkedThreadIds: [],
|
||||
linkedLandmarkIds: [],
|
||||
acts: [
|
||||
{
|
||||
id: 'custom-scene-camp-act-1',
|
||||
sceneId: 'custom-scene-camp',
|
||||
title: '第一幕',
|
||||
summary: '主交互角色与后排角色一同出现。',
|
||||
stageCoverage: ['opening'],
|
||||
backgroundImageSrc: '/act-1.png',
|
||||
encounterNpcIds: ['npc-front', 'npc-back-1', 'npc-back-2'],
|
||||
primaryNpcId: 'npc-front',
|
||||
oppositeNpcId: 'npc-front',
|
||||
eventDescription: '第一幕事件',
|
||||
linkedThreadIds: [],
|
||||
advanceRule: 'after_primary_contact',
|
||||
actGoal: '重新进入首幕',
|
||||
transitionHook: '首幕回场',
|
||||
},
|
||||
{
|
||||
id: 'custom-scene-camp-act-2',
|
||||
sceneId: 'custom-scene-camp',
|
||||
title: '第二幕',
|
||||
summary: '这是死亡前已经推进到的幕。',
|
||||
stageCoverage: ['expansion'],
|
||||
backgroundImageSrc: '/act-2.png',
|
||||
encounterNpcIds: ['npc-front', 'npc-back-1', 'npc-back-2'],
|
||||
primaryNpcId: 'npc-front',
|
||||
oppositeNpcId: 'npc-front',
|
||||
eventDescription: '第二幕事件',
|
||||
linkedThreadIds: [],
|
||||
advanceRule: 'after_primary_contact',
|
||||
actGoal: '推进第二幕',
|
||||
transitionHook: '第二幕推进',
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
} as NonNullable<GameState['customWorldProfile']>;
|
||||
|
||||
setRuntimeCustomWorldProfile(customWorldProfile);
|
||||
const firstScene = getScenePresetsByWorld(WorldType.CUSTOM)[0]!;
|
||||
|
||||
return {
|
||||
worldType: WorldType.CUSTOM,
|
||||
customWorldProfile,
|
||||
playerCharacter: {
|
||||
id: 'hero',
|
||||
name: '测试主角',
|
||||
title: '旅人',
|
||||
description: '测试角色',
|
||||
backstory: '测试背景',
|
||||
avatar: '/hero.png',
|
||||
portrait: '/hero.png',
|
||||
assetFolder: 'hero',
|
||||
assetVariant: 'default',
|
||||
attributes: {
|
||||
strength: 10,
|
||||
agility: 10,
|
||||
intelligence: 10,
|
||||
spirit: 10,
|
||||
},
|
||||
personality: 'calm',
|
||||
skills: [],
|
||||
adventureOpenings: {},
|
||||
},
|
||||
runtimeStats: {
|
||||
playTimeMs: 0,
|
||||
lastPlayTickAt: null,
|
||||
hostileNpcsDefeated: 0,
|
||||
questsAccepted: 0,
|
||||
itemsUsed: 0,
|
||||
scenesTraveled: 0,
|
||||
},
|
||||
currentScene: 'Story',
|
||||
storyHistory: [],
|
||||
characterChats: {},
|
||||
animationState: AnimationState.DIE,
|
||||
currentEncounter: null,
|
||||
npcInteractionActive: false,
|
||||
currentScenePreset: firstScene,
|
||||
sceneHostileNpcs: [],
|
||||
playerX: 0,
|
||||
playerOffsetY: 0,
|
||||
playerFacing: 'right',
|
||||
playerActionMode: 'idle',
|
||||
scrollWorld: false,
|
||||
inBattle: false,
|
||||
playerHp: 0,
|
||||
playerMaxHp: 100,
|
||||
playerMana: 0,
|
||||
playerMaxMana: 20,
|
||||
playerSkillCooldowns: {},
|
||||
activeCombatEffects: [],
|
||||
playerCurrency: 0,
|
||||
playerInventory: [],
|
||||
playerEquipment: {
|
||||
weapon: null,
|
||||
armor: null,
|
||||
relic: null,
|
||||
},
|
||||
npcStates: {
|
||||
'npc-front': {
|
||||
affinity: -20,
|
||||
helpUsed: false,
|
||||
chattedCount: 0,
|
||||
giftsGiven: 0,
|
||||
inventory: [],
|
||||
recruited: false,
|
||||
},
|
||||
'npc-back-1': {
|
||||
affinity: 8,
|
||||
helpUsed: false,
|
||||
chattedCount: 0,
|
||||
giftsGiven: 0,
|
||||
inventory: [],
|
||||
recruited: false,
|
||||
},
|
||||
'npc-back-2': {
|
||||
affinity: 6,
|
||||
helpUsed: false,
|
||||
chattedCount: 0,
|
||||
giftsGiven: 0,
|
||||
inventory: [],
|
||||
recruited: false,
|
||||
},
|
||||
},
|
||||
quests: [],
|
||||
roster: [],
|
||||
companions: [],
|
||||
currentBattleNpcId: 'npc-front',
|
||||
currentNpcBattleMode: 'fight',
|
||||
currentNpcBattleOutcome: 'fight_defeat',
|
||||
sparReturnEncounter: null,
|
||||
sparPlayerHpBefore: null,
|
||||
sparPlayerMaxHpBefore: null,
|
||||
sparStoryHistoryBefore: null,
|
||||
storyEngineMemory: {
|
||||
discoveredFactIds: [],
|
||||
activeThreadIds: [],
|
||||
resolvedScarIds: [],
|
||||
recentCarrierIds: [],
|
||||
currentSceneActState: {
|
||||
sceneId: 'custom-scene-camp',
|
||||
chapterId: 'custom-scene-camp-chapter',
|
||||
currentActId: 'custom-scene-camp-act-2',
|
||||
currentActIndex: 1,
|
||||
completedActIds: ['custom-scene-camp-act-1'],
|
||||
visitedActIds: ['custom-scene-camp-act-1', 'custom-scene-camp-act-2'],
|
||||
},
|
||||
},
|
||||
} as GameState;
|
||||
}
|
||||
|
||||
describe('postBattleFlow', () => {
|
||||
afterEach(() => {
|
||||
ensureSceneEncounterPreviewMock.mockReset();
|
||||
setRuntimeCustomWorldProfile(null);
|
||||
});
|
||||
|
||||
it('rebuilds revived first-scene state through encounter preview restoration', () => {
|
||||
const reviveState = createReviveState();
|
||||
const previewRestoredState = {
|
||||
...reviveState,
|
||||
currentEncounter: {
|
||||
id: 'npc-front',
|
||||
kind: 'npc' as const,
|
||||
characterId: 'npc-front',
|
||||
npcName: '正面对手',
|
||||
npcDescription: '正面对手的测试描述',
|
||||
npcAvatar: '正',
|
||||
context: '敌对角色',
|
||||
xMeters: 12,
|
||||
},
|
||||
};
|
||||
ensureSceneEncounterPreviewMock.mockReturnValue(previewRestoredState);
|
||||
|
||||
const revived = buildRevivedFirstSceneState(reviveState);
|
||||
|
||||
expect(ensureSceneEncounterPreviewMock).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
currentScenePreset: expect.objectContaining({
|
||||
id: 'custom-scene-camp',
|
||||
}),
|
||||
currentEncounter: null,
|
||||
sceneHostileNpcs: [],
|
||||
playerHp: 100,
|
||||
playerMana: 20,
|
||||
inBattle: false,
|
||||
currentNpcBattleOutcome: null,
|
||||
storyEngineMemory: expect.objectContaining({
|
||||
currentSceneActState: expect.objectContaining({
|
||||
currentActId: 'custom-scene-camp-act-1',
|
||||
currentActIndex: 0,
|
||||
}),
|
||||
}),
|
||||
}),
|
||||
);
|
||||
expect(revived).toBe(previewRestoredState);
|
||||
});
|
||||
});
|
||||
@@ -1,4 +1,5 @@
|
||||
import { getScenePresetById, getScenePresetsByWorld } from '../../data/scenePresets';
|
||||
import { ensureSceneEncounterPreview } from '../../data/sceneEncounterPreviews';
|
||||
import {
|
||||
advanceSceneActRuntimeState,
|
||||
buildInitialSceneActRuntimeState,
|
||||
@@ -169,7 +170,7 @@ export function buildRevivedFirstSceneState(state: GameState): GameState {
|
||||
storyEngineMemory: undefined,
|
||||
});
|
||||
|
||||
return {
|
||||
const revivedBaseState = {
|
||||
...state,
|
||||
currentScenePreset: firstScene,
|
||||
currentEncounter: null,
|
||||
@@ -195,19 +196,34 @@ export function buildRevivedFirstSceneState(state: GameState): GameState {
|
||||
...storyEngineMemory,
|
||||
currentSceneActState: firstActState,
|
||||
},
|
||||
};
|
||||
} satisfies GameState;
|
||||
|
||||
// 中文注释:角色复活后要回到“开局进入世界”同一套首幕 encounter preview
|
||||
// 构建链,而不是只清空战斗态。这样第一幕主交互 NPC 与同幕陪衬 NPC
|
||||
// 会按既有槽位一起恢复,避免退化成所有人站成一排。
|
||||
return ensureSceneEncounterPreview(revivedBaseState);
|
||||
}
|
||||
|
||||
export function buildDeathStory(state: GameState): StoryMoment {
|
||||
export function buildDeathStory(
|
||||
state: GameState,
|
||||
deferredOptions?: StoryOption[],
|
||||
): StoryMoment {
|
||||
const firstSceneName =
|
||||
state.worldType
|
||||
? getScenePresetsByWorld(state.worldType)[0]?.name
|
||||
: state.currentScenePreset?.name;
|
||||
|
||||
return {
|
||||
text: firstSceneName
|
||||
? `你在战斗中倒下,随后在${firstSceneName}重新醒来。`
|
||||
: '你在战斗中倒下,随后重新醒来。',
|
||||
options: [buildContinueOption()],
|
||||
// 中文注释:复活后的“继续前进”只负责揭示已经准备好的首场景入口,
|
||||
// 不能再次触发普通剧情推演,否则容易直接被推进到主 NPC 执行态。
|
||||
deferredOptions:
|
||||
deferredOptions && deferredOptions.length > 0
|
||||
? deferredOptions
|
||||
: undefined,
|
||||
streaming: false,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -301,6 +301,13 @@ function bridgeServerNpcBattleSnapshot(params: {
|
||||
sceneHostileNpcs: resolvedBattleFormation,
|
||||
currentEncounter: null,
|
||||
npcInteractionActive: false,
|
||||
// 中文注释:服务端兼容链路若未带回战前遭遇,则沿用进入战斗前的原始 encounter,
|
||||
// 让后续 fight_victory / spar_complete 都能恢复到正确站位,而不是战斗中的临时坐标。
|
||||
sparReturnEncounter:
|
||||
snapshotState.sparReturnEncounter ??
|
||||
(previousState.currentEncounter?.kind === 'npc'
|
||||
? previousState.currentEncounter
|
||||
: null),
|
||||
},
|
||||
} satisfies HydratedSavedGameSnapshot;
|
||||
}
|
||||
|
||||
@@ -937,6 +937,9 @@ describe('runtimeStoryCoordinator', () => {
|
||||
yOffset: 62,
|
||||
},
|
||||
]);
|
||||
expect(result.hydratedSnapshot.gameState.sparReturnEncounter).toEqual(
|
||||
gameState.currentEncounter,
|
||||
);
|
||||
});
|
||||
|
||||
it('realigns non-empty npc_fight battle snapshots back to the visible pre-battle formation', async () => {
|
||||
|
||||
@@ -446,8 +446,12 @@ export async function runLocalStoryChoiceContinuation(params: {
|
||||
],
|
||||
};
|
||||
fallbackState = revivedState;
|
||||
const revivedDeferredOptions =
|
||||
params.buildFallbackStoryForState(revivedState, params.character).options;
|
||||
params.setGameState(revivedState);
|
||||
params.setCurrentStory(buildDeathStory(revivedState));
|
||||
params.setCurrentStory(
|
||||
buildDeathStory(revivedState, revivedDeferredOptions),
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -527,7 +527,10 @@ describe('storyChoiceRuntime', () => {
|
||||
setIsLoading: vi.fn(),
|
||||
setGameState,
|
||||
setCurrentStory: setCurrentStory as (story: StoryMoment) => void,
|
||||
buildFallbackStoryForState: () => createStory('fallback'),
|
||||
buildFallbackStoryForState: () =>
|
||||
createStory('fallback', [
|
||||
createOption('idle_explore_forward'),
|
||||
]),
|
||||
turnVisualMs: 1,
|
||||
});
|
||||
|
||||
@@ -541,6 +544,11 @@ describe('storyChoiceRuntime', () => {
|
||||
expect(setCurrentStory).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
text: expect.stringContaining('重新醒来'),
|
||||
options: [
|
||||
expect.objectContaining({
|
||||
functionId: 'story_continue_adventure',
|
||||
}),
|
||||
],
|
||||
}),
|
||||
);
|
||||
expect(setCurrentStory).not.toHaveBeenCalledWith(
|
||||
|
||||
@@ -350,8 +350,12 @@ export async function runServerRuntimeChoiceAction(params: {
|
||||
params.setGameState(deathState);
|
||||
await sleep(PLAYER_REVIVE_DELAY_MS);
|
||||
const revivedState = buildRevivedFirstSceneState(deathState);
|
||||
const revivedDeferredOptions =
|
||||
params.buildFallbackStoryForState(revivedState, params.character).options;
|
||||
params.setGameState(revivedState);
|
||||
params.setCurrentStory(buildDeathStory(revivedState));
|
||||
params.setCurrentStory(
|
||||
buildDeathStory(revivedState, revivedDeferredOptions),
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -490,6 +490,7 @@ export function createStoryNpcEncounterActions({
|
||||
(hostileNpc) => hostileNpc.id,
|
||||
);
|
||||
const restoredEncounter =
|
||||
state.sparReturnEncounter ??
|
||||
(state.currentEncounter?.kind === 'npc' ? state.currentEncounter : null) ??
|
||||
activeBattleHostiles[0]?.encounter ??
|
||||
({
|
||||
|
||||
Reference in New Issue
Block a user