Generic Consumable I (#500)

(an instance of Generic Boomerang Thing made by Dred)

     This generic contains the basic functionality required for items that can be consumed. Also, as a child of the Generic Boomerang Thing #261, kids of this will return home after a substantial delay (1 hour) if they aren't consumed entirely before then.

Go to location of this object, Consumable Storage Room.



VERB SOURCE CODE:

consume:
"Does the special effects when this is consumed.";
"this.consume_db:find(consume_verb) should return data in this format:";
"(NUM amt consumed, STR what player sees, STR what room sees, LIST {OBJ, STR verb, 
NUM delay, LIST args} for fork delayed response)";
if ((caller != this) || (this == this.consumable_root))
    return E_PERM;
endif
con_verb = args[1];
if (valid(this.consume_db) && $object_utils:has_callable_verb(this.consume_db, "find"))
    if (eff = this.consume_db:find(con_verb))
        player:tell(this:main_subs(eff[2]));
        player.location:announce(this:main_subs(eff[3]));
        this:consumed_amt(eff[1]);
        if (eff[4])
            fork (eff[4][3])
                eff[4][1]:(eff[4][2])(this, con_verb, eff[1], @eff[4][4]);
            endfork
        endif
    else
        player:tell("For some reason, you can't ", con_verb, " your ", this.name, 
".");
    endif
else
    player:tell("Unfortunately, there doesn't seem to be any way to ", con_verb, 
" that.");
endif
.


build:
"Sets up the consumable. Expects args:";
"(STR this new name, STR|LIST this new description)";
if (this == this.consumable_root)
    return E_PERM;
endif
this:load_verb();
this.amount = this.max_amount;
this:set_name(args[1]);
this:set_aliases({args[1]});
this:set_description(args[2]);
this:moveto(player);
.


consumed_amt:
if (caller != this)
    return E_PERM;
endif
this.amount = this.amount - args[1];
if (this.amount <= 0)
    this:cleanup();
endif
.


main_subs:
"Usual subs. But have this verb so children can override and put in special subs 
as needed.";
msg = args[1];
return $string_utils:pronoun_sub(msg);
.


cleanup:
if ((caller != this) || (this == this.consumable_root))
    return E_PERM;
endif
if (this.consume_verbs)
    delete_verb(this, this.consume_verbs[1]);
endif
this.amount = this.max_amount;
this:moveto(this.home);
.


load_verb:
if ((caller != this) || (this == this.consumable_root))
    return E_PERM;
endif
if (this.consume_verbs)
    fullname = $string_utils:from_list(this.consume_verbs, " ");
    add_verb(this, {this.consumable_root.owner, "rd", fullname}, {"this", "none", 
"none"});
    set_verb_code(this, this.consume_verbs[1], {"this:consume(verb);"});
endif
.


description:
return this:main_subs(this.description);
.



PROPERTY DATA:
      consume_verbs
      consume_db
      amount
      max_amount
      consumable_root

CHILDREN:
Generic Drink Object Generic Drug Object