eldhamud/boards/
eldhamud/clans/
eldhamud/classes/
eldhamud/councils/
eldhamud/deity/
eldhamud/doc/
eldhamud/doc/DIKU/
eldhamud/doc/MERC/
eldhamud/doc/mudprogs/
eldhamud/houses/
//
// C Implementation: crafting
//
// Description:
//
// Crafting.c will contain code related to the weapons and armor crafting system
// Some of the code below is copyright to various snippet authors and contains
// any headers or comments they have added. Any origional code below by Tommi
// may be used in whole or in part as long as any comment is left inplace and
// that you agree to make any changes,additions or improvements available
// to the public domain via a snippet posted on a public website.
//
// Author: tommi <powell123@yahoo.com>, (C) 2005
//
// Copyright: See COPYING file that comes with this distribution
//
//
#include <sys/types.h>
#include <string.h>
#include "mud.h"
#include "crafting.h"


/*Tailor skill by Tamarae -(tamarae@zdnetonebox.com) written for The Kravothian Mysts
 *Tailoring is the act of sewing pieces of material together to create handmade clothing
 *which in turn can be dyed many different colors and worn.  Part of the Tailoring group
 *written by Tamarae
 *Tailor skill by Tamarae -(tamarae@zdnetonebox.com)
 *Syntax: tailor <material> <clothing type>
 *
 * Tailor skill ported over to smaug1.4a by Vladaar 12-22-01 
 *
 *Modified and changed how it works, SmaugFUSS1.4 by Tommi 2005*/

