Integrate unfinished server-rs refactor worklists

This commit is contained in:
2026-04-30 13:39:06 +08:00
parent 62934b0809
commit 7ab0933f6d
676 changed files with 24487 additions and 21531 deletions

View File

@@ -1,3 +1,12 @@
use crate::*;
use module_combat::resolve_combat_action as resolve_battle_state_action;
use module_inventory::apply_inventory_mutation as apply_inventory_slot_mutation;
use module_npc::resolve_npc_interaction as resolve_npc_interaction_domain;
use module_quest::{
acknowledge_quest_completion as acknowledge_quest_record_completion,
apply_quest_signal as apply_quest_record_signal,
};
#[spacetimedb::table(accessor = player_progression)]
pub struct PlayerProgression {
#[primary_key]
@@ -874,6 +883,79 @@ pub fn get_story_session_state(
}
}
fn continue_story_tx(
ctx: &ReducerContext,
input: StoryContinueInput,
) -> Result<(StorySessionSnapshot, StoryEventSnapshot), String> {
validate_story_continue_input(&input).map_err(|error| error.to_string())?;
let current = ctx
.db
.story_session()
.story_session_id()
.find(&input.story_session_id)
.ok_or_else(|| "story_session 不存在,无法继续推进".to_string())?;
let current_snapshot = build_story_session_snapshot_from_row(&current);
let (next_snapshot, event_snapshot) =
apply_story_continue(current_snapshot, input).map_err(|error| error.to_string())?;
ctx.db
.story_session()
.story_session_id()
.delete(&current.story_session_id);
ctx.db.story_session().insert(StorySession {
story_session_id: next_snapshot.story_session_id.clone(),
runtime_session_id: next_snapshot.runtime_session_id.clone(),
actor_user_id: next_snapshot.actor_user_id.clone(),
world_profile_id: next_snapshot.world_profile_id.clone(),
initial_prompt: next_snapshot.initial_prompt.clone(),
opening_summary: next_snapshot.opening_summary.clone(),
latest_narrative_text: next_snapshot.latest_narrative_text.clone(),
latest_choice_function_id: next_snapshot.latest_choice_function_id.clone(),
status: next_snapshot.status,
version: next_snapshot.version,
created_at: Timestamp::from_micros_since_unix_epoch(next_snapshot.created_at_micros),
updated_at: Timestamp::from_micros_since_unix_epoch(next_snapshot.updated_at_micros),
});
ctx.db.story_event().insert(StoryEvent {
event_id: event_snapshot.event_id.clone(),
story_session_id: event_snapshot.story_session_id.clone(),
event_kind: event_snapshot.event_kind,
narrative_text: event_snapshot.narrative_text.clone(),
choice_function_id: event_snapshot.choice_function_id.clone(),
created_at: Timestamp::from_micros_since_unix_epoch(event_snapshot.created_at_micros),
});
Ok((next_snapshot, event_snapshot))
}
fn get_story_session_state_tx(
ctx: &ReducerContext,
input: StorySessionStateInput,
) -> Result<(StorySessionSnapshot, Vec<StoryEventSnapshot>), String> {
validate_story_session_state_input(&input).map_err(|error| error.to_string())?;
let session = ctx
.db
.story_session()
.story_session_id()
.find(&input.story_session_id)
.ok_or_else(|| "story_session 不存在".to_string())?;
let session_snapshot = build_story_session_snapshot_from_row(&session);
let mut events = ctx
.db
.story_event()
.iter()
.filter(|row| row.story_session_id == input.story_session_id)
.map(|row| build_story_event_snapshot_from_row(&row))
.collect::<Vec<_>>();
events.sort_by_key(|event| (event.created_at_micros, event.event_id.clone()));
Ok((session_snapshot, events))
}
// 当前阶段先把 quest_record / quest_log 立成最小任务真相源,后续再把奖励结算和 story action 总分发接进来。
#[spacetimedb::reducer]