skylib_fluffos_v3/
skylib_fluffos_v3/bin/
skylib_fluffos_v3/bin/db/
skylib_fluffos_v3/fluffos-2.9-ds2.04/
skylib_fluffos_v3/fluffos-2.9-ds2.04/ChangeLog.old/
skylib_fluffos_v3/fluffos-2.9-ds2.04/Win32/
skylib_fluffos_v3/fluffos-2.9-ds2.04/compat/
skylib_fluffos_v3/fluffos-2.9-ds2.04/compat/simuls/
skylib_fluffos_v3/fluffos-2.9-ds2.04/include/
skylib_fluffos_v3/fluffos-2.9-ds2.04/testsuite/
skylib_fluffos_v3/fluffos-2.9-ds2.04/testsuite/clone/
skylib_fluffos_v3/fluffos-2.9-ds2.04/testsuite/command/
skylib_fluffos_v3/fluffos-2.9-ds2.04/testsuite/data/
skylib_fluffos_v3/fluffos-2.9-ds2.04/testsuite/etc/
skylib_fluffos_v3/fluffos-2.9-ds2.04/testsuite/include/
skylib_fluffos_v3/fluffos-2.9-ds2.04/testsuite/inherit/
skylib_fluffos_v3/fluffos-2.9-ds2.04/testsuite/inherit/master/
skylib_fluffos_v3/fluffos-2.9-ds2.04/testsuite/log/
skylib_fluffos_v3/fluffos-2.9-ds2.04/testsuite/single/
skylib_fluffos_v3/fluffos-2.9-ds2.04/testsuite/single/tests/compiler/
skylib_fluffos_v3/fluffos-2.9-ds2.04/testsuite/single/tests/efuns/
skylib_fluffos_v3/fluffos-2.9-ds2.04/testsuite/single/tests/operators/
skylib_fluffos_v3/fluffos-2.9-ds2.04/testsuite/u/
skylib_fluffos_v3/fluffos-2.9-ds2.04/tmp/
skylib_fluffos_v3/fluffos-2.9-ds2.04/windows/
skylib_fluffos_v3/mudlib/
skylib_fluffos_v3/mudlib/cmds/
skylib_fluffos_v3/mudlib/cmds/admin/
skylib_fluffos_v3/mudlib/cmds/guild-race/
skylib_fluffos_v3/mudlib/cmds/living/broken/
skylib_fluffos_v3/mudlib/cmds/player/group_cmds/
skylib_fluffos_v3/mudlib/cmds/playtester/
skylib_fluffos_v3/mudlib/d/admin/
skylib_fluffos_v3/mudlib/d/admin/room/
skylib_fluffos_v3/mudlib/d/admin/room/we_care/
skylib_fluffos_v3/mudlib/d/admin/save/
skylib_fluffos_v3/mudlib/d/admin/text/
skylib_fluffos_v3/mudlib/d/learning/TinyTown/buildings/
skylib_fluffos_v3/mudlib/d/learning/TinyTown/map/
skylib_fluffos_v3/mudlib/d/learning/TinyTown/roads/
skylib_fluffos_v3/mudlib/d/learning/chars/
skylib_fluffos_v3/mudlib/d/learning/functions/
skylib_fluffos_v3/mudlib/d/learning/handlers/
skylib_fluffos_v3/mudlib/d/learning/help_topics/
skylib_fluffos_v3/mudlib/d/learning/help_topics/npcs/
skylib_fluffos_v3/mudlib/d/learning/help_topics/objects/
skylib_fluffos_v3/mudlib/d/learning/help_topics/rcs_demo/
skylib_fluffos_v3/mudlib/d/learning/help_topics/rcs_demo/RCS/
skylib_fluffos_v3/mudlib/d/learning/help_topics/rooms/
skylib_fluffos_v3/mudlib/d/learning/help_topics/rooms/crowd/
skylib_fluffos_v3/mudlib/d/learning/help_topics/rooms/situations/
skylib_fluffos_v3/mudlib/d/learning/save/
skylib_fluffos_v3/mudlib/d/learning/school/
skylib_fluffos_v3/mudlib/d/learning/school/add_sc/
skylib_fluffos_v3/mudlib/d/learning/school/characters/
skylib_fluffos_v3/mudlib/d/learning/school/general/
skylib_fluffos_v3/mudlib/d/learning/school/getting-started/
skylib_fluffos_v3/mudlib/d/learning/school/getting-started/basic_commands/
skylib_fluffos_v3/mudlib/d/learning/school/getting-started/edtutor/
skylib_fluffos_v3/mudlib/d/learning/school/getting-started/unix_tutor/
skylib_fluffos_v3/mudlib/d/learning/school/items/
skylib_fluffos_v3/mudlib/d/learning/school/npc_school/
skylib_fluffos_v3/mudlib/d/learning/school/room_school/
skylib_fluffos_v3/mudlib/d/learning/school/room_school/room_basic/
skylib_fluffos_v3/mudlib/d/learning/school/room_school/situations/
skylib_fluffos_v3/mudlib/d/learning/school/room_school/terrain_tutor/
skylib_fluffos_v3/mudlib/d/learning/text/
skylib_fluffos_v3/mudlib/d/liaison/
skylib_fluffos_v3/mudlib/d/mudlib/
skylib_fluffos_v3/mudlib/d/mudlib/changes/
skylib_fluffos_v3/mudlib/d/playtesters/
skylib_fluffos_v3/mudlib/d/playtesters/effects/
skylib_fluffos_v3/mudlib/d/playtesters/handlers/
skylib_fluffos_v3/mudlib/d/playtesters/items/
skylib_fluffos_v3/mudlib/d/sage/
skylib_fluffos_v3/mudlib/doc/
skylib_fluffos_v3/mudlib/doc/creator/
skylib_fluffos_v3/mudlib/doc/driver/
skylib_fluffos_v3/mudlib/doc/driver/efuns/arrays/
skylib_fluffos_v3/mudlib/doc/driver/efuns/buffers/
skylib_fluffos_v3/mudlib/doc/driver/efuns/calls/
skylib_fluffos_v3/mudlib/doc/driver/efuns/compile/
skylib_fluffos_v3/mudlib/doc/driver/efuns/filesystem/
skylib_fluffos_v3/mudlib/doc/driver/efuns/floats/
skylib_fluffos_v3/mudlib/doc/driver/efuns/functions/
skylib_fluffos_v3/mudlib/doc/driver/efuns/general/
skylib_fluffos_v3/mudlib/doc/driver/efuns/mappings/
skylib_fluffos_v3/mudlib/doc/driver/efuns/mixed/
skylib_fluffos_v3/mudlib/doc/driver/efuns/mudlib/
skylib_fluffos_v3/mudlib/doc/driver/efuns/numbers/
skylib_fluffos_v3/mudlib/doc/driver/efuns/parsing/
skylib_fluffos_v3/mudlib/doc/login/
skylib_fluffos_v3/mudlib/doc/lpc/basic_manual/
skylib_fluffos_v3/mudlib/doc/lpc/intermediate/
skylib_fluffos_v3/mudlib/doc/new/add_command/
skylib_fluffos_v3/mudlib/doc/new/events/
skylib_fluffos_v3/mudlib/doc/new/handlers/
skylib_fluffos_v3/mudlib/doc/new/living/race/
skylib_fluffos_v3/mudlib/doc/new/living/spells/
skylib_fluffos_v3/mudlib/doc/new/object/
skylib_fluffos_v3/mudlib/doc/new/player/
skylib_fluffos_v3/mudlib/doc/new/room/guild/
skylib_fluffos_v3/mudlib/doc/new/room/outside/
skylib_fluffos_v3/mudlib/doc/new/room/storeroom/
skylib_fluffos_v3/mudlib/doc/object/
skylib_fluffos_v3/mudlib/doc/playtesters/
skylib_fluffos_v3/mudlib/doc/policy/
skylib_fluffos_v3/mudlib/doc/weapons/
skylib_fluffos_v3/mudlib/global/
skylib_fluffos_v3/mudlib/global/creator/
skylib_fluffos_v3/mudlib/handlers/
skylib_fluffos_v3/mudlib/include/casino/
skylib_fluffos_v3/mudlib/include/cmds/
skylib_fluffos_v3/mudlib/include/effects/
skylib_fluffos_v3/mudlib/include/npc/
skylib_fluffos_v3/mudlib/include/room/
skylib_fluffos_v3/mudlib/include/shops/
skylib_fluffos_v3/mudlib/net/daemon/
skylib_fluffos_v3/mudlib/net/daemon/chars/
skylib_fluffos_v3/mudlib/net/inherit/
skylib_fluffos_v3/mudlib/net/obj/
skylib_fluffos_v3/mudlib/net/obj/BACKUPS/
skylib_fluffos_v3/mudlib/obj/amulets/
skylib_fluffos_v3/mudlib/obj/armours/plate/
skylib_fluffos_v3/mudlib/obj/b_day/
skylib_fluffos_v3/mudlib/obj/clothes/transport/horse/
skylib_fluffos_v3/mudlib/obj/faith/symbols/
skylib_fluffos_v3/mudlib/obj/fungi/
skylib_fluffos_v3/mudlib/obj/gatherables/
skylib_fluffos_v3/mudlib/obj/instruments/
skylib_fluffos_v3/mudlib/obj/media/
skylib_fluffos_v3/mudlib/obj/misc/player_shop/
skylib_fluffos_v3/mudlib/obj/monster/godmother/
skylib_fluffos_v3/mudlib/obj/monster/transport/
skylib_fluffos_v3/mudlib/obj/rings/
skylib_fluffos_v3/mudlib/obj/scabbards/
skylib_fluffos_v3/mudlib/obj/spells/
skylib_fluffos_v3/mudlib/obj/stationery/
skylib_fluffos_v3/mudlib/obj/stationery/envelopes/
skylib_fluffos_v3/mudlib/obj/toys/
skylib_fluffos_v3/mudlib/obj/vessels/
skylib_fluffos_v3/mudlib/obj/weapons/axes/
skylib_fluffos_v3/mudlib/obj/weapons/chains/
skylib_fluffos_v3/mudlib/obj/weapons/maces/BACKUPS/
skylib_fluffos_v3/mudlib/save/autodoc/
skylib_fluffos_v3/mudlib/save/book_handler/
skylib_fluffos_v3/mudlib/save/books/history/calarien/
skylib_fluffos_v3/mudlib/save/mail/
skylib_fluffos_v3/mudlib/save/new_soul/data/
skylib_fluffos_v3/mudlib/save/parcels/
skylib_fluffos_v3/mudlib/save/playerinfo/
skylib_fluffos_v3/mudlib/save/players/d/
skylib_fluffos_v3/mudlib/save/players/s/
skylib_fluffos_v3/mudlib/save/random_names/
skylib_fluffos_v3/mudlib/save/random_names/data/
skylib_fluffos_v3/mudlib/save/terrains/
skylib_fluffos_v3/mudlib/save/terrains/tutorial_desert/
skylib_fluffos_v3/mudlib/save/terrains/tutorial_grassy_field/
skylib_fluffos_v3/mudlib/save/terrains/tutorial_mountain/
skylib_fluffos_v3/mudlib/save/todo_lists/
skylib_fluffos_v3/mudlib/secure/
skylib_fluffos_v3/mudlib/secure/cmds/admin/
skylib_fluffos_v3/mudlib/secure/cmds/lord/
skylib_fluffos_v3/mudlib/secure/config/
skylib_fluffos_v3/mudlib/secure/handlers/autodoc/
skylib_fluffos_v3/mudlib/secure/handlers/intermud/
skylib_fluffos_v3/mudlib/secure/include/global/
skylib_fluffos_v3/mudlib/secure/save/
skylib_fluffos_v3/mudlib/secure/save/handlers/
skylib_fluffos_v3/mudlib/secure/std/
skylib_fluffos_v3/mudlib/secure/std/classes/
skylib_fluffos_v3/mudlib/secure/std/modules/
skylib_fluffos_v3/mudlib/std/creator/
skylib_fluffos_v3/mudlib/std/dom/
skylib_fluffos_v3/mudlib/std/effects/
skylib_fluffos_v3/mudlib/std/effects/external/
skylib_fluffos_v3/mudlib/std/effects/fighting/
skylib_fluffos_v3/mudlib/std/effects/magic/
skylib_fluffos_v3/mudlib/std/effects/magic/BACKUPS/
skylib_fluffos_v3/mudlib/std/effects/other/BACKUPS/
skylib_fluffos_v3/mudlib/std/effects/priest/
skylib_fluffos_v3/mudlib/std/effects/room/
skylib_fluffos_v3/mudlib/std/environ/
skylib_fluffos_v3/mudlib/std/guilds/
skylib_fluffos_v3/mudlib/std/guilds/old/
skylib_fluffos_v3/mudlib/std/languages/
skylib_fluffos_v3/mudlib/std/liquids/
skylib_fluffos_v3/mudlib/std/npc/
skylib_fluffos_v3/mudlib/std/npc/goals/
skylib_fluffos_v3/mudlib/std/npc/goals/basic/
skylib_fluffos_v3/mudlib/std/npc/goals/misc/
skylib_fluffos_v3/mudlib/std/npc/plans/
skylib_fluffos_v3/mudlib/std/npc/plans/basic/
skylib_fluffos_v3/mudlib/std/npc/types/
skylib_fluffos_v3/mudlib/std/npc/types/helper/
skylib_fluffos_v3/mudlib/std/npcs/
skylib_fluffos_v3/mudlib/std/outsides/
skylib_fluffos_v3/mudlib/std/races/shadows/
skylib_fluffos_v3/mudlib/std/room/basic/BACKUPS/
skylib_fluffos_v3/mudlib/std/room/basic/topography/
skylib_fluffos_v3/mudlib/std/room/controller/
skylib_fluffos_v3/mudlib/std/room/inherit/topography/
skylib_fluffos_v3/mudlib/std/room/topography/area/
skylib_fluffos_v3/mudlib/std/room/topography/iroom/
skylib_fluffos_v3/mudlib/std/room/topography/milestone/
skylib_fluffos_v3/mudlib/std/shadows/curses/
skylib_fluffos_v3/mudlib/std/shadows/disease/
skylib_fluffos_v3/mudlib/std/shadows/fighting/
skylib_fluffos_v3/mudlib/std/shadows/healing/
skylib_fluffos_v3/mudlib/std/shadows/magic/
skylib_fluffos_v3/mudlib/std/shadows/poison/
skylib_fluffos_v3/mudlib/std/shadows/room/
skylib_fluffos_v3/mudlib/std/shops/controllers/
skylib_fluffos_v3/mudlib/std/shops/objs/
skylib_fluffos_v3/mudlib/std/shops/player_shop/
skylib_fluffos_v3/mudlib/std/socket/
skylib_fluffos_v3/mudlib/std/soul/d/
skylib_fluffos_v3/mudlib/std/soul/e/
skylib_fluffos_v3/mudlib/std/soul/i/
skylib_fluffos_v3/mudlib/std/soul/j/
skylib_fluffos_v3/mudlib/std/soul/k/
skylib_fluffos_v3/mudlib/std/soul/l/
skylib_fluffos_v3/mudlib/std/soul/n/
skylib_fluffos_v3/mudlib/std/soul/o/
skylib_fluffos_v3/mudlib/std/soul/q/
skylib_fluffos_v3/mudlib/std/soul/r/
skylib_fluffos_v3/mudlib/std/soul/u/
skylib_fluffos_v3/mudlib/std/soul/v/
skylib_fluffos_v3/mudlib/std/soul/y/
skylib_fluffos_v3/mudlib/std/soul/z/
skylib_fluffos_v3/mudlib/std/stationery/
skylib_fluffos_v3/mudlib/w/
skylib_fluffos_v3/mudlib/w/default/
skylib_fluffos_v3/mudlib/w/default/armour/
skylib_fluffos_v3/mudlib/w/default/clothes/
skylib_fluffos_v3/mudlib/w/default/item/
skylib_fluffos_v3/mudlib/w/default/npc/
skylib_fluffos_v3/mudlib/w/default/room/
skylib_fluffos_v3/mudlib/w/default/weapon/
skylib_fluffos_v3/mudlib/www/
skylib_fluffos_v3/mudlib/www/java/
skylib_fluffos_v3/mudlib/www/secure/
skylib_fluffos_v3/mudlib/www/secure/lpc/advanced/
skylib_fluffos_v3/mudlib/www/secure/lpc/intermediate/
skylib_fluffos_v3/win32/
/**
 * Item shop inherit.
 * @author Pinkfish
 * @change /17/03/00 Aquilo Separated the storing and duplicating of
 * items which was moved to /std/shops/inherit/clone_on_demand
 * @see /std/shops/inherit/clone_on_demand
 */

