/* The salesman, always after a tidy profit and the satisfaction of a sale, is
   a social individual...Maybe overly so... <grin> */

int sales_spec(struct char_data *ch, struct char_data *pl, int cmd, char *arg)
{
   char buf[MAX_STRING_LENGTH],
	arg1[MAX_STRING_LENGTH],arg2[MAX_STRING_LENGTH];
   int i_val = 0;
   struct obj_data *selling=0, *s_item = 0, *obj=0;
   struct char_data *c_obj=0,*k, *dummy_char, *old_follow=NULL;

   extern void do_insult(struct char_data *ch,char *argument,int cmd);
   extern void do_say(struct char_data *ch,char *argument,int cmd);

   /* Find out if we have anything to sell, either in first equipment slot */
   /* or something being carried */
   if(witness(ch,pl,cmd,arg))
	return(TRUE);

   if (selling = ch->equipment[WIELD])
      i_val = ch->equipment[WIELD]->obj_flags.cost * 2 + 3;
   else if (selling = ch->carrying)
      i_val = ch->carrying->obj_flags.cost * 2 + 3;
   /* Handle cases where we might care what a player does: buy, steal, etc. */
   if (cmd != 0) {
      argument_interpreter(arg,arg1,arg2);
      if (*arg1) c_obj=get_char_room(arg1,ch->in_room);
      switch(cmd) {
         case 9:
         case 113:
         case 118:
         case 120:
         case 121:
         case 123:
         case 138:
         case 160:
            /* Actions of questionable intent */
            if(c_obj!=ch || GET_POS(ch)<=POSITION_SLEEPING)
               return FALSE;
            if(pl->player.sex != 2) {
               act("$N slaps you before you can even begin.",
                  FALSE,pl,0,ch,TO_CHAR);
               act("$N slaps $n for his naughty intentions.",
                  FALSE,pl,0,ch,TO_ROOM);
            }
            return TRUE;
            break;
         case 19:
            if(c_obj!=ch || GET_POS(ch)<=POSITION_SLEEPING)
               return FALSE;
            do_say(ch,"I can talk all day, but only you can buy...",0);
            return TRUE;
            break;
         case 23:
            /* The salesman suffers from acceptance anxiety :-) */
	    if(GET_POS(ch)<=POSITION_SLEEPING)
		return FALSE;
	    do_action(pl, arg1, cmd);
            act("$n smiles too, trying to join in on the fun.",
               TRUE,ch,0,0,TO_ROOM);
            return TRUE;
            break;
         case 33:
            if(c_obj!=ch || GET_POS(ch)<=POSITION_SLEEPING)
               return FALSE;
            do_insult(pl,arg,0);
            act("$N humbles you with a greater insult.",FALSE,pl,
		0,ch,TO_CHAR);
            act("$N snaps back with a greater insult.",FALSE,pl,
		0,ch,TO_ROOM);
            return TRUE;
            break;
         case 46:
            if(c_obj!=ch)
               return FALSE;
            if(GET_POS(ch) != POSITION_SLEEPING)
               act("$N is not sleeping.",FALSE,pl,0,ch,TO_CHAR);
            else {
               act("Your gentle nudging awakens $N, who yawns and clears his throat.",FALSE,pl,0,ch,TO_CHAR);
               act("$n nudges $N awake.",FALSE,pl,0,ch,TO_ROOM);
               GET_POS(ch) = POSITION_STANDING;
            }
            return TRUE;
            break;
         case 94:
            /* An exchange of poking */
            if(c_obj!=ch || GET_POS(ch)<=POSITION_SLEEPING)
               return FALSE;
	    do_action(pl, arg, 94);
	    act("$N pokes you back.",FALSE,pl,0,ch,TO_CHAR);
	    act("$N pokes $n back.",TRUE,pl,0,ch,TO_ROOM);
            return TRUE;
            break;
         case 154:
            if(c_obj!=ch || GET_POS(ch)<=POSITION_SLEEPING)
               return FALSE;
            act("Oof! $N knocks you down.",FALSE,pl,0,ch,TO_CHAR);
            act("$n tries to backstab $N who, more alert than \
he appears, slams\n\r$m down on the ground instead.",FALSE,pl,0,ch,TO_ROOM);
            do_say(ch,"I've dealt with your kind before!",0);
            GET_POS(pl) = POSITION_SITTING;
            return TRUE;
            break;
         case 56:
            /* "To buy is to be" is the salesman's motto... */
            if (strlen(arg1)==0 || GET_POS(ch)<=POSITION_SLEEPING || !selling)
		return FALSE;
            if (c_obj==ch) {
               do_say(ch,"I'm not for sale, idiot!",0);
               return TRUE;
            }
            if (!generic_find(arg1,FIND_OBJ_EQUIP,ch,&dummy_char,&s_item))
               s_item=get_obj_in_list(arg1,selling);
            if (strlen(arg2)==0) {
	       if(!get_char_room_vis(pl, "2.salesman")) {
                  if(s_item==selling) {
                     if(transact(ch,s_item,pl,i_val)) {
			if(ch->master)
	                        stop_follower(ch);
                        REMOVE_BIT(ch->specials.act,ACT_SENTINEL);
                     }
                  } else if (s_item) {
                     sprintf(buf,"$n grins and says, 'Buy the %s \
first, and then I'll\n\rconsider selling you the %s.",selling->short_description,
s_item->short_description);
                     act(buf,FALSE,ch,0,0,TO_ROOM);
                  } else do_say(ch,"Sell you what?",0);
                  return(TRUE);
               } else if(ch==get_char_room_vis(ch,"salesman")){
                  sprintf(buf,"$n arches an eyebrow and says, 'Who \
\n\r'ya talkin' to, %s?'\n\rUse: BUY <OBJ> [FROM] <SELLER>.",pl->player.name);
                  act(buf,FALSE,ch,0,0,TO_ROOM);
               } else
                  do_say(ch,"Yeah, we can't ALL oblige you, ya know?",0);
            } else {
               if (ch == get_char_room_vis(pl,arg2)) {
                  if (s_item==selling) {
                     if(transact(ch,s_item,pl,i_val)) {
			if(ch->master)
				stop_follower(ch);
                        REMOVE_BIT(ch->specials.act,ACT_SENTINEL);
		     }
                  } else
                     do_say(ch,"I don't have that.",0);
                  return(TRUE);
               }
            }
            break;
         default:
            return FALSE;
            break;
      }
   } else if (IS_LIGHT(ch->in_room)) {
      if (GET_POS(ch) == POSITION_SLEEPING) {
         ch->specials.position = POSITION_STANDING;
         act("$n becomes alert, ready to assault any \
unsuspecting\n\rpersons with $s salesmanship.",TRUE,ch,0,0,TO_ROOM);
      }
      if (ch->master) {
         if (!selling) {
            /* No items to sell, must have had item stolen */
            act("$n looks puzzled.",TRUE,ch,0,0,TO_ROOM);
            stop_follower(ch);
            REMOVE_BIT(ch->specials.act,ACT_SENTINEL);
            return(FALSE);
         }
         i_val = selling->obj_flags.cost * 2 + 4;
         if (ch->master->in_room == ch->in_room) {
            if (ch->specials.spec[0] > 108) { /* Number is not fixed in stone */
               act("$n throws $s hands up in disgust.",TRUE,
                     ch,0,0,TO_ROOM);
               old_follow=ch->master;
               stop_follower(ch);
               REMOVE_BIT(ch->specials.act,ACT_SENTINEL);
            } else {
	       if(GET_POS(ch->master)<=POSITION_SLEEPING)
			return(0);
 	       buf[0]=0;
               switch (number(0,14)) {
                  case 0:
                     act("$n says 'I tell you this $o is of the finest quality.'",FALSE,ch,selling,0,TO_ROOM);
                     break;
                  case 1:
                     sprintf(buf,"Only %d pieces of gold - a bargain!",i_val);
                     do_say(ch,buf,0);
                     break;
                  case 2:
                     buf[0]='a';
                     act("$N splutters 'You know, I have six\
 hungry wives\n\rand a child to feed...'",FALSE,pl,0,ch,TO_CHAR);
                     break;
                  case 3:
	             act("$N waves the $p in your face.",
                         FALSE,pl,selling,ch,TO_CHAR);
	             act("$N waves the $p in $n's face.",
                         FALSE,pl,selling,ch,TO_ROOM);
		     break;
		  case 4:
		     act("The salesman demonstrates the unique usefulness of the $o.",TRUE,ch,selling,0,TO_ROOM);
		     break;
		  case 5:
		     do_action(ch,"",107);
		     break;
                  default:
                     break;
               }
               if(buf[0]) {
                  act("$n tries to sell the $o to $N.",FALSE,ch,selling,ch->master,TO_NOTVICT);
                  ch->specials.spec[0] +=1;
               }
            }
         } else {
           stop_follower(ch);
           REMOVE_BIT(ch->specials.act,ACT_SENTINEL);
	 }
      }
      if (!ch->master && !selling ) {
         SET_BIT(ch->specials.act,ACT_SCAVENGER);
         if(number(0,5)==0) act("$n scans the floor.",TRUE,ch,0,0,TO_ROOM);
      } else if(!ch->master) {
         REMOVE_BIT(ch->specials.act,ACT_SCAVENGER);
         for(k=world[ch->in_room].people;pl=k;k=k->next_in_room) {
            if (/*!IS_NPC(pl) &&*/ number(0,4)<3 && CAN_SEE(ch,pl) &&
	         !circle_follow(ch,pl)&&old_follow!=pl) {
               add_follower(ch,pl);
               SET_BIT(ch->specials.act,ACT_SENTINEL);
               sprintf(buf,"The salesman saunters up to you and says, 'Hey %s! \
Have I got a\n\rdeal for you! Take a look at this magnificent $o.\n\rIsn't it \
just a dream? And it can be yours for just %d coins!'",pl->player.name, i_val);
               act(buf,FALSE,pl,selling,0,TO_CHAR);
               act("$N makes a sales pitch to $n.",FALSE,pl,
                  0,ch,TO_ROOM);
               ch->specials.spec[0] = 100;
               break;
            }  
         }
      }
   } else if(GET_POS(ch) > POSITION_SLEEPING) {
      if(!ch->equipment[WEAR_LIGHT]) {  /* See if we have a light source */
         for(obj=ch->carrying;obj;obj=obj->next_content) {
            if(obj->obj_flags.type_flag==ITEM_LIGHT) {
	       do_grab(ch,obj->name,0);
               return(FALSE);
            }
         }
      } else {
	 do_remove(ch,obj->name,0);
	 do_drop(ch,obj->name,0);
         return(FALSE);
      }
      if(number(0,5) == 0) {
         GET_POS(ch) = POSITION_SLEEPING;
         do_say(ch,"Ah, must be time to go to bed!",0);
         act("The sounds of violent snoring filter through the area.",FALSE,
            ch,0,0,TO_ROOM);
         if (ch->master) {
            stop_follower(ch);
            REMOVE_BIT(ch->specials.act,ACT_SENTINEL);
         }
      }
   }
   return(FALSE);
}

