shopkeeper

obj
OBJECT
	obj/shopkeeper

SYNOPSIS
	inherit "/obj/shopkeeper";

	#include <properties.h>

LAST UPDATE
	Suamor, 13-Sep-96, 12 11:34:30 MET

DESCRIPTION
	The shopkeeper handles additional services to the normal functions
	which /std/shop offers. These services are simply new commands
	executed on certain objects either from the shop or from the player
	resp. his environment. The shopkeeper itself does not implement
	the services but all what is needed to perform them like paying,
	getting the objects from the shop and paying the service itself.
	The shopkeeper only works if he is included into a shop because
	he doesn't wants to keep the money by himself.

	The shopkeeper offers the following commands:
	'list service(s)'  will list all services implemented in this
	                   shopkeeper.
	'show service <what>'  shows the description of the service
	                       <what> to the player.
	'<service> <...>  Executes the service, the exact syntax is up
	                  to the writer of a service

	The functions of the shopkeeper:

	object Service(string scomm,string sobjects,int force)
	  This is the central function of the shopkeeper. It implements
	  all services and is called whenever the player wants to execute
	  a service.  This function is not implemented in the shopkeeper
	  itself but only called from here (!). <scomm> is the command
	  of the service and <sobjects> are the objects which should be
	  used for the service. Up to now both arguments are required.
          <force> should be only used if you intend to clone the object
          and pay it (see in the full example in EXAMPLES section the
          Service() and f.e. the make_chair() function).

	I recommand to use the following technique when you want to make
	a service which requires several objects to create a new one:
	- use a general command name f.e.  'make'
	- the added argument is the object which should be built f.e.
          'make ladder' tells you to create a ladder from several short
	  and long wood pieces.

        mapping P_SERVICES    "Services"
	mapping SetServices(mapping serv)
	mapping QueryServices()
	  You should not access this functions directly usually.
	  Set/Query all information about the service, i.e. the
	  command, the price and a long description.

	void AddService(string scomm,string sdescr,int price)
	  Add a service to the list of services. <scomm> is the
	  command, <sdescr> is the long description and <price>
	  is the price of the service.

	void RemoveService(string scomm)
	  Removes the service with command <scomm> from the list
	  of services if existant.

	string GetServCommand(string scomm)
	  This commands checks whether the service with command
	  <scomm> exists and if it returns the command <scomm>.

	string P_SERVDESC "ServDesc"
	void SetServDesc(string scomm,string sdesc)
	string QueryServDesc(string scomm)
	  Sets/Queries a service description for the service
	  command <scomm>. <sdesc> is the long description.

        string P_SERVPRICE "ServPrice"
	void SetServPrice(string scomm,string price)
	int QueryServPrice(string scomm)
	  Sets/Queries the service price for the service command
          <scomm>. <price> is the price in copper coins.

	All the aboce commands are used for configuring the shopkeeper.
	As usual the properties cna also be Set using the Set() or
	Query() functions (f.e. Query(P_SERVICEPRICE).). To be able
	to use these properties you have to include shopkeeper.h
	The four functions below can be used as well for configuring
	if you want to replace the usual 'list' and 'show verbs as
	well as for disabling them like in std/shop-

	public string SetList(string verb) { return Pverb_list = verb; }
	public string QueryList() { return Pverb_list; }

	public string SetShow(string verb) { return Pverb_show = verb; }
	public string QueryShow() { return Pverb_show; }
	  These four function are similar to the corresponding shop
	  function except that they are used to list the services or
	  show a service. The functions do_show(), do_list() except
	  that the second argument is 'service' (as descibed above).


	protected object GetShopObject(string shopobj)
	  This function must be used to get an object from the shop
	  in which the shopkeeper is. It tests it the shopkeeper is
	  really in a shop and does the object on a list of shop-
	  objects for later reference in pay_service(). It returns
	  you the shopobject specified by <shopobj> if it exists.


	protected varargs int buy_routine(object ob,int force)
	  Similar to the std/shop function except it does not
	  give the item to the player.

	protected int pay_service(string scomm,int force)
	  This function is called when the service is done before
	  the player actually gets the object. It calls in the
	  shop where the shopkeeper is the check_money() function
	  to pay every shopobject (see GetShopObject()). The same
	  function is called to pay the service itself.


	The following functions implement the commands itself.

	public object do_service(string str1,string str2)
	  Every time the player executes a service this function is
	  called. It checks the command and calls Service() and
	  pay_service(). If all went well it moves the created
	  object in the player's inventory and returns it.
	  
	public int do_show(string scomm)
	public int do_list(string str)
	  Similar to the shop functions. It shows a service if he
	  exists to the player and shows the whole list. The Str
	  resp. scomm command must contain the string service or
	  the functions will return 0, so the corresponding shop
	  functions may be executed.
	  
	Functions modified by /obj/shopkeeper:
	
	create()
	  Makes some default settings. Most important is that it
	  sets questions which the shopkeeper may be asked (f.e.
	  the usual shop functions). The question "service","services"
	  should be added by every shopkeeper even if it is only a
	  indirect call to the do_list() function (indirect because
	  do_list() requires the 'service� aragument). Questions
	  about the services itself are recommanded as well.

	init()
	  adds the service commands by using add_comm().

INHERITANCE TREE
	obj/shopkeeper
	  |-std/npc
	  |-std/shop/comm
	  `-std/shop/trading

EXAMPLES
	inherit "/obj/shopkeeper"

	do_inscribe()
	{
		// Your inscription function here :-)
	}
	
	object Service(string scomm,string sobjects)
	{
		if (scomm=="inscribe") return do_inscribe();
		// ...
		return 0;
	}
		
	create()
	{
	  ::create();
	  // Example for implementing inscription:

	  AddService("inscribe",
	"You may inscribe a thing you want to buy, just type the following:\n"+
	"inscribe [really] <thing you want to inscribe> <inscription>\n"+
	"and I will look in my store for it and if I have it, sell it to you\n"+
	"with the added inscription.\n"
	,50);
	
	  AddQuestion(({"inscribe","inscribing"}),
	  // ... more services
	}


	A full example can be found here: /d/halfling/common/npc/mevig.c

BUGS/TODO

	None known. The appraise() command should be implemented.

SEE ALSO
	shop(S), npc(S)