File size: 7,464 Bytes
4c75d73
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
"""

Sample Weather Plugin for MMORPG

Adds weather effects and seasonal changes to the game world

"""

from src.interfaces.plugin_interfaces import IWeatherPlugin, PluginMetadata, PluginType
from typing import Dict, List, Any
import random
import time

class WeatherPlugin(IWeatherPlugin):
    """Plugin that adds dynamic weather system to the game."""
    
    def __init__(self):
        self._metadata = PluginMetadata(
            id="weather_system",
            name="Weather System",
            version="1.0.0",
            author="MMORPG Dev Team",
            description="Adds dynamic weather effects and seasonal changes",
            plugin_type=PluginType.SERVICE,
            dependencies=[],
            config={
                "weather_change_interval": 300,
                "enable_seasons": True,
                "weather_effects_enabled": True
            }
        )
        self._enabled = False
        self._weather_state = {
            "current_weather": "sunny",
            "temperature": 20,
            "season": "spring",
            "last_change": time.time()
        }
        self._weather_types = [
            "sunny", "cloudy", "rainy", "stormy", "foggy", "snowy"
        ]
        
    @property
    def metadata(self) -> PluginMetadata:
        return self._metadata
    
    def initialize(self, context: Dict[str, Any]) -> bool:
        """Initialize the weather plugin."""
        try:
            self._config = self._metadata.config
            self._enabled = True
            print("Weather Plugin initialized successfully")
            self._update_weather()
            return True
        except Exception as e:
            print(f"Failed to initialize Weather Plugin: {e}")
            return False
    
    def shutdown(self) -> bool:
        """Shutdown the weather plugin."""
        try:
            self._enabled = False
            print("Weather Plugin shut down")
            return True
        except Exception as e:
            print(f"Error shutting down Weather Plugin: {e}")
            return False
    
    def get_status(self) -> Dict[str, Any]:
        """Get weather plugin status."""
        return {
            "enabled": self._enabled,
            "current_weather": self._weather_state["current_weather"],
            "temperature": self._weather_state["temperature"],
            "season": self._weather_state["season"],
            "effects_enabled": self._config.get("weather_effects_enabled", True) if hasattr(self, '_config') else True
        }
    
    def get_weather_info(self) -> Dict[str, Any]:
        """Get current weather information."""
        if not self._enabled:
            return {}
            
        return {
            "weather": self._weather_state["current_weather"],
            "temperature": self._weather_state["temperature"],
            "season": self._weather_state["season"],
            "description": self._get_weather_description()
        }
    
    def update_weather(self) -> Dict[str, Any]:
        """Update weather conditions."""
        if not self._enabled:
            return {}
            
        current_time = time.time()
        interval = self._config.get("weather_change_interval", 300)
        
        if current_time - self._weather_state["last_change"] > interval:
            self._update_weather()
            self._weather_state["last_change"] = current_time
            
        return self.get_weather_info()
    
    def apply_weather_effects(self, player_data: Dict[str, Any]) -> Dict[str, Any]:
        """Apply weather effects to player."""
        if not self._enabled or not self._config.get("weather_effects_enabled", True):
            return player_data
            
        effects = player_data.copy()
        weather_modifier = self._get_weather_modifier()
        
        if "stats" not in effects:
            effects["stats"] = {}
        
        effects["stats"]["weather_modifier"] = weather_modifier
        effects["weather_description"] = self._get_weather_description()
        
        return effects
    
    def _update_weather(self):
        """Internal method to update weather conditions."""
        self._weather_state["current_weather"] = random.choice(self._weather_types)
        
        base_temp = self._get_seasonal_base_temperature()
        weather_modifier = self._get_weather_temperature_modifier()
        self._weather_state["temperature"] = base_temp + weather_modifier + random.randint(-5, 5)
        
        if self._config.get("enable_seasons", True):
            seasons = ["spring", "summer", "autumn", "winter"]
            if random.random() < 0.01:
                current_season_idx = seasons.index(self._weather_state["season"])
                self._weather_state["season"] = seasons[(current_season_idx + 1) % len(seasons)]
    
    def _get_seasonal_base_temperature(self) -> int:
        """Get base temperature for current season."""
        season_temps = {
            "spring": 15,
            "summer": 25,
            "autumn": 10,
            "winter": 0
        }
        return season_temps.get(self._weather_state["season"], 15)
    
    def _get_weather_temperature_modifier(self) -> int:
        """Get temperature modifier based on weather."""
        weather_mods = {
            "sunny": 5,
            "cloudy": 0,
            "rainy": -3,
            "stormy": -5,
            "foggy": -2,
            "snowy": -10
        }
        return weather_mods.get(self._weather_state["current_weather"], 0)
    
    def _get_weather_description(self) -> str:
        """Get descriptive text for current weather."""
        weather = self._weather_state["current_weather"]
        temp = self._weather_state["temperature"]
        season = self._weather_state["season"]
        
        descriptions = {
            "sunny": f"Bright and sunny {season} day ({temp} degrees C)",
            "cloudy": f"Overcast {season} sky ({temp} degrees C)",
            "rainy": f"Light rain falling in {season} ({temp} degrees C)",
            "stormy": f"Thunderstorm brewing this {season} ({temp} degrees C)",
            "foggy": f"Thick fog blankets the {season} landscape ({temp} degrees C)",
            "snowy": f"Snow falling gently in {season} ({temp} degrees C)"
        }
        return descriptions.get(weather, f"Unknown weather in {season} ({temp} degrees C)")
    
    def _get_weather_modifier(self) -> Dict[str, float]:
        """Get weather-based stat modifiers."""
        weather = self._weather_state["current_weather"]
        
        modifiers = {
            "sunny": {"movement_speed": 1.1, "visibility": 1.0, "morale": 1.1},
            "cloudy": {"movement_speed": 1.0, "visibility": 0.95, "morale": 0.95},
            "rainy": {"movement_speed": 0.8, "visibility": 0.9, "morale": 0.9},
            "stormy": {"movement_speed": 0.6, "visibility": 0.7, "morale": 0.8},
            "foggy": {"movement_speed": 0.9, "visibility": 0.5, "morale": 0.85},
            "snowy": {"movement_speed": 0.7, "visibility": 0.8, "morale": 0.9}
        }
        
        return modifiers.get(weather, {"movement_speed": 1.0, "visibility": 1.0, "morale": 1.0})

def create_plugin():
    """Factory function to create the plugin instance."""
    return WeatherPlugin()