new RPG system

This commit is contained in:
2026-06-05 14:57:15 +03:00
parent 6189a5fb74
commit 01b16dbeaa
29 changed files with 2395 additions and 311 deletions
+21 -3
View File
@@ -7,7 +7,6 @@ from services.memory import (
get_last_assistant_message_id,
update_session_plot_arc,
update_message_choices,
seed_quests_from_arc,
get_quests,
)
from services.rpg_state import apply_narrator_post
@@ -64,7 +63,10 @@ async def ensure_plot_arc_and_quests(
if arc:
return arc
from services.rpg_locale import infer_rp_language
facts_block = facts_to_prompt(session.get("facts_json", "[]"))
lang = infer_rp_language([{"role": "assistant", "content": greeting}])
arc = await generate_plot_arc(
persona.get("name", "Character"),
persona.get("description", ""),
@@ -72,13 +74,17 @@ async def ensure_plot_arc_and_quests(
greeting,
facts_block=facts_block,
genre=genre,
lang=lang,
recent_context=f"assistant: {greeting}",
)
if not arc:
return {}
await update_session_plot_arc(session_id, json.dumps(arc, ensure_ascii=False))
if seed_quests:
await seed_quests_from_arc(session_id, arc)
from services.rpg_story import sync_quest_to_current_step
await sync_quest_to_current_step(session_id, arc)
return arc
@@ -122,6 +128,9 @@ async def process_opening(session_id: str, persona_id: str, *, rpg: bool) -> dic
quests_pre = await get_quests(session_id)
narr_ctx = format_narrator_context(arc, quests_pre, session.get("status_quo") or "")
from services.rpg_locale import infer_rp_language
o_lang = infer_rp_language([{"role": "assistant", "content": first_mes_text}])
post = await narrator_post(
persona.get("name", persona_id),
ctx_txt,
@@ -129,12 +138,17 @@ async def process_opening(session_id: str, persona_id: str, *, rpg: bool) -> dic
facts_block,
is_opening=True,
extra_context=narr_ctx,
lang=o_lang,
)
if rpg_settings.get("choices", True):
choices = choices_from_narrator(post.get("choices") or [])
await apply_narrator_post(session_id, post, rpg_settings, session)
from services.rpg_state import apply_narrator_post_with_story
await apply_narrator_post_with_story(
session_id, post, rpg_settings, session, arc=arc
)
session = await get_session(session_id) or session
status_quo = session.get("status_quo") or status_quo
outfit_json = session.get("outfit_json") or outfit_json
@@ -150,6 +164,10 @@ async def process_opening(session_id: str, persona_id: str, *, rpg: bool) -> dic
sd_out = await run_sd_for_message(bundle, msg_id) if bundle else {}
updated = await get_session(session_id)
if rpg and msg_id:
from services.memory import save_state_snapshot
await save_state_snapshot(session_id, msg_id)
affinity = updated.get("affinity", 0) if updated else 0
if msg_id and choices: