cast.c

skylib_mudos_v1/mudlib/cmds/living/cast.c · 3.9 KB

From the archive skylib_mudos_v1.tar.gz

Download the archive   « Back to the archive contents

#include <spells.h>
#include <player.h>

inherit COMMAND_BASE;

int do_cast_spell(string words, object *targets, object *using, string args) {
    //int count;
    //string *bits;
    string spell;
    string spell_nick;
    mapping spells;


    if( !ENV(TP) ) {
        add_failed_mess("You are in limbo; you cannot cast spells here.\n");
        return 0;
    }
    if( TP->query_property("dead") ) {
        add_failed_mess("$Ving spells while dead?  I don't think so.\n");
        return 0;
    }

    spells = this_player()->query_spells();

    spell = words;
    spell_nick = (string)this_player()->expand_nickname( spell );

    if ( !spells[ spell ] ) {
        if ( !spells[ spell_nick] ) {
            if (strsrch(words, " using ") != -1 ||
              strsrch(words, " on ") != -1 ||
              strsrch(words, " from ") != -1 ||
              strsrch(words, " at ") != -1) {
                return -1;
            }
            add_failed_mess( "You do not know any spell called "+words +".\n");
            return -1;
        }
        spell = spell_nick;
    }

    if( !spells[spell][S_OBJECT]->query_is_spell() ) {
        add_failed_mess("You do not know any spell called "+words+".\n");
        return -1;
    }

    this_player()->adjust_time_left(-(2*ROUND_TIME));

    if (!stringp(spells[ spell ][ S_OBJECT ]) ||
      catch(load_object( spells[spell][S_OBJECT])) ) {
        add_failed_mess("Badly added spell.\n");
        return -1;
    } else {
        //      if(!load_object(spells[spell][S_OBJECT])->cast_spell(args, targets, using)) {
        if (!call_other( spells[ spell ][ S_OBJECT ],
            "query_cast_spell",
            TP,
            args,
            targets,
            using, )) {
            return -1;
        } else {
            return 1;
        }
    }
} /* do_cast_spell() */

int do_cast_scroll( string spell,
  object *things,
  string args,
  object *targets,
  object *using) {
    string spell_ob;

    if ( sizeof( things ) > 1 ) {
        add_failed_mess( "You can't cast a spell from more than one "+
          "scroll at once.\n" );
        return 0;
    }
    if ( !things[ 0 ]->query_magic_scroll() ) {
        add_failed_mess("$I is not a magic scroll.\n", things);
        return 0;
    }
    if ( lower_case(things[ 0 ]->query_spell_name()) != lower_case(spell) ) {
        add_failed_mess("$I does not contain the spell " + spell + ".\n", things);
        return 0;
    }
    spell_ob = things[ 0 ]->query_spell();
    return spell_ob->cast_spell_new(args, 1, targets, using);
} /* cast() */

mixed *query_patterns() {
    return ({
      "<string'spell'>",
      (: do_cast_spell($4[0], ({ }), ({ }), "") :),
      "<string'spell'> {on|at} <indirect:object'target'>",
      (: do_cast_spell($4[0], $1, ({ }), "") :),
      "<string'spell'> {on|at} <indirect:any-living'living target'>",
      (: do_cast_spell($4[0], $1, ({ }), "") :),
      "<string'spell'> with <string'arguments'>",
      (: do_cast_spell($4[0], ({ }), ({ }), $4[1]) :),
      "<string'spell'> {on|at} <indirect:object'target'> with <string'arguments'>",
      (: do_cast_spell($4[0], $1, ({ }), $4[3]) :),
      "<string'spell'> using <indirect:object'components'>",
      (: do_cast_spell($4[0], ({ }), $1, "") :),
      "<string'spell'> {on|at} <indirect:object'target'> using <indirect:object'components'>",
      (: do_cast_spell($4[0], $1[0], $1[1], "") :),

      "<string'spell'> from <indirect:object'scroll'> {on|at} <indirect:object'target'> with <string'arguments'>",
      (: do_cast_scroll($4[0], $1[0], $4[3], $1[1], ({ })) :),
      "<string'spell'> from <indirect:object'scroll'> with <string'arguments'>",
      (: do_cast_scroll($4[0], $1, $4[2], ({ }), ({ })) :),
      "<string'spell'> from <indirect:object'scroll'> {on|at} <indirect:object'target'>",
      (: do_cast_scroll($4[0], $1[0], 0, $1[1], ({ })) :),
      "<string'spell'> from <indirect:object'scroll'>",
      (: do_cast_scroll($4[0], $1, 0, ({ }), ({ })) :)
    });
} /* query_patterns() */

Site Stats

Snippets: 1791
Codebases: 571