com/drain.c and help/drain - examples for course 13

[previous example] [course 13] [Table of contents] [next example]
/* Filename      : drain.c
 * Description   : the guild spell 'drain'
 *
 * written       : 30-05-1998 - Gunner
 * last modified : 31-05-1998 - Gunner
 * HTML-Version  : 13-02-2000 - Ghorwin
 */

#include "/doc/crashcourse/course13/include/guild.h"
#include "/doc/crashcourse/course13/include/spells.h"
inherit I_COMMAND;

string
query_action()
{
    return "drain";
}

string
short_help()
{
    return "Drain the surroundings of power, transforming that power "
        "into dark power.\n";
}

string
help()
{
    return GUILD_HELPDIR + "drain";
}

void
drain_room(object room, object player, int timeout)
{
    object ob;
    int heal = 0;

    if (!room)
    {
        if (player)
        {
            tell_object(player,"You feel the drain spell wear off.\n");
            player->remove_tmp_prop("mod_cast_drain");
        }
        return;
    }

    if (!player)
    {
        tell_room(room,"The dark cold leaves the room.\n");
        return;
    }

    if (timeout <= 0)
    {
        tell_object(player,"You feel the drain spell wear off.\n");
        tell_room(room,"The dark cold leaves the room.\n");
        player->remove_tmp_prop("mod_cast_drain");
        return;
    }

    heal += 4; // Baseheal from the room itself

    tell_room(room,"You feel a dark cold surround you.\n",({player}));

    foreach(ob in all_inventory(room))
    {
        if (living(ob) && !ob->query_property("no_fight") &&
            !ob->query_property("no_drain") && !ob->query_tmp_prop("no_fight") &&
            !ob->query_tmp_prop("no_drain") && !ob->query_dead() &&
            ob != player)
        {
            ob->hit_player(DRAIN_DAMAGE,DRAIN_TYPE,TO);
            heal += DRAIN_DAMAGE;
        }
    }

    player->reduce_spell_point(-heal);

    call_out("drain_room",DRAIN_TIME,room,player,timeout-1);
}

static int
main(string arg)
{
    object room;

    if (arg) arg = lower_case(arg);
    if (arg != "area" && arg != "surroundings")
        NOT_FAIL("Drain what?\n");

    room = environment(TP);

    if (!room)
        NOT_FAIL("Error! No environment!\n");

    CHECK_SPECIAL(room);
    CHECK_NOFIGHT(room);
    CHECK_MATTACK(room);
    CHECK_SP(TP,DRAIN_COST);
    CHECK_BUSY(TP);

    if (TP->query_tmp_prop("mod_cast_drain"))
        FAIL("You have already cast this spell. Wait for it to wear off.\n")

    TP->add_tmp_prop("mod_cast_drain",1);

    tell_object(TP,"You summon the powers of darkness.\n");
    tell_room(room,Q_NAME(TP) + " summons the powers of darkness.\n",({TP}));

    call_out("drain_room",DRAIN_TIME,room,TP,DRAIN_TIMEOUT);

    SET_BUSY(TP);
    REDUCE_SP(TP,DRAIN_COST);

    return 1;
}

help/drain


        ~~     DRAIN     ~~

MAGIC NEEDED: 50

DESCRIPTION:

Summon the powers of darkness to suck out the powers of your
surroundings. The powers will be transformed into dark powers
and will help you in your quest for a world of darkness.

        ~~     DRAIN     ~~