void do_tailor( CHAR_DATA *ch, char *argument )
{
  char arg1[MAX_INPUT_LENGTH];
  char arg2[MAX_INPUT_LENGTH];
  char buf[MAX_INPUT_LENGTH];
  char exdesc[20], ctype[20];
  OBJ_DATA *clothing, *material, *sewkit;
  int random_number;

  /* Do we have the skill? */
  if ( !IS_NPC(ch) && !(LEARNED(ch,gsn_tailor)))
  {
    send_to_char( "You better leave that to those who have been trained to tailor.\n\r", ch );
    return;
  }


  argument = one_argument( argument, arg1 );
  if ( arg1[0] == '\0' )
  {
    send_to_char( "Tailor using which material?\n\r", ch );
    send_to_char( "Syntax: tailor corpse <clothing>\n\r", ch);
    send_to_char( "Available clothing types:  cap, scarf, gloves, boots, belt, pants, tunic, cloak, bracer, vest, whip\n\r", ch);
    return;
  }

  argument = one_argument( argument, arg2 );
  if ( arg2[0] == '\0' )
  {
    send_to_char( "Syntax: tailor corpse <clothing>\n\r", ch);
    send_to_char( "Which type of clothing are you trying to tailor?\n\r", ch );
    send_to_char( "Available clothing types:  cap, scarf, gloves, boots, belt, pants, tunic, cloak, bracer, vest, whip\n\r", ch);
    return;
  }

  if ( ( material = get_obj_carry( ch, arg1 ) ) == NULL )
  {
    send_to_char( "You do not have any material to stitch.\n\r", ch );
    return;
  }

  if (material->pIndexData->vnum != OBJ_VNUM_CORPSE)
  {
    send_to_char("Sorry, you many only tailor the skins of corpses.\n\r", ch);
    return;
  }

  if ( ( sewkit = get_eq_char( ch, WEAR_HOLD ) ) == NULL || sewkit->pIndexData->vnum != OBJ_VNUM_SEWKIT )
  {
    send_to_char( "You need a sewing kit in order to tailor.\n\r", ch );
    return;
  }

  if ( number_percent() < LEARNED(ch, gsn_tailor)  ) /* create the clothing - success! */
  {
    if (!str_cmp(arg2,"cap"))
    {
      clothing = create_object(get_obj_index(OBJ_VNUM_CLOTHING), 0);
      SET_BIT(clothing->wear_flags,ITEM_WEAR_HEAD);
      strcpy(ctype, "cap" );
      clothing->weight = 10;
    }
    else if (!str_cmp(arg2,"scarf"))
    {
      clothing = create_object(get_obj_index(OBJ_VNUM_CLOTHING), 0);
      SET_BIT(clothing->wear_flags,ITEM_WEAR_NECK);
      strcpy(ctype, "scarf" );
      clothing->weight = 5;
    }

    else if (!str_cmp(arg2,"bracer"))
    {
      clothing = create_object(get_obj_index(OBJ_VNUM_CLOTHING), 0);
      SET_BIT(clothing->wear_flags,ITEM_WEAR_WRIST);
      strcpy(ctype, "bracer" );
      clothing->weight = 5;
    }
    else if (!str_cmp(arg2,"vest"))
    {
      clothing = create_object(get_obj_index(OBJ_VNUM_CLOTHING), 0);
      SET_BIT(clothing->wear_flags,ITEM_WEAR_ABOUT);
      strcpy(ctype, "vest" );
      clothing->weight = 5;
    }
    else if (!str_cmp(arg2,"tunic"))
    {
      clothing = create_object(get_obj_index(OBJ_VNUM_CLOTHING), 0);
      SET_BIT(clothing->wear_flags,ITEM_WEAR_BODY);
      strcpy(ctype, "tunic" );
      clothing->weight = 15;
    }
    else if (!str_cmp(arg2,"gloves"))
    {
      clothing = create_object(get_obj_index(OBJ_VNUM_CLOTHING), 0);
      SET_BIT(clothing->wear_flags,ITEM_WEAR_HANDS);
      strcpy(ctype, "pair of gloves" );
      clothing->weight = 5;
    }
    else if (!str_cmp(arg2,"boots"))
    {
      clothing = create_object(get_obj_index(OBJ_VNUM_CLOTHING), 0);
      SET_BIT(clothing->wear_flags,ITEM_WEAR_FEET);
      strcpy(ctype, "pair of boots" );
      clothing->weight = 10;
    }
    else if (!str_cmp(arg2,"pants"))
    {
      clothing = create_object(get_obj_index(OBJ_VNUM_CLOTHING), 0);
      SET_BIT(clothing->wear_flags,ITEM_WEAR_LEGS);
      strcpy(ctype, "pair of pants" );
      clothing->weight = 15;
    }
    else if (!str_cmp(arg2,"belt"))
    {
      clothing = create_object(get_obj_index(OBJ_VNUM_CLOTHING), 0);
      SET_BIT(clothing->wear_flags,ITEM_WEAR_WAIST);
      strcpy(ctype, "belt" );
      clothing->weight = 5;
    }
    else if (!str_cmp(arg2,"cloak"))
    {
      clothing = create_object(get_obj_index(OBJ_VNUM_CLOTHING), 0);
      SET_BIT(clothing->wear_flags,ITEM_WEAR_ABOUT);
      strcpy(ctype, "cloak" );
      clothing->weight = 20;
    }
    else if (!str_cmp(arg2,"whip"))
    {
      clothing = create_object(get_obj_index(OBJ_VNUM_FORGE_WEAPON), 0);

      clothing->value[0] = 13; //set the condition to perfect
      if(ch->level < 10)	// sets the num dice
        clothing->value[1] = 4;
      else if(ch->level < 20)
        clothing->value[1] = 6;
      else if(ch->level < 30)
        clothing->value[1] = 8;
      else if(ch->level < 40)
        clothing->value[1] = 10;
      else if(ch->level < 50)
        clothing->value[1] = 12;
      else if(ch->level < 60)
        clothing->value[1] = 14;
      else if(ch->level < 70)
        clothing->value[1] = 16;
      else if(ch->level < 80)
        clothing->value[1] = 18;
      else if(ch->level < 90)
        clothing->value[1] = 20;
      else
        clothing->value[1] = 22;


      clothing->value[2] = ch->level* 2;  //sets the size dice
      if (clothing->value[2] <= 20)
        clothing->value[2] = 20;

      clothing->level = ch->level;
      clothing->cost = 100;
      clothing->value[0] = 13;
      clothing->value[3] = 4;
      clothing->weight = 10;

      sprintf( buf, "tailored leather whip" );
      STRFREE( clothing->name );
      clothing->name = STRALLOC (buf);
      sprintf( buf, "a handmade tailored leather whip");
      STRFREE( clothing->short_descr );
      clothing->short_descr = STRALLOC ( buf );
      sprintf( buf, "A handmade tailored leather whip by %s", ch->name);
      STRFREE( clothing->description );
      clothing->description = STRALLOC ( buf );
      obj_to_char( clothing, ch );
      extract_obj( material );
      send_to_char("You snip and sew, creating a new leather whip.\n\r", ch);
      act( AT_ACTION, "$n snips and sews creating a new leather whip.", ch, NULL, NULL, TO_ROOM );
      learn_from_success( ch, gsn_tailor );
      return;

    }
    else
    {
      send_to_char( "Available clothing types:  cap, scarf, gloves, boots, belt, pants, tunic, cloak\n\r", ch);
      return;
    }

    random_number = number_range(0, 9);
    switch( random_number )
    {
    case 0:
      strcpy(exdesc, "fringed" );
      break;
    case 1:
      strcpy(exdesc, "embroidered" );
      break;
    case 2:
      strcpy(exdesc, "lacy"    );
      break;
    case 3:
      strcpy(exdesc, "scalloped" );
      break;
    case 4:
      strcpy(exdesc, "reinforced" );
      break;
    case 5:
      strcpy(exdesc, "stitched" );
      break;
    case 6:
      strcpy(exdesc, "double-stitched" );
      break;
    case 7:
      strcpy(exdesc, "patched" );
      break;
    case 8:
      strcpy(exdesc, "tailored" );
      break;
    case 9:
      strcpy(exdesc, "woven" );
      break;
    }
    separate_obj( material );
    obj_from_char( material );
    clothing->level = ch->level;
    clothing->cost = ( ch->level ) * 75;


    clothing->value[0] = ch->level / 4 + 5;
    if (clothing->value[0] < 5)
      clothing->value[0] = 5;
    clothing->value[1] = clothing->value[0];
    clothing->value[3] = 13;
    SET_BIT(clothing->item_type,ITEM_ARMOR);
    SET_BIT(clothing->wear_flags,ITEM_TAKE);
    sprintf( buf, "%s %s", exdesc, ctype );
    STRFREE( clothing->name );
    clothing->name = STRALLOC (buf);
    sprintf( buf, "a handmade %s %s", exdesc, ctype );
    STRFREE( clothing->short_descr );
    clothing->short_descr = STRALLOC ( buf );
    sprintf( buf, "A handmade %s crafted by %s", ctype, ch->name);
    STRFREE( clothing->description );
    clothing->description = STRALLOC ( buf );
    obj_to_char( clothing, ch );
    extract_obj( material );
    send_to_char("You snip and sew, creating a new piece of clothing.\n\r", ch);
    act( AT_ACTION, "$n snips and sews creating a new piece of clothing.", ch, NULL, NULL, TO_ROOM );
    learn_from_success( ch, gsn_tailor );
    return;
  }

  else
    random_number = number_range(0, 100);
  if (random_number < 20) /*did the sewkit break?*/
  {

    act( AT_ACTION, "$n pulls too hard on the needle and it breaks!", ch, NULL, NULL, TO_ROOM);
    send_to_char( "You pull too hard on the needle and it breaks!\n\r", ch );
    extract_obj( sewkit );
    learn_from_failure( ch, gsn_tailor );
    return;
  }
  else if (random_number > 20 && random_number < 40) /*small chance to loose all your material*/
  {
    send_to_char( "Your thread knots, and your material is ruined.\n\r", ch);
    act( AT_ACTION, "$n gets a knot in the thread and ruins the material.", ch, NULL, NULL, TO_ROOM);
    extract_obj( material );
    learn_from_failure( ch, gsn_tailor );
    return;
  }

  else if (random_number > 40 && random_number < 60)
  {
    send_to_char("You snip and sew, but only make a mess.\n\r", ch);
    act( AT_ACTION, "$n snips and sews but doesn't make anything useful.", ch, NULL, NULL, TO_ROOM);
    learn_from_failure( ch, gsn_tailor );
    return;
  }

  else if (random_number >60 && random_number < 100)
  {
    send_to_char("A small tear appears in the fabric, destroying all your work.\n\r", ch);
    act( AT_ACTION, "$n tears the fabric, making a total mess.", ch, NULL, NULL, TO_ROOM);
    learn_from_failure( ch, gsn_tailor );
    return;
  }
}

