/* Adjustments to check_social 
 * contributors include, Mindus, Fury, Aurora. No license stated.
 * This version does not include ability to set personal preferences to local/global/off
 * Only the ability to send a social to anyone, anywhere whom you can see etc.
 */

bool check_social( CHAR_DATA *ch, char *command, char *argument )
{
    char arg[MAX_INPUT_LENGTH];
    char buf[MAX_INPUT_LENGTH];
    CHAR_DATA *victim;
    SOCIALTYPE *social;
    CHAR_DATA *remfirst, *remlast, *remtemp; /* for ignore cmnd */

    if ( (social=find_social(command)) == NULL )
	return FALSE;

    if ( !IS_NPC(ch) && xIS_SET(ch->act, PLR_NO_EMOTE) )
    {
	send_to_char( "You are anti-social!\n\r", ch );
	return TRUE;
    }
   
    switch ( ch->position )
    {
    case POS_DEAD:
	send_to_char( "Lie still; you are DEAD.\n\r", ch );
	return TRUE;

    case POS_INCAP:
    case POS_MORTAL:
	send_to_char( "You are hurt far too bad for that.\n\r", ch );
	return TRUE;

    case POS_STUNNED:
	send_to_char( "You are too stunned to do that.\n\r", ch );
	return TRUE;

    case POS_SLEEPING:
	/*
	 * I just know this is the path to a 12" 'if' statement.  :(
	 * But two players asked for it already!  -- Furey
	 */
	if ( !str_cmp( social->name, "snore" ) )
	    break;
	send_to_char( "In your dreams, or what?\n\r", ch );
	return TRUE;

    }

    remfirst = NULL;
    remlast = NULL;
    remtemp = NULL;
    
    one_argument( argument, arg );
    if ( arg[0] == '\0' )
    {
      if( !social->others_no_arg || !social->char_no_arg)
      {
        send_to_char("Incomplete social, try again soon.\n\r", ch);
        sprintf(buf, "Social %s", social->name);
        bug(buf);
        return TRUE;
      }
	act( AT_SOCIAL, social->others_no_arg, ch, NULL, victim, TO_ROOM    );
	act( AT_SOCIAL, social->char_no_arg,   ch, NULL, victim, TO_CHAR    );
    }
    else if ( ( victim = get_char_world( ch, arg ) ) == NULL )
    {
    	for(victim = remfirst; victim; victim = victim->next_in_room)
    	{
    		if(nifty_is_name(victim->name,arg) ||
    			nifty_is_name_prefix(arg,victim->name))
    		{
    			set_char_color(AT_IGNORE, ch);
    			ch_printf(ch,"%s is ignoring you.\n\r",
    				victim->name);
    			break;
    		}
    	}
    }
    else if((victim = get_char_world(ch, arg)) != NULL && !IS_NPC(victim) 
       && (victim->in_room->vnum != ch->in_room->vnum))
    {
      if( !social->vict_found || !social->char_found)
      {
        send_to_char("Incomplete social, try again soon.\n\r", ch);
        sprintf(buf, "Social %s", social->name);
        bug(buf);
        return TRUE;
      }
      strcpy( buf, "From afar...");
      strcat( buf, social->vict_found );
      act( AT_SOCIAL, buf, ch, NULL, victim, TO_VICT );
      strcpy( buf, "From afar...");
      strcat( buf, social->char_found);
      act( AT_SOCIAL, buf, ch, NULL, victim, TO_CHAR );
    }
    else if(victim != NULL && !IS_NPC(victim) && victim != ch)
    {
      if( !social->vict_found || !social->char_found || !social->others_found)
      {
        send_to_char("Incomplete social, try again soon.\n\r", ch);
        sprintf(buf, "Social %s", social->name);
        bug(buf);
        return TRUE;
      }
      act( AT_SOCIAL, social->vict_found,    ch, NULL, victim, TO_VICT    );
      act( AT_SOCIAL, social->char_found,    ch, NULL, victim, TO_CHAR    );
      act( AT_SOCIAL, social->others_found,   ch, NULL, victim, TO_NOTVICT );
    }
    else if ( victim == ch )
    {
      if( !social->char_auto || !social->others_auto)
      {
        send_to_char("Incomplete social, try again soon.\n\r", ch);
        sprintf(buf, "Social %s", social->name);
        bug(buf);
        return TRUE;
      }
	act( AT_SOCIAL, social->others_auto,   ch, NULL, victim, TO_ROOM    );
	act( AT_SOCIAL, social->char_auto,     ch, NULL, victim, TO_CHAR    );
    }
    else
    {
      if( !social->char_found || !social->others_found || !social->vict_found)
      {
        send_to_char("Incomplete social, try again soon.\n\r", ch);
        sprintf(buf, "Social %s", social->name);
        bug(buf);
        return TRUE;
      }
	act( AT_SOCIAL, social->others_found,  ch, NULL, victim, TO_NOTVICT );
	act( AT_SOCIAL, social->char_found,    ch, NULL, victim, TO_CHAR    );
	act( AT_SOCIAL, social->vict_found,    ch, NULL, victim, TO_VICT    );

	if ( !IS_NPC(ch) && IS_NPC(victim)
	&&   !IS_AFFECTED(victim, AFF_CHARM)
	&&   IS_AWAKE(victim) 
	&&   !HAS_PROG(victim->pIndexData, ACT_PROG) )
	{
	    switch ( number_bits( 4 ) )
	    {
	    case 0:
		if (IS_EVIL(ch) && !is_safe(victim, ch, TRUE)) /* was IS_EVIL(ch) ||.... didn't make sense to me - FB */
		  multi_hit( victim, ch, TYPE_UNDEFINED );
		else
		if ( IS_NEUTRAL(ch) )
		{
		    act( AT_ACTION, "$n slaps $N.",  victim, NULL, ch, TO_NOTVICT );
		    act( AT_ACTION, "You slap $N.",  victim, NULL, ch, TO_CHAR    );
		    act( AT_ACTION, "$n slaps you.", victim, NULL, ch, TO_VICT    );
		}
		else
		{
		    act( AT_ACTION, "$n acts like $N doesn't even exist.",  victim, NULL, ch, TO_NOTVICT );
		    act( AT_ACTION, "You just ignore $N.",  victim, NULL, ch, TO_CHAR    );
		    act( AT_ACTION, "$n appears to be ignoring you.", victim, NULL, ch, TO_VICT    );
		}
		break;

	    case 1: case 2: case 3: case 4:
	    case 5: case 6: case 7: case 8:
		act( AT_SOCIAL, social->others_found,
		    victim, NULL, ch, TO_NOTVICT );
		act( AT_SOCIAL, social->char_found,
		    victim, NULL, ch, TO_CHAR    );
		act( AT_SOCIAL, social->vict_found,
		    victim, NULL, ch, TO_VICT    );
		break;

	    case 9: case 10: case 11: case 12:
		act( AT_ACTION, "$n slaps $N.",  victim, NULL, ch, TO_NOTVICT );
		act( AT_ACTION, "You slap $N.",  victim, NULL, ch, TO_CHAR    );
		act( AT_ACTION, "$n slaps you.", victim, NULL, ch, TO_VICT    );
		break;
	    }
	}
    }
    
    /* Replace the chars in the ignoring list to the room */
    /* note that the ordering of the players in the room  */
    /* might change					  */
    for(victim = remfirst; victim; victim = remtemp)
    {
    	remtemp = victim->next_in_room;
    	char_to_room(victim, ch->in_room);
    }

    return TRUE;
}

