Skip to main content

lock_handler

Function lock_handler 

Source
pub fn lock_handler(
    world: &mut AmbleWorld,
    view: &mut View,
    pattern: &str,
) -> Result<bool>
Expand description

Locks a container item, securing it against unauthorized access.

This handler locks container items, preventing them from being opened until they are unlocked with an appropriate key. Locking is primarily used for puzzle mechanics and security.

§Parameters

  • world - Mutable reference to the game world
  • view - Mutable reference to the player’s view for feedback messages
  • pattern - Pattern string to match against containers in current room

§Returns

Returns Ok(()) after attempting to lock the container.

§Container State Logic

  • Non-container: Cannot be locked (no lock mechanism)
  • Already locked: Acknowledges current state
  • Open/Closed: Successfully locks the container

§Key Requirements

Unlike unlocking, locking typically doesn’t require specific keys in most game implementations, though this could be extended to require lock-specific tools or abilities.

§Scope

Only searches the current room for containers to lock, as locking items in inventory is less commonly needed in gameplay scenarios.

§Errors

Returns an error if the player’s current room cannot be determined or if the targeted container cannot be located within the world state.