
// THIS WORKS

void improve_wpn(CHAR_DATA * ch, int dtype, int right_hand)
{
    OBJ_DATA *wield;
    char      bufskill[20];
    char      buf[MAX_INPUT_LENGTH];
    int       dice1;
    int       dice2;
    int       trapper;
  int       max_skl = 200;
//    int       max_skl = max_wpn(ch);
    int       amount = 0;

    dice1 = number_percent();
    dice2 = number_percent();

    if (IS_NPC(ch))
        return;


	if (ch->class == 0 && ch->tier2 == 0 && ch->tier3 == 0
	&& ch->tier4 == 0 && ch->tier5 == 0) max_skl += 200;

        if (IS_DEMON(ch)) max_skl += 200;

        if (IS_ANGEL(ch)) max_skl += 350;
        if (IS_DARK_ANGEL(ch)) max_skl += 350;

        if (IS_NINJA(ch)) max_skl += 300;
        if (IS_PALADIN(ch)) max_skl += 350;
        if (IS_ANTIPALADIN(ch)) max_skl += 350;

        if (IS_TANARRI(ch)) max_skl += 200;
        if (IS_THIEF(ch)) max_skl += 150;
        if (IS_ELEMENTAL(ch)) max_skl += 200;
        if (IS_SHAPESHIFTER(ch)) max_skl += 200;
        if (IS_DROW(ch))
	{
	 max_skl += 300;
        if (IS_SET(ch->special, SPC_DROW_WAR)) max_skl += 100;
	else if (ch->generation < 3) max_skl += 100;
        }

        if (IS_BLADEMASTER(ch)) max_skl += 200;
        if (IS_MONK(ch)) max_skl += 300;
        if (IS_KAHN(ch)) max_skl += 200;

        if (IS_MAGE(ch)) max_skl += 100;

        if (IS_ASSASSIN(ch)) max_skl += 350;
        if (IS_DRAGON(ch)) max_skl += 100;
        if (IS_DEATHKNIGHT(ch)) max_skl += 350;

        if (IS_WEREWOLF(ch)) max_skl += 300;
        if (IS_VAMPIRE(ch)) max_skl += 350;

        if (IS_ANGEL(ch) && dtype == 1) max_skl += 150;
        if (IS_DARK_ANGEL(ch) && dtype == 1) max_skl += 150;
        if (IS_MONK(ch) && dtype == 1) max_skl += 150;
        if (IS_KAHN(ch) && dtype == 1) max_skl += 150;

	if (IS_BLADEMASTER(ch) && (dtype == WPN_KNIFE
	|| dtype == WPN_DAGGER || dtype == WPN_SHORTSWORD
	|| dtype == WPN_LONGSWORD || dtype == WPN_BASTARDSWORD
	|| dtype == WPN_BROADSWORD || dtype == WPN_SICKLE))
	max_skl += 200;



    if (right_hand == 1)
        wield = get_eq_char(ch, WEAR_WIELD);
    else if (right_hand == 2)
        wield = get_eq_char(ch, WEAR_HOLD);
    else if (right_hand == 4)
        wield = get_eq_char(ch, WEAR_THIRD);
    else if (right_hand == 4)
        wield = get_eq_char(ch, WEAR_FOURTH);
    else if (right_hand == 5)
        wield = get_eq_char(ch, WEAR_TWO_HANDED);
    else 
        wield = get_eq_char(ch, WEAR_TWO_HANDED2);

    if (wield == NULL)
        dtype = TYPE_HIT;
    if (dtype == TYPE_UNDEFINED)
    {
        dtype = TYPE_HIT;
        if (wield != NULL)
	{
	if (wield->item_type == ITEM_WEAPON)
            dtype += wield->value[3];
	}
    }
    if (dtype < 1000 || dtype > 1019)
        return;
    dtype -= 1000;
/*
    if (ch->generation == 2)
        max_skl += max_skl * 0.1;
    else if (ch->generation == 1)
        max_skl += max_skl * 0.2;
    if (max_skl > 1500)
        max_skl = 1500;
*/
    if (ch->wpn[dtype] >= max_skl)
        return;

    trapper = ch->wpn[dtype];
//    if ((dice1 > ch->wpn[dtype] || dice2 > ch->wpn[dtype])
//      || (dice1 >= 5 || dice2 >= 5))
//    {
        amount += 1;
        if (get_curr_wis(ch) > 25)
            amount += 1;
        if (get_curr_wis(ch) > 75)
            amount += 1;

        ch->wpn[dtype] += amount;

        if (ch->wpn[dtype] >= max_skl)
            ch->wpn[dtype] = max_skl;

     if (100 + get_curr_wis(ch) > number_range(1, 1500))
     {
        if (amount > 0 && ch->wpn[dtype] < max_skl)
        {
            if (wield == NULL || dtype == 0)
                sprintf(buf,
                        "#B--#WYour #Gunarmed combat #Wimproves by #R%d#B)#n.\n\r",
                        amount);
            else
                sprintf(buf,
                        "#B--#WYour skill with #Y%s #Wimproves by #R%d#B)#n\n\r",
                        wield->short_descr, amount);
            send_to_char(buf, ch);
        }
    }
    else
        return;
//    if (trapper == ch->wpn[dtype])
//        return;

    if (ch->wpn[dtype] == 1)
        sprintf(bufskill, "slightly skilled");
    else if (ch->wpn[dtype] == 26)
        sprintf(bufskill, "reasonable");
    else if (ch->wpn[dtype] == 51)
        sprintf(bufskill, "fairly competent");
    else if (ch->wpn[dtype] == 76)
        sprintf(bufskill, "highly skilled");
    else if (ch->wpn[dtype] == 101)
        sprintf(bufskill, "very dangerous");
    else if (ch->wpn[dtype] == 126)
        sprintf(bufskill, "extremely deadly");
    else if (ch->wpn[dtype] == 151)
        sprintf(bufskill, "an expert");
    else if (ch->wpn[dtype] == 176)
        sprintf(bufskill, "a master");
    else if (ch->wpn[dtype] == 200)
        sprintf(bufskill, "a grand master");
    else if (ch->wpn[dtype] == 201)
        sprintf(bufskill, "supremely skilled");
    else if (ch->wpn[dtype] == 501)
        sprintf(bufskill, "wicked skilled");
    else if (ch->wpn[dtype] == 1000)
        sprintf(bufskill, "divinely skilled");
    else
        return;

    if (wield == NULL || dtype == 0)
        sprintf(buf, "#GYou are now %s at unarmed combat.\n\r",
                bufskill);
    else
        sprintf(buf, "#GYou are now %s with %s.\n\r#n", bufskill,
                wield->short_descr);

    send_to_char(buf, ch);
    return;
}

