dsII/extra/wolfpaw/
dsII/lib/cmds/admins/
dsII/lib/cmds/common/
dsII/lib/cmds/creators/include/
dsII/lib/cmds/creators/include/SCCS/
dsII/lib/daemon/services/
dsII/lib/doc/
dsII/lib/domains/Ylsrim/
dsII/lib/domains/Ylsrim/adm/
dsII/lib/domains/Ylsrim/armor/
dsII/lib/domains/Ylsrim/broken/
dsII/lib/domains/Ylsrim/fish/
dsII/lib/domains/Ylsrim/meal/
dsII/lib/domains/Ylsrim/npc/
dsII/lib/domains/Ylsrim/virtual/
dsII/lib/domains/Ylsrim/weapon/
dsII/lib/domains/campus/adm/
dsII/lib/domains/campus/etc/
dsII/lib/domains/campus/meals/
dsII/lib/domains/campus/npc/
dsII/lib/domains/campus/txt/
dsII/lib/domains/campus/txt/ai/charles/
dsII/lib/domains/campus/txt/ai/charles/bak2/
dsII/lib/domains/campus/txt/ai/charles/bak2/bak1/
dsII/lib/domains/campus/txt/ai/charly/
dsII/lib/domains/campus/txt/ai/charly/bak/
dsII/lib/domains/campus/txt/jenny/
dsII/lib/domains/default/creator/
dsII/lib/domains/default/doors/
dsII/lib/domains/default/etc/
dsII/lib/domains/default/weap/
dsII/lib/domains/town/doors/
dsII/lib/domains/town/txt/
dsII/lib/domains/town/virtual/
dsII/lib/lib/comp/
dsII/lib/lib/lvs/
dsII/lib/lib/user/
dsII/lib/lib/virtual/
dsII/lib/log/archive/
dsII/lib/log/chan/
dsII/lib/log/errors/
dsII/lib/log/open/
dsII/lib/obj/book_source/
dsII/lib/obj/include/
dsII/lib/realms/template/
dsII/lib/realms/template/area/armor/
dsII/lib/realms/template/area/npc/
dsII/lib/realms/template/area/obj/
dsII/lib/realms/template/area/room/
dsII/lib/realms/template/area/weap/
dsII/lib/realms/template/bak/
dsII/lib/realms/template/cmds/
dsII/lib/save/
dsII/lib/save/kills/o/
dsII/lib/secure/cfg/
dsII/lib/secure/cfg/classes/
dsII/lib/secure/cfg/races/SCCS/
dsII/lib/secure/cmds/creators/include/
dsII/lib/secure/cmds/players/
dsII/lib/secure/cmds/players/include/
dsII/lib/secure/daemon/include/
dsII/lib/secure/lib/
dsII/lib/secure/lib/include/
dsII/lib/secure/lib/net/
dsII/lib/secure/lib/net/include/
dsII/lib/secure/lib/std/
dsII/lib/secure/modules/
dsII/lib/secure/npc/
dsII/lib/secure/obj/include/
dsII/lib/secure/room/
dsII/lib/secure/save/boards/
dsII/lib/secure/save/postal/c/cratylus/
dsII/lib/secure/save/votes/
dsII/lib/secure/tmp/
dsII/lib/secure/verbs/creators/
dsII/lib/shadows/
dsII/lib/spells/
dsII/lib/tmp/
dsII/lib/verbs/admins/include/
dsII/lib/verbs/common/
dsII/lib/verbs/common/include/
dsII/lib/verbs/creators/include/
dsII/lib/verbs/players/include/SCCS/
dsII/lib/verbs/rooms/
dsII/lib/verbs/rooms/include/
dsII/lib/www/
dsII/v22.2b14/
dsII/v22.2b14/Win32/
dsII/v22.2b14/compat/
dsII/v22.2b14/compat/simuls/
dsII/v22.2b14/testsuite/
dsII/v22.2b14/testsuite/clone/
dsII/v22.2b14/testsuite/command/
dsII/v22.2b14/testsuite/data/
dsII/v22.2b14/testsuite/etc/
dsII/v22.2b14/testsuite/include/
dsII/v22.2b14/testsuite/inherit/
dsII/v22.2b14/testsuite/inherit/master/
dsII/v22.2b14/testsuite/log/
dsII/v22.2b14/testsuite/single/
dsII/v22.2b14/testsuite/single/tests/compiler/
dsII/v22.2b14/testsuite/single/tests/efuns/
dsII/v22.2b14/testsuite/single/tests/operators/
dsII/v22.2b14/testsuite/u/
dsII/v22.2b14/tmp/
dsII/win32/
#include <lib.h>

inherit LIB_ITEM;
inherit LIB_CLOSE;
inherit LIB_LIGHT;
inherit LIB_CAPTURE;

int BugDies = 0;

static void create() {
    AddSave(({ "BugDies" }));
    item::create();
    close::create();
    capture::create();
    light::create();
    SetKeyName("jar");
    SetId( ({ "jar" }) );
    SetShort("a jar");
    SetLong("A jar with lid.  The lid has holes poked in "
      "the top.  It would be perfect to catch bugs in.");
    SetDestroyOnSell(1);
    SetMass(100);
    SetValue(30);
    SetClosed(1);
    SetMaxCapture(1);
    if( BugDies > 1 ) {
	set_heart_beat(2);
    }
}

static void heart_beat() {
    BugDies -= 2;
    if( BugDies < 1 ) {
	eventDarken();
    }
}

int direct_light_obj() { // They cannot use the light command
    return 0;
}

mixed CanCapture(object who, object target) {
    if( !target->id("lightning bug") ) {
	return "The jar has a fit as you try to capture something other "
	"than a lightning bug!";
    }
    if( GetLit() ) {
	return "You already have a lightning bug in there!";
    }
    if( GetClosed() ) {
	return "The jar must be open!";
    }
    return 1;
}

mixed eventCapture(object who, object target) {
    mixed tmp = capture::eventCapture(who, "lightning bug");

    if( tmp != 1 ) {
	return tmp;
    }
    target->eventDestruct();
    who->eventPrint("You capture a lightning bug in your jar!");
    environment(who)->eventPrint(who->GetName() + " captures a lightning bug "
      "with " + possessive(who) + " jar.", who);
    SetLit(1);
    BugDies = 360;
    set_heart_beat(2);
}

mixed eventDarken() {
    object env = environment();

    if( env ) {
	env->eventPrint("The %^YELLOW%^lighning bug%^RESET%^ dies.");
    }
    if( living(env) && (env = environment(env)) ) {
	env->eventPrint(possessive_noun(environment()->GetName()) +
	  " lightning bug dies and " + possessive(environment()) +
	  " jar goes dark.", environment());
    }
    capture::eventFree("lightning bug");
    SetLit(0);
    return 1;
}

mixed eventFree(object who, string target) {
    mixed tmp = capture::eventFree(target);
    object bug;

    if( tmp != 1 ) {
	return tmp;
    }
    if( GetClosed() ) {
	eventOpen(who, "jar");
    }
    SetLit(0);
    environment(who)->eventPrint("A lightning bug flies free of the jar!");
    bug = new("/realms/ariel/wonder/monsters/lbug");
    bug->eventMove(environment(who));
    return 1;
}

varargs mixed eventOpen(object who, string id, object tool) {
    mixed tmp = close::eventOpen(who, id, tool);

    if( tmp != 1 ) {
	return tmp;
    }
    if( sizeof(GetCaptured()) ) {
	eventFree(who, "lightning bug");
    }
    return 1;
}

string GetShort() {
    string tmp = item::GetShort();

    if( GetLit() ) {
	tmp += "\nIt is holding a lightning bug.";
    }
    if( GetClosed() ) {
	tmp += "\nIt is closed.";
    }
    else {
	tmp += "\nIt is open.";
    }
    return tmp;
}

string GetLong(string str) {
    string tmp = item::GetLong();

    if( GetLit() ) {
	tmp += "\nIt is glowing.";
    }
    if( GetClosed() ) {
	tmp += "\nIt is closed.";
    }
    else {
	tmp += "\nIt is open.";
    }
    return tmp;

}