fix pytest for new awaken avatars
This commit is contained in:
@@ -190,7 +190,8 @@ def load_game(save_path: Optional[Path] = None) -> Tuple["World", "Simulator", L
|
||||
# 重建Simulator
|
||||
simulator_data = save_data.get("simulator", {})
|
||||
simulator = Simulator(world)
|
||||
simulator.birth_rate = simulator_data.get("birth_rate", CONFIG.game.npc_birth_rate_per_month)
|
||||
# 兼容旧存档 "birth_rate"
|
||||
simulator.awakening_rate = simulator_data.get("awakening_rate", simulator_data.get("birth_rate", CONFIG.game.npc_awakening_rate_per_month))
|
||||
|
||||
print(f"存档加载成功!共加载 {len(all_avatars)} 个角色")
|
||||
return world, simulator, existed_sects
|
||||
|
||||
@@ -120,7 +120,7 @@ def load_game(save_path: Optional[Path] = None) -> Tuple[World, Simulator, List[
|
||||
# 重建Simulator
|
||||
simulator_data = save_data.get("simulator", {})
|
||||
simulator = Simulator(world)
|
||||
simulator.birth_rate = simulator_data.get("birth_rate", CONFIG.game.npc_birth_rate_per_month)
|
||||
simulator.awakening_rate = simulator_data.get("awakening_rate", simulator_data.get("birth_rate", CONFIG.game.npc_awakening_rate_per_month))
|
||||
|
||||
print(f"存档加载成功!共加载 {len(all_avatars)} 个角色")
|
||||
return world, simulator, existed_sects
|
||||
|
||||
@@ -139,7 +139,7 @@ def save_game(
|
||||
|
||||
# 保存模拟器数据
|
||||
simulator_data = {
|
||||
"birth_rate": simulator.birth_rate
|
||||
"awakening_rate": simulator.awakening_rate
|
||||
}
|
||||
|
||||
# 组装完整的存档数据
|
||||
|
||||
@@ -67,7 +67,7 @@ def save_game(
|
||||
|
||||
# 保存模拟器数据
|
||||
simulator_data = {
|
||||
"birth_rate": simulator.birth_rate
|
||||
"awakening_rate": simulator.awakening_rate
|
||||
}
|
||||
|
||||
# 组装完整的存档数据(不含 events,事件在 SQLite 中)
|
||||
|
||||
@@ -22,7 +22,7 @@ from src.classes.death_reason import DeathReason
|
||||
class Simulator:
|
||||
def __init__(self, world: World):
|
||||
self.world = world
|
||||
self.birth_rate = CONFIG.game.npc_birth_rate_per_month # 从配置文件读取NPC每月出生率
|
||||
self.awakening_rate = CONFIG.game.npc_awakening_rate_per_month # 从配置文件读取NPC每月觉醒率(凡人晋升修士)
|
||||
|
||||
def _phase_update_perception_and_knowledge(self):
|
||||
"""
|
||||
@@ -199,7 +199,7 @@ class Simulator:
|
||||
events = []
|
||||
for avatar in self.world.avatar_manager.get_living_avatars():
|
||||
avatar.update_age(self.world.month_stamp)
|
||||
if random.random() < self.birth_rate:
|
||||
if random.random() < self.awakening_rate:
|
||||
age = random.randint(16, 60)
|
||||
gender = random.choice(list(Gender))
|
||||
name = get_random_name(gender)
|
||||
|
||||
@@ -23,7 +23,7 @@ ai:
|
||||
game:
|
||||
init_npc_num: 9
|
||||
sect_num: 3 # init_npc_num大于sect_num时,会随机选择sect_num个宗门
|
||||
npc_birth_rate_per_month: 0
|
||||
npc_awakening_rate_per_month: 0.01
|
||||
fortune_probability: 0.005
|
||||
misfortune_probability: 0.005
|
||||
|
||||
|
||||
@@ -63,7 +63,7 @@ async def test_simulator_birth_logic(base_world):
|
||||
)
|
||||
|
||||
sim = Simulator(base_world)
|
||||
sim.birth_rate = 1.0 # 必生
|
||||
sim.awakening_rate = 1.0 # 必生
|
||||
|
||||
# Patch 掉 create_random_mortal,避免依赖复杂的宗门/地图数据
|
||||
with patch('src.sim.simulator.create_random_mortal', return_value=mock_avatar):
|
||||
@@ -74,7 +74,7 @@ def test_save_load_cycle(temp_save_dir):
|
||||
sim = Simulator(world)
|
||||
# Modify a config value on the instance to check if it persists
|
||||
test_birth_rate = 0.99
|
||||
sim.birth_rate = test_birth_rate
|
||||
sim.awakening_rate = test_birth_rate
|
||||
|
||||
# 4. Prepare Existed Sects (Empty for this basic test)
|
||||
existed_sects = []
|
||||
@@ -119,7 +119,7 @@ def test_save_load_cycle(temp_save_dir):
|
||||
assert loaded_avatar.hp.cur == 80
|
||||
|
||||
# Verify Simulator
|
||||
assert loaded_sim.birth_rate == test_birth_rate
|
||||
assert loaded_sim.awakening_rate == test_birth_rate
|
||||
|
||||
# Verify World/Simulator linkage
|
||||
assert loaded_sim.world == loaded_world
|
||||
|
||||
Reference in New Issue
Block a user