#include <armoury.h>
#include <money.h>
#include <move_failures.h>

#define INFINITE_LEFT 10000
#define TYPE "item shop type"
#define DISPLAY "display in shop"

inherit "/std/shops/inherit/clone_on_demand";
inherit "/std/shops/inherit/shopkeeper_base";

private nosave int _no_steal;
private nosave int _steal_difficulty;
private nosave string _shoplift_handler;
private nosave function _open_func;
private nosave function _list_func;
private nosave function _browse_func;
private nosave function _buy_func;
private nosave function _sort_func;

int do_word_buy(string str);
int do_word_browse(string str);
int do_buy( object *things );
int do_browse( object *things );
void remove_property(string name);
mixed query_property(string name);

void create() {
    TO->add_help_file("item_shop");
} /* create() */

/** @ignore yes */
void reset() {
    ::reset();
    // This is incremented by shoplifting.
    if( !random( 3 ) )
        TO->remove_property("inventory_loss");
} /* reset() */

mixed switch_extra_properties() { return ({ TYPE, DISPLAY }); }

/**
 * This method tells us if the shop is really a shop or not.
 * @return 1 always
 */
int query_shop() { return 1; }

/**
 * This method returns the items which can potentially be shop lifted
 * with the passed in string.
 * @param str the name for the object to attempt to shop lift
 * @return the array of matching objects
 * @see query_steal_difficulty()
 * @see query_shoplift_response_handler()
 */
