Author Topic: Portal-book  (Read 1947 times)

Offline z993126

  • BFF
  • ***
  • Posts: 128
    • View Profile
Portal-book
« on: September 17, 2011, 05:57:14 PM »
/verbs/rooms/enter.c
Code: [Select]
/*    /verbs/rooms/enter.c
 *    from the Dead Souls Mud Library
 *    created by Descartes of Borg 951104
 *    Version: @(#) enter.c 1.2@(#)
 *    Last modified: 96/10/15
 *    2011-Sep-16 - T. Cook added additional enter forms with STR
 */

#include <lib.h>
#include "include/enter.h"

inherit LIB_VERB;

static void create(){
verb::create();
SetVerb( "enter" );
SetRules( "into OBJ", "OBJ", "STR in OBJ", "STR of OBJ", "OBJ STR", "OBJ at STR" );
SetErrorMessage( "Enter what?" );
SetHelp(
"Syntax:  '%^B_WHITE%^%^BLACK%^enter %^MAGENTA%^<PLACE>%^RESET%^'\n"
"         '%^B_WHITE%^%^BLACK%^enter into <PLACE>%^RESET%^'\n\n"
"Moves you into the place you specify.  Whereas the \"go\" "
"command is designed for motion towards something, the "
"\"enter\" command is designed for motion into something.\n"
"See also:  go"
);
}

mixed can_enter_obj(){
if( this_player()->GetParalyzed() ){
return "You cannot do anything, because you are paralyzed.";
}
if( !stringp( hobbled( this_player() ) ) ){
return "Your injuries prevent easy movement.  Perhaps you should try crawling.";
}
return 1;
}

mixed can_enter_into_obj(){
return can_enter_obj();
}

mixed can_enter_str_word_obj(){
if( this_player()->GetParalyzed() ){
return "You cannot do anything, because you are paralyzed.";
}
return 1;
}

mixed can_enter_obj_str(){
if( this_player()->GetParalyzed() ){
return "You cannot do anything, because you are paralyzed.";
}
return 1;
}

mixed can_enter_obj_word_str(){
if( this_player()->GetParalyzed() ){
return "You cannot do anything, because you are paralyzed.";
}
return 1;
}

mixed do_enter_obj( object targ, string what ){
return targ->eventEnter( this_player(), remove_article( lower_case( what ) ) );
}

mixed do_enter_into_obj( object targ, string what ){
do_enter_obj( targ, what );
}

mixed do_enter_str_word_obj( string str, string word, object obj ){
return obj->eventEnter( obj, str );
}

mixed do_enter_obj_str( object obj, string str ){
return obj->eventEnter( obj, str );
}

mixed do_enter_obj_word_str( object obj, string word, string str ){
return obj->eventEnter( obj, str );
}

Some notes about the book:  it can be opened or closed, and it can be entered when open.  Its home object is a container item (in this case, a shelf which is a surface), and it will automatically return to its home if taken from the library room (this is to prevent abuse by carrying a book that connects to one world into another world).

geographybook.c
Code: [Select]
#include <lib.h>

inherit LIB_STORAGE;

mixed direct_enter_obj(){ return 1; }
mixed direct_enter_into_obj(){ return direct_enter_obj(); }
mixed direct_enter_str_word_obj(){ return 1; }
mixed direct_enter_obj_word_str(){ return 1; }
mixed direct_enter_obj_str(){ return 1; }

private string s_title = "Geography";
private string s_home = "/domains/interlibrary/obj/shelf01";
private object o_library = find_object( "/domains/interlibrary/room/library" );
private object *o_exits = ({
"/domains/campus/room/start",
"/domains/town/room/vill_road1"
});
private object o_home = sizeof( children( s_home ) ) > 0 ? children( s_home )[0] : new( s_home );

