@@ -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 () => {
|
||||
|
||||
Reference in New Issue
Block a user