Skip to main content

unlock_handler

Function unlock_handler 

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

Unlocks a locked container using an appropriate key from inventory.

This handler attempts to unlock locked containers by checking the player’s inventory for items with the appropriate unlocking abilities. Success requires having the right key, and unlocking may trigger game events.

§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 unlock the container.

§Key System

The function searches inventory for items with ItemAbility::Unlock:

  • Specific keys: Target a particular container by id
  • Universal keys: Can unlock any container (master keys)

§Container State Logic

  • Non-container: Cannot be unlocked (no lock)
  • Already unlocked: Acknowledges current state
  • Locked with valid key: Successfully unlocks to closed state
  • Locked without key: Denies access with helpful message

§Trigger Effects

Unlocking fires TriggerCondition::Unlock, which can:

  • Advance puzzle sequences requiring specific unlocking order
  • Reveal important story items or clues
  • Trigger narrative events or character reactions
  • Enable access to new areas or content

§Security Model

The key must be in the player’s inventory - keys in the room or in other containers cannot be used, maintaining gameplay challenge.

§Errors

Returns an error if the player’s current room cannot be determined, if the targeted container cannot be resolved from the world state, or if trigger evaluation fails.