> cat /wizhelp/wizcoding4

========================================================================
                    MUD Coding Tutorial - Part 4
========================================================================

NPCs aren't implemented yet, but here's how to add interactive elements.

ROOM ACTIONS:
```python
def load():
    room = Room(name="shrine", description="...")
    
    # Custom search handler
    def custom_search(player, params):
        if params == "altar":
            player.message("You find a hidden switch!")
            # Create item
            from lib.models.objects import Consumable
            key = Consumable(name="ancient key")
            player.inventory.add_item(key)
        else:
            player.message("You find nothing special.")
    
    room.search_handler = custom_search
    return room
```

INTERACTIVE DESCRIPTIONS:
```python
room.description_items = [
    DescriptionItem(
        name="fountain",
        aliases=["water", "pool"],
        description="Crystal water sparkles invitingly.",
        action=lambda p: heal_player(p)
    ),
    DescriptionItem(
        name="statue",
        aliases=["warrior", "stone"],
        description="A warrior frozen in stone."
    )
]

def heal_player(player):
    player.current_hp = player.max_hp
    player.message("The water heals you!")
```

ROOM EVENTS:
```python
def load():
    room = Room(...)
    
    def on_enter(player):
        # 20% chance of event
        if random.random() < 0.2:
            player.message("A chill runs down your spine...")
            # Spawn item
            sword = create_object('cursed_blade')
            room.inventory.add_item(sword)
            player.message("A sword materializes!")
    
    room.on_enter_handler = on_enter
    return room
```

PUZZLE EXAMPLE:
```python
# Track puzzle state
room.puzzle_solved = False
room.switches = {'red': False, 'blue': False}

def flip_switch(player, color):
    if color not in room.switches:
        player.message("No such switch.")
        return
    
    room.switches[color] = not room.switches[color]
    player.message(f"You flip the {color} switch.")
    
    # Check solution
    if room.switches['red'] and room.switches['blue']:
        room.puzzle_solved = True
        player.message("The door unlocks!")
        # Unlock exit
        for exit in room.exits:
            if exit.name == "north":
                exit.locked = False
```

Continue with help wizcoding5

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

> _