object *query_shop_lift_items( string str, object player ) {
    return filter( match_objects_for_existence( str, ({ query_cont() }) ),
        (: query_num_items_left($1) > 0 :) );
} /* query_shop_lift_items() */

/**
 * This method turns the objects into real objects (if that is
 * nessessary, it is not with a normal shop).
 * @param ob the object to turn into a normal object
 */
object shoplift_success( object ob ) {
    object real_ob;

    real_ob = create_real_object(ob);

    return real_ob;

} /* shoplift_success() */

string query_shoplift_response_handler() { return _shoplift_handler; }
void set_shoplift_response_handler( string word ) { _shoplift_handler = word; }

/**
 * This method sets the function to evaluate to detmine if the shop
 * is open or not.
 * @param func the function to evaluate for openness
 * @see query_open_func()
 * @see set_open_condition()
 */
void set_open_func( function func ) { _open_func = func; }

/**
 * This method makes it compatible with the way that the open stuff works in
 * the normal shops.
 * @param func the function to evaluate for openness
 * @see set_open_func()
 * @see query_open_func()
 */
void set_open_condition( function func ) { _open_func = func; }

/**
 * This method returns the function to evaulate to dermine if the
 * shop is open or not.
 * @return the function to use for openess
 * @see set_open_func()
 * @see set_open_condition()
 */
