世界事件

World Event System

概述

世界事件系统管理游戏中的动态新闻和市场事件,包括新闻广播、价格触发器和 UI 调整。

1. 新闻广播(News Broadcasting)

通过 NewsManager 实现全局新闻系统:

  • 新闻来源:市场事件、冒险结果、世界状态变化
  • 显示方式:滚动字幕或弹窗通知
  • 持久化:最近 N 条新闻保存在内存中
# 发送新闻
news_manager.broadcast_news({
    "type": "market_event",
    "title": "铁矿石价格飙升!",
    "content": "受战争影响,铁矿石价格上涨30%",
    "importance": "high"
})

2. 市场事件(Market Events)

铁矿石价格触发器示例

当铁矿石价格达到特定阈值时触发事件:

价格阈值 触发事件 效果
> 150% 矿工罢工 供应减少,价格继续上涨
> 200% 政府干预 价格稳定,禁止投机
< 50% 矿场关闭 供应减少,价格反弹
< 30% 行业崩溃 商品暂时退市
# 价格触发器检查
func _on_price_updated(commodity_id, new_price, base_price):
    var ratio = new_price / base_price
    
    if ratio > 2.0:
        trigger_event("government_intervention", commodity_id)
    elif ratio > 1.5:
        trigger_event("worker_strike", commodity_id)
    elif ratio < 0.3:
        trigger_event("industry_collapse", commodity_id)
    elif ratio < 0.5:
        trigger_event("mine_closure", commodity_id)

3. UI 调整

事件触发时 UI 需要相应更新:

  • 新闻横幅:显示事件通知,支持队列显示
  • 价格图表:在事件发生点添加标记
  • 商品图标:状态异常时添加警告指示器
  • 交易界面:限制交易时显示禁用状态
# UI 更新信号
signal news_received(news_data)
signal market_event_triggered(event_type, commodity_id)
signal trading_restricted(commodity_id, reason)

事件处理流程

游戏时间推进
    │
    ▼
EventManager.check_triggers()
    │
    ├─→ 检查价格阈值
    ├─→ 检查随机事件
    └─→ 检查季节/日期事件
    │
    ▼
触发事件 → 生成新闻 → 更新 UI → 应用效果

配置文件

事件定义在 gdt/data/events/ 目录下:

events/
├── market_events.json    # 市场相关事件
├── world_events.json     # 世界状态事件
├── seasonal_events.json  # 季节性事件
└── random_events.json    # 随机事件