/
SilentMists/class/
SilentMists/gods/
SilentMists/player/
/***************************************************************************
 *  Original Diku Mud copyright (C) 1990, 1991 by Sebastian Hammer,        *
 *  Michael Seifert, Hans Henrik St{rfeldt, Tom Madsen, and Katja Nyboe.   *
 *                                                                         *
 *  Merc Diku Mud improvments copyright (C) 1992, 1993 by Michael          *
 *  Chastain, Michael Quan, and Mitchell Tse.                              *
 *                                                                         *
 *  In order to use any part of this Merc Diku Mud, you must comply with   *
 *  both the original Diku license in 'license.doc' as well the Merc       *
 *  license in 'license.txt'.  In particular, you may not remove either of *
 *  these copyright notices.                                               *
 *                                                                         *
 *  Much time and thought has gone into this software and you are          *
 *  benefitting.  We hope that you share your changes too.  What goes      *
 *  around, comes around.                                                  *
 ***************************************************************************/

/***************************************************************************
*	ROM 2.4 is copyright 1993-1995 Russ Taylor			   *
*	ROM has been brought to you by the ROM consortium		   *
*	    Russ Taylor (rtaylor@pacinfo.com)				   *
*	    Gabrielle Taylor (gtaylor@pacinfo.com)			   *
*	    Brian Moore (rom@rom.efn.org)				   *
*	By using this code, you have agreed to follow the terms of the	   *
*	ROM license, in the file Rom24/doc/rom.license			   *
***************************************************************************/

#if defined(macintosh)
#include <types.h>
#else
#include <sys/types.h>
#include <sys/time.h>
#endif
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include <ctype.h>
#include "merc.h"

DECLARE_DO_FUN(do_say		);

void do_repair(CHAR_DATA *ch, char *argument)
{
    CHAR_DATA *mob;
    char arg[MAX_INPUT_LENGTH];
    char buf[MAX_INPUT_LENGTH];
    OBJ_DATA *obj;
    int cost;

    for ( mob = ch->in_room->people; mob; mob = mob->next_in_room )
    {
        if (!IS_NPC(mob)) continue;
	if (mob->spec_fun == spec_lookup("spec_repairman") )
            break;
    }
 
    if ( mob == NULL )
    {
        send_to_char( "You can't do that here.\n\r", ch );
        return;
    }

    one_argument(argument,arg);

    if (arg[0] == '\0')
    {
	do_say(mob,"I will repair a weapon for you, for a price.");
	send_to_char("Type estimate <weapon> to be assessed for damage.\n\r",ch);
	return;
    }
    if (( obj = get_obj_carry(ch, arg, ch)) == NULL)
    {
	do_say(mob,"You don't have that item");
	return;
    }

    if (obj->pIndexData->vnum == OBJ_VNUM_HAMMER)
    {
     do_say(mob,"That hammer is beyond my power.");
     return;
    }

    if (obj->condition >= 100)
    {
	do_say(mob,"But that item is not broken.");
        return;
    }

    if (obj->cost == 0)
    {
	sprintf(buf ,"%s is beyond repair.\n\r", obj->short_descr);
	do_say(mob,buf);
   	return;
    }

    cost = ( (obj->level * 10) +
		((obj->cost * (100 - obj->condition)) /100)    );
    cost /= 100;

    if (cost > ch->gold)
    {
	do_say(mob,"You do not have enough gold for my services.");
	return;
    }

    WAIT_STATE(ch,PULSE_VIOLENCE);

    ch->gold -= cost;
    mob->gold += cost;
    sprintf(buf, "$N takes %s from $n, repairs it, and returns it to $n", obj->short_descr); 
    act(buf,ch,NULL,mob,TO_ROOM);
    sprintf(buf, "%s takes %s, repairs it, and returns it\n\r", mob->short_descr, obj->short_descr);
    send_to_char(buf, ch);
    obj->condition = 100;
}

void do_estimate(CHAR_DATA *ch, char *argument)
{
    char buf[MAX_INPUT_LENGTH];
    OBJ_DATA *obj;
    CHAR_DATA *mob; 
    char arg[MAX_INPUT_LENGTH];
    int cost;
    
    for ( mob = ch->in_room->people; mob; mob = mob->next_in_room )
    {
        if (!IS_NPC(mob)) continue;
	if (mob->spec_fun == spec_lookup("spec_repairman") )
            break;
    }
 
    if ( mob == NULL )
    {
        send_to_char( "You can't do that here.\n\r", ch );
        return;
    }
    
    one_argument(argument, arg);
    
    if (arg[0] == '\0')
    {
	do_say(mob,"Try estimate <item>");
   	return; 
    } 
    if ((obj = (get_obj_carry(ch, arg, ch))) == NULL)
    {
	do_say(mob,"You don't have that item");
	return;
    }
    if (obj->pIndexData->vnum == OBJ_VNUM_HAMMER)
	{
	    do_say(mob,"That hammer is beyond my power.");
	    return;
	}
    if (obj->condition >= 100)
    {
	do_say(mob,"But that item's not broken");
	return;
    }
    if (obj->cost == 0)
    {
	do_say(mob,"That item is beyond repair");
    	return;
    } 
    
    cost = ( (obj->level * 10) +
		((obj->cost * (100 - obj->condition)) /100)    );
    cost /= 100;

    sprintf(buf, "It will cost %d to fix that item", cost);
    do_say(mob,buf);
}