/*Dye clothing skill by Tamarae -(tamarae@zdnetonebox.com) written for The Kravothian Mysts
 *This Dyeing skill will allow a tailor to change the color of a piece of handmade clothing by
 *using a dye.  Nice touch for RP muds.  Part of the Tailoring group by Tamarae
 */

/*Dye clothing skill by Tamarae -(tamarae@zdnetonebox.com)
 *Syntax: dye <clothing>
 */
/* Ported dye to smaug1.4a 12-22-01 Vladaar */
/* Cleaned up and updated to SmaugFuss Tommi Jan 2005 */


void do_dye( CHAR_DATA *ch, char *argument )
{
  char arg1[MAX_INPUT_LENGTH];
  char arg2[MAX_INPUT_LENGTH];
  char buf[MAX_INPUT_LENGTH];
  OBJ_DATA *clothing, *dye;
  int chance2;

  chance2 = (LEARNED(ch,gsn_dye));
  /* Do we have the skill? */
  if ( !IS_NPC(ch) && !(LEARNED(ch,gsn_dye)))
  {
    send_to_char( "You better go and learn how to dye things first!.\n\r", ch );
    return;
  }

  /* Do we have the components? */

  argument = one_argument( argument, arg1 );
  if ( arg1[0] == '\0' )
  {
    send_to_char( "Dye what?\n\r", ch );
    send_to_char("Syntax: Dye (object) <color>\n\r", ch);
    send_to_char("Available colors are: &rRed &BBlue &pPurple &YYellow &WWhite &bDblue &GGreen &CCyan &OBrown &gDgreen &cDcyan.\n\r", ch );
    return;
  }

  if ( ( clothing = get_obj_carry( ch, arg1 ) ) == NULL )
  {
    send_to_char( "You do  not have anything to dye.\n\r", ch );
    return;
  }

  argument = one_argument( argument, arg2 );
  if ( arg2[0] == '\0' )
  {
    send_to_char( "Which color?\n\r", ch );
    send_to_char("Available colors are: &rRed &BBlue &pPurple &YYellow &WWhite &bDblue &GGreen &CCyan &OBrown &gDgreen &cDcyan.\n\r", ch );
    return;
  }

  dye  = get_eq_char(ch,WEAR_HOLD);
  if (dye == NULL || dye->item_type != ITEM_DYE)
  {
    send_to_char("You need a set of dyes.\n\r",ch);
    return;
  }

  if (clothing->pIndexData->vnum != OBJ_VNUM_CLOTHING)
  {
    send_to_char("Sorry, you many only dye handmade clothing types.\n\r", ch);
    return;
  }

  /* dye the clothing - success! */
  if ( can_use_skill(ch, number_percent(),gsn_dye ) )
  {

    if (!str_cmp(arg2,"red"))
    {
      sprintf( buf, "&r%s&w", clothing->short_descr );
      STRFREE( clothing->short_descr );
      clothing->short_descr = STRALLOC( buf );
    }

    else if (!str_cmp(arg2,"blue"))
    {
      sprintf( buf, "&B%s&w", clothing->short_descr );
      STRFREE( clothing->short_descr );
      clothing->short_descr = STRALLOC( buf );
    }

    else if (!str_cmp(arg2,"purple"))
    {
      sprintf( buf, "&p%s&w", clothing->short_descr );
      STRFREE( clothing->short_descr );
      clothing->short_descr = STRALLOC( buf );
    }

    else if (!str_cmp(arg2,"yellow"))
    {
      sprintf( buf, "&Y%s&w", clothing->short_descr );
      STRFREE( clothing->short_descr );
      clothing->short_descr = STRALLOC( buf );
    }
    else if (!str_cmp(arg2,"white"))
    {
      sprintf( buf, "&W%s&w", clothing->short_descr );
      STRFREE( clothing->short_descr );
      clothing->short_descr = STRALLOC( buf );
    }

    else if (!str_cmp(arg2,"dblue"))
    {
      sprintf( buf, "&b%s&w", clothing->short_descr );
      STRFREE( clothing->short_descr );
      clothing->short_descr = STRALLOC( buf );
    }
    else if (!str_cmp(arg2,"green"))
    {
      sprintf( buf, "&g%s&w", clothing->short_descr );
      STRFREE( clothing->short_descr );
      clothing->short_descr = STRALLOC( buf );
    }

    else if (!str_cmp(arg2,"cyan"))
    {
      sprintf( buf, "&C%s&w", clothing->short_descr );
      STRFREE( clothing->short_descr );
      clothing->short_descr = STRALLOC( buf );
    }

    else if (!str_cmp(arg2,"dgreen"))
    {
      sprintf( buf, "&G%s&w", clothing->short_descr );
      STRFREE( clothing->short_descr );
      clothing->short_descr = STRALLOC( buf );
    }
    else if (!str_cmp(arg2,"dcyan"))
    {
      sprintf( buf, "&c%s", clothing->short_descr );
      STRFREE( clothing->short_descr );
      clothing->short_descr = STRALLOC( buf );
    }
    else if (!str_cmp(arg2,"brown"))
    {
      sprintf( buf, "&O%s&w", clothing->short_descr );
      STRFREE( clothing->short_descr );
      clothing->short_descr = STRALLOC( buf );
    }
    else
    {
      send_to_char("Available colors are: &rRed &BBlue &pPurple &YYellow &WWhite &bDblue &GGreen &CCyan &OBrown &gDgreen &cDcyan.\n\r", ch );
      return;
    }
    extract_obj( dye );
    send_to_char("You dye the material elegantly.\n\r", ch);
    act( AT_IMMORT, "$n dyes the material elegantly.", ch, NULL, NULL, TO_ROOM );
    learn_from_success(ch, gsn_dye);

  }
  else  /* failure of skill */
  {
    extract_obj( dye );
    send_to_char("You fail to dye the clothing properly.\n\r", ch);
    act( AT_IMMORT, "$n fails to dye the clothing properly.", ch, NULL, NULL, TO_ROOM );
    learn_from_failure(ch, gsn_dye);
  }
}



