tests / test_node_events_trigger.py
# -*- coding: utf-8 -*-
"""模拟跑 Day 8-15 剧情,验证节点专属事件触发"""
import os
import sys
sys.path.insert(0, 'D:/1979')
from demo import DemoGame, DALIAN_SHENYANG_ROUTE
from src.node_events import NODE_EVENTS
os.environ['DEEPSEEK_API_KEY'] = 'test'
def simulate_route():
game = DemoGame()
game.day = 8
game.current_node_index = 0
game._triggered_node_events = set() # 手动标记已触发
while game.current_node_index < len(DALIAN_SHENYANG_ROUTE) - 1:
current_node = DALIAN_SHENYANG_ROUTE[game.current_node_index]
next_node = DALIAN_SHENYANG_ROUTE[game.current_node_index + 1]
distance = next_node.distance - current_node.distance
print(f"\n{'=' * 56}")
print(f"第 {game.day} 天 · 当前: {current_node.name}")
print(f"下一站: {next_node.name} (距离 {distance}km)")
print(f"{'=' * 56}")
# 检查节点专属事件
game._trigger_node_event(current_node)
# 自动推进(模拟走 n)
fuel_cost = distance * 0.5
if game.vehicle.fuel < fuel_cost:
print(f"\n⚠ 柴油不足,跳过推进")
break
mods = game.world.advance_modifiers()
if not mods["can_advance"]:
print(f"⚠ {game.world.weather}禁行,跳过")
game.day += 1
continue
game.vehicle.fuel -= fuel_cost
game.world.advance_km(distance)
game.world.advance_time(3)
game.day += 1
game.current_node_index += 1
print(f"\n→ 抵达 {next_node.name}")
if game.reached_shenyang:
print("\n" + "=" * 56)
print("抵达沈阳,走剧情")
print("=" * 56)
# 触发沈阳专属事件
game._trigger_node_event(next_node)
break
input("\n按回车继续下一步...")
if __name__ == '__main__':
simulate_route()