- Python FastAPI 引擎:世界状态模拟、全局能量条、世界事件系统 - Node.js WebSocket 服务器:实时通信、事件队列批处理 - 前端仪表盘:世界状态可视化、行动日志、事件展示 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
109 lines
3.1 KiB
Python
109 lines
3.1 KiB
Python
"""世界级事件池"""
|
|
from typing import Callable, List, Dict, Any, Optional
|
|
from .models import WorldState, Weather, GlobalEventInfo, WorldEffect
|
|
|
|
|
|
class GlobalEvent:
|
|
"""世界级事件定义"""
|
|
def __init__(
|
|
self,
|
|
name: str,
|
|
description: str,
|
|
apply_effect: Callable[[WorldState], None],
|
|
effect_type: str,
|
|
effect_duration: int = 5,
|
|
mood_modifier: int = 0
|
|
):
|
|
self.name = name
|
|
self.description = description
|
|
self.apply_effect = apply_effect
|
|
self.effect_type = effect_type
|
|
self.effect_duration = effect_duration
|
|
self.mood_modifier = mood_modifier
|
|
|
|
def to_info(self) -> GlobalEventInfo:
|
|
return GlobalEventInfo(name=self.name, description=self.description)
|
|
|
|
def create_world_effect(self) -> WorldEffect:
|
|
return WorldEffect(
|
|
type=self.effect_type,
|
|
name=self.name,
|
|
intensity=abs(self.mood_modifier),
|
|
remaining_ticks=self.effect_duration,
|
|
mood_modifier=self.mood_modifier
|
|
)
|
|
|
|
|
|
# 事件效果函数
|
|
def effect_festival(state: WorldState) -> None:
|
|
"""节日效果:天气变晴,情绪+5"""
|
|
state.weather = Weather.SUNNY
|
|
state.town_mood = min(10, state.town_mood + 5)
|
|
|
|
|
|
def effect_storm(state: WorldState) -> None:
|
|
"""暴风雨效果:天气变雨,情绪-3"""
|
|
state.weather = Weather.RAINY
|
|
state.town_mood = max(-10, state.town_mood - 3)
|
|
|
|
|
|
def effect_scandal(state: WorldState) -> None:
|
|
"""丑闻效果:情绪-5"""
|
|
state.town_mood = max(-10, state.town_mood - 5)
|
|
|
|
|
|
def effect_miracle(state: WorldState) -> None:
|
|
"""奇迹效果:天气变晴,情绪+3"""
|
|
state.weather = Weather.SUNNY
|
|
state.town_mood = min(10, state.town_mood + 3)
|
|
|
|
|
|
def effect_fire(state: WorldState) -> None:
|
|
"""火灾效果:情绪-4"""
|
|
state.town_mood = max(-10, state.town_mood - 4)
|
|
|
|
|
|
# 世界级事件池
|
|
GLOBAL_EVENT_POOL: List[GlobalEvent] = [
|
|
GlobalEvent(
|
|
name="小镇节日",
|
|
description="居民们欢聚一堂,举办盛大庆典!",
|
|
apply_effect=effect_festival,
|
|
effect_type="festival",
|
|
effect_duration=5,
|
|
mood_modifier=2,
|
|
),
|
|
GlobalEvent(
|
|
name="暴风雨来袭",
|
|
description="乌云密布,暴风雨席卷小镇。",
|
|
apply_effect=effect_storm,
|
|
effect_type="storm",
|
|
effect_duration=4,
|
|
mood_modifier=-1,
|
|
),
|
|
GlobalEvent(
|
|
name="惊天丑闻",
|
|
description="镇长的秘密被曝光,全镇哗然。",
|
|
apply_effect=effect_scandal,
|
|
effect_type="scandal",
|
|
effect_duration=6,
|
|
mood_modifier=-2,
|
|
),
|
|
GlobalEvent(
|
|
name="彩虹奇迹",
|
|
description="雨后天空出现绚丽彩虹。",
|
|
apply_effect=effect_miracle,
|
|
effect_type="miracle",
|
|
effect_duration=3,
|
|
mood_modifier=1,
|
|
),
|
|
GlobalEvent(
|
|
name="火灾警报",
|
|
description="镇中心发生火情,消防队紧急出动。",
|
|
apply_effect=effect_fire,
|
|
effect_type="fire",
|
|
effect_duration=4,
|
|
mood_modifier=-2,
|
|
),
|
|
]
|