
From clap@wolfenet.com Tue Apr 21 13:14:18 1998
Date: Mon, 20 Apr 1998 18:00:09 -0000
From: Dave Clapper <clap@wolfenet.com>
To: 'Darkoth' <darkoth@rep.mudservices.com>
Subject: RE: Study snippet

/* The study command will allow your players to learn spells from studying
wands, staves, or scrolls.  If you only want them to be able to study one
of these items, the others can easily be removed.  Study was originally
written for Yrth, yrth.mudservices.com 5000.  I don't ask for any credit,
except to leave the study by Absalom comment in void do_study.  I can be
reached for questions about the snippet at clap@wolfenet.com.  Reports on
bugs, enhancements, etc. are greatly welcomed. */

/* In interp.h, add: */

DECLARE_DO_FUN( do_study	);

/* In interp.c, add: */

    { "study",		do_study,	POS_RESTING,	 0,  LOG_NORMAL, 1 },

/* in act_obj.c, add: */

void do_study( CHAR_DATA *ch, char *argument ) /* study by Absalom */
{
    char arg[MAX_INPUT_LENGTH];
    OBJ_DATA *obj;
    int sn = 0;

    one_argument( argument, arg );

    if ( arg[0] == '\0' )
    {
	send_to_char( "Study what?\n\r", ch );
	return;
    }

    if ( ( obj = get_obj_carry( ch, arg, ch ) ) == NULL )
    {
	send_to_char( "You do not have that item.\n\r", ch );
	return;
    }

    if ( obj->item_type != ITEM_STAFF && obj->item_type != ITEM_WAND &&
	obj->item_type != ITEM_SCROLL )
    {
	send_to_char( "You can only study scrolls, wands, and staves.\n\r", ch );
	return;
    }

    act( "$n studies $p.", ch, obj, NULL, TO_ROOM );
    act( "You study $p.", ch, obj, NULL, TO_CHAR );

    if (ch->level < obj->level)
	{
	send_to_char("You cannot glean any knowledge from it.\n\r",ch);
	act( "$p burns brightly and is gone.", ch, obj, NULL, TO_CHAR );
	extract_obj( obj );
	}

    if (obj->item_type == ITEM_STAFF)
	{
	sn = obj->value[3];
	if ( sn < 0 || sn >= MAX_SKILL || skill_table[sn].spell_fun == 0 )
	    {
	    bug( "Do_study: bad sn %d.", sn );
	    return;
	    }
	if ( number_percent() >= 20 + get_skill(ch,gsn_staves) * 4/5)
	    {
	    send_to_char("You cannot glean any knowledge from it.\n\r",ch);
	    check_improve(ch,gsn_staves,FALSE,2);
	    act( "$p burns brightly and is gone.", ch, obj, NULL, TO_CHAR );
	    extract_obj( obj );
	    return;
	    }
	if ( ch->pcdata->learned[sn])
	    {
	    send_to_char("You already know that spell!\n\r",ch);
	    return;
	    }
	ch->pcdata->learned[sn] = 1;
	act("You have learned the art of $t!",
	ch,skill_table[sn].name,NULL,TO_CHAR);
	check_improve(ch,gsn_staves,TRUE,2);
	act( "$p burns brightly and is gone.", ch, obj, NULL, TO_CHAR );
	extract_obj( obj );
	return;
	}

    if (obj->item_type == ITEM_WAND)
	{
	sn = obj->value[3];
	if ( sn < 0 || sn >= MAX_SKILL || skill_table[sn].spell_fun == 0 )
	    {
	    bug( "Do_study: bad sn %d.", sn );
	    return;
	    }
	if ( number_percent() >= 20 + get_skill(ch,gsn_wands) * 4/5)
	    {
	    send_to_char("You cannot glean any knowledge from it.\n\r",ch);
	    check_improve(ch,gsn_wands,FALSE,2);
	    act( "$p burns brightly and is gone.", ch, obj, NULL, TO_CHAR );
	    extract_obj( obj );
	    return;
	    }
	if ( ch->pcdata->learned[sn])
	    {
	    send_to_char("You already know that spell!\n\r",ch);
	    return;
	    }
	ch->pcdata->learned[sn] = 1;
	act("You have learned the art of $t!",
	ch,skill_table[sn].name,NULL,TO_CHAR);
	check_improve(ch,gsn_wands,TRUE,2);
	act( "$p burns brightly and is gone.", ch, obj, NULL, TO_CHAR );
	extract_obj( obj );
	return;
	}

    if (obj->item_type == ITEM_SCROLL)
	{
	sn = obj->value[1];
	if ( sn < 0 || sn >= MAX_SKILL || skill_table[sn].spell_fun == 0 )
	    {
	    bug( "Do_study: bad sn %d.", sn );
	    return;
	    }
	if ( number_percent() >= 20 + get_skill(ch,gsn_scrolls) * 4/5)
	    {
	    send_to_char("You cannot glean any knowledge from it.\n\r",ch);
	    check_improve(ch,gsn_scrolls,FALSE,2);
	    act( "$p burns brightly and is gone.", ch, obj, NULL, TO_CHAR );
	    extract_obj( obj );
	    return;
	    }
	if ( ch->pcdata->learned[sn])
	    {
	    send_to_char("You already know that spell!\n\r",ch);
	    return;
	    }
	ch->pcdata->learned[sn] = 1;
	act("You have learned the art of $t!",
	ch,skill_table[sn].name,NULL,TO_CHAR);
	check_improve(ch,gsn_scrolls,TRUE,2);
	act( "$p burns brightly and is gone.", ch, obj, NULL, TO_CHAR );
	extract_obj( obj );
	return;
	}

}
