gauntlets.c and gauntlets.c - examples for course 07

[previous example] [course07] [Table of contents] [next example]
/* Filename      : gauntlets.c
 * Description   : very protective gauntlets
 *
 * written       : 03-10-1996 - Gunner
 * last modified : 27-05-1998 - Gunner
 * HTML-Version  : 04-02-2000 - Ghorwin
 */

#include <mudlib.h>
inherit I_ARMOUR;

#define FUNC "/doc/crashcourse/course07/gauntletsfuncs"

create()
{
    ::create();
    set_name("magical gauntlets");
    add_id(({"gauntlet","gauntlets","magical gauntlet","magic gauntlet",
        "magic gauntlets","pair of gauntlets","pair of magical gauntlets",
        "pair of magic gauntlets","pair of enchanted gauntlets",
        "enchanted gauntlet","enchanted gauntlets"}));
    set_short("A pair of magical gauntlets");
    set_long("The gauntlets seem to be magically enchanted. They must "
        "have some hidden powers.\n");
    set_weight(2);
    set_value(300+random(200));
    set_type("glove");
    set_info("The gauntlets will keep you safe from a couple of weaknesses. "
        "But, only for a little while.\n");
  
    add_hook("__wear",(:call_other,FUNC,"wear_gauntlets",this_object():));
    add_hook("__remove",(:call_other,FUNC,"remove_gauntlets",this_object():));
  
    add_property(({"hidden","magic","metal"}));
    replace_program(I_ARMOUR);
}

gauntletsfuncs.c


/* Filename      : hat2funcs.c
 * Description   : the functionfile for gauntlets.c
 *
 * written       : 03-10-1996 - Gunner
 * last modified : 27-05-1998 - Gunner
 * HTML-Version  : 04-02-2000 - Ghorwin
 */

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

#define TIMEOUT 20+random(20)
#define DAMAGE 20+random(10)

/* 
 * wear_gauntlets : called by the __wear hook in gauntlets.c
 */
void
wear_gauntlets(object gaunts)
{
    object wearer, room;

    wearer = environment(gaunts);
    if (!wearer) return;      // Something's wrong here...
    room = environment(wearer);
    if (!room) return;        // Something's wrong here...

    tell_object(wearer,"As you wear the gauntlets, they sting your arms!\n");
    wearer->hit_player(DAMAGE,"electricity",PR,"glove");

    wearer->add_tmp_prop("no_disarm",1);
    wearer->add_tmp_prop("no_disease",1);
    call_out("remove_props",TIMEOUT,wearer);
}

/* 
 * remove_gauntlets : called by the __remove hook in gauntlets.c
 */
void
remove_gauntlets(object gaunts)
{
    object wearer, room;

    wearer = environment(gaunts);
    if (!wearer) return;      // Something's wrong here...
    room = environment(wearer);
    if (!room) return;        // Something's wrong here...

    tell_object(wearer,"As you remove the gauntlets, they sting your arms!\n");
    wearer->hit_player(DAMAGE,"electricity",PR,"glove");

    wearer->add_tmp_prop("no_disarm",-1);
    wearer->add_tmp_prop("no_disease",-1);
    remove_call_out("remove_props");
}

/* 
 * remove_props : restore the player after the effect of the wear is gone      
 */
void
remove_props(object wearer)
{
    if (!wearer) return;  // The player's gone?? Bah.
    wearer->add_tmp_prop("no_disarm",-1);
    wearer->add_tmp_prop("no_disease",-1);
}