void do_mining( CHAR_DATA *ch, char *argument )
{
  char arg [MAX_INPUT_LENGTH];
  OBJ_DATA *obj, *bonus;
  OBJ_INDEX_DATA *ore;
  int add_weight, range, vnum, random_number;
  int CHANCE = 80;
  /* Ore types default to dirt as a failsafe
     PC's will now NOT fail to mine in any room
     But just dig up dirt in the room they are mining 
     in City will always fail.
  */
  int ore_rare = OBJ_VNUM_ORE_DIRT;
  int ore_ultrarare = OBJ_VNUM_ORE_DIRT;
  int ore_common = OBJ_VNUM_ORE_DIRT;
  int ore_ultracommon = OBJ_VNUM_ORE_DIRT;

  if ( IS_NPC(ch) )
  {
    send_to_char( "Mobs cannot use this skill.\n\r", ch );
    return;
  }
  if ( IS_AFFECTED( ch, AFF_CHARM ) )
  {
    send_to_char( "You can't concentrate enough for that.\n\r", ch );
    return;
  }
  if ( ch->mount )
  {
    send_to_char( "You can't do that while mounted.\n\r", ch );
    return;
  }
  if( IS_PLR_FLAG( ch, PLR_ONMAP ) )
  {
    send_to_char( "You cannot mine out in the wilderness.\n\r", ch );
    return;
  }
  if(ch->in_room->sector_type == SECT_CITY)
  {
    send_to_char( "You will not find any ore inside a city.\n\r", ch );
    return;
  }
  if ( ch->move < 20 )
  {
    send_to_char( "You do not have enough movement left to mine.\n\r", ch );
    return;
  }
   if (ch->carry_weight > can_carry_w(ch))
   {
   send_to_char("You look to be over loaded and cannot mine anymore",ch);
   return;
   }
  
  switch( ch->substate )
  {
  default:

    add_timer( ch, TIMER_DO_FUN, UMIN(skill_table[gsn_mine]->beats, 3), do_mining, 1);
    ch->alloc_ptr = str_dup( arg );
    send_to_char( "You begin mining...\n\r", ch );
    act( AT_PLAIN, "$n begins mining...", ch, NULL, NULL, TO_ROOM );
    return;

  case 1:
    if ( !ch->alloc_ptr )
    {
      send_to_char( "Your mining was interrupted!\n\r", ch );
      act( AT_PLAIN, "$n's mining was interrupted!", ch, NULL, NULL, TO_ROOM );
      bug( "do_mining: alloc_ptr NULL", 0 );
      return;
    }
    strcpy( arg, ch->alloc_ptr );
    DISPOSE( ch->alloc_ptr );
    break;

  case SUB_TIMER_DO_ABORT:
    DISPOSE( ch->alloc_ptr );
    ch->substate = SUB_NONE;
    send_to_char( "You stop mining...\n\r", ch );
    act( AT_PLAIN, "$n stops mining...", ch, NULL, NULL, TO_ROOM );
    return;
  }

  ch->substate = SUB_NONE;

  /* ORE ULTRA RARE 5% chance to mine*/
  if (xIS_SET(ch->in_room->room_flags,ROOM_MITHRIL))
  {
    ore_ultrarare = OBJ_VNUM_ORE_MITHRIL;
  }

  else if (xIS_SET(ch->in_room->room_flags,ROOM_BLACKMITE))
  {
    ore_ultrarare = OBJ_VNUM_ORE_BLACKMITE;
  }

  else if (xIS_SET(ch->in_room->room_flags,ROOM_RUNITE))
  {
    ore_ultrarare = OBJ_VNUM_ORE_RUNITE;
  }

  else if (xIS_SET(ch->in_room->room_flags,ROOM_ADAMANTITE))
  {
    ore_ultrarare = OBJ_VNUM_ORE_ADAMANT;
  }
  
  /* ORE RARE 10 % chance to mine*/
  if (xIS_SET(ch->in_room->room_flags,ROOM_TITANIUM))
  {
    ore_rare = OBJ_VNUM_ORE_TITANIUM;
  }

  /* ORE COMMON 15% chance to mine*/
  if (xIS_SET(ch->in_room->room_flags,ROOM_GOLD))
  {
    ore_common = OBJ_VNUM_ORE_GOLD;
  }

  else if (xIS_SET(ch->in_room->room_flags,ROOM_SILVER))
  {
    ore_common = OBJ_VNUM_ORE_SILVER;
  }

  /* ORE VERY COMMON 25% chance to mine*/
  if (xIS_SET(ch->in_room->room_flags,ROOM_IRON))
  {
    ore_ultracommon = OBJ_VNUM_ORE_IRON;
  }
  /* Gain less chance of dirt and rocks if using pick or miners helm*/
  if ( ( bonus = get_eq_char( ch, WEAR_HOLD ) ) != NULL )
    {
      if (bonus->pIndexData->vnum == OBJ_VNUM_QUEST_PICK)
        CHANCE -= 10;
    }
  if ( ( bonus = get_eq_char( ch, WEAR_HEAD ) ) != NULL )
    {
      if (bonus->pIndexData->vnum == OBJ_VNUM_QUEST_HELM)
        CHANCE -= 10;
    }
  /* Roll to determine what ore you get*/
  random_number = number_range(0, CHANCE);
  if (random_number < 6)
  {
    vnum = ore_ultrarare;
  }
  else if (random_number < 16)
  {
    vnum = ore_rare;
  }
  else if (random_number < 31)
  {
    vnum = ore_common;
  }
  else if (random_number < 56)
  {
    vnum = ore_ultracommon;
  }
  else
  {
    vnum = OBJ_VNUM_ORE_DIRT;
  }

  /* Roll to determine how much ore weight*/
  switch(range = number_range( 1, 4 ))
  {
  case 1:
    add_weight = 1;
    break;
  case 2:
    add_weight = 2;
    break;
  case 3:
    add_weight = 3;
    break;
  case 4:
    add_weight = 4;
    break;
  }
  ore = get_obj_index( vnum );
  if ( ore == NULL )
  {
    bug( "do_mining: Cannot locate item for vnum %d", vnum );
    send_to_char( "Oops. Slight bug here. The immortals have been notified.\n\r", ch );
    return;
  }
  /* Check we have the ore object*/
  /* Apply new weight to the ore*/
  if ( number_percent() < ch->pcdata->learned[gsn_mine] )
  {
    if ( ( obj = get_obj_vnum( ch, vnum ) ) != NULL ) //we have the object now we need to add the weight to it
    {
      obj->weight += add_weight;
 //     obj_from_char(obj);
 //     obj_to_char(obj, ch);
      ch->carry_weight += add_weight;
      ch_printf( ch, "After some intense mining, you unearth %s!\n\r", obj->short_descr );
    }
    if ( ( obj = get_obj_vnum( ch, vnum ) ) == NULL ) //we dont have the object better put one in the inventory
    {
      obj = create_object( ore, 1 );
      obj = obj_to_char( obj, ch );
      ch_printf( ch, "After some intense mining, you unearth %s!\n\r", obj->short_descr );
    }

    
    learn_from_success( ch, gsn_mine );
    ch->move -= 20; //take this much if your sucessfull
    if ( ch->move < 1 )
      ch->move = 0;
  }
  else
  {
    send_to_char("You fail to find anything usefull",ch);
    learn_from_success( ch, gsn_mine );
    ch->move -= 10; //take this much if your sucessfull
    if ( ch->move < 1 )
      ch->move = 0;
  }

  return;
}