function query_open_func() { return _open_func; }

/**
 * This method sets the function to use when buying something from
 * the shop.  The function will be called with two arguements, the
 * first is the player, the second is the array of objects being
 * bought.
 * @param func the function to set
 * @see set_list_function()
 * @see set_buy_function()
 * @see set_browse_function()
 * @see query_buy_function()
 */
void set_buy_function( function func ) { _buy_func = func; }

/**
 * This method returns the functionto be used when buying something.
 * @return the function to be used when buying something
 * @see query_list_function()
 * @see query_browse_function()
 * @see set_buy_function()
 */
function query_buy_function() { return _buy_func; }

/**
 * This method sets the function to use when browseing something from
 * the shop.  The function will be called with two arguements, the
 * first is the player, the second is the array of objects being
 * browsed.
 * @param func the function to set
 * @see set_list_function()
 * @see set_buy_function()
 * @see set_browse_function()
 * @see query_browse_function()
 */
void set_browse_function( function func ) { _browse_func = func; }

/**
 * This method returns the functionto be used when browseing something.
 * @return the function to be used when browseing something
 * @see query_list_function()
 * @see query_browse_function()
 * @see set_buy_function()
 */
function query_browse_function() { return _browse_func; }

/**
 * This method sets the function to use when listing something from
 * the shop.  The function will be called with two arguements, the
 * first is the player, the second is the array of objects being
 * bought.
 * @param func the function to set
 * @see set_list_function()
 * @see set_buy_function()
 * @see set_browse_function()
 * @see query_list_function()
 */
