[Package Index | Mudlib Index | Effect Index]

File /std/shops/player_shop/shopkeeper.c

The standard inheritable object for player-run shop npc shopkeepers.

Description

With the exception of the office, the shopkeeper contains the most complex code. This npc is intended to mimic a player as closely as possible. It adds and removes stock, and uses the cash register in the same way as a player. It moves through the shop to the correct area to perform its tasks. It logs sales and purchases in the same way as an employee. The exceptions, as far as a customer is concerned, are that money and items are implicitly given to the npc when a transaction is initiated.

Probably the most 'intelligent' functions of the npc are to do with money. Historically, the npc was limited to the lowest denomination and was therefore limited by the amount of this coin in the customer's possession, or the contents of the register. It also meant that a large transaction could result in several hundred coins being exchanged.

The npc now has the ability to take the appropriate coins from a player during a sale, and to get the correct amount of money from the register depending upon its contents. It will start with the highest value coins and work downwards until it has the correct amount of money to pay for the goods received. Unfortunately, the npc cannot yet handle change, and will therefore return the goods to the customer if unable to get the correct money from the register.

The npc will work between the hours specified by the creator, and can also be sent home by an employee. The npc will also return home if attacked. In this instance, the attacker will be banned from the shop automatically, and fired if they are an employee.

The npc will conduct some standard tests on items before they are bought from a customer. These are mainly basic stuff like checking the item is stocked by the shop. Any custom rules (such as not buying unpickled bits, uncharged magic wands, certain types of 'things') can be specified by the creator. Obviously, this may have an impact on code-maintenance if players change the list of stocked items regularly. However, I haven't had to change these rules significantly in the last year or so at Tarnach's.

See also:
/include/player_shop.h, /std/shops/player_shop/office.c, /std/shops/player_shop/mgr_office.c, /std/shops/player_shop/storeroom.c, /std/shops/player_shop/shop_front.c and /std/shops/player_shop/shopkeeper.c

Written by Ringo

Started 1st August 1999

Example

#include "path.h"

inherit "/std/shops/player_shop/shopkeeper";

void setup()
{
   set_name( "betty" );
   set_short( "Miss Betty Scuttle" );
   basic_setup( "human" , "fighter" , 15 );
   set_gender( "female" );
   add_alias( ({ "scuttle", "betty scuttle", "miss betty scuttle" }) );
   set_long( "This is Miss Scuttle, an amiable middle-aged lady who "
     "helps out in the shop from time to time.\n" );
   set_office( PATH + "office" );
   set_dearie( ({ "love", "my dear", "dear", "honey" }) );
   set_work_hours( ({0,0,23,59,}) );
}

object *item_test( mixed * items )
{
   object *give_back_wand= ({}),
          *give_back_unpickled = ({});

   foreach( object ob in items )
   {
      if ( ob->query_magic_wand() && !ob->query_charges() )
      {
         give_back_wand += ({ ob });
      }
   }

   if ( sizeof( give_back_wand ) )
   {
      do_command( "'I'm sorry, we don't buy uncharged magic wands." );
   }

   foreach( object ob in items )
   {
      if ( ( ob->query_property( "corpse bit" )  &&  !ob->no_decay()  &&
         !ob->query_cured() ) || ob->query_decay_speed() )
      {
         give_back_unpickled += ({ ob });
      }
   }
   if ( sizeof( give_back_unpickled ) )
   {
      do_command( "'We can't accept unpickled items." );
   }
   return ( give_back_wand + give_back_unpickled );
}

Inherits

This class inherits the following classes /obj/monster.c

Includes

This class includes the following files /include/move_failures.h, /include/shops/bank.h, /include/money.h, /include/living.h and /include/player_shop.h

Method index

Public Functions

These are functions that everyone can access.

.

Protected Functions

These are functions that only objects inheriting the class can access.