void do_restring( CHAR_DATA *ch, char *argument )
{

  CHAR_DATA *mob = NULL;
  char arg [MAX_INPUT_LENGTH];
  char arg1 [MAX_INPUT_LENGTH];
  char arg2 [MAX_INPUT_LENGTH];
  OBJ_DATA *obj = NULL;
  int value;

  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-Name> <Field> <String>\n\r",ch);
    send_to_char("    fields: name short long\n\r",ch);
    return;
  }

  if ( ( obj = get_obj_world( ch, arg ) ) == NULL )
  {
    send_to_char( "There is nothing like that in all the realms.\n\r", ch );
    return;
  }

  for ( mob = ch->in_room->first_person; mob; mob = ch->next_in_room )
  {
    if ( IS_NPC(mob) && xIS_SET(mob->act, ACT_RESTRING) )
      break;
  }

  if ( !mob  )
  {
    send_to_char( "You need to be at a restringer to do that.\n\r", ch );
    return;
  }

  if( ch->gold < 2000)
  {
    send_to_char( "&rYou do not have enough money to restring anything!\n\r", ch);
    return;
  }

  strcpy( arg, obj->name );
  separate_obj( obj );
  value = atoi( arg2 );
  if ( !str_cmp( arg1, "name" ) )
  {
    STRFREE( obj->name );
    obj->name = STRALLOC( arg2 );
    send_to_char( "Ok.\n\r", ch );
    ch->gold -= 2000;
    return;
  }

  if ( !str_cmp( arg1, "short" ) )
  {
    STRFREE( obj->short_descr );
    obj->short_descr = STRALLOC( arg2 );
    send_to_char( "Ok.\n\r", ch );
    ch->gold -= 2000;
    return;
  }

  if ( !str_cmp( arg1, "long" ) )
  {
    STRFREE( obj->description );
    obj->description = STRALLOC( arg2 );
    send_to_char( "Ok.\n\r", ch );
    ch->gold -= 2000;
    return;
  }
}

