inherit "/std/weapon";

#include <macros.h>
#include <wa_types.h>
#include <stdproperties.h>
#include <formulas.h>
#include <ss_types.h>
#include <tasks.h>

void
create_weapon()
{
    set_name("sword");
    set_adj(({ "black", "iced" }));
    set_short("black iced sword");
    set_long("A sword forged from strange, black ice.\n");

    set_default_weapon(30, 30, W_SWORD, W_SLASH | W_IMPALE, W_LEFT);

    add_prop(OBJ_M_NO_BUY, 1);
    add_prop(OBJ_I_VOLUME, 2800);
    add_prop(OBJ_I_WEIGHT, 9000);
    add_prop(OBJ_I_VALUE, F_VALUE_WEAPON(30, 30) + 1000);
}

/*
 * did_hit() is called whenever the weapon is used.  We redefine it
 * to do extra damage when we hit an elf.
 */
public varargs int
did_hit(int aid, string hdesc, int phurt, object enemy, int dt,
                int phit, int dam)
{
    int resistance;
    object attacker = query_wielded();

    /* did_hit() is called even when the weapon misses, so we need
     * to check if phurt < 0 before we do any special damage.  If
     * phurt < 0, then it was a missed attack.
     */
    if (phurt < 0)
    {
        return ::did_hit(aid, hdesc, phurt, enemy, dt, phit, dam);
    }

    /* We only want to do the special damage if the target is an elf,
     * and then only 1 in 10 attacks.
     */
    if ((enemy->query_race_name() == "elf") && !random(10))
    {
        attacker->catch_tell("The black iced sword emanates with strange energy, freezing an enemy.\n");
        enemy->catch_tell(attacker->query_The_possessive_name(enemy) +
            " black iced sword emanates with strange energy, freezing you.\n");
        enemy->tell_watcher(QCTPNAME(attacker) + " black iced sword " +
            "emanates with strange energy, freezing "+QCTPNAME(attacker)+".\n", attacker);

        /* Do the extra damage, taking the magic resistance into account */
    	enemy->hit_me(200 * (100 - resistance) / 100, MAGIC_DT,
            attacker, -1);

        /* Kill the target, if appropriate */
        if (enemy->query_hp() <= 0)
	{
            enemy->do_die(attacker);
	}
    }

    return ::did_hit(aid, hdesc, phurt, enemy, dt, phit, dam);
}