int eventEnter( object o_obj, string s_str ){
int i_ret, i_ch = 0;
string s_enter, s_exit, s_que = "";

if( environment( this_player() ) != o_library ){
write( "The book '" + s_title + "' dissolves into purple mist, vanishing from your inventory!" );
this_object()->SetClosed( 1 );
this_object()->eventMove( o_home );
tell_room( o_library, "The book '" + s_title + "' flickers into existence on " + o_home->GetShort() + "." );
return 0;
}

if( GetClosed() ){
write( "You cannot enter the book while it's closed." );
say( this_player()->GetName() + " stares at the cover of their book." );
return 0;
}

if( sizeof( s_str ) > 0 && sscanf( s_str, "%(chapter|illumination|picture|plate) %d", s_que, i_ch ) == 2 ){
if( i_ch < sizeof( o_exits ) + 1 ){
--i_ch;
}else{
write( "The book '" + s_title +"' doesn't have that many chapters." );
say( this_player()->GetName() + " flips through the pages of a book." );
return 0;
}
}else if( sizeof( o_exits ) == 1 ){
i_ch = 0;
}else{
write( sprintf(
"The '%s' book has %s chapters; you must decide which one you want to enter.",
s_title, cardinal( sizeof( o_exits ) )
) );
return 0;
}

if( i_ch > 0 ){
s_enter  = "$N enters chapter " + cardinal( i_ch + 1 ) + " of the book '" + s_title + "', which falls to ";
s_enter += "the floor with a quiet thump.";
}else{
s_enter  = "$N enters the book '" + s_title + "', which falls to the floor with a quiet thump.";
}
s_exit = "$N tumbles out of thin air!";

i_ret = this_player()->eventMoveLiving( o_exits[i_ch], s_enter, s_exit );

if( i_ret ){
this_object()->eventMove( o_library );
}else{
write( "You fail to enter the book." ); return 0;
}
return 1;
}

string GetLong(){
string s_long;
int i_count, i_countmax;
if( environment( this_player() ) != o_library ){
write( "The book '" + s_title + "' dissolves into purple mist, vanishing from your inventory!" );
this_object()->SetClosed( 1 );
this_object()->eventMove( o_home );
tell_room( o_library, "The book '" + s_title + "' flickers into existence on " + o_home->GetShort() + "." );
return "";
}
if( this_object()->GetOpen() == 1 ){
s_long  = "Strange, magickal energies infuse the crisp, vellum leaves of this leatherbound tome, drawing ";
s_long += "your attention inwards, inwards.  Richly-crafted illuminations, dazzling to behold and preceding ";
s_long += "each chapter, are so compelling that you suppose you could very well enter them.\n";
s_long += "This book has the following chapters:  ";
i_countmax = sizeof( o_exits );
for( i_count = 0; i_count < i_countmax; i_count++ ){
s_long += "Chapter %^BOLD%^" + ( i_count + 1 ) + "%^RESET%^, ";
s_long += "%^BOLD%^" + o_exits[i_count]->GetShort() + "%^RESET%^";
if( i_countmax > 1 && i_count < i_countmax - 1 ){ s_long += "; "; }
}
}else{
s_long  = "Strange, magickal energies infuse the soft, indigo velvet-bound cover of this book, on which is ";
s_long += "inscribed in gold leaf the title '" + s_title + "'.  Who knows what you might find when you open ";
s_long += "this book?";
}
return s_long;
}

void create() {
::create();
SetKeyName( "book" );
SetId( ({ "book", s_title, lower_case( s_title ), s_title + " book", lower_case( s_title ) + " book" }) );
SetAdjectives( ({ "small", "indigo", "velvet-bound" }) );
SetShort( "a '" + s_title + "' book" );
SetLong( (: GetLong :) );
AddDescriptors( "size", "small" );
AddDescriptors( "material", "velvet-bound" );
AddDescriptors( "colour", "indigo" );
SetMass( 457 );
SetMaxCarry( 0 );
SetBaseCost( "silver", 100000 );
SetCanClose( 1 );
SetClosed( 1 );
}

void init(){ ::init(); }

Offline Atomic

  • BFF
  • ***
  • Posts: 115
  • To infinity and beyond!
    • View Profile
Re: Portal-book
« Reply #1 on: September 26, 2011, 08:55:30 AM »
Fun, thanks for sharing  ;)
Always remember that the early bird gets the worm first, but the fi...*SNAP*...second mouse gets the cheese.