This commit is contained in:
2026-04-29 20:56:59 +08:00
parent fb6f455530
commit 730f485f48
200 changed files with 9881 additions and 2221 deletions

View File

@@ -37,7 +37,11 @@ pub fn project_story_engine_after_action(
battle_outcome,
);
apply_thread_signal_updates(game_state, &mut memory, &signals);
ensure_scene_chapter_state(game_state, &mut memory);
// 中文注释NPC 战斗入口只是把当前 NPC 切入战斗结算,
// 不能顺手触发“首进场景章节任务”。否则玩家点战斗会误以为被系统自动接了任务。
if should_update_scene_chapter_state(function_id) {
ensure_scene_chapter_state(game_state, &mut memory);
}
let previous_chapter = read_object_field(game_state, "chapterState")
.or_else(|| read_object_field(&memory, "currentChapter"))
@@ -141,6 +145,10 @@ fn ensure_array_field(root: &mut Map<String, Value>, key: &str) {
}
}
fn should_update_scene_chapter_state(function_id: &str) -> bool {
!matches!(function_id, "npc_fight" | "npc_spar")
}
fn collect_story_signals(
previous_state: &Value,
next_state: &Value,
@@ -1566,4 +1574,51 @@ mod tests {
.all(|mutation| mutation["mutationType"] != json!("enemy_pressure"))
);
}
#[test]
fn story_engine_projector_does_not_create_chapter_quest_on_npc_battle_entry() {
let previous_state = json!({
"worldType": "WUXIA",
"currentScene": "Story",
"storyHistory": [],
"quests": [],
"currentScenePreset": {
"id": "scene-bridge",
"name": "断桥口",
"description": "风从桥下吹上来。",
"npcs": [{
"id": "npc-guide",
"name": "沈七",
"hostile": false
}]
},
"currentEncounter": {
"kind": "npc",
"id": "npc-guide",
"npcName": "沈七"
},
"storyEngineMemory": {
"activeThreadIds": ["thread-bridge"]
}
});
let mut next_state = previous_state.clone();
next_state["inBattle"] = Value::Bool(true);
next_state["currentEncounter"] = Value::Null;
project_story_engine_after_action(
&previous_state,
&mut next_state,
"与沈七战斗",
"沈七已经进入战斗节奏。",
"npc_fight",
Some("ongoing"),
);
assert!(
next_state["quests"]
.as_array()
.is_some_and(|items| items.is_empty())
);
assert_eq!(next_state["chapterState"]["chapterQuestId"], Value::Null);
}
}