void do_forge(CHAR_DATA *ch, char *argument)
{
  OBJ_DATA *ore;
  OBJ_DATA *forged_item;
  AFFECT_DATA *paf;
  CHAR_DATA *forge = NULL;
  bool set_weapon = FALSE;
  char arg[MAX_INPUT_LENGTH];
  char arg1[MAX_INPUT_LENGTH];
  char buf[MAX_STRING_LENGTH];
  char ore_name[20], obj_name[20];
  int item_type, ore_remove, ore_apply_1, ore_apply_2, apply_amount, apply_amount_2, weapon_type, weapon_mod,
  weapon_weight, armor_weight, dam_mod, ac_mod, cost_mod;


  argument = one_argument( argument, arg );
  argument = one_argument( argument, arg1 );

  for ( forge = ch->in_room->first_person; forge; forge = forge->next_in_room )
  {
    if ( IS_NPC(forge) && xIS_SET(forge->act, ACT_FORGE) )
    {
      break;
    }
    else
    {
      send_to_char("You need to be at a blacksmith to be able to forge!\n\r", ch);
      return;
    }
  }

  if ( arg[0] == '\0' || arg1[0] == '\0' )
  {
    send_to_char("Syntax: forge  <ore> <item_type>\n\r",ch);
    send_to_char("Example: forge mithril sword\n\r",ch);
    send_to_char("Also see help forge for more details.\n\r",ch);
    return;
  }


  //determine if ch has ore and assign values to object based on ore type
  if ( ( ore = get_obj_carry( ch, arg ) ) == NULL )
  {
    sprintf(buf, "Sorry, you do not have any '%s' ore.\n\r", arg);
    send_to_char(buf,ch);
    return;
  }
  if ( ore->item_type != ITEM_ORE )
  {
    send_to_char("That is not real ore, you need to go and mine the real thing!!!\n\r",ch);
    return;
  }
  if (!str_cmp(arg, ore->name))
  {
    if (!str_cmp(arg,"mithril"))
    {
      strcpy(ore_name, "Mithril" );
      ore_apply_1 = APPLY_HITROLL;
      ore_apply_2 = APPLY_DAMROLL;
      apply_amount = ch->level / 10 + number_fuzzy(4);
      apply_amount_2 = ch->level / 10 + number_fuzzy(4);
      dam_mod = 6;


    }

    else if (!str_cmp(arg,"blackmite"))
    {
      strcpy(ore_name, "Blackmite" );
      ore_apply_1 = APPLY_HIT;
      ore_apply_2 = APPLY_SAVING_ROD;
      apply_amount = ch->level / 10 + number_fuzzy(4);
      apply_amount_2 = ch->level / 20 + number_fuzzy(4)*-1;
      dam_mod = 4;
    }

    else if (!str_cmp(arg,"adamantite"))
    {
      strcpy(ore_name, "Adamantite" );
      ore_apply_1 = APPLY_MANA;
      ore_apply_2 = APPLY_STR;
      apply_amount = ch->level / 10 + number_fuzzy(4);
      apply_amount_2 = 3 + number_fuzzy(4);
      dam_mod = 2;
    }

    else if (!str_cmp(arg,"silver"))
    {
      strcpy(ore_name, "Silver" );
      ore_apply_1 = APPLY_WIS;
      ore_apply_2 = APPLY_CHA;
      apply_amount = 3 + number_fuzzy(4);
      apply_amount_2 = 3 + number_fuzzy(4);
      dam_mod = 0;
    }

    else if (!str_cmp(arg,"runite"))
    {
      strcpy(ore_name, "Runite" );
      ore_apply_1 = APPLY_AC;
      ore_apply_2 = APPLY_SAVING_SPELL;
      apply_amount = (ch->level / 10 + number_fuzzy(4))*-1;
      apply_amount_2 = ch->level / 20 + number_fuzzy(4)*-1;
      dam_mod = 6;
    }

    else if (!str_cmp(arg,"gold"))
    {
      strcpy(ore_name, "Gold" );
      ore_apply_1 = APPLY_LCK;
      ore_apply_2 = APPLY_INT;
      apply_amount = 3 + number_fuzzy(4);
      apply_amount_2 = 3 + number_fuzzy(4);
      dam_mod = 1;
    }

    else if (!str_cmp(arg,"titanium"))
    {
      strcpy(ore_name, "Titanium" );
      ore_apply_1 = APPLY_MOVE;
      ore_apply_2 = APPLY_CON;
      apply_amount = ch->level / 10 + number_fuzzy(4);
      apply_amount_2 = 3 + number_fuzzy(4);
      dam_mod = 2;

    }
    else if (!str_cmp(arg,"iron"))
    {
      strcpy(ore_name, "Iron" );
      ore_apply_1 = APPLY_MOVE;
      ore_apply_2 = APPLY_CON;
      apply_amount = ch->level / 10 + number_fuzzy(4);
      apply_amount_2 = 3 + number_fuzzy(4);
      dam_mod = 2;

    }
  }
  else
  {
    send_to_char( "That is not propper ore, pleace go and mine it.\n\r", ch );
    return;
  }

  // determine the object type and set the values on it.
  // weapons section
  if (!str_cmp(arg1,"sword"))
  {
    set_weapon = TRUE;
    strcpy(obj_name, "Sword" );
    weapon_type = 1;
    ore_remove = 50;
    weapon_mod = 0;
    weapon_weight = 10;
    ore_remove = 40;
    cost_mod = 10;
  }

  else if (!str_cmp(arg1,"broadsword"))
  {
    set_weapon = TRUE;
    strcpy(obj_name, "Broadsword" );
    weapon_type = 3;
    ore_remove = 60;
    weapon_mod = 1;
    weapon_weight = 14;
    ore_remove = 50;
    cost_mod = 12;
  }

  else if (!str_cmp(arg1,"polearm"))
  {
    set_weapon = TRUE;
    strcpy(obj_name, "Polearm" );
    weapon_type = 8;
    ore_remove = 70;
    weapon_mod = 3;
    weapon_weight = 16;
    ore_remove = 60;
    cost_mod = 14;
  }
  else if (!str_cmp(arg1,"mace"))
  {
    set_weapon = TRUE;
    strcpy(obj_name, "Mace" );
    weapon_type = 7;
    ore_remove = 50;
    weapon_mod = 1;
    weapon_weight = 8;
    ore_remove = 35;
    cost_mod = 9;
  }
  else if (!str_cmp(arg1,"dagger"))
  {
    set_weapon = TRUE;
    strcpy(obj_name, "Dagger" );
    weapon_type = 11;
    ore_remove = 40;
    weapon_mod = -1;
    weapon_weight = 5;
    ore_remove = 20;
    cost_mod = 6;
  }
  else if (!str_cmp(arg1,"whip"))
  {
    set_weapon = TRUE;
    strcpy(obj_name, "Whip" );
    weapon_type = 4;
    ore_remove = 40;
    weapon_mod = -2;
    weapon_weight = 7;
    ore_remove = 30;
    cost_mod = 7;
  }
  else if (!str_cmp(arg1,"claw"))
  {
    set_weapon = TRUE;
    strcpy(obj_name, "Claw" );
    weapon_type = 5;
    ore_remove = 30;
    weapon_mod = -3;
    weapon_weight = 5;
    ore_remove = 20;
    cost_mod = 5;
  }
  else if (!str_cmp(arg1,"crossbow"))
  {
    set_weapon = TRUE;
    strcpy(obj_name, "Crossbow" );
    weapon_type = 13;
    ore_remove = 45;
    weapon_mod = -1;
    weapon_weight = 10;
    ore_remove = 40;
    cost_mod = 10;
  }
  else if (!str_cmp(arg1,"longbow"))
  {
    set_weapon = TRUE;
    strcpy(obj_name, "Longbow" );
    weapon_type = 14;
    ore_remove = 55;
    weapon_mod = 2;
    weapon_weight = 12;
    ore_remove = 50;
    cost_mod = 12;
  }

  // armours section
  else if (!str_cmp(arg1,"ring"))
  {
    item_type = ITEM_WEAR_FINGER;
    strcpy(obj_name, "Ring" );
    armor_weight = 3;
    ac_mod = 0;
    ore_remove = 20;
    cost_mod = 3;
  }
  else if (!str_cmp(arg1,"cloak"))
  {
    item_type = ITEM_WEAR_NECK;
    strcpy(obj_name, "Cloak" );
    armor_weight = 5;
    ac_mod = 2;
    ore_remove = 60;
    cost_mod = 5;
  }
  else if (!str_cmp(arg1,"vest"))
  {
    item_type = ITEM_WEAR_BODY;
    strcpy(obj_name, "Vest" );
    armor_weight = 7;
    ac_mod = 2;
    ore_remove = 50;
    cost_mod = 7;
  }
  else if (!str_cmp(arg1,"helmet"))
  {
    item_type = ITEM_WEAR_HEAD;
    strcpy(obj_name, "Helmet" );
    armor_weight = 7;
    ac_mod = 5;
    ore_remove = 50;
    cost_mod = 7;
  }
  else if (!str_cmp(arg1,"leggings"))
  {
    item_type = ITEM_WEAR_LEGS;
    strcpy(obj_name, "pair of Leggings" );
    armor_weight = 5;
    ac_mod = 3;
    ore_remove = 45;
    cost_mod = 5;
  }
  else if (!str_cmp(arg1,"boots"))
  {
    item_type = ITEM_WEAR_FEET;
    strcpy(obj_name, "pair of boots" );
    armor_weight = 4;
    ac_mod = 5;
    ore_remove = 40;
    cost_mod = 4;
  }
  else if (!str_cmp(arg1,"gloves"))
  {
    item_type = ITEM_WEAR_HANDS;
    strcpy(obj_name, "pair of Gloves" );
    armor_weight = 3;
    ac_mod = 3;
    ore_remove = 30;
    cost_mod = 3;
  }
  else if (!str_cmp(arg1,"sleeves"))
  {
    item_type = ITEM_WEAR_ARMS;
    strcpy(obj_name, "pair of Sleeves" );
    armor_weight = 5;
    ac_mod = 3;
    ore_remove = 35;
    cost_mod = 5;
  }
  else if (!str_cmp(arg1,"shield"))
  {
    item_type = ITEM_WEAR_SHIELD;
    strcpy(obj_name, "Shield" );
    armor_weight = 10;
    ac_mod = 10;
    ore_remove = 80;
    cost_mod = 10;
  }
  else if (!str_cmp(arg1,"chestplate"))
  {
    item_type = ITEM_WEAR_ABOUT;
    strcpy(obj_name, "Chestplate" );
    armor_weight = 14;
    ac_mod = 5;
    ore_remove = 70;
    cost_mod = 14;
  }
  else if (!str_cmp(arg1,"belt"))
  {
    item_type = ITEM_WEAR_WAIST;
    strcpy(obj_name, "Belt" );
    armor_weight = 3;
    ac_mod = 0;
    ore_remove = 20;
    cost_mod = 3;
  }
  else if (!str_cmp(arg1,"bracer"))
  {
    item_type = ITEM_WEAR_WRIST;
    strcpy(obj_name, "Bracer" );
    armor_weight = 4;
    ac_mod = 2;
    ore_remove = 25;
    cost_mod = 4;
  }
  else if (!str_cmp(arg1,"earing"))
  {
    item_type = ITEM_WEAR_EARS;
    strcpy(obj_name, "Earing" );
    armor_weight = 1;
    ac_mod = 0;
    ore_remove = 15;
    cost_mod = 2;
  }
  else if (!str_cmp(arg1,"visor"))
  {
    item_type = ITEM_WEAR_FACE;
    strcpy(obj_name, "Visor" );
    armor_weight = 2;
    ac_mod = 0;
    ore_remove = 20;
    cost_mod = 3;
  }
  else if (!str_cmp(arg1,"glasses"))
  {
    item_type = ITEM_WEAR_EYES;
    strcpy(obj_name, "Glasses" );
    armor_weight = 2;
    ac_mod = -5;
    ore_remove = 15;
    cost_mod = 3;
  }
  else if (!str_cmp(arg1,"backpack"))
  {
    item_type = ITEM_WEAR_BACK;
    strcpy(obj_name, "Backpack" );
    armor_weight = 10;
    ac_mod = 2;
    ore_remove = 60;
    cost_mod = 10;
  }
  else if (!str_cmp(arg1,"anklet"))
  {
    item_type = ITEM_WEAR_ANKLE;
    strcpy(obj_name, "Anklet" );
    armor_weight = 2;
    ac_mod = 1;
    ore_remove = 20;
    cost_mod = 3;
  }
  else
  {
    send_to_char("Sorry we do not have that object type.\n\r", ch);
    return;
  }



  if (ore_remove > ore->weight)
  {
    send_to_char( "You do not have enought ore to make that object\n\r", ch);
    return;
  }

  ore->weight -= ore_remove; //remove the amount of ore used to make the object
  ch->carry_weight -= ore_remove;
  if(ore->weight <=2)
  {
    separate_obj( ore );
    obj_from_char( ore );
  }


  if(!set_weapon)
  {
    forged_item = create_object(get_obj_index(OBJ_VNUM_FORGE_ARMOR), 0);
    SET_BIT(forged_item->wear_flags,item_type);
    forged_item->weight = armor_weight;
    forged_item->value[0] = ((ch->level/4 +5) + dam_mod + ac_mod);  //sets the armor
    forged_item->value[3] = 12; //set the condition to perfect

    send_to_char("You work and work the ore, turning it into a peice of armor.\n\r", ch);
    act( AT_ACTION, "$n works and work the ore, turning it into a peice of armor.", ch, NULL, NULL, TO_ROOM );
  }
  if(set_weapon)
  {
    forged_item = create_object(get_obj_index(OBJ_VNUM_FORGE_WEAPON), 0);

    forged_item->value[0] = 13; //set the condition to perfect
    if(ch->level < 10)	// sets the num dice
      forged_item->value[1] = 4;
    else if(ch->level < 20)
      forged_item->value[1] = 6;
    else if(ch->level < 30)
      forged_item->value[1] = 8;
    else if(ch->level < 40)
      forged_item->value[1] = 10;
    else if(ch->level < 50)
      forged_item->value[1] = 12;
    else if(ch->level < 60)
      forged_item->value[1] = 14;
    else if(ch->level < 70)
      forged_item->value[1] = 16;
    else if(ch->level < 80)
      forged_item->value[1] = 18;
    else if(ch->level < 90)
      forged_item->value[1] = 20;
    else
      forged_item->value[1] = 22;


    forged_item->value[2] = ((ch->level/10) + dam_mod) * (forged_item->value[1] + weapon_mod );  //sets the size dice
    if (forged_item->value[2] <= 20)
      forged_item->value[2] = 20;

    forged_item->value[3] = weapon_type;
    forged_item->weight = weapon_weight;

    send_to_char("You work and work the ore, turning it into a new weapon.\n\r", ch);
    act( AT_ACTION, "$n works and work the ore, turning it into a new weapon.", ch, NULL, NULL, TO_ROOM );

  }

  forged_item->level = ch->level;
  forged_item->cost = ( ch->level ) * cost_mod * number_fuzzy(10);


  /* right not lets set some effects on the eq based on differnt ore values */
  CREATE( paf, AFFECT_DATA, 1 );
  paf->type           = -1;
  paf->duration       = -1;
  paf->location       = ore_apply_1;
  paf->modifier       = apply_amount;
  xCLEAR_BITS(paf->bitvector);
  LINK( paf, forged_item->first_affect, forged_item->last_affect, next, prev );

  CREATE( paf, AFFECT_DATA, 1 );
  paf->type           = -1;
  paf->duration       = -1;
  paf->location       = ore_apply_2;
  paf->modifier       = apply_amount_2;
  xCLEAR_BITS(paf->bitvector);
  LINK( paf, forged_item->first_affect, forged_item->last_affect, next, prev );


  sprintf( buf, "%s %s", ore_name, obj_name );
  STRFREE( forged_item->name );
  forged_item->name = STRALLOC (buf);

  sprintf( buf, "A forged %s %s", ore_name, obj_name );
  STRFREE( forged_item->short_descr );
  forged_item->short_descr = STRALLOC (buf);

  sprintf( buf, "A %s %s forged by %s", ore_name, obj_name, ch->name );
  STRFREE( forged_item->description );
  forged_item->description = STRALLOC (buf);

  obj_to_char( forged_item, ch ); //finally you get the newly forged object

  learn_from_success(ch, gsn_forge);
  return;
}