src / lingmuxue.py
# -*- coding: utf-8 -*-
"""Lingmuxue - 1979 凌暮雪(哈尔滨机械中专下乡知青,反动学术权威后代)
设定:哈尔滨机械中专下乡知青,反动学术权威后代,黑五类子女。
学机械出身,能拆发动机像拆手表。负责车辆维修/无线电解密/发电机组。
对话接口当前是规则占位(character_chat 那套 LLM + 记忆库 后接)。
"""
import random
class Lingmuxue:
"""1979 凌暮雪状态封装(七维生存系统扩展)。
七维状态:
hp: 生命值 0-100
temperature: 体温 °C
hunger: 饥饿 0-100
thirst: 口渴 0-100
radiation: 辐射 mSv 0-1000
fatigue: 疲劳 0-100
morale: 精神 0-100(<10无声离开)
特殊:
trust: 信任度 0-100(关系核心指标)
left_silently: 是否已无声离开(morale<10触发)
memory: list[dict] 互动记录
"""
MAX_HP = 100.0
def __init__(self) -> None:
# 核心生命
self.hp = 82.0
self._max_hp_cap = 100.0
# 七维状态
self.temperature = 36.3 # 女性基础体温略低
self.hunger = 35.0
self.thirst = 25.0
self.radiation = 8.0
self.fatigue = 30.0
self.morale = 48.0
# 关系与状态
self.trust = 38.0
self.intimacy = 0 # 亲密度 0-100(与 trust 不同,代表情感亲密程度)
self.alive = True
self.left_silently = False
self.memory: list[dict] = []
self._dialogue_count = 0
# 幻觉系统
self._hallucination_active = False
self._hallucination_timer = 0
# 战斗系统字段(Combat 类访问)
self.name = "凌暮雪"
self.id = "lingmuxue"
self.ap = 3 # 行动点(每回合重置)
self.state = "normal" # normal/injured/fatigue/hallucination
# 专业等级(出国线结局判定)1-5
self.professional_level = 1
@property
def max_hp(self) -> float:
return self._max_hp_cap
@max_hp.setter
def max_hp(self, value: float) -> None:
self._max_hp_cap = value
@property
def hp_ratio(self) -> float:
return max(0.0, min(1.0, self.hp / self.MAX_HP))
@property
def temperature_state(self) -> str:
"""体温状态机返回字符串描述。"""
t = self.temperature
if t >= 36.5 and t <= 37.5:
return "舒适"
elif t >= 35.0 and t < 36.5:
return "寒冷"
elif t >= 32.0 and t < 35.0:
return "冰冻"
elif t >= 28.0 and t < 32.0:
return "冻伤"
elif t >= 25.0 and t < 28.0:
return "失温"
else:
return "死亡"
def take_damage(self, amount: float) -> None:
self.hp = max(0.0, self.hp - amount)
if self.hp <= 0:
self.alive = False
def heal(self, amount: float) -> float:
healed = min(amount, self._max_hp_cap - self.hp)
self.hp += healed
return healed
def leave_silently(self) -> None:
"""深夜无声离开。游戏继续,但副驾驶空了。"""
self.left_silently = True
self.alive = False
def consume_food(self, amount: float) -> None:
"""消耗食物,减少饥饿。"""
self.hunger = max(0.0, self.hunger - amount)
def consume_water(self, amount: float) -> None:
"""消耗水,减少口渴。"""
self.thirst = max(0.0, self.thirst - amount)
def consume_fuel_liters(self, amount: float) -> None:
"""消耗燃料(占位,实际由vehicle管理)。"""
pass
def is_hallucinating(self) -> bool:
"""检查是否处于幻觉状态。"""
return self._hallucination_active
def tick_effects(self, world=None, vehicle=None, lingmuxue=None) -> list:
"""每小时tick的效果结算。返回事件列表。"""
events = []
# 1. 体温连锁
if self.temperature < 35.0:
self.fatigue = min(100.0, self.fatigue + 2.0)
events.append("凌暮雪体温过低,疲劳加速")
if self.temperature < 32.0 and self.temperature >= 28.0:
self.hp = max(0.0, self.hp - 2.0)
events.append("凌暮雪冻伤:HP-2/h")
if random.random() < 0.3:
old_cap = self._max_hp_cap
self._max_hp_cap = max(50.0, self._max_hp_cap - 5.0)
events.append(f"凌暮雪冻伤永久失去HP上限:{old_cap:.0f}→{self._max_hp_cap:.0f}")
if self.temperature < 28.0 and self.temperature >= 25.0:
self.hp = max(0.0, self.hp - 5.0)
events.append("凌暮雪失温:HP-5/h")
if random.random() < 0.4:
self._hallucination_active = True
self._hallucination_timer = 3
events.append("凌暮雪失温引发幻觉")
if self.temperature < 35.0 and self.temperature >= 32.0:
self.hp = max(0.0, self.hp - 0.5)
self.fatigue = min(100.0, self.fatigue * 1.4)
self.morale = max(0.0, self.morale - 1.0)
events.append("凌暮雪冰冻:HP-0.5/h,疲劳+40%,精神-1/h")
# 2. 饥饿连锁
if self.hunger > 80:
self.morale = max(0.0, self.morale - 3.0)
events.append("凌暮雪极度饥饿:精神-3/h")
# 3. 口渴连锁
if self.thirst > 80:
self.hp = max(0.0, self.hp - 2.0)
events.append("凌暮雪极度口渴:HP-2/h")
# 4. 辐射连锁
if self.radiation > 600:
self.hp = max(0.0, self.hp - 3.0)
self.morale = max(0.0, self.morale - 3.0)
events.append("凌暮雪急性辐射病:HP-3/h,精神-3/h")
elif self.radiation > 300:
self.hp = max(0.0, self.hp - 1.0)
self.morale = max(0.0, self.morale - 3.0)
events.append("凌暮雪辐射中毒:HP-1/h,精神-3/h")
# 5. 疲劳连锁
if self.fatigue > 80:
self.morale = max(0.0, self.morale - 5.0)
events.append("凌暮雪极度疲劳:精神-5/h")
# 6. 精神低落幻觉
if self.morale < 20 and not self._hallucination_active:
if random.random() < 0.1:
self._hallucination_active = True
self._hallucination_timer = 2
events.append("凌暮雪精神崩溃引发幻觉")
# 7. 幻觉计时器递减
if self._hallucination_active:
self._hallucination_timer -= 1
if self._hallucination_timer <= 0:
self._hallucination_active = False
events.append("凌暮雪幻觉消退")
# 8. 体温自然恢复
if self.temperature < 36.5:
self.temperature += 0.05
elif self.temperature > 37.5:
self.temperature -= 0.1
# 9. 精神<10:无声离开判定
if self.morale < 10 and not self.left_silently:
self.leave_silently()
events.append("凌暮雪精神崩溃,无声离开了")
return events
# ---------- 对话(占位接口) ----------
def talk(self, player_input: str, bridge=None, context: dict = None) -> str:
"""玩家主动跟凌暮雪说话,返回她的回应。
优先使用 bridge(character_chat 对话桥接层)动态生成对话,
失败时降级到规则占位文本。
Args:
player_input: 玩家说的话。
bridge: DialogueBridge 实例(可选)。
context: 游戏上下文(可选)。
"""
if self.left_silently:
return "(副驾驶是空的。她的半瓶水还在你这边。)"
self._dialogue_count += 1
text = (player_input or "").strip()
# 幻觉状态下,她说一些她不会说的话
if self._hallucination_active:
return self._hallucination_talk(text)
# 优先使用 bridge 动态生成
if bridge is not None:
try:
reply = bridge.talk(text, context=context)
if reply:
return reply
except Exception:
pass
# 降级到占位规则:关键词触发 + 轮次兜底
if not text:
return self._placeholder_silence()
lowered = text.lower()
if any(k in text for k in ("想你", "喜欢你", "爱你")):
return self._placeholder_affection()
if any(k in text for k in ("你怎么样", "还好吗", "没事吧")):
return "……嗯。就是手有点冷。"
if any(k in text for k in ("车", "修", "发动机", "零件")):
return self._placeholder_mechanical()
if any(k in text for k in ("哈尔滨", "海参崴", "去哪", "走哪")):
return "……先到哈尔滨再说。后面的事,到了再说。"
if "饿" in text:
return "……我那半块饼,你吃。我不饿。"
if "冷" in text:
return "……靠过来一点。"
# 兜底:按轮次循环占位
return self._placeholder_round()
def _hallucination_talk(self, text: str) -> str:
"""幻觉状态下的对话变体——她说一些她不会说的话。"""
pool = [
"其实我一直想去看看大海……但我不敢说。",
"你知道吗?我爸爸不是坏人。他只是……生错了年代。",
"如果我死了,你会记得我吗?",
"我恨这个世界,也恨我自己。",
"我们逃走吧,去一个没有人的地方。",
"你有没有想过,这一切都是一场梦?",
"我不信任你。从来都没有。",
"我要走了。再见。",
]
return random.choice(pool)
# ---------- 占位台词池(临时) ----------
def _placeholder_silence(self) -> str:
lines = [
"……你没说话。她也没说话。",
"她盯着窗外的白桦林,没回头。",
"驾驶室里只有发动机的声音。",
]
return random.choice(lines)
def _placeholder_affection(self) -> str:
return "……你别突然说这个。"
def _placeholder_mechanical(self) -> str:
lines = [
"……发动机是冻着了,不是坏。等我敲两下。",
"活塞销磨损得厉害,先凑合开,到了再换。",
"……曲轴间隙大了一点,我听着声音就知道。",
]
return random.choice(lines)
def _placeholder_round(self) -> str:
pool = [
"……嗯。",
"她没立刻接话。",
"……你想说什么?",
"她把头发别到耳后,没看你。",
"……车还要开多久?",
"她转头看你一眼,又看回前路。",
]
return pool[self._dialogue_count % len(pool)]
# ---------- 主动搭话(公路段触发) ----------
def road_chatter(self, world, vehicle, player, bridge=None) -> str:
"""公路段随机搭话。基于当前状态加权挑(占位)。
Args:
world: World 实例。
vehicle: Vehicle 实例。
player: Player 实例。
bridge: DialogueBridge 实例(可选)。
"""
if self.left_silently:
return "(副驾驶空着。车外的风声很响。)"
# 幻觉状态下的搭话
if self._hallucination_active:
return self._hallucination_road_chatter()
# 根据状态挑话题
if vehicle.fuel < 30:
chatter_input = "油表指针往下了"
elif self.hp < 40:
chatter_input = "我有点撑不住了"
elif world.time_phase == "深夜":
chatter_input = "夜了,困不困"
elif player.hp < 50:
chatter_input = "你脸色不好"
elif self.temperature < 35.0:
chatter_input = "好冷"
elif self.hunger > 70:
chatter_input = "好饿"
elif self.morale < 30:
chatter_input = "我们会死在这里吗"
else:
chatter_input = None
# 如果有 bridge 且有话题,尝试动态生成
if bridge is not None and chatter_input:
try:
context = {
'day': getattr(world, 'day', 1),
'trust': self.trust,
'weather': getattr(world, 'weather', '未知'),
}
reply = bridge.talk(chatter_input, context=context)
if reply:
return reply
except Exception:
pass
# 降级到硬编码池
if vehicle.fuel < 30:
return "……油表指针往下了。你看到了吗?"
if self.hp < 40:
return "……我有点撑不住了。不过没事,能到。"
if world.time_phase == "深夜":
return "……夜了。你困不困?换我开一会儿?"
if player.hp < 50:
return "……你脸色不好。要不歇一下?"
if self.temperature < 35.0:
return "……我好冷。你能不能……抱我一下?"
if self.hunger > 70:
return "……肚子好饿。还有吃的吗?"
if self.morale < 30:
return "……你说,我们会死在这里吗?"
pool = [
"……你说,哈尔滨还在吗?",
"她卷着发梢,看着窗外。",
"……昨天那个苏军驾驶员,俄语口音怪怪的。",
"你这杆56半,退弹壳的时候会卡吗?",
"……我爸要是活着,看到我们现在这样,会说什么呢。",
]
return random.choice(pool)
def _hallucination_road_chatter(self) -> str:
"""幻觉状态下的公路搭话。"""
pool = [
"你看,前面有个人在向我们招手……等等,那里没有人?",
"我听到有人在叫我的名字。是你吗?",
"这辆车……好像不是我开的那辆。",
"天怎么变成红色了?",
"你不要丢下我一个人……",
]
return random.choice(pool)
# ---------- 显示 ----------
def status_line(self) -> str:
if self.left_silently:
return "凌暮雪:副驾驶空了。她的半瓶水还在你这边。"
hp_bar = "█" * int(self.hp_ratio * 8) + "░" * (8 - int(self.hp_ratio * 8))
temp_state = self.temperature_state
hallucination_mark = " [幻觉]" if self._hallucination_active else ""
return (
f"凌暮雪(哈尔滨机械中专下乡知青·反动学术权威后代){hallucination_mark}\n"
f" HP [{hp_bar}] {self.hp:5.1f}/{self.MAX_HP:.0f}\n"
f" 体温 {self.temperature:5.1f}°C [{temp_state}]\n"
f" 饥饿 {self.hunger:5.1f} 口渴 {self.thirst:5.1f}\n"
f" 辐射 {self.radiation:.1f} mSv\n"
f" 疲劳 {self.fatigue:5.1f} 精神 {self.morale:5.1f} 信任 {self.trust:5.1f}"
)
def __repr__(self) -> str:
if self.left_silently:
return "<Lingmuxue 已无声离开>"
return f"<Lingmuxue hp={self.hp:.1f} trust={self.trust:.1f} temp={self.temperature:.1f}>"