> cat /wizhelp/wizcoding5
========================================================================
MUD Coding Tutorial - Part 5
========================================================================
Advanced features: plugins, complex puzzles, area design.
COMPLETE PLUGIN:
```python
# /lib/plugins/dice_game.py
import random
def handle_roll(player, params):
"""roll [dice] - Roll dice (d6, d20, etc)"""
if not params:
dice = 6
else:
try:
dice = int(params.replace('d', ''))
except:
player.message("Usage: roll [d6/d20/etc]")
return
result = random.randint(1, dice)
player.message(f"You roll a d{dice}: {result}!")
# Show to room
room = player.game_state.rooms.get(player._location)
for uuid, entity in room.inventory.get_items():
if hasattr(entity, 'is_player') and entity != player:
entity.message(f"{player.name} rolls a d{dice}: {result}!")
def setup_plugin(game_state):
return {
'name': 'Dice Rolling',
'version': '1.0',
'author': 'YourName',
'description': 'Roll various dice',
'commands': {'roll': handle_roll}
}
```
AREA WITH PUZZLE:
```python
# Multiple connected rooms with color puzzle
# See color_puzzle_plugin.py for full example
ROOMS = {
'entry': {
'desc': 'Four colored doors lead away.',
'exits': ['red', 'blue', 'green', 'yellow']
},
'red_room': {
'desc': 'A red switch glows on the wall.',
'switch_color': 'red'
},
# ... more rooms
}
def create_puzzle_area():
rooms = []
for name, data in ROOMS.items():
room = Room(name=f"puzzle_{name}",
description=data['desc'])
if 'switch_color' in data:
# Add switch logic
add_switch(room, data['switch_color'])
rooms.append(room)
return rooms
```
DYNAMIC ROOMS:
```python
class WeatherRoom(Room):
"""Room that changes with time"""
def get_description(self):
hour = datetime.now().hour
if 6 <= hour < 12:
return "Morning sun illuminates the garden."
elif 12 <= hour < 18:
return "Afternoon shadows stretch across."
elif 18 <= hour < 22:
return "Twilight paints everything purple."
else:
return "Darkness shrouds the garden."
```
ROOM CONNECTIONS:
```python
def connect_area():
"""Connect multiple rooms"""
rooms = {
'hall': Room(name="hall"),
'library': Room(name="library"),
'vault': Room(name="vault")
}
# Bidirectional connections
connect_rooms(rooms['hall'], 'north',
rooms['library'], 'south')
connect_rooms(rooms['library'], 'east',
rooms['vault'], 'west')
return list(rooms.values())
def connect_rooms(room1, dir1, room2, dir2):
room1.exits.append(Exit(dir1, room2.name))
room2.exits.append(Exit(dir2, room1.name))
```
Continue with help wizcoding6
========================================================================
>
_