amulet.c and amuletfuncs.c - examples for course 05

[previous example] [course05] [Table of contents] [next example]
/* Filename      : amulet.c
 * Description   : a magical amulet
 *
 * written       : 02-10-1996 - Gunner
 * last modified : 26-05-1998 - Gunner
 * HTML-Version  : 01-02-2000 - Ghorwin
 */

#include <mudlib.h>
inherit I_ARMOUR;

#define FUNC "/doc/crashcourse/course05/amuletfuncs"

create()
{
    ::create();
    set_name("burnt amulet");
    add_id(({"amulet","wooden amulet","strange amulet"}));
    set_short("A burnt amulet");
    set_long("This wooden amulet seems kinda burnt. Wonder why it "
        "hasn't burnt up?\n");
    set_weight(1);
    set_type("amulet");
    set_value(200+random(200));
    set_ac(1);

    // Set a special infotext which only spells and special
    // abilities will display. All special items should	    
    // use this.
    set_info("A magical amulet which contains some powers of fire. "
        "'cast fireball' seems like a good idea.\n");

    // magic = all magical items should have this property
    add_property(({"hidden","magic","wood"}));

    // Let's call the 'cast_fireball' function if the player
    // uses the cast command
    add_trigger("cast",(:call_other,FUNC,"cast_fireball":));

    replace_program(I_ARMOUR);
}

amuletfuncs.c


/* Filename      : amuletfuncs.c
 * Description   : the functionfile for amulet.c
 *
 * written       : 02-10-1996 - Gunner
 * last modified : 05-11-1997 - Gunner
 * HTML-Version  : 01-02-2000 - Ghorwin
 */

#include <mudlib.h>
    /* Let's also include our new definitionsfile..	        */
#include "/doc/crashcourse/defs.h"
inherit I_DAEMON;

    /* NOTE! This kind of attack "weapons" would not get past   */
    /* QC since it's much too strong. It is only meant as       */
    /* an example.                                              */

/*
 * cast_fireball : called by the trigger 'cast' in amulet.c
 */
int
cast_fireball(string arg)
{
    object attacker;

        // If the player typed something else but 'cast fireball'
        // then nothing shall happen

    if (!arg || arg != "fireball")
        NOT_FAIL("Cast what?\n");

    attacker = TP->query_attack();      // Who is attacking the player?

    if (!attacker)                      // Noone??
        return notify_fail("Nothing happens.\n");

        // Okay, the player has typed the correct sentence and is
        // under attack. Let's make things happen.

    tell_object(TP,"A fireball shoots out of the amulet and hits " +
        attacker->query_name() + "!\n");
    tell_object(attacker, "A fireball shoots out of " + TP->query_name() +
        "'s amulet and hits you!\n");
    tell_room(environment(TP),"A fireball shoot out of " + TP->query_name() +
        "'s amulet and hits " + attacker->query_name() + "!\n",({TP,attacker}));

        // Hit the attacker with fire damage!
    attacker->hit_player(20+random(10),"fire",TP);

    return 1;
}