remember.c

skylib_mudos_v1/mudlib/cmds/guild-race/magic/remember.c · 6.4 KB

From the archive skylib_mudos_v1.tar.gz

Download the archive   « Back to the archive contents

#include <effect.h>
#include <language.h>
#include <tasks.h>

#define SKILL "magic.spells.mental"

inherit COMMAND_BASE;

int cmd( string words ) {
   int i, bonus, chance, outcome, power, total_power;
   string spell, book, spell_path, *names;
   object page, *things;
   mapping spells;
   mixed *writing;

   if ( !words || ( words == "" ) )
      return notify_fail( "Remember what?\n" );
   if ( this_player()->query_remembering_spell() )
      return notify_fail( "You are already remembering a spell.\n" );
   if ( sscanf( words, "%s from %s", spell, book ) != 2 )
      return notify_fail( "Syntax: remember <spell> from <book|scroll>\n" );
   things = ({present( book, TP)});
   if ( !sizeof( things ) )
      return notify_fail( "You do not have "+ book +" from which to remember "
            "a spell.\n" );
   if ( sizeof( things ) > 1 )
      return notify_fail( "You can't remember spells from more than one "
            "place at once.\n" );
   if ( things[ 0 ]->query_magic_scroll() ) {
      if ( (string)things[ 0 ]->query_spell_name() != spell )
         return notify_fail( (string)things[ 0 ]->the_short() +" does not "
               "contain "+ spell +".\n" );
      spell_path = (string)things[ 0 ]->query_spell();
   } else {
      writing = (mixed *)things[ 0 ]->query_read_mess();
      if ( !sizeof( writing ) )
         return notify_fail( "There is nothing on the page of "+
               (string)things[ 0 ]->the_short() +".\n" );
      for ( i = 0; i < sizeof( writing ); i++ ) {
         if ( !LANGUAGE_HAND->
               query_language_magic( writing[ i ][ READ_LANG ] ) )
            continue;
         /* Got to know it completely to use it at the moment */
         if ( this_player()->query_skill(
              LANGUAGE_HAND->query_language_written_skill(
                                  writing[ i ][ READ_LANG ])) < 99)
            continue;
         if ( writing[ i ][ READ_STR ][ 1 ] == spell ) {
            page = (object)things[ 0 ]->query_current_page();
            if ( !page )
               page = things[ 0 ];
            spell_path = writing[ i ][ READ_STR ][ 0 ];
         }
      }
      if ( !page )
         return notify_fail( (string)things[ 0 ]->the_short() +" does not "
               "have the spell "+ spell +" on the open page.\n" );
   }
   spells = (mapping)this_player()->query_spells();
   if ( spells[ spell ] )
      return notify_fail( "You already know the rituals for "+ spell +".\n" );
   names = keys( spells );
   for ( i = 0; i < sizeof( names ); i++ )
      if ( spells[ names[ i ] ][ 0 ]->query_magic_spell() )
         total_power += (int)spells[ names[ i ] ][ 0 ]->query_power_level();
   power = (int)spell_path->query_power_level();
   bonus = (int)this_player()->query_skill_bonus( SKILL, 1 );
   if ( total_power + power > 30 + bonus )
      return notify_fail( "Your mind is too full of magic spells to try to "
            "remember "+ spell +" as well.\n" );
   if ( !page ) {
      outcome = (int)things[ 0 ]->test_skill();
      if ( outcome == FAIL )
         return notify_fail( "You're not sure how to remember "+ spell +
               " from "+ (string)things[ 0 ]->the_short() +".\n" );
   }
   chance = ( power * power ) / 4 * ( 2 + total_power ) / 2;
   chance /= ( 1 + (int)things[ 0 ]->query_binding_force() );
   chance /= bonus / 10 + 1;
   this_player()->add_effect( file_name( this_object() ), ({ power, chance,
         spell, things[ 0 ], page, spell_path, outcome }) );
   return 1;
} /* cmd() */

void beginning( object player, mixed *args, int id ) {
   tell_object( player, "You start remembering "+ args[ 2 ] +" from "+
         (string)args[ 3 ]->the_short() +".\n" );
   tell_room( environment( player ), (string)player->one_short() +
         " begins to peer with great concentration at "+
         (string)args[ 3 ]->a_short() +".\n", player );
   player->submit_ee( 0, ({ args[ 0 ] / 2, ( 3 * args[ 0 ] ) / 2 }),
         EE_REMOVE );
} /* beginning() */

void end( object player, mixed *args, int id ) {
   if ( !args[ 3 ] ) {
      tell_object( player, "You appear to have lost your text...\n" );
      tell_room( environment( player ), (string)player->one_short() +
            " looks around and blinks slowly.\n", player );
      return;
   }
   if ( member_array( environment( args[ 3 ] ), ({ player,
         environment( player ) }) ) == -1 ) {
      tell_object( player, (string)args[ 3 ]->the_short() +" doesn't seem "
            "to be here now.\n" );
      tell_room( environment( player ), (string)player->one_short() +
            " looks puzzled.\n", player );
      return;
   }
   if ( !args[ 4 ] )
      args[ 3 ]->clear_spell( args[ 6 ] == AWARD );
   if ( random( 500 ) > args[ 1 ] ) {
      tell_object( player, "You successfully remember "+ args[ 2 ] +" from "+
            (string)args[ 3 ]->the_short() +".\n" );
      tell_room( environment( player ), (string)player->the_short() +
            " stops staring at "+ (string)args[ 3 ]->a_short() +".\n",
            player );
      player->add_spell( args[ 2 ], args[ 5 ], "cast_spell" );
      return;
   }
   if ( environment( player )->escaped_spell() )
      return;
/* This needs to be checked...
   if ( args[ 4 ] )
      args[ 4 ]->remove_writing( args[ 2 ] );
*/
   tell_object( player, "Oh no!  The spell slips out of your mind and "
         "materialises nearby!\n" );
   tell_room( environment( player ), (string)player->the_short() +
         " is suddenly rocked from side to side, steam coming out of "+
         (string)player->query_possessive() +" ears.\n", player );
   args[ 5 ]->create_lost_spell( environment( player ) );
} /* end() */

string query_classification() { return "magic.remember"; }

string query_shadow_ob() { return "/std/commands/shadows/remember"; }

int teach( object thing ) {
   thing->add_known_command( "remember" );
   return 1;
} /* teach() */

string help() {
   return "Syntax: remember <spell> from <book|scroll>\n\n"
         "Find a book, like the one in the gymnasium, or a magic scroll and "
         "remember a spell from it.  Books have the spells stored more "
         "tightly, so remembering only takes a copy, as it were; if you "
         "use a scroll, on the other hand, the spell will be removed "
         "from it.\n\n"
         "Your capacity for remembering spells is determined by your "
         "skill bonus in "+ SKILL +".\n\n"
         "Example:\n\n"
         "> remember Brassica Oleracea Ambulata from tome\n\n"
         "See also:\n  forget, cast, scribe\n";
} /* help() */

Site Stats

Snippets: 1791
Codebases: 571