> cat /wizhelp/wizadvanced5

========================================================================
                  Advanced: Room Commands
========================================================================

Adding custom commands and interactions to rooms.

CUSTOM COMMANDS:
```python
def load():
    room = Room(name="altar_room")
    
    def pray_command(player, params):
        """pray [deity] - Pray at the altar"""
        if not params:
            player.message("Pray to whom?")
            return
        
        deity = params.lower()
        if deity == "pkwar":
            player.message("The altar glows! You are blessed!")
            player.current_hp = player.max_hp
            player.current_sp = player.max_sp
        else:
            player.message("The altar remains silent.")
    
    # Add command to room
    room.custom_commands = {
        "pray": pray_command,
        "worship": pray_command  # Alias
    }
    
    return room
```

INTERACTIVE OBJECTS:
```python
def load():
    room = Room(name="fountain_room")
    
    # Track fountain state
    room.fountain_uses = 3
    
    def drink_command(player, params):
        if params != "fountain":
            player.message("Drink from what?")
            return
        
        if room.fountain_uses <= 0:
            player.message("The fountain is dry.")
            return
        
        room.fountain_uses -= 1
        
        # Random effect
        effect = random.choice([
            ("healing", 100),
            ("poison", -50),
            ("strength", 5),
            ("teleport", "random")
        ])
        
        if effect[0] == "healing":
            player.heal(effect[1])
            player.message("The water heals you!")
        elif effect[0] == "poison":
            player.take_damage(abs(effect[1]))
            player.message("The water burns! It's poisoned!")
        elif effect[0] == "strength":
            player.message("You feel stronger!")
            # Apply temporary buff
        elif effect[0] == "teleport":
            player.message("The world spins...")
            player.move("town_square")
    
    room.custom_commands = {"drink": drink_command}
    
    # Update description item
    room.description_items = [
        DescriptionItem(
            name="fountain",
            description=lambda: f"A marble fountain. It has {room.fountain_uses} uses remaining."
        )
    ]
    
    return room
```

ROOM-WIDE EFFECTS:
```python
def load():
    room = Room(
        name="gravity_chamber",
        description="The air feels heavy here."
    )
    
    # Custom tick effect
    def room_heartbeat():
        """Called every game tick"""
        for uuid, entity in room.inventory.get_items():
            if hasattr(entity, 'is_player') and entity.is_player:
                # Drain SP in high gravity
                if entity.current_sp > 0:
                    entity.current_sp -= 1
                    if entity.current_sp % 10 == 0:
                        entity.message("The gravity drains your energy...")
    
    room.on_heartbeat = room_heartbeat
    
    # Modify combat in this room
    def modify_combat(attacker, target, damage):
        # Half damage in high gravity
        return damage // 2
    
    room.combat_modifier = modify_combat
    
    return room
```

MULTI-ROOM COMMANDS:
```python
# Plugin to add area-wide intercom system
def handle_intercom(player, params):
    """intercom <message> - Broadcast to nearby rooms"""
    if not params:
        player.message("Say what?")
        return
    
    current = player._location
    area_rooms = [
        "lab_entrance", "lab_main", "lab_storage"
    ]
    
    for room_name in area_rooms:
        room = player.game_state.rooms.get(room_name)
        if room:
            room.broadcast(f"[INTERCOM] {player.name}: {params}")
```

COMMAND VALIDATION:
```python
def safe_command(player, params):
    """Example of input validation"""
    # Limit parameter length
    if len(params) > 100:
        player.message("That's too long!")
        return
    
    # Check for valid characters
    if not params.replace(" ", "").isalnum():
        player.message("Use only letters and numbers.")
        return
    
    # Rate limiting
    if not hasattr(player, 'last_command_time'):
        player.last_command_time = 0
    
    import time
    now = time.time()
    if now - player.last_command_time < 2:
        player.message("Please wait before using that again.")
        return
    
    player.last_command_time = now
    # Command logic here
```

========================================================================    

> _