int jester(struct char_data *ch, struct char_data *pl, int cmd, char *arg)
{
	void do_say(struct char_data *ch, char *argument, int cmd);

	if(witness(ch,pl,cmd,arg))
		return(TRUE);

	if (cmd)
		return(0);

	switch (number(0, 60))
	{
		case 0:
			do_say(ch, "You are a real stinker!", 0);
		   return(1);
		case 1:
			do_say(ch, "Have you considered getting a lobotomy?", 0);
			return(1);
		case 2:
			do_say(ch, "You're as stupid as you look!", 0);
			return(1);
		case 3:
			do_say(ch, "Get a real hair-cut!", 0);
			return(1);
		case 4:
			act("$n does a backflip.",TRUE,ch,0,0,TO_ROOM);
			do_say(ch, "Ha!",0);
			return(1);
		default:
			return(0);
	}
}

/* Another mob-based special... */
int waiter(struct char_data *ch,struct char_data *pl,int cmd,char *arg)
{
	int check1,check2,check3,check4,check5;
	char buf[MAX_STRING_LENGTH];
	struct obj_data *i;
	
	if(witness(ch,pl,cmd,arg))
		return(TRUE);

	if(cmd==2 && ch->in_room==real_room(12576)) {
		check1=real_object(12530);
		check2=real_object(12531);
		check3=real_object(12532);
		check4=-1;
		check5=-1; /* For when I add other menu items */
		for(i=pl->carrying;i;i=i->next_content) {
			if(i->item_number==check1 || i->item_number==check2
                            || i->item_number==check3 || i->item_number==check4
			    || i->item_number==check5){
				act("The waiter prevents you from leaving.",
					FALSE,pl,0,0,TO_CHAR);
				act("The waiter prevents $n from leaving.",
					FALSE,pl,0,0,TO_ROOM);
				do_say(ch,"You must finish your meal here!",0);
				return(TRUE);
			}
		}
	}
	return(shop_keeper(ch,pl,cmd,arg));
}

