void main()
{
	// Default for Library 1: unlock the second floor
	set_property( "choiceAdventure80", "99" );
	// Default for Library 2: unlock the gallery quest
	set_property( "choiceAdventure81", "1" );
	set_property( "choiceAdventure87", "2" );
	// We search for a choice adventure to advance.
	cli_execute( "conditions add 1 choiceadv" );
	adventure( my_adventures(), $location[haunted library] );
	// Rather than incrementally doing things (retrieve towel,
	// come back, or unlock gallery, then come back), we do it
	// all at once to save logic.
	// A person manually adventuring in the browser will return
	// to the map no matter what, either to unlock the gallery
	// or to advance to the second floor.
	// So, if KoLmafia returns to the map to figure out what to
	// do next, it's perfectly reasonable. :)  We figure out if
	// we hit the stair choice by seeing if manor2 is available.
	if ( visit_url( "manor.php" ).contains_text( "manor2.php" ) )
	{
		// Ignore the rise of spookyraven adventure
		set_property( "choiceAdventure80", "4" );
		// The gallery unlock adventure is an auto-stop adventure,
		// so we don't need to use conditions before KoLmafia stops
		// automatically when it sees it.
		adventure( my_adventures(), $location[haunted library] );
	}
	else
	{
		// We have two options.  Ignore the spookyraven adventure,
		// or use it to unlock the staircase.  Obviously, one is
		// more efficient than the other.
		set_property( "choiceAdventure81", "99" );
		// Now, as long as we hit a choice adventure, KoLmafia will
		// unlock the second floor stairs.  So we go do it.
		cli_execute( "conditions add 1 choiceadv" );
		adventure( my_adventures(), $location[haunted library] );
	}
	// Retrieve the gallery key from the conservatory
	adventure( 1, $location[haunted conservatory] );
}