void do_restring( CHAR_DATA *ch, char *argument )
{
    char buf  [MAX_INPUT_LENGTH];
    char arg  [MAX_INPUT_LENGTH];
    char arg1 [MAX_INPUT_LENGTH];
    char arg2 [MAX_INPUT_LENGTH];
    CHAR_DATA *mob;
    OBJ_DATA *obj;
    int cost = 2000;

    for ( mob = ch->in_room->people; mob; mob = mob->next_in_room )
    {
        if ( IS_NPC(mob) && IS_SET(mob->act, ACT_IS_HEALER) )
            break;
    }
 
    if ( mob == NULL )
    {
        send_to_char( "You can't do that here.\n\r", ch );
        return;
    }

    smash_tilde( argument );
    argument = one_argument( argument, arg );
    argument = one_argument( argument, arg1 );
    strcpy( arg2, argument );

	if ( arg[0] == '\0' || arg1[0] == '\0' || arg2[0] == '\0' )
	{
		send_to_char("Syntax:\n\r",ch);
		send_to_char("  restring <obj> <field> <string>\n\r",ch);
		send_to_char("    fields: name short long\n\r",ch);
		return;
	}

    if ((obj = (get_obj_carry(ch, arg, ch))) == NULL)
    {
		send_to_char("The Stringer says '`sYou don't have that item``.'\n\r", ch);
		return;
    }

	cost += (obj->level * 1500);

    if (cost > ch->gold)
    {
		act("$N says 'You do not have enough gold for my services.'",
		  ch,NULL,mob,TO_CHAR);
		return;
    }
    
	if ( !str_prefix( arg1, "name" ) )
	{
		free_string( obj->name );
		obj->name = str_dup( arg2 );
	}
	else
	if ( !str_prefix( arg1, "short" ) )
	{
		free_string( obj->short_descr );
        obj->short_descr = str_dup(arg2);
	}
	else
	if ( !str_prefix( arg1, "long" ) )
	{
		free_string( obj->description );
		obj->description = str_dup( arg2 );
	}
	else
	{
		send_to_char("That's not a valid Field.\n\r",ch);
		return;
	}
	
    WAIT_STATE(ch,PULSE_VIOLENCE);

    ch->gold -= cost;
    mob->gold += cost;
    sprintf(buf, "$N takes $n's item, tinkers with it, and returns it to $n.");
	act(buf,ch,NULL,mob,TO_ROOM);
  sprintf(buf,"%s takes your item, tinkers with it, and returns %s to you.\n\r", mob->short_descr, obj->short_descr);
  send_to_char(buf,ch);
  send_to_char("Remember, if we find your new string offensive, we will not be happy.\n\r", ch);
  send_to_char(" This is your ONE AND ONLY Warning.\n\r", ch);
}


void do_smithing(CHAR_DATA *ch, char *argument)
{
    char arg[MAX_INPUT_LENGTH];
    char buf[MAX_INPUT_LENGTH];
    OBJ_DATA *obj;
    OBJ_DATA *hammer;

    if ( IS_NPC(ch)
    ||   ch->level < skill_table[gsn_smithing].skill_level[ch->class] )
    {
	send_to_char("Huh?\n\r", ch );
	return;
    }


    if ( ch->fighting )
    {
        send_to_char( "Wait until the fight finishes.\n\r", ch );
        return;
    }

    one_argument(argument,arg);

    if (arg[0] == '\0')
    {
	send_to_char("Which object do you want to repair.\n\r",ch);
	return;
    }

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

   if (obj->condition >= 100)
    {
	send_to_char("But that item is not broken.\n\r",ch);
	return;
    }

    if (( hammer = get_hold_char(ch)) == NULL)
    {
	send_to_char("You are not holding a hammer.\n\r",ch);
	return;
    }

    if ( hammer->pIndexData->vnum != OBJ_VNUM_HAMMER )
    {
	send_to_char("That is not the correct hammer.\n\r",ch);
	return;
    }

    WAIT_STATE(ch,2 * PULSE_VIOLENCE);
    if ( number_percent() > get_skill(ch,gsn_smithing) )    
     {
      check_improve(ch,gsn_smithing,FALSE,8);
    sprintf(buf, "$n try to repair %s with the hammer.But $n fails.", obj->short_descr); 
    act(buf,ch,NULL,obj,TO_ROOM);
    sprintf(buf, "You failed to repair %s\n\r", obj->short_descr);
    send_to_char(buf, ch);
    hammer->condition -= 25;
     }
    else
     {
    check_improve(ch,gsn_smithing,TRUE,4);
    sprintf(buf, "$n repairs %s with the hammer.", obj->short_descr); 
    act(buf,ch,NULL,NULL,TO_ROOM);
    sprintf(buf, "You repair %s\n\r", obj->short_descr);
    send_to_char(buf, ch);
    obj->condition = UMAX( 100 , 
	 obj->condition + ( get_skill(ch,gsn_smithing) / 2) );
    hammer->condition -= 25;
     }
   if (hammer->condition < 1)  extract_obj( hammer );
   return;
}