// buy.c

inherit F_CLEAN_UP;

int main(object me, string arg)
{
	string item, targ;
	object ob, owner;
	int price, afford;
	object* inv;

    if( this_player()->is_busy() )
			return notify_fail("æء\n");

	if( !arg || sscanf(arg, "%s from %s", item, targ)!=2 )
		return notify_fail("ָʽbuy <ĳ> from <ĳ>\n");

	if( !objectp(owner = present(targ, environment(me))) )
		return notify_fail("Ҫ˭\n");

	if( userp(owner) ) {
		message_vision("$N$n" + item + "\n", me, owner);
	        notify_fail("ԷԸ㽻ס\n");
		return 1;
	}

	if( (price = owner->buy_object(me, item)) == -1 ) return 1;
	if( price < 1 ) return 0;

	if( afford = me->can_afford(price) ) {
      	if( afford==2 ) 
			return notify_fail("û㹻ǮƱûҵÿ\n");

		me->start_busy(1);
		if(owner->complete_trade(me, item)) {
		  me->pay_money(price);
		  return 1;
		} else {
		  me->pay_money(price);
		    return 1;
		}
	} else
		return notify_fail("Ǯ\n");
}

int help(object me)
{
   write( @HELP
ָʽ: buy <something> from <someone>

һָԴĳЩƷ
HELP
   );
   return 1;
}