void set_list_function( function func ) { _list_func = func; }

/**
 * This method returns the functionto be used when listing something.
 * @return the function to be used when listing something
 * @see query_buy_function()
 * @see query_browse_function()
 * @see set_list_function()
 */
function query_list_function() { return _list_func; }

/**
 * This method determins if the shop is open.  THis will use the open
 * function to determine this.
 * @param player the player we are seeing if it is open for
 * @return 1 if it is open, 0 if not
 */
private int is_open( object player ) {
    if( !check_shopkeeper_open() )
        return 0;
    if( _open_func )
        return evaluate( _open_func, player );
    return 1;
} /* is_open() */

/**
 * This method sets a function to be used to sort the inventory when it
 * is printed out.
 * @param func the function to use to sort the inventory
 * @see query_sort_function()
 */
void set_sort_function( function func ) { _sort_func = func; }

/**
 * This method returns the function used to sort the inventory of the
 * shop when it is printed out.
 * @return the function to use to sort the inventory
 * @see set_sort_function()
 */
function query_sort_function() { return _sort_func; }

/**
 * Sets this room as being unstealable.
 * @param i 1 if the room is unable to be stolen from
 * @see query_no_steal()
 */
void set_no_steal( int i ) { _no_steal = i; }

/**
 * Queries to see if the room is unstealable.
 * @return 1 for making the room unstealable
 * @see set_no_steal()
 */