int cookie(struct char_data *ch,struct char_data *pl,int cmd,char *arg)
{
	/* Have him kick people he can see out through side door... */
	if(witness(ch,pl,cmd,arg))
		return(TRUE);

	if(pl) {
		/* perhaps put in something later */
	} else {
		switch(number(1,15)) {
			case 1:
				do_action(ch,"cookie",244);
				break;
			case 2:
				do_action(ch,"",106); /* He burps */
				switch(number(1,3)) {
					case 1:
						do_say(ch,"Mmm! Mammoth!",0);
						break;
					case 2:
						do_say(ch,"Mmm! Yak liver!",0);
						break;
					case 3:
						do_say(ch,"Hmm. Can't quite place that one.",0);
						break;
					default:
						break;
				}
			default:
				break;
		}
	}
	return(FALSE);
}

int mage_anapest(struct char_data *ch,struct char_data *pl,int cmd,char *arg)
{
	char buf[MAX_STRING_LENGTH];
	struct char_data *who,*i,*temp;
	char arg1[MAX_STRING_LENGTH],arg2[MAX_STRING_LENGTH];

	if(GET_POS(ch) <= POSITION_SLEEPING)
		return(FALSE);
	if(pl) {
		switch(cmd) {
			case 154:
				do_action(ch,"",31);
				spell_teleport(GET_LEVEL(ch),ch,pl,NULL);
				act("She apparently doesn't like that.\n\r",
					FALSE,pl,0,0,TO_CHAR);
				return(TRUE);
				break;
			default:
				break;
		}
	} else {
		if(ch->in_room==real_room(12581)) {
			for(i=world[ch->in_room].people,temp=i->next_in_room;
						i;i=temp,temp=i->next_in_room){
				if(i!=ch && GET_CLASS(i) != CLASS_MAGIC_USER){
					do_say(ch,"Be gone!",0);
					/* Get rid of them */
					spell_teleport(GET_LEVEL(ch),ch,i,NULL);
				} else if(i!=ch && GET_ALIGNMENT(i) > 350) {
					sprintf(buf,"%s I don't think I like you!",i->player.name);
					do_tell(ch,buf,0);
				}
			}
		}
	}
				
	return(guild(ch,pl,cmd,arg));
}

