update celestial phenon

This commit is contained in:
bridge
2025-11-13 12:15:08 +08:00
parent ec8e4db96f
commit 62fa84a809
9 changed files with 289 additions and 11 deletions

View File

@@ -88,6 +88,13 @@ def load_game(save_path: Optional[Path] = None) -> Tuple["World", "Simulator", L
# 重建World对象
world = World(map=game_map, month_stamp=month_stamp)
# 重建天地灵机
from src.classes.celestial_phenomenon import celestial_phenomena_by_id
phenomenon_id = world_data.get("current_phenomenon_id")
if phenomenon_id is not None and phenomenon_id in celestial_phenomena_by_id:
world.current_phenomenon = celestial_phenomena_by_id[phenomenon_id]
world.phenomenon_start_year = world_data.get("phenomenon_start_year", 0)
# 获取本局启用的宗门
existed_sect_ids = world_data.get("existed_sect_ids", [])
existed_sects = [sects_by_id[sid] for sid in existed_sect_ids if sid in sects_by_id]

View File

@@ -82,7 +82,10 @@ def save_game(
# 构建世界数据
world_data = {
"month_stamp": int(world.month_stamp),
"existed_sect_ids": [sect.id for sect in existed_sects]
"existed_sect_ids": [sect.id for sect in existed_sects],
# 天地灵机
"current_phenomenon_id": world.current_phenomenon.id if world.current_phenomenon else None,
"phenomenon_start_year": world.phenomenon_start_year if hasattr(world, 'phenomenon_start_year') else 0,
}
# 保存所有Avatar第一阶段不含relations

View File

@@ -12,6 +12,7 @@ from src.classes.name import get_random_name
from src.utils.config import CONFIG
from src.run.log import get_logger
from src.classes.fortune import try_trigger_fortune
from src.classes.celestial_phenomenon import get_random_celestial_phenomenon
class Simulator:
def __init__(self, world: World):
@@ -120,6 +121,61 @@ class Simulator:
fortune_events = await try_trigger_fortune(avatar)
events.extend(fortune_events)
return events
def _phase_update_celestial_phenomenon(self):
"""
更新天地灵机:
- 检查当前天象是否到期
- 如果到期,则随机选择新天象
- 生成世界事件记录天象变化
天象变化时机:
- 从游戏第二年101年开始
- 每5年或当前天象指定的持续时间变化一次
"""
events = []
current_year = self.world.month_stamp.get_year()
current_month = self.world.month_stamp.get_month()
# 第一年100年不触发天象
if current_year < 101:
return events
# 初次运行在101年1月设置初始天象
if self.world.current_phenomenon is None and current_month == Month.JANUARY:
new_phenomenon = get_random_celestial_phenomenon()
if new_phenomenon:
self.world.current_phenomenon = new_phenomenon
self.world.phenomenon_start_year = current_year
# 生成世界事件(不绑定任何角色)
event = Event(
self.world.month_stamp,
f"天降异象!{new_phenomenon.name}{new_phenomenon.desc}",
related_avatars=None # 世界事件,不绑定角色
)
events.append(event)
elif self.world.current_phenomenon is not None:
# 检查是否到期(每年一月检查)
if current_month == Month.JANUARY:
elapsed_years = current_year - self.world.phenomenon_start_year
if elapsed_years >= self.world.current_phenomenon.duration_years:
# 天象到期,更换新天象
old_phenomenon = self.world.current_phenomenon
new_phenomenon = get_random_celestial_phenomenon()
if new_phenomenon:
self.world.current_phenomenon = new_phenomenon
self.world.phenomenon_start_year = current_year
# 生成天象变化事件
event = Event(
self.world.month_stamp,
f"{old_phenomenon.name}消散,天地异象再现!{new_phenomenon.name}{new_phenomenon.desc}",
related_avatars=None # 世界事件
)
events.append(event)
return events
def _phase_log_events(self, events):
"""
@@ -158,14 +214,17 @@ class Simulator:
# 6. 被动结算(时间效果+奇遇)
events.extend(await self._phase_passive_effects())
# 7. 日志
# 7. 更新天地灵机
events.extend(self._phase_update_celestial_phenomenon())
# 8. 日志
# 统一写入事件管理器
if hasattr(self.world, "event_manager") and self.world.event_manager is not None:
for e in events:
self.world.event_manager.add_event(e)
self._phase_log_events(events)
# 8. 时间推进
# 9. 时间推进
self.world.month_stamp = self.world.month_stamp + 1