int query_no_steal() { return _no_steal; }

/**
 * Sets the steal difficulty of the room.
 * @param i the steal difficulty of the room
 */
void set_steal_difficulty( int i ) { _steal_difficulty = i; }

/**
 * This method returns the steal difficulty of the room.
 * @return the steal difficulty of the room
 */
int query_steal_difficulty(int i) { return _steal_difficulty; }

/** @ignore yes */
void init() {
   if( query_cont() ) {
       add_command("list", "[all]" );
       add_command("browse", "<indirect:object:"+file_name(query_cont())+">");
       add_command("browse", "<word>", (: do_word_browse($4[0]) :) );
       add_command("buy", "<indirect:object:"+file_name(query_cont())+">");
       add_command("buy", "<word>", (: do_word_buy($4[0]) :) );
   }
} /* init() */

private object find_object_from_number( int number ) {
    object *things;

    things = all_inventory( query_cont() );
    if( number >= sizeof( things ) ) {
        add_failed_mess("There is no item with that label.\n");
        return 0;
    }

    if( _sort_func )
        things = sort_array( things, _sort_func );

    return things[number];

} /* find_object_from_number() */

private string letter_name( int letter, object* things ) {
    string bing;

    if( sizeof(things) > 26 ) {
        bing = "AA";
        bing[0] = 'A' + (letter / 26);
        bing[1] = 'A' + (letter % 26);
        return bing;
    }

    bing = "A";
    bing[0] = 'A' + letter;

    return bing;

} /* letter_name() */

private string start_letter() {
    object *things;

    things = INV( query_cont() );

    return letter_name( 0, things );

} /* start_letter() */

private string end_letter() {
    object *things;

    things = INV( query_cont() );

    return letter_name( sizeof(things) - 1, things );

} /* end_letter() */

private int query_number_from_string( string name ) {
    object *things;
    int pos, sz;

    things = INV( query_cont() );

    if( ( sz = sizeof(things) ) > 26 ) {
        if( strlen(name) != 2 )
            return -1;

        name = lower_case(name);
        if( name[0] < 'a' || name[0] > 'z' )
            return -1;

        if( name[1] < 'a' || name[1] > 'z' )
            return -1;

        pos = ( name[0] - 'a') * 26 + name[1] - 'a';
        if( pos >= sz )
            return -1;

        return pos;

    }

    if( strlen(name) != 1 )
        return -1;

    name = lower_case(name);
    if( name[0] < 'a' || name[0] > 'z' )
        return -1;

    pos = name[0] - 'a';
    if( pos >= sz )
        return -1;

    return pos;

} /* query_number_from_string() */

/**
 * This method returns the cost of the item shop object being talked about.
 * @param thing the thing to get the cost of
 * @return the cost of the thing
 */
int query_cost( object thing ) {
    int cost;
    string place;

    if( !thing )
        return 0;

    if( ENV( thing ) == query_cont() &&
        ( cost = thing->query_property("cost here") ) )
        return cost;

    cost = thing->query_value_at(TO);

    if( !place = query_property("place") )
        return cost;

    // This avoids problems with rounding errors.
    cost = MONEY_H->query_total_value(
           MONEY_H->create_money_array( cost, place ), place );

    if( ENV( thing ) == query_cont() )
        thing->add_property("cost here", cost );

    return cost;

} /* query_cost() */

/** @ignore yes */
int do_list( string str ) {
    int i, left;
    string list, place, display;
    object thing, *listed, *things;

    if( !is_open(TP) )
        return -1;

    place = query_property("place");
    if( !place || place == "")
        place = "default";

    if( !query_cont() ) {
        add_failed_mess("There is nothing to buy here.\n");
        return 0;
    }

    listed = ({ });
    list = "";

    things = INV( query_cont() );

    if( _sort_func )
        things = sort_array( things, _sort_func );

    foreach ( thing in things ) {
        if( !left = query_num_items_left(thing) ) {
            i++;
            continue;
        }

        display = (string)thing->query_property( DISPLAY );

        if( !stringp(display) && thing->short() )
            display = (string)thing->a_short();

        if( display ) {
            list += "$I$6=   "+letter_name( i, things )+": "+display+" for "+
                MONEY_H->money_value_string( TO->query_cost( thing ), place );
            if( left == INFINITE_LEFT )
                list += " (plenty left).$I$0=\n";
            else
                list += " (" + query_num( left, 0 ) +" left).\n";
            listed += ({ thing });
        }
        i++;
    }

    if( list == "") {
        add_failed_mess("There is nothing to buy here.\n");
        return 0;
    }

    list = PLAYER_OBJ->convert_message(list);

    tell_object( TP, "$P$item list$P$"
        "The following items are for sale:\n" + list );

    add_succeeded_mess( ({"", "$N list$s the inventory.\n"}) );

    if( _list_func )
        evaluate( _list_func, TP, listed );

    do_shopkeeper_list();
    return 1;

} /* do_list() */

/** @ignore yes */
int do_word_buy( string str ) {
    object thing;
    int i;

    if( !is_open(TP) )
        return -1;

    if( strlen( str ) <= 2 ) {
        if( ( i = query_number_from_string( str ) ) == -1 ) {
            add_failed_mess("The item label must be from "+
                start_letter()+" to "+end_letter()+".\n");
            return 0;
        }

        if( !thing = find_object_from_number( i ) )
            return 0;

        return do_buy( ({ thing }) );
    }

    return 0;

} /* do_word_buy() */