int landshark(struct char_data *ch,struct char_data *pl,int cmd,char *arg)
{
	if(!pl) {
		if(ch->specials.spec[0] && GET_POS(ch)>POSITION_FIGHTING) {
			switch(ch->specials.spec[0]) {
				case 1:
					do_say(ch,"Flowers.",0);
					break;
				case 2:
					do_say(ch,"Candygram.",0);
					break;
				case 3:
					do_say(ch,"Plumber.",0);
					break;
				case 4:
					do_say(ch,"I'm only a dolphin.",0);
					ch->specials.spec[0]=-1;
					SET_BIT(ch->specials.act,ACT_AGGRESSIVE);
					break;
				default:
					break;
			}
			ch->specials.spec[0]++;
		} else if(!number(0,9) &&!ch->specials.spec[0]) {
			ch->specials.spec[0]=1;
			REMOVE_BIT(ch->specials.act,ACT_AGGRESSIVE);
		}
	}
	return(FALSE);
}

int spore_ball(struct char_data *ch,struct char_data *pl,int cmd,char *arg)
{
	struct char_data *k;

	if(cmd==-1) {
		act("$n crumples, a noxious gas escaping its interior.",FALSE,ch,0,0,TO_ROOM);
		if(is_in_safe(ch))
			act("The gas dissipates harmlessly.",FALSE,ch,0,0,TO_ROOM);
		else
			for(k=world[ch->in_room].people;k;k=k->next_in_room)
				if(k!=ch)
					spell_poison(24,ch,k,0);
	}
	return(FALSE);
}