Exemple #1
0
/*
 * Find an obj in a list.
 */
obj_data *get_obj_list( char_data * ch, const string & argument, list < obj_data * >source )
{
   string arg;
   list < obj_data * >::iterator iobj;

   int number = number_argument( argument, arg );
   int count = 0;
   for( iobj = source.begin(  ); iobj != source.end(  ); ++iobj )
   {
      obj_data *obj = *iobj;

      if( ch->can_see_obj( obj, false ) && hasname( obj->name, arg ) )
         if( ( count += obj->count ) >= number )
            return obj;
   }

   /*
    * If we didn't find an exact match, run through the list of objects
    * again looking for prefix matching, ie swo == sword.
    * Added by Narn, Sept/96
    */
   count = 0;
   for( iobj = source.begin(  ); iobj != source.end(  ); ++iobj )
   {
      obj_data *obj = *iobj;

      if( ch->can_see_obj( obj, false ) && nifty_is_name_prefix( arg, obj->name ) )
         if( ( count += obj->count ) >= number )
            return obj;
   }
   return NULL;
}
Exemple #2
0
bool check_social( CHAR_DATA * ch, const char *command, const char *argument )
{
   char arg[MAX_INPUT_LENGTH];
   CHAR_DATA *victim, *victim_next;
   SOCIALTYPE *social;
   CHAR_DATA *removed[128];   /* What are the chances of more than 128? */
   ROOM_INDEX_DATA *room;
   int i = 0, k = 0;

   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!\r\n", ch );
      return TRUE;
   }

   switch ( ch->position )
   {
      case POS_DEAD:
         send_to_char( "Lie still; you are DEAD.\r\n", ch );
         return TRUE;

      case POS_INCAP:
      case POS_MORTAL:
         send_to_char( "You are hurt far too bad for that.\r\n", ch );
         return TRUE;

      case POS_STUNNED:
         send_to_char( "You are too stunned to do that.\r\n", 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?\r\n", ch );
         return TRUE;
   }

   /*
    * Search room for chars ignoring social sender and 
    * remove them from the room until social has been  
    * completed              
    */
   room = ch->in_room;
   for( victim = ch->in_room->first_person; victim; victim = victim_next )
   {
      if( i == 127 )
         break;
      victim_next = victim->next_in_room;
      if( is_ignoring( victim, ch ) )
      {
         if( !IS_IMMORTAL( ch ) || get_trust( victim ) > get_trust( ch ) )
         {
            removed[i] = victim;
            i++;
            UNLINK( victim, room->first_person, room->last_person, next_in_room, prev_in_room );
         }
         else
         {
            set_char_color( AT_IGNORE, victim );
            ch_printf( victim, "You attempt to ignore %s," " but are unable to do so.\r\n", ch->name );
         }
      }
   }

   one_argument( argument, arg );
   victim = NULL;
   if( arg[0] == '\0' )
   {
      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_room( ch, arg ) ) == NULL )
   {
      /*
       * If they aren't in the room, they may be in the list of 
       * people ignoring...                 
       */
      if( i != 0 )
      {
         for( k = 0, victim = removed[0]; k < i; k++, victim = removed[k] )
         {
            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.\r\n", victim->name );
               break;
            }
         }
      }

      if( !victim )
         send_to_char( "They aren't here.\r\n", ch );
   }
   else if( victim == ch )
   {
      act( AT_SOCIAL, social->others_auto, ch, NULL, victim, TO_ROOM );
      act( AT_SOCIAL, social->char_auto, ch, NULL, victim, TO_CHAR );
   }
   else
   {
      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                
    */
   if( i != 0 )
   {
      for( k = 0, victim = removed[0]; k < i; k++, victim = removed[k] )
      {
         LINK( victim, room->first_person, room->last_person, next_in_room, prev_in_room );
      }
   }

   return TRUE;
}