Files
hunjing/backend/app/models/personality_emotion.py
T
2026-08-21 16:00:13 +08:00

33 lines
1.4 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""灵核情绪状态持久化(设计 §11.4)。"""
from datetime import datetime
from sqlalchemy import DateTime, Float, ForeignKey, String
from sqlalchemy.orm import Mapped, mapped_column
from app.core.time import utc_now
from app.db.base import Base
class CharacterEmotionState(Base):
"""角色当前情绪状态(单行 per character,最新状态 + 触发溯源)。
设计 §11.4:``mood`` / ``intensity`` 由辰正 ``time.*`` 事件驱动动态维护;
``baseline_*`` 同步自人格版本 ``emotion_baseline``,作为衰减回归锚点。
同步写 ``Character.current_mood_id``(激活既有字段,前端列表无需 join)。
"""
__tablename__ = "character_emotion_states"
character_id: Mapped[str] = mapped_column(
String(80), ForeignKey("characters.id"), primary_key=True
)
mood: Mapped[str] = mapped_column(String(40), nullable=False, default="neutral")
intensity: Mapped[float] = mapped_column(Float, nullable=False, default=0.2)
baseline_mood: Mapped[str] = mapped_column(String(40), nullable=False, default="neutral")
baseline_intensity: Mapped[float] = mapped_column(Float, nullable=False, default=0.2)
updated_at: Mapped[datetime] = mapped_column(
DateTime(timezone=True), default=utc_now, onupdate=utc_now
)
last_trigger_event_id: Mapped[str | None] = mapped_column(String(80), nullable=True)