/*


 ---  ---  ---  ---  ---  ---          ---  ---  ---  --- 
 |S|  |P|  |I|  |R|  |A|  |L|          |V|  |O|  |I|  |D| 
 ---  ---  ---  ---  ---  ---          ---  ---  ---  ---
 
 
 Add this command directly below do_practice in act_info.c


   You will of course need to add this command to your mud 
 using whatever method you use
 (stock uses tables.c and mud.h)




 ----------------------------------------------------------
 
*/






void do_practice2( CHAR_DATA *ch, char *argument )
{
    char buf[MAX_STRING_LENGTH];
    char skn[MAX_INPUT_LENGTH];
    int ability;
    int sn;
    int ln=0;
    

    if ( IS_NPC(ch) )
	return;

    if ( argument[0] == '\0' )
    {
	int	col;
	sh_int	lasttype, cnt;

	col = cnt = 0;	lasttype = SKILL_SPELL;
	set_pager_color( AT_MAGIC, ch );
	
	
	// for loop to move through linked list
	for ( ability = 0 ; ability < MAX_ABILITY ; ability++ )
        {
	 
              sprintf(skn, 
              "\n\r&R+&r-&w-&r-&w-&r-&w-&r-&w-&r-&w-&r-&w-&r-&w-&r-&w-&r-&w-&r-&w-&r-&w-&r-&w-&r-&w-&r-&w-&r-&z[&w%15s&z]&r-&w-&r-&w-&r-&w-&r-&w-&r-&w-&r-&w-&r-&w-&r-&w-&r-&w-&r-&w-&r-&w-&r-&w-&r-&w-&r-&w-&r-&w-&R+\n\r"
              , ability_name[ability] );
              
              
            
         
         send_to_pager(skn,ch);
         
 
	      for ( sn = 0; sn < top_sn; sn++ )
	      {
	      	
	      	if ( !skill_table[sn]->name )
		break;
		
		
		
            
        
                
	    if (  ch->pcdata->learned[sn] <= 0  &&  ch->skill_level[skill_table[sn]->guild] < skill_table[sn]->min_level )
 	        continue;

	    if ( ch->pcdata->learned[sn] == 0
	    &&   SPELL_FLAG(skill_table[sn], SF_SECRETSKILL) )
		continue;
		
	/*
this below is the ranges used

Can turn on or off with the config command
if you have the flag set in mud.h
and the proper code in the config function
in act_info.c

-cirus
		1 - 20, 21 - 40, 41 - 60, 61 - 80, 81 - 100
		unlearned - bad - novice - trained - Expert - Master
		*/
	              if( skill_table[sn]->guild == ability ) 
	              {
	              	if(ln == 1) ++ln;
	              	if(ln == 0) ++ln;
	                        if( !IS_NPC(ch) )
                                 {  
                                  if( IS_SET(ch->pcdata->flags, PCFLAG_TEXT_PRACTICE) )
                                  {
		                  pager_printf( ch, "&z%25s ", skill_table[sn]->name);
		                  if(ch->pcdata->learned[sn] >= 0  && ch->pcdata->learned[sn] <= 17 ) pager_printf(ch, "&B[&rUnlearned&B]");
                                  if(ch->pcdata->learned[sn] >= 18 && ch->pcdata->learned[sn] <= 20 ) pager_printf(ch, "&B[&WTerrible &B]");
                                  if(ch->pcdata->learned[sn] >= 21 && ch->pcdata->learned[sn] <= 40 ) pager_printf(ch, "&B[&RBad      &B]");
		                  if(ch->pcdata->learned[sn] >= 41 && ch->pcdata->learned[sn] <= 60 ) pager_printf(ch, "&B[&gNovice   &B]");
		                  if(ch->pcdata->learned[sn] >= 61 && ch->pcdata->learned[sn] <= 80 ) pager_printf(ch, "&B[&GTrained  &B]");
		                  if(ch->pcdata->learned[sn] >= 81 && ch->pcdata->learned[sn] <= 90 ) pager_printf(ch, "&B[&OExpert   &B]");
		                  if(ch->pcdata->learned[sn] >= 91 && ch->pcdata->learned[sn] <= 100) pager_printf(ch, "&B[&YMaster   &B]");
                                  }
                                  else
                                  {
		                  pager_printf( ch, "&z%25s &w%3d%%  ",
		                  skill_table[sn]->name, ch->pcdata->learned[sn] );
                                  }
	                         }
	                }
	                
		
		                 if( ln == 2)
		                 {
		                  send_to_pager("\n\r",ch);
		                  ln = 0;
		                 }
	             }
                           
	          }
	     

    } // if the argument supplied does not equal null
    else
    {
	CHAR_DATA *mob;
	int adept;
	bool can_prac = TRUE;

	if ( !IS_AWAKE(ch) )
	{
	    send_to_char( "In your dreams, or what?\n\r", ch );
	    return;
	}

	for ( mob = ch->in_room->first_person; mob; mob = mob->next_in_room )
	    if ( IS_NPC(mob) && IS_SET(mob->act, ACT_PRACTICE) )
		break;

	if ( !mob )
	{
	    send_to_char( "You can't do that here.\n\r", ch );
	    return;
	}

	
	sn = skill_lookup( argument );
   
        if ( sn == -1 )
        {
            act( AT_TELL, "$n tells you 'I've never heard of that one...'",
		mob, NULL, ch, TO_VICT );
	    return;
        }
	
	if ( skill_table[sn]->guild < 0  || skill_table[sn]->guild >= MAX_ABILITY )
        {
	    act( AT_TELL, "$n tells you 'I cannot teach you that...'",
		mob, NULL, ch, TO_VICT );
	    return;
	}
	
	if ( can_prac &&  !IS_NPC(ch)
	&&   ch->skill_level[skill_table[sn]->guild] < skill_table[sn]->min_level )
	{
	    act( AT_TELL, "$n tells you 'You're not ready to learn that yet...'",
		mob, NULL, ch, TO_VICT );
	    return;
	}

	if ( is_name( skill_tname[skill_table[sn]->type], CANT_PRAC ) )
	{
	    act( AT_TELL, "$n tells you 'I do not know how to teach that.'",  
		  mob, NULL, ch, TO_VICT );
	    return;
	}

	/*
	 * Skill requires a special teacher
	 */
	if ( skill_table[sn]->teachers && skill_table[sn]->teachers[0] != '\0' )
	{
	    sprintf( buf, "%d", mob->pIndexData->vnum );
	    if ( !is_name( buf, skill_table[sn]->teachers ) )
	    {
		act( AT_TELL, "$n tells you, 'I know not know how to teach that.'",
		    mob, NULL, ch, TO_VICT );
		return;
	    }
	}
        else
        {
                act( AT_TELL, "$n tells you, 'I know not know how to teach that.'",
		    mob, NULL, ch, TO_VICT );
		return;
        }
	
	adept = 20;

        if ( ch->gold < skill_table[sn]->min_level*10 )
	{
	    sprintf ( buf , "$n tells you, 'I charge %d credits to teach that. You don't have enough.'" , skill_table[sn]->min_level*10 );
	    act( AT_TELL, "$n tells you 'You don't have enough credits.'",
		mob, NULL, ch, TO_VICT );
	    return;
	}

	if ( ch->pcdata->learned[sn] >= adept )
	{
	    sprintf( buf, "$n tells you, 'I've taught you everything I can about %s.'",
		skill_table[sn]->name );
	    act( AT_TELL, buf, mob, NULL, ch, TO_VICT );
	    act( AT_TELL, "$n tells you, 'You'll have to practice it on your own now...'",
		mob, NULL, ch, TO_VICT );
	}
	else
	{
	    ch->gold -= skill_table[sn]->min_level*10;
	    ch->pcdata->learned[sn] += int_app[get_curr_int(ch)].learn;
	    act( AT_ACTION, "You practice $T.",
		    ch, NULL, skill_table[sn]->name, TO_CHAR );
	    act( AT_ACTION, "$n practices $T.",
		    ch, NULL, skill_table[sn]->name, TO_ROOM );
	    if ( ch->pcdata->learned[sn] >= adept )
	    {
		ch->pcdata->learned[sn] = adept;
		act( AT_TELL,
		 "$n tells you. 'You'll have to practice it on your own now...'",
		 mob, NULL, ch, TO_VICT );
	    }	
	  }
    }
    return;
}