axeofdeception.c and axefuncs.c - examples for course 09

[previous example] [course09] [Table of contents] [next example]
/* Filename      : axeofdeception.c
 * Description   : a very special weapon
 *
 * written       : 05-10-1996 - Gunner
 * last modified : 11-07-1998 - Gunner
 * HTML-Version  : 06-02-2000 - Ghorwin
 */

#include <mudlib.h>
inherit I_WEAPON;

#define FUNC "/doc/crashcourse/course09/axefuncs"

create()
{
    ::create();
    set_name("axe of deception");
    add_id(({"axe","bloody axe"}));
    set_short("A bloody axe");
    set_long("This axe sure is bloody. Whoever wielded this axe must "
        "have spent it well...\n");
    add_item("blood","The axe is covered in blood.\n");
    set_weight(4);
    set_value(1000+random(500));
    set_class(15+random(6));
    set_damage_type("chop");
    set_weapon_type("axe");
    set_info("It's the infamous Axe Of Deception.\n");
    
    set_hit_func((:call_other,FUNC,"axe_hit",this_object():));
    add_property(({"hidden","magic","metal"}));
    replace_program(I_WEAPON);
}

axefuncs.c


/* Filename      : axefuncs.c
 * Description   : the functionfile for axeofdeception.c
 *
 * written       : 05-10-1996 - Gunner
 * last modified : 28-05-1998 - Gunner
 * HTML-Version  : 06-02-2000 - Ghorwin
 */

#include <mudlib.h>
#include <colours.h>
#include "/doc/crashcourse/defs.h"
inherit I_DAEMON;

#define BASE 20         /* Basedamage */

int
axe_hit(object axe, object att)
{
    object attweap;
    object room     = ENV(att);
    object wielder  = axe->query_wielded_by();
    int ran         = random(100);
    int hit         = BASE + random(20);

    if (ran > 90)       // Special hits every ~10th round
    {
        switch (hit)    // Hit messages... With colours...
        {
            case BASE :
                tell_object(wielder,
                    COL_YH(wielder,"You run the axe into " + Q_NAME(att) +
                    ", hurting " + Q_OBJ(att) + " badly!\n"));
                tell_object(att,
                    COL_HY(att,Q_NAME(wielder) + " runs " + Q_POSS(wielder) +
                    " axe into you, hurting you badly!\n"));
                tell_room(room,Q_NAME(wielder) + " runs " + Q_POSS(wielder) +
                    " axe into " + Q_NAME(att) + ", hurting " +
                    Q_OBJ(att) + " badly!\n", ({wielder,att}));
                break;

            case BASE+1..BASE+10 :
                tell_object(wielder,
                    COL_YH(wielder,"You run the axe through the flesh "
                    "of " + Q_NAME(att) + "!\n"));
                tell_object(att,
                    COL_HY(att,Q_NAME(wielder) + " runs " + Q_POSS(wielder) +
                    " axe through your flesh!\n"));
                tell_room(room,Q_NAME(wielder) + " runs " + Q_POSS(wielder) +
                    " axe through " + Q_NAME(att) + "'s flesh!\n",({wielder,att}));
                break;

            case BASE+11..BASE+19 :
                tell_object(wielder,
                    COL_YH(wielder,"You let your the axe cut " + Q_NAME(att) +
                    " to the bone!\n"));
                tell_object(att,
                    COL_HY(att,Q_NAME(wielder) + " lets " + Q_POSS(wielder) +
                    " axe cut you to the bone!\n"));
                tell_room(room,Q_NAME(wielder) + " lets " + Q_POSS(wielder) +
                    " axe cut " + Q_NAME(att) + " to the bone!\n",({wielder,att}));
                break;
        }
    }
    if (ran < 5)     // 5% chance for the deception... Bad luck...
    {
        if (axe->unwield(1) == 0) return 0;          // Couldn't unwield...
        axe->move(att);

        tell_object(wielder,
            COL_HY(wielder,"The axe suddenly disapproves of you and "
            "decides to help your enemy! It stuns your hand and "
            "flies over to your enemy!\n"));
        tell_object(att,
            COL_YH(att,Q_NAME(wielder) + "'s axe suddenly flies over "
            "to you!\n"));
        tell_room(room,Q_NAME(wielder) + "'s axe suddenly flies over to " +
            Q_NAME(att) + "!\n",({wielder,att}));
        wielder->hit_player(10+random(10),"electricity",axe,"glove");

        attweap = att->query_weapon(1);
        if (attweap)
            if (attweap->unwield() == 0) return 0;   // Couldn't unwield...
        axe->wield();
    }

    if (ran > 90)
        return hit;     // Return the extra hits
    else
        return 0;
}