/** @ignore yes */
int do_buy( object *things ) {
    int i, cost, value, ret;
    string place;
    object thing, *sold;

    if( !is_open(TP) )
        return -1;

    sold = ({ });

    for( i = 0; i < sizeof(things); i++ ) {
        if( query_num_items_left( things[i] ) <= 0 ) {
            add_failed_mess("The shop is sold out of "+
                things[ i ]->query_plural()+".\n");
            return 0;
        }

        place = query_property("place");
        if( !place || place == "")
            place = "default";

        value = TP->query_value_in( place );
        if( place != "default" )
            value += TP->query_value_in("default");

        if( ( cost = TO->query_cost( things[i] ) ) > value ) {
            add_failed_mess("You cannot afford to buy $I.\n", things[i..i] );
        } else {
            mixed arr, str;
            object ob;

            if( !ob = ( thing = create_real_object( things[i] ) ) ) {
                add_failed_mess("Something has broken, please file a bug "
                    "report.  Thank you.\n");
                return 0;
            }

            ret = 1;
            TP->pay_money( arr = MONEY_H->create_money_array( cost, place ),
                place );

            TO->something_bought( thing, TP, cost );
            if( query_property("package items") )
                thing = TO->package_item( thing );

            str = "You buy $I for "+MONEY_H->money_string(arr);

            if( thing->move(TP) ) {
                thing->move(TO);
                str += ", but unfortunately you cannot pick "+
                    ( query_group(ob) ? "them up, so they are" :
                    "it up, so it is")+ " left "+
                    ( TO->query_property("here") || "on the floor")+
                    " for you";
            }
            add_succeeded_mess( ({ str+".\n", "$N $V $I.\n"}), ({ ob }) );
            sold += ({ thing });
        }
    }

    if( _buy_func )
        evaluate( _buy_func, TP, sold );

    if( ret )
        do_shopkeeper_buy();

    return ret;

} /* do_buy() */

/** @ignore yes */
int do_word_browse( string words ) {
    int i;
    object thing;

    if( !is_open(TP) )
        return -1;

    if( strlen( words ) <= 2 ) {
        if( ( i = query_number_from_string( words ) ) == -1 ) {
            add_failed_mess("The item label must be from "+
                start_letter()+" to "+end_letter()+".\n");
            return 0;
        }

        if( !thing = find_object_from_number( i ) )
            return 0;

        return do_browse( ({ thing }) );
    }

    return 0;

} /* do_browse_word() */

/** @ignore yes */
int do_browse( object *things ) {
    int i, sz, num;
    string place, mess;

    if( !is_open(TP) )
        return -1;

    place = query_property("place");
    if( !place || place == "")
        place = "default";

    mess = "";
    sz = sizeof(things);

    for( i = 0; i < sz; i++ ) {
        object ob;

        if( query_num_items_left( ob = things[i] ) ) {
            mess += ob->the_short()+" is priced at "+
                MONEY_H->money_value_string( TO->query_cost( ob ),
                place )+" and looks like:\n"+ob->long();
            add_succeeded_mess( ({"", "$N $V $I.\n"}), things[i..i] );
            num++;
        }
    }

    if( !num ) {
        add_failed_mess("The shop is sold out of $I.\n", things );
        return 0;
    }

    write("$P$Browse things$P$" + mess );

    if( _browse_func )
        evaluate( _browse_func, TP, things );

    do_shopkeeper_browse();
    return 1;

} /* do_browse() */

/** @ignore yes */
void event_shoplift( object command_ob, object thief, object victim ) {
    if( stringp(_shoplift_handler) ) {
        if( _shoplift_handler != "none")
            _shoplift_handler->handle_shoplift( thief, victim );
    } else if( functionp(_shoplift_handler) ) {
         evaluate( _shoplift_handler, thief, victim );
    } else {
        THEFT_H->handle_shoplift( thief, victim );
    }
} /* event_shoplift() */

/** @ignore yes */
mixed stats() { return clone_on_demand::stats() + shopkeeper_base::stats(); }