magic.cpp

magic.cpp · 205.9 KB

From the archive wotl-src.zip

Download the archive   « Back to the archive contents

/**************************************************************************/
// magic.cpp - spells etc
/***************************************************************************
 * The Dawn of Time v1.69r (c)1997-2004 Michael Garratt                    *
 * >> A number of people have contributed to the Dawn codebase, with the   *
 *    majority of code written by Michael Garratt - www.dawnoftime.org     *
 * >> To use this source code, you must fully comply with all the licenses *
 *    in licenses.txt... In particular, you may not remove this copyright  *
 *    notice.                                                              *
 ***************************************************************************
 * >> Original Diku Mud copyright (c)1990, 1991 by Sebastian Hammer,       *
 *    Michael Seifert, Hans Henrik St{rfeldt, Tom Madsen, & Katja Nyboe.   *
 * >> Merc Diku Mud improvements copyright (C) 1992, 1993 by Michael       *
 *    Chastain, Michael Quan, and Mitchell Tse.                            *
 * >> ROM 2.4 is copyright 1993-1995 Russ Taylor and has been brought to   *
 *    you by the ROM consortium: Russ Taylor(rtaylor@pacinfo.com),         *
 *    Gabrielle Taylor(gtaylor@pacinfo.com) & Brian Moore(rom@rom.efn.org) *
 * >> Oblivion 1.2 is copyright 1996 Wes Wagner                            *
 **************************************************************************/

#include "include.h" // dawn standard includes

#include "magic.h"
#include "msp.h"
#include "ictime.h"

// command procedures needed
DECLARE_DO_FUN(do_look		);
DECLARE_DO_FUN(do_far_scan);
DECLARE_DO_FUN(do_bug);
char *format_obj_to_char (OBJ_DATA *, char_data *, bool Short);/*act_info.c*/
bool check_skin( char_data *ch, char_data *victim);
bool check_strength( int level, char_data *ch, char_data *victim, bool &half );
char *get_weapontype(OBJ_DATA *obj);
bool check_social(char_data *ch,char * command, char * argument, bool global);

// Local functions
void	say_spell	args(( char_data *ch, int sn, CLASS_CAST_TYPE type ) );
void	check_components(  char_data *ch, int sn );
bool   immune_dispel args(( char_data *victim, int dispel_level) ); 

// imported functions
bool    remove_obj      args( ( char_data *ch, int iWear, bool fReplace ) );

/**************************************************************************/
// Lookup a skill by name - exact match
int skill_exact_lookup( const char *name )
{
    int sn;

    for ( sn = 0; sn < MAX_SKILL; sn++ )
    {
		if ( IS_NULLSTR(skill_table[sn].name))
			break;
		if ( !str_cmp( name, skill_table[sn].name ) )
			return sn;
    }

    return -1;
}

/**************************************************************************/
// Lookup a skill by name.
int skill_lookup( const char *name )
{
	int sn;
	if(!str_cmp(name, "second")){
		name="dual wield";
	}    

	sn=skill_exact_lookup(name);

	if(sn>-1){
		return sn;
	}

    for ( sn = 0; sn < MAX_SKILL; sn++ )
    {
	if ( IS_NULLSTR(skill_table[sn].name))
	    break;
	if ( LOWER(name[0]) == LOWER(skill_table[sn].name[0])
	&&   !str_prefix( name, skill_table[sn].name ) )
	    return sn;
    }

    return -1;
}

/**************************************************************************/
int find_spell( char_data *ch, const char *name, bool spellonly)
{
    // finds a spell the character can cast if possible
    int sn, found = -1;
	int first=0;
	int last=MAX_SKILL;
	
	if(IS_NPC(ch)){
		return skill_lookup(name);
	}

	if(spellonly){
		first=FIRST_SPELL;
		last=LAST_SPELL+1;
	}

	// exact match first
    for ( sn = first; sn < last; sn++ ){
        if (skill_table[sn].name == NULL){
            break;
		}
        if (!str_cmp(name,skill_table[sn].name)){
            if ( found == -1){
                found = sn;
			}
            if (get_skill(ch,sn) > 0){
                return sn;
			}
        }
    }

	// substring match
    for ( sn = first; sn < last; sn++ ){
        if (skill_table[sn].name == NULL){
            break;
		}
        if (LOWER(name[0]) == LOWER(skill_table[sn].name[0])
        &&  !str_prefix(name,skill_table[sn].name)){
            if ( found == -1){
                found = sn;
			}
            if (get_skill(ch,sn) > 0){
                return sn;
			}
        }
    }
    return found;
}

/**************************************************************************/
// Utter mystical words for an sn.
void say_spell( char_data *ch, int sn, CLASS_CAST_TYPE type )
{
    char buf  [MSL];
    char buf2 [MSL];
    char_data *rch;
    char *pName;
    int iSyl;
    int length;

    struct syl_type
    {
	char *	old;
	char *	nw;
    };

    static const struct syl_type syl_table[] =
    {
	{ " ",		" "		},
	{ "ar",		"abra"		},
	{ "au",		"kada"		},
	{ "bless",	"fido"		},
	{ "blind",	"nose"		},
	{ "bur",	"mosa"		},
	{ "cu",		"judi"		},
	{ "de",		"oculo"		},
	{ "en",		"unso"		},
	{ "light",	"dies"		},
	{ "lo",		"hi"		},
	{ "mor",	"zak"		},
	{ "move",	"sido"		},
	{ "ness",	"lacri"		},
	{ "ning",	"illa"		},
	{ "per",	"duda"		},
	{ "ra",		"gru"		},
	{ "fresh",	"ima"		},
	{ "re",		"candus"	},
	{ "son",	"sabru"		},
	{ "tect",	"infra"		},
	{ "tri",	"cula"		},
	{ "ven",	"nofo"		},
	{ "a", "a" }, { "b", "b" }, { "c", "q" }, { "d", "e" },
	{ "e", "z" }, { "f", "y" }, { "g", "o" }, { "h", "p" },
	{ "i", "u" }, { "j", "y" }, { "k", "t" }, { "l", "r" },
	{ "m", "w" }, { "n", "i" }, { "o", "a" }, { "p", "s" },
	{ "q", "d" }, { "r", "f" }, { "s", "g" }, { "t", "h" },
	{ "u", "j" }, { "v", "z" }, { "w", "x" }, { "x", "n" },
	{ "y", "l" }, { "z", "k" },
	{ "", "" }
    };

	buf[0]	= '\0';
	for ( pName = skill_table[sn].name; *pName != '\0'; pName += length )
	{
		for ( iSyl = 0; (length = str_len(syl_table[iSyl].old)) != 0; iSyl++ )
		{
			if ( !str_prefix( syl_table[iSyl].old, pName ))
			{
				strcat( buf, syl_table[iSyl].nw );
				break;
			}
		}
		
		if ( length == 0 )
			length = 1;
	}

	switch (type){
		case CCT_MAXCAST:
		case CCT_NONE:
		sprintf( buf2, "$n takes in a deep breath.");
		sprintf( buf, "$n takes in a deep breath.");
		break;

		case CCT_MAGE:
		sprintf( buf2, "$n utters the words, '%s'.", buf );
		sprintf( buf,  "$n utters the words, '%s'.", skill_table[sn].name );
		break;

		case CCT_CLERIC:
		sprintf( buf2, "$n prays the words, '%s'.", buf );
		sprintf( buf,  "$n prays the words, '%s'.", skill_table[sn].name );
		break;
		case CCT_DRUID:
		sprintf( buf2, "$n summons the elements of nature using the words, '%s'.", buf );
		sprintf( buf,  "$n summons the elements of nature using the words, '%s'.", skill_table[sn].name );
		break;
		// Bardic songs won't be encrypted by the syl_table
		case CCT_BARD:
		sprintf( buf2, "$n's eyes glow with power." );
		sprintf( buf,  "$n's eyes glow with power.");
		break;
	}

	// MSP Spell Sound

	if ( !IS_NULLSTR( skill_table[sn].msp_sound )){
		msp_to_room(MSPT_SPELL, skill_table[sn].msp_sound, 
							0, 
							ch,
							false,
							true);
	}

    for ( rch = ch->in_room->people; rch; rch = rch->next_in_room )
    {
		if ( rch != ch ){
			if(IS_AFFECTED(rch, AFF_DETECT_MAGIC))
				act("Mana swirls around $n as $e shapes it.", ch, NULL, rch, TO_VICT);
			if(!IS_SET(skill_table[sn].flags, SKFLAGS_SILENT))
			{	
				if ( !is_affected(rch, gsn_deafness)) {

					// imms always get the name of the spell
					if(IS_IMMORTAL(rch)){
						act( buf, ch, NULL, rch, TO_VICT );
						continue;
					}

					if(IS_NPC(ch))
					{
						if(IS_SET(ch->act,ACT_CLERIC)){
							act( class_lookup("cleric")==rch->clss ? buf : buf2, ch, NULL, rch, TO_VICT );
						}else if(IS_SET(ch->act,ACT_MAGE)){
							act( class_lookup("mage")==rch->clss ? buf : buf2, ch, NULL, rch, TO_VICT );
						}else{
							act( buf2, ch, NULL, rch, TO_VICT );
						}
					}else{
						act( ch->clss==rch->clss || IS_IMMORTAL(rch)? buf : buf2, ch, NULL, rch, TO_VICT );
					}
				} else {
					if ( !IS_AFFECTED( rch, AFF_BLIND ) || !is_affected( rch, gsn_blindness )){
						act( "You see $N's lips moving.", rch, NULL, ch, TO_CHAR );
					}
				}
			}
		}
    }
    return;
}



/**************************************************************************/
// Compute a saving throw - Negative apply's make saving throw better.
// a higher save value, the better for the victim
bool saves_spell( int level, char_data *victim, int dam_type )
{
    int save;

    save = 50 + ( victim->level - level) * 5 - victim->saving_throw * 2;
    if (IS_AFFECTED(victim,AFF_BERSERK))
	save += victim->level/2;

	if ( IS_NPC(victim) && IS_SET(victim->act, ACT_IS_UNSEEN))
	{
		return true;
	}

    switch(check_immune(victim,dam_type))
    {
		case IS_IMMUNE:		return true;
		case IS_RESISTANT:	save *= 2;	break;
		case IS_VULNERABLE:	save /= 2;	break;
    }

    if (!IS_NPC(victim) && class_table[victim->clss].fMana)
	save = 9 * save / 10;
    save = URANGE( 5, save, 95 );
    return number_percent( ) < save;
}

/**************************************************************************/
// RT save for dispels 
bool saves_dispel( int dis_level, int spell_level, int duration)
{
    int save;
    
    if (duration == -1)
      spell_level += 15;
      // very hard to dispel permanent effects

    save = 50 + (spell_level - dis_level) * 5;
    save = URANGE( 5, save, 95 );
    return number_percent( ) < save;
}


/**************************************************************************/
// co-routine for dispel magic and cancellation 
// return true if successful
bool check_dispel( int dis_level, char_data *victim, int sn)
{
    AFFECT_DATA *af, *af_next;
	int type;
	bool result=false;
	SPELL_FUN * spell_fun=NULL;

    if (count_affected_by_base_spell(victim, sn)>0)
    {
		// get the parent spell function if appropriate
		if(sn>=FIRST_SPELL && sn<=LAST_SPELL){
			spell_fun= skill_table[sn].spell_fun;
		}
		if(spell_fun==spell_null){
			spell_fun=NULL;
		}

		if(immune_dispel(victim, dis_level) )
			return false; 

        for ( af = victim->affected; af; af = af_next )
        {
			af_next=af->next;

			type=af->type;
			if(	(		spell_fun
				  &&	type>=FIRST_SPELL 
				  &&	type<=LAST_SPELL 
				  &&	skill_table[type].spell_fun == spell_fun
				)
				|| (type == sn) )
            {
                if (!saves_dispel(dis_level,af->level,af->duration))
                {
					affect_remove( victim, af);

					if ( !IS_NULLSTR(skill_table[type].msg_off) )
					{
						victim->printlnf( "%s", skill_table[type].msg_off );
					}
					result=true;
			}else{ // weaken the spell slightly
					af->level--;
				}
            }
        }
    }
    return result;
}

/**************************************************************************/
bool check_component( char_data *ch, int sn )
{
    OBJ_DATA *obj;

    if ( IS_NPC( ch )) return true;	// mobs don't need components (yet)

    for ( obj = ch->carrying; obj; obj = obj->next_content )
	{
		if ( obj->item_type == ITEM_COMPONENT && obj->value[1] == sn )
		{
			if ( --obj->value[0] == 0 )
			{
				act ( "$p has been consumed by your magic.", ch, obj, NULL, TO_CHAR );
				extract_obj( obj );
			}
			else if ( obj->value[0] < 0 )
			{
				obj->value[0] = -1;
			}
			return true;
		}
	}

	if ( !obj )
	{
		ch->println( "You lack the proper ingredient for this spell." );
		return false;
    }
    return true;
}


/**************************************************************************/
// The kludgy global is for spells who want more stuff from command line.
char *target_name;
/**************************************************************************/
void do_newcast( char_data *ch, char *argument, int cast_level, CLASS_CAST_TYPE type )
{
    char arg1[MIL];
    char arg2[MIL];
    char_data *victim;
    OBJ_DATA *obj;
	EXIT_DATA *pexit;
	int *pdoor;
    void *vo;
    int mana;
    int sn;
    int target;
    int roll;
    int spell_level;
	int mana_result;
	int door;
	AFFECT_DATA *paf; // For spell grouping
	
    // Switched NPC's can cast spells, but others can't.
    if (IS_UNSWITCHED_MOB(ch))
		return;

	if(!IS_ADMIN( ch ) && IS_OOC( ch )){
		ch->println( "You can not use magic in an ooc area." );
		return;
	}
	
	if ( IS_SET( ch->in_room->room_flags, ROOM_ANTIMAGIC )) {
		ch->println( "Your cannot conjure up a spark of magic here." );
		return;
	}
	
	// Check to see if ch is charmed and being ordered to cast
    if ( IS_AFFECTED(ch,AFF_CHARM) && !IS_SET( ch->dyn, DYN_IS_BEING_ORDERED ))
	{
		ch->println( "You must wait for your master to tell you to cast a spell." );
		return;
	}
	
    target_name = one_argument( argument, arg1 );
    one_argument( target_name, arg2 );
	
    if ( IS_NULLSTR(arg1))
    {
		switch (type){
		case CCT_MAXCAST:
		case CCT_NONE:
			ch->println( "Breathe what where?");
			break;
			
		case CCT_MAGE:
			ch->println( "Cast which what where?");
			break;
			
		case CCT_CLERIC:
			ch->println( "Commune which what where?");
			break;
			
		case CCT_DRUID:
			ch->println( "Summon which what where?");
			break;
		case CCT_BARD:
			ch->println( "Sing which song?" );
			break;
		}
		return;
    }

	REMOVE_BIT( ch->dyn, DYN_SUCCESS_CAST );		//  Starts out false

    // check that it is a spell, and skill is above 0% 
    if ( ( sn = find_spell( ch,arg1, true ) ) < 0
		|| get_skill(ch,sn) ==0
		|| !IS_SPELL(sn))
    {
        ch->printlnf( "You don't know any spells of the name '%s'.", arg1 );
        return;
    }
	
	// do a level check if they aren't an imm and the level 
	// on the spell is an imm level
	// a skill of 101 in the skill is a budget hack to make 
	// an acception to this
	if (!IS_NPC(ch))
	{
		if (( (skill_table[sn].skill_level[ch->clss] >=LEVEL_IMMORTAL
			   || (skill_table[sn].skill_level[ch->clss]==0))
			&& !IS_IMMORTAL(ch)) && ch->pcdata->learned[sn] !=101)
		{
			ch->wrapln("This spell is not castable by your class... "
				"even though for some reason you have it... It may have been "
				"removed from your class for game balances purposes... talk to an "
				"admin to get a refund for on the pracs you have spent on it.");
			return;
		}
	}
	
    if ( ch->position < skill_table[sn].minimum_position ){
        ch->println( "You can't concentrate enough." );
        return;
    }

	if ( IS_SET(skill_table[sn].sect_restrict, 1<<ch->in_room->sector_type) )
	{
		ch->printlnf( "You can't seem to cast %s %s.", 
			skill_table[sn].name, 
			sector_desc[ch->in_room->sector_type].name);
		return;
	}
	
    mana = skill_table[sn].min_mana;
	
    if(get_skill(ch,gsn_mana_focusing))
    {
		if( (roll = number_range(1,100)) < get_skill(ch,gsn_mana_focusing))
		{
			mana-=mana*(roll/2)/100;
		}
    }

    if(event_active == 7)
    {
	ch->printlnf("The magic around you shifts and warps.");
	int warp = number_range(1,4);
	if(warp == 1)
		mana -= (mana/4);
	if(warp == 2)
		mana = (mana/2);
	if(warp == 3)
		mana += (mana/4);
	if(warp == 4)
		mana += (mana/10);
    }
	
    /*
	* Locate targets.
	*/
    victim	= NULL;
    obj		= NULL;
    vo		= NULL;
    target	= TARGET_NONE;
	
    switch ( skill_table[sn].target )
    {
    default:
        bugf( "Do_cast: bad target for sn %d.", sn );
        return;
		
    case TAR_IGNORE:
		// Check to see if the spell is component based and if they've got it
		if ( skill_table[sn].component_based )
		{
			if ( !check_component( ch, sn ))
				return;
		}
        break;
		
    case TAR_MOB_OFFENSIVE:
    case TAR_CHAR_OFFENSIVE:
        if ( arg2[0] == '\0' )
        {
            if ( ( victim = ch->fighting ) == NULL )
            {
                ch->println( "Cast the spell on whom?" );
                return;
            }
        }
        else
        {
            if ( ( victim = get_char_room( ch, target_name ) ) == NULL )
            {
                ch->printlnf( "Can't see any '%s' here.", target_name );
				if (ch->desc && ch->desc->repeat>5){
					WAIT_STATE( ch, 3 * PULSE_VIOLENCE );
				}
                return;
            }
        }
		
		// target restriction checks
		if((IS_NPC(victim) && IS_SET(skill_table[sn].flags,SKFLAGS_NO_NPCTARGET))
			||(!IS_NPC(victim) && IS_SET(skill_table[sn].flags,SKFLAGS_NO_PCTARGET)))
		{
            ch->println( "Not on that target." );
            return;
		}
		
		// is safe check
        if ( !IS_NPC(ch) ) 
		{   
            if (is_safe(ch,victim) && victim != ch)
            {
                ch->println( "Not on that target." );
                return;
            }
        }

		if ( !can_initiate_combat( ch, victim, CIT_GENERAL | CIT_CASTING_SPELL )) return;

        if ( IS_AFFECTED(ch, AFF_CHARM) && ch->master == victim )
        {
            ch->println( "You can't do that on your own follower." );
            return;
        }
		
        vo = (void *) victim;
        target = TARGET_CHAR;
		
		// Check to see if the spell is component based and if they've got it
		if ( skill_table[sn].component_based )
		{
			if ( !check_component( ch, sn ))
				return;
		}
        break;
		
    case TAR_CHAR_DEFENSIVE:
        if ( arg2[0] == '\0' )
        {
            victim = ch;
        }
        else
        {
            if ( ( victim = get_char_room( ch, target_name ) ) == NULL )
            {
				ch->printlnf( "You can't see any '%s' here.", target_name );
				return;
            }
        }
		
		// Start Grouping check
		for (paf = victim->affected; paf; paf=paf->next)
			for(int i=0; spell_group_flags[i].name; i++)
				if (   IS_SET(skill_table[sn].spellgroup, spell_group_flags[i].bit)
					&& IS_SET(skill_table[paf->type].spellgroup, spell_group_flags[i].bit) )
				{
					if (victim == ch)
						ch->println( "But you're already affected by something similar!");
					else
						ch->printlnf( "But %s is already affected by something similar!", victim->short_descr);
					return;
				}
				// End Grouping check
				
				vo = (void *) victim;
				target = TARGET_CHAR;
				
				// Check to see if the spell is component based and if they've got it
				if ( skill_table[sn].component_based )
				{
					if ( !check_component( ch, sn ))
						return;
				}
				break;
				
    case TAR_CHAR_SELF:
        if ( !IS_NULLSTR(arg2)
			&& !str_cmp(target_name, "self") 
			&& !is_name( target_name, ch->name ) )
        {
            ch->println( "You cannot cast this spell on another." );
            return;
        }
		
		// Start Grouping check
		for (paf = ch->affected; paf; paf=paf->next)
			for(int i=0; spell_group_flags[i].name; i++)
				if (   IS_SET(skill_table[sn].spellgroup, spell_group_flags[i].bit)
					&& IS_SET(skill_table[paf->type].spellgroup, spell_group_flags[i].bit) )
				{
					ch->println( "But you're already affected by something similar!" );
					return;
				}
				// End Grouping check
				
				vo = (void *) ch;
				target = TARGET_CHAR;
				
				// Check to see if the spell is component based and if they've got it
				if ( skill_table[sn].component_based )
				{
					if ( !check_component( ch, sn ))
						return;
				}
				break;
				
    case TAR_OBJ_INV:
        if ( arg2[0] == '\0' )
        {
            ch->println( "What should the spell be cast upon?" );
			return;
        }
		
        if ( ( obj = get_obj_carry( ch, target_name ) ) == NULL )
        {
            ch->printlnf( "You are not carrying any '%s'.", target_name );
            return;
        }
		
        vo = (void *) obj;
        target = TARGET_OBJ;
		
		// Check to see if the spell is component based and if they've got it
		if ( skill_table[sn].component_based )
		{
			if ( !check_component( ch, sn ))
				return;
		}
        break;
		
	case TAR_DIRECTION:
        if (arg2[0] == '\0')
		{
			ch->println( "Cast the spell in what direction?" );
			return;
		}
		
		door = dir_lookup( arg2);
		
		if ( door == -1 )
		{
			ch->printlnf( "'%s' is an invalid direction.", arg2 ); 
			return;
		}
		
		if ( (pexit = ch->in_room->exit[door]) == NULL || pexit->u1.to_room == NULL )
		{
			ch->println( "There is no exit in that direction." );
			return;
		}
		
		pdoor = &door;
		
		vo = (void *) pdoor;
		target = TARGET_CHAR;
		
		// Check to see if the spell is component based and if they've got it
		if ( skill_table[sn].component_based )
		{
			if ( !check_component( ch, sn ))
				return;
		}
		break;
		
    case TAR_OBJ_MOB_OFF:
    case TAR_OBJ_CHAR_OFF:
        if (arg2[0] == '\0')
        {
            if ((victim = ch->fighting) == NULL)
            {
				ch->println( "Cast the spell on whom or what?" );
				return;
            }
			
            target = TARGET_CHAR;
        }
        else if ((victim = get_char_room(ch,target_name)) != NULL)
        {
            target = TARGET_CHAR;
        }
		
        if (target == TARGET_CHAR) // check the sanity of the attack        		
		{
			// target restriction checks
			if((IS_NPC(victim) && IS_SET(skill_table[sn].flags,SKFLAGS_NO_NPCTARGET))
				||(!IS_NPC(victim) && IS_SET(skill_table[sn].flags,SKFLAGS_NO_PCTARGET)))
			{
				ch->println( "Not on that target." );
				return;
			}
			
			// is safe check
            if(is_safe_spell(ch,victim,false) && victim != ch)
            {
				ch->println( "Not on that target." );
				return;
            }
			
            if ( IS_AFFECTED(ch, AFF_CHARM) && ch->master == victim )
            {
                ch->println( "You can't do that on your own follower." );
                return;
			}
			
            vo = (void *) victim;
        }
        else if ((obj = get_obj_here(ch,target_name)) != NULL)
        {
            vo = (void *) obj;
            target = TARGET_OBJ;
        }
        else
        {
            ch->printlnf( "You don't see any '%s' here.", target_name );
            return;
        }
		// Check to see if the spell is component based and if they've got it
		if ( skill_table[sn].component_based )
		{
			if ( !check_component( ch, sn ))
				return;
		}
        break; 
		
    case TAR_OBJ_CHAR_DEF:
        if (arg2[0] == '\0')
		{
			// Start Grouping check
			for (paf = ch->affected; paf; paf=paf->next)
				for(int i=0; spell_group_flags[i].name; i++)
					if (   IS_SET(skill_table[sn].spellgroup, spell_group_flags[i].bit)
						&& IS_SET(skill_table[paf->type].spellgroup, spell_group_flags[i].bit) )
					{
						ch->println( "But you're already affected by something similar!" );
						return;
					}
					// End Grouping check
					
					vo = (void *) ch;
					target = TARGET_CHAR;
        }
        else if ((victim = get_char_room(ch,target_name)) != NULL)
        {
			// Start Grouping check
			for (paf = victim->affected; paf; paf=paf->next)
				for(int i=0; spell_group_flags[i].name; i++)
					if (   IS_SET(skill_table[sn].spellgroup, spell_group_flags[i].bit)
						&& IS_SET(skill_table[paf->type].spellgroup, spell_group_flags[i].bit) )
					{
						ch->printlnf( "But %s is already affected by something similar!", victim->short_descr);
						return;
					}
					//End Grouping check
					
					vo = (void *) victim;
					target = TARGET_CHAR;
        }
        else if ((obj = get_obj_carry(ch,target_name)) != NULL)
        {
            vo = (void *) obj;
            target = TARGET_OBJ;
        }
        else
        {
            ch->printlnf( "You don't see any '%s' here.", target_name );
            return;
        }
		
		// Check to see if the spell is component based and if they've got it
		if ( skill_table[sn].component_based ){
			if ( !check_component( ch, sn )){
				return;
			}
		}
        break;
    }// end of spell type switch
	
    if ( !IS_NPC(ch) && ch->mana < mana )
    {
        ch->println( "You don't have enough mana." );
        return;
    }

	if(IS_SET(ch->config2, CONFIG2_BEHOLDER_EYE))
	{
		ch->println( "Your anti-magic ray prevents you from using your power." );
		return;
	}
	
    say_spell( ch, sn, type );
	if(victim && IS_AFFECTED3(victim, AFF3_DETECT_TAINT))
    {
            switch(number_range(1, 8))
            {
                    case 1: victim->println("A wave of revulsion rushes over you.");
                                    break;
                    case 2: victim->println("Your stomach flips for a moment.");
                                    break;
                    case 3: victim->println("Nausea and dizziness suddenly hit you full force.");
                                    break;
                    case 4: victim->println("For a moment your vision doubles.");
                                    break;
                    case 5: victim->println("Your skin feels like acid has been poured on it.");
                                    break;
                    case 6: victim->println("A rancid smell floats past your nose.");
                                    break;
                    case 7: victim->println("For just a moment, a painful scream hits your ears full force.");
                                    break;
                    case 8: victim->println("A taste like blood, dirt and rotten eggs sits on your tongue.");
                                    break;
            }
    }
	if(!IS_SET(ch->config2, CONFIG2_HOLYCAST))
		WAIT_STATE( ch, skill_table[sn].beats );
	
	// can't spam charming yourself to improve at it
	if (sn==gsn_charm_person && victim==ch)
	{
		if (number_percent( ) > get_skill(ch,sn) )
		{
			ch->mana -= mana / 2;
			ch->println( "You lost your concentration." );
		}
		else
		{
			ch->mana -= mana;
			ch->println( "You like yourself even better!" );
		}
		return;
	}
	
    if(get_skill(ch,gsn_mana_focusing))
    {
		if( (roll = number_range(1,100)) < get_skill(ch,gsn_mana_focusing))
		{
			check_improve(ch,gsn_mana_focusing, true, 5);
		}
		else
			check_improve(ch,gsn_mana_focusing, false, 5);
    }
	if (!IS_SET(TRUE_CH(ch)->config2, CONFIG2_HOLYCAST) &&
        number_percent( ) > ((get_skill(ch,sn) + ch->modifiers[STAT_SD] - 5) / (is_affected(ch, gsn_deafness) ? 2 : 1)))
    {
		ch->mana -= mana / 2;
		if(is_affected(ch, gsn_deafness))
			ch->println("You think you may have mispronounced something...");
		else
			ch->println( "You lost your concentration." );
		check_improve(ch,sn,false,1);
    }
    else
    {
        spell_level=ch->level;
		
		
		// moon casting mods by Kalahn
		// mage 
		if (HAS_CLASSFLAG(ch, CLASSFLAG_CASTING_AFFECTED_BY_MOON))
		{
			spell_level += weather_info[ch->in_room->sector_type].mage_castmod;
			if (spell_level<1)
				spell_level=1;
			
		}
		// spellfilcher at half
		if (HAS_CLASSFLAG(ch, CLASSFLAG_CASTING_HALFAFFECTED_BY_MOON))
		{
			spell_level += (weather_info[ch->in_room->sector_type].mage_castmod/2);
			if (spell_level<1)
				spell_level=1;
			
		}
				
		if(get_skill(ch,gsn_sorcery))
		{
			if( (roll = number_range(1,100)) < get_skill(ch,gsn_sorcery))
			{
				spell_level+=roll/5;
				check_improve(ch,gsn_sorcery, true, 5);
			}
			else
				check_improve(ch,gsn_sorcery, false, 5);
		}
		
		if(get_skill(ch,gsn_occultism))
		{
			if( (roll = number_range(1,100)) < get_skill(ch,gsn_occultism))
			{
				spell_level+=ch->in_room->death_energy * roll / 100;
				check_improve(ch,gsn_occultism, true, 5);
			}
			else
				check_improve(ch,gsn_occultism, false, 5);
		}
		if ( IS_SET(skill_table[sn].sect_dampen, 1<<ch->in_room->sector_type) )
			spell_level -= number_range(1,20);
		else if ( IS_SET(skill_table[sn].sect_enhance, 1<<ch->in_room->sector_type) )
			spell_level += number_range(1,10);
		
		// cast_level override if casted from do_castatlevel
		if (cast_level)
			spell_level=cast_level;

		if (!skill_table[sn].spell_fun){
			ch->printlnf( "'%s' is not a spell!", skill_table[sn].name);
			return;
		}

		// spell cast on barbarian turns into a spell_fear_magic instead.
		if( victim 
			&& HAS_CLASSFLAG(victim, CLASSFLAG_MAGIC_ANTIPATHY) 
			&& number_range(1,3)==1 
			&& IS_SET(skill_table[sn].flags, SKFLAGS_MAGICAL_ANTIPATHY) 
			&& !victim->fighting)
		{
			ch->printlnf( "Your spell has set %s into a maddening frenzy!", victim->short_descr);
			sn = gsn_fear_magic;
		}

		if(victim && IS_SET(victim->config2, CONFIG2_BEHOLDER_EYE))
		{
			act("Your anti-magic ray prevents $n's magic.", ch, NULL, victim, TO_VICT);
			act("$N's anti-magic ray prevents $n magic.", ch, NULL, victim, TO_NOTVICT);
			act("$N anti-magic ray prevents your power.", ch, NULL, victim, TO_CHAR);
			return;
		}
		
		SET_BIT( ch->dyn, DYN_SUCCESS_CAST );

		if (IS_NPC(ch) || class_table[ch->clss].fMana)
			// clss has spells 
			mana_result = (*skill_table[sn].spell_fun) ( sn, spell_level, ch, vo,target);
        else
            mana_result = (*skill_table[sn].spell_fun) (sn, spell_level, ch, vo,target);
		
		switch( mana_result )
		{
		case NO_MANA:
			mana = 0;
			break;
		case HALF_MANA:
			if ( mana > 0 )
				mana /= 2;
			break;
		case DOUBLE_MANA:
			if ( mana > 0 )
				mana *= 2;
			break;
		case ALL_MANA:
			mana = ch->mana;
		default:
			break;
		}
        ch->mana -= mana;
		
		if (!IS_NPC(ch))
		{
			// record when the spell was last used
			//ch->pcdata->last_used[sn]= current_time;
		}
		
        check_improve(ch,sn,true,1);
    }

    if ((skill_table[sn].target == TAR_CHAR_OFFENSIVE
		||   (skill_table[sn].target == TAR_OBJ_CHAR_OFF && target == TARGET_CHAR)
		||   (skill_table[sn].target == TAR_OBJ_MOB_OFF && target == TARGET_CHAR && IS_NPC(victim))
		||   (skill_table[sn].target == TAR_MOB_OFFENSIVE && IS_NPC(victim)))
		&&   ch
		&&   ch->in_room
		&&   victim != ch
		&&   victim->master != ch)
    {
        char_data *vch;
        char_data *vch_next;
		
        for ( vch = ch->in_room->people; vch; vch = vch_next )
        {
            vch_next = vch->next_in_room;
            if ( victim == vch && victim->fighting == NULL )
            { 
				multi_hit( victim, ch, TYPE_UNDEFINED );
				break;
            }
        }
    }
	
	if (skill_table[sn].target == TAR_MOB_OFFENSIVE && !IS_NPC(victim) && ch!=victim)
	{
		ch->pksafe=0;
		if (ch->pknorecall<5)
			ch->pknorecall=5;
	}
	
    return;
}

/**************************************************************************/
void do_power( char_data *ch, char *argument )
{
	if(!IS_NPC(ch) && (TRUE_CH(ch)->level<LEVEL_IMMORTAL) )
	{
		if(ch->race == race_lookup("lich") )
		{ do_newcast( ch, argument, 0, CCT_BARD);
		  return; 
		}
		else if(ch->race == race_lookup("angel") )
		{ do_newcast( ch, argument, 0, CCT_BARD);
		  return;
		}
		else if(ch->race == race_lookup("demon") )
		{ do_newcast( ch, argument, 0, CCT_BARD);
		  return;
		}
		do_huh(ch,"");
		return;

	}
	do_newcast( ch, argument, 0, CCT_BARD);
	return; 
}
/**************************************************************************/
void do_breath( char_data *ch, char *argument )
{
    char arg1[MIL];
    char_data *victim;
    OBJ_DATA *obj;
	EXIT_DATA *pexit;
	int *pdoor;
   int cast_level = ch->level;
    void *vo;
    int mana;
    int sn=gsn_cupcake_breath;
    int target;
    int roll;
    int spell_level;
	int mana_result;
	int door;
	AFFECT_DATA *paf; // For spell grouping
	
    // Switched NPC's can cast spells, but others can't.
    if (IS_UNSWITCHED_MOB(ch))
		return;

	if(ch->race == race_lookup("demon") )
	{ 
		ch->println("Use POWER <breath weapon> <victim>.");
		return;
	}

	
	if(!IS_IMMORTAL(ch) && (!IS_DRAGON(ch) || IS_DRAGONFORM(ch)) && !IS_NPC(ch))
	{
		do_huh(ch, "");
		return;
	}

	if(!IS_ADMIN( ch ) && IS_OOC( ch )){
		ch->println( "You can not use your breath weapon in an ooc area." );
		return;
	}


	// Check to see if ch is charmed and being ordered to cast
    if ( IS_AFFECTED(ch,AFF_CHARM) && !IS_SET( ch->dyn, DYN_IS_BEING_ORDERED ))
	{
		ch->println( "You must wait for your master to tell you to use your breath weapon" );
		return;
	}
	
    target_name = one_argument( argument, arg1 );
	
    if ( IS_NULLSTR(arg1))
    {
	switch (ch->altform.subtype)
	{	
		case DRAGON_RED:
		case DRAGON_GOLD:
			ch->println( "Breathe fire where?");
			break;
		case DRAGON_WHITE:
		case DRAGON_SILVER:
		case DRAGON_CLOUD:
			ch->println( "Breathe frost where?");
			break;
		case DRAGON_COPPER:
		case DRAGON_EMERALD:
		case DRAGON_BLACK:
			ch->println( "Breathe acid where?");
			break;
		case DRAGON_BRASS:
		case DRAGON_GREEN:
			ch->println( "Breathe poison where?");
			break;
		case DRAGON_BRONZE:
		case DRAGON_CRYSTAL:
		case DRAGON_BLUE:
			ch->println( "Breathe lightning where?");
			break;
		case DRAGON_STEEL:
			ch->println( "Breathe a blast of steel where?");
			break;
		case DRAGON_SHADOW:
			ch->println( "Breathe a shadow blast where?");
			break;
		default:
			ch->println(" Breath a cupcake blast where?");
			break;
	}
	return;
    }
	switch (ch->altform.subtype)
	{
		case DRAGON_RED:
		case DRAGON_GOLD:
			sn=gsn_fire_breath;
			break;
		case DRAGON_WHITE:
		case DRAGON_SILVER:
		case DRAGON_CLOUD:
			sn=gsn_frost_breath;
			break;
		case DRAGON_COPPER:
		case DRAGON_EMERALD:
		case DRAGON_BLACK:
			sn=gsn_acid_breath;
			break;
		case DRAGON_BRASS:
		case DRAGON_GREEN:
			sn=gsn_gas_breath;
			break;
		case DRAGON_BRONZE:
		case DRAGON_CRYSTAL:
		case DRAGON_BLUE:
			sn=gsn_lightning_breath;
			break;
		case DRAGON_STEEL:
			sn=gsn_steel_breath;
			break;
		case DRAGON_SHADOW:
			sn=gsn_shadow_breath;
			break;
		default:
		 	sn=gsn_cupcake_breath;
			break;
	}

	REMOVE_BIT( ch->dyn, DYN_SUCCESS_CAST );		//  Starts out false

	// do a level check if they aren't an imm and the level 
	// on the spell is an imm level
	// a skill of 101 in the skill is a budget hack to make 
	// an acception to this
	if (!IS_NPC(ch))
	{
		if (( (skill_table[sn].skill_level[ch->clss] >=LEVEL_IMMORTAL
			   || (skill_table[sn].skill_level[ch->clss]==0))
			&& !IS_IMMORTAL(ch)) && ch->pcdata->learned[sn] !=101)
		{
			ch->wrapln("This spell is not castable by your class... "
				"even though for some reason you have it... It may have been "
				"removed from your class for game balances purposes... talk to an "
				"admin to get a refund for on the pracs you have spent on it.");
			return;
		}
	}
	
    if ( ch->position < skill_table[sn].minimum_position ){
        ch->println( "You can't concentrate enough." );
        return;
    }
	
    mana = skill_table[sn].min_mana;
	
    if(get_skill(ch,gsn_mana_focusing))
    {
		if( (roll = number_range(1,100)) < get_skill(ch,gsn_mana_focusing))
		{
			mana-=mana*(roll/2)/100;
		}
    }


    /*
	* Locate targets.
	*/
    victim	= NULL;
    obj		= NULL;
    vo		= NULL;
    target	= TARGET_NONE;
	
    switch ( skill_table[sn].target )
    {
    default:
        bugf( "Do_cast: bad target for sn %d.", sn );
        return;
		
    case TAR_IGNORE:
		// Check to see if the spell is component based and if they've got it
		if ( skill_table[sn].component_based )
		{
			if ( !check_component( ch, sn ))
				return;
		}
        break;
		
    case TAR_MOB_OFFENSIVE:
    case TAR_CHAR_OFFENSIVE:
        if ( arg1[0] == '\0' )
        {
            if ( ( victim = ch->fighting ) == NULL )
            {
                ch->println( "Breathe on whom ?" );
                return;
            }
        }
        else
        {
            if ( ( victim = get_char_room( ch, target_name ) ) == NULL )
            {
                ch->printlnf( "Can't see any '%s' here.", target_name );
				if (ch->desc && ch->desc->repeat>5){
					WAIT_STATE( ch, 3 * PULSE_VIOLENCE );
				}
                return;
            }
        }
		
		// target restriction checks
		if((IS_NPC(victim) && IS_SET(skill_table[sn].flags,SKFLAGS_NO_NPCTARGET))
			||(!IS_NPC(victim) && IS_SET(skill_table[sn].flags,SKFLAGS_NO_PCTARGET)))
		{
            ch->println( "Not on that target." );
            return;
		}
		
		// is safe check
        if ( !IS_NPC(ch) ) 
		{   
            if (is_safe(ch,victim) && victim != ch)
            {
                ch->println( "Not on that target." );
                return;
            }
        }

		if ( !can_initiate_combat( ch, victim, CIT_GENERAL | CIT_CASTING_SPELL )) return;

        if ( IS_AFFECTED(ch, AFF_CHARM) && ch->master == victim )
        {
            ch->println( "You can't do that on your own follower." );
            return;
        }
		
        vo = (void *) victim;
        target = TARGET_CHAR;
		
		// Check to see if the spell is component based and if they've got it
		if ( skill_table[sn].component_based )
		{
			if ( !check_component( ch, sn ))
				return;
		}
        break;
		
    case TAR_CHAR_DEFENSIVE:
        if ( arg1[0] == '\0' )
        {
            victim = ch;
        }
        else
        {
            if ( ( victim = get_char_room( ch, target_name ) ) == NULL )
            {
				ch->printlnf( "You can't see any '%s' here.", target_name );
				return;
            }
        }
		
		// Start Grouping check
		for (paf = victim->affected; paf; paf=paf->next)
			for(int i=0; spell_group_flags[i].name; i++)
				if (   IS_SET(skill_table[sn].spellgroup, spell_group_flags[i].bit)
					&& IS_SET(skill_table[paf->type].spellgroup, spell_group_flags[i].bit) )
				{
					if (victim == ch)
						ch->println( "But you're already affected by something similar!");
					else
						ch->printlnf( "But %s is already affected by something similar!", victim->short_descr);
					return;
				}
				// End Grouping check
				
				vo = (void *) victim;
				target = TARGET_CHAR;
				
				// Check to see if the spell is component based and if they've got it
				if ( skill_table[sn].component_based )
				{
					if ( !check_component( ch, sn ))
						return;
				}
				break;
				
    case TAR_CHAR_SELF:
        if ( !IS_NULLSTR(arg1)
			&& !str_cmp(target_name, "self") 
			&& !is_name( target_name, ch->name ) )
        {
            ch->println( "You cannot breathe this on another." );
            return;
        }
		
		// Start Grouping check
		for (paf = ch->affected; paf; paf=paf->next)
			for(int i=0; spell_group_flags[i].name; i++)
				if (   IS_SET(skill_table[sn].spellgroup, spell_group_flags[i].bit)
					&& IS_SET(skill_table[paf->type].spellgroup, spell_group_flags[i].bit) )
				{
					ch->println( "But you're already affected by something similar!" );
					return;
				}
				// End Grouping check
				
				vo = (void *) ch;
				target = TARGET_CHAR;
				
				// Check to see if the spell is component based and if they've got it
				if ( skill_table[sn].component_based )
				{
					if ( !check_component( ch, sn ))
						return;
				}
				break;
				
    case TAR_OBJ_INV:
        if ( arg1[0] == '\0' )
        {
            ch->println( "What object are you trying to breathe upon?" );
			return;
        }
		
        if ( ( obj = get_obj_carry( ch, target_name ) ) == NULL )
        {
            ch->printlnf( "You are not carrying any '%s'.", target_name );
            return;
        }
		
        vo = (void *) obj;
        target = TARGET_OBJ;
		
		// Check to see if the spell is component based and if they've got it
		if ( skill_table[sn].component_based )
		{
			if ( !check_component( ch, sn ))
				return;
		}
        break;
		
	case TAR_DIRECTION:
        if (arg1[0] == '\0')
		{
			ch->println( "Breathe in what direction?" );
			return;
		}
		
		door = dir_lookup( arg1);
		
		if ( door == -1 )
		{
			ch->printlnf( "'%s' is an invalid direction.", arg1 ); 
			return;
		}
		
		if ( (pexit = ch->in_room->exit[door]) == NULL || pexit->u1.to_room == NULL )
		{
			ch->println( "There is no exit in that direction." );
			return;
		}
		
		pdoor = &door;
		
		vo = (void *) pdoor;
		target = TARGET_CHAR;
		
		// Check to see if the spell is component based and if they've got it
		if ( skill_table[sn].component_based )
		{
			if ( !check_component( ch, sn ))
				return;
		}
		break;
		
    case TAR_OBJ_MOB_OFF:
    case TAR_OBJ_CHAR_OFF:
        if (arg1[0] == '\0')
        {
            if ((victim = ch->fighting) == NULL)
            {
				ch->println( "Breathe on whom or what?" );
				return;
            }
			
            target = TARGET_CHAR;
        }
        else if ((victim = get_char_room(ch,target_name)) != NULL)
        {
            target = TARGET_CHAR;
        }
		
        if (target == TARGET_CHAR) // check the sanity of the attack        		
		{
			// target restriction checks
			if((IS_NPC(victim) && IS_SET(skill_table[sn].flags,SKFLAGS_NO_NPCTARGET))
				||(!IS_NPC(victim) && IS_SET(skill_table[sn].flags,SKFLAGS_NO_PCTARGET)))
			{
				ch->println( "Not on that target." );
				return;
			}
			
			// is safe check
            if(is_safe_spell(ch,victim,false) && victim != ch)
            {
				ch->println( "Not on that target." );
				return;
            }
			
            if ( IS_AFFECTED(ch, AFF_CHARM) && ch->master == victim )
            {
                ch->println( "You can't do that on your own follower." );
                return;
			}
			
            vo = (void *) victim;
        }
        else if ((obj = get_obj_here(ch,target_name)) != NULL)
        {
            vo = (void *) obj;
            target = TARGET_OBJ;
        }
        else
        {
            ch->printlnf( "You don't see any '%s' here.", target_name );
            return;
        }
		// Check to see if the spell is component based and if they've got it
		if ( skill_table[sn].component_based )
		{
			if ( !check_component( ch, sn ))
				return;
		}
        break; 
		
    case TAR_OBJ_CHAR_DEF:
        if (arg1[0] == '\0')
		{
			// Start Grouping check
			for (paf = ch->affected; paf; paf=paf->next)
				for(int i=0; spell_group_flags[i].name; i++)
					if (   IS_SET(skill_table[sn].spellgroup, spell_group_flags[i].bit)
						&& IS_SET(skill_table[paf->type].spellgroup, spell_group_flags[i].bit) )
					{
						ch->println( "But you're already affected by something similar!" );
						return;
					}
					// End Grouping check
					
					vo = (void *) ch;
					target = TARGET_CHAR;
        }
        else if ((victim = get_char_room(ch,target_name)) != NULL)
        {
			// Start Grouping check
			for (paf = victim->affected; paf; paf=paf->next)
				for(int i=0; spell_group_flags[i].name; i++)
					if (   IS_SET(skill_table[sn].spellgroup, spell_group_flags[i].bit)
						&& IS_SET(skill_table[paf->type].spellgroup, spell_group_flags[i].bit) )
					{
						ch->printlnf( "But %s is already affected by something similar!", victim->short_descr);
						return;
					}
					//End Grouping check
					
					vo = (void *) victim;
					target = TARGET_CHAR;
        }
        else if ((obj = get_obj_carry(ch,target_name)) != NULL)
        {
            vo = (void *) obj;
            target = TARGET_OBJ;
        }
        else
        {
            ch->printlnf( "You don't see any '%s' here.", target_name );
            return;
        }
		
		// Check to see if the spell is component based and if they've got it
		if ( skill_table[sn].component_based ){
			if ( !check_component( ch, sn )){
				return;
			}
		}
        break;
    }// end of spell type switch
	
    if ( !IS_NPC(ch) && ch->mana < mana )
    {
        ch->println( "You don't have enough mana." );
        return;
    }
	ch->println( "You take in a deep breath." );
	act("$n takes in a deep breath.", ch, NULL, NULL, TO_ROOM);
	
	if(!IS_SET(ch->config2, CONFIG2_HOLYCAST))
		WAIT_STATE( ch, skill_table[sn].beats );
	
    if(get_skill(ch,gsn_mana_focusing))
    {
		if( (roll = number_range(1,100)) < get_skill(ch,gsn_mana_focusing))
		{
			check_improve(ch,gsn_mana_focusing, true, 5);
		}
		else
			check_improve(ch,gsn_mana_focusing, false, 5);
    }
	
    if ( number_percent( ) > ((get_skill(ch,sn) + ch->modifiers[STAT_SD] - 5)
		/ (is_affected(ch, gsn_deafness) ? 2 : 1)))
    {
		ch->mana -= mana / 2;
		if(is_affected(ch, gsn_deafness))
			ch->println("You think you may have mispronounced something...");
		else
			ch->println( "You lost your concentration." );
		check_improve(ch,sn,false,1);
    }
    else
    {
        spell_level=ch->level;
		
		
		if(get_skill(ch,gsn_sorcery))
		{
			if( (roll = number_range(1,100)) < get_skill(ch,gsn_sorcery))
			{
				spell_level+=roll/5;
				check_improve(ch,gsn_sorcery, true, 5);
			}
			else
				check_improve(ch,gsn_sorcery, false, 5);
		}
		
		if(get_skill(ch,gsn_occultism))
		{
			if( (roll = number_range(1,100)) < get_skill(ch,gsn_occultism))
			{
				spell_level+=ch->in_room->death_energy * roll / 100;
				check_improve(ch,gsn_occultism, true, 5);
			}
			else
				check_improve(ch,gsn_occultism, false, 5);
		}
		if ( IS_SET(skill_table[sn].sect_dampen, 1<<ch->in_room->sector_type) )
			spell_level -= number_range(1,20);
		else if ( IS_SET(skill_table[sn].sect_enhance, 1<<ch->in_room->sector_type) )
			spell_level += number_range(1,10);
		
		// cast_level override if casted from do_castatlevel
		if (cast_level)
			spell_level=cast_level;

		if (!skill_table[sn].spell_fun){
			ch->printlnf( "'%s' is not a spell!", skill_table[sn].name);
			return;
		}

		// spell cast on barbarian turns into a spell_fear_magic instead.
		if( victim 
			&& HAS_CLASSFLAG(victim, CLASSFLAG_MAGIC_ANTIPATHY) 
			&& number_range(1,3)==1 
			&& IS_SET(skill_table[sn].flags, SKFLAGS_MAGICAL_ANTIPATHY) 
			&& !victim->fighting)
		{
			ch->printlnf( "Your spell has set %s into a maddening frenzy!", victim->short_descr);
			sn = gsn_fear_magic;
		}
		
		SET_BIT( ch->dyn, DYN_SUCCESS_CAST );

		if (IS_NPC(ch) || class_table[ch->clss].fMana)
			// clss has spells 
			mana_result = (*skill_table[sn].spell_fun) ( sn, spell_level, ch, vo,target);
        else
            mana_result = (*skill_table[sn].spell_fun) (sn, spell_level, ch, vo,target);
		
		switch( mana_result )
		{
		case NO_MANA:
			mana = 0;
			break;
		case HALF_MANA:
			if ( mana > 0 )
				mana /= 2;
			break;
		case DOUBLE_MANA:
			if ( mana > 0 )
				mana *= 2;
			break;
		case ALL_MANA:
			mana = ch->mana;
		default:
			break;
		}
        ch->mana -= mana;
		
		if (!IS_NPC(ch))
		{
			// record when the spell was last used
			//ch->pcdata->last_used[sn]= current_time;
		}
		
        check_improve(ch,sn,true,1);
    }
	
    if ((skill_table[sn].target == TAR_CHAR_OFFENSIVE
		||   (skill_table[sn].target == TAR_OBJ_CHAR_OFF && target == TARGET_CHAR)
		||   (skill_table[sn].target == TAR_OBJ_MOB_OFF && target == TARGET_CHAR && IS_NPC(victim))
		||   (skill_table[sn].target == TAR_MOB_OFFENSIVE && IS_NPC(victim)))
		&&   ch
		&&   ch->in_room
		&&   victim != ch
		&&   victim->master != ch)
    {
        char_data *vch;
        char_data *vch_next;
		
        for ( vch = ch->in_room->people; vch; vch = vch_next )
        {
            vch_next = vch->next_in_room;
            if ( victim == vch && victim->fighting == NULL )
            { 
				multi_hit( victim, ch, TYPE_UNDEFINED );
				break;
            }
        }
    }
	
	if (skill_table[sn].target == TAR_MOB_OFFENSIVE && !IS_NPC(victim) && ch!=victim)
	{
		ch->pksafe=0;
		if (ch->pknorecall<5)
			ch->pknorecall=5;
	}
	
    return;
}
/**************************************************************************/
void do_summon( char_data *ch, char *argument )
{
	if(!IS_NPC(ch) && (TRUE_CH(ch)->level<LEVEL_IMMORTAL) ){
		if(class_table[ch->clss].class_cast_type==CCT_NONE){
			ch->println( "What would you know about summoning nature?" );
			return;
		}

		if(class_table[ch->clss].class_cast_type!=CCT_DRUID){
			ch->println( "Try cast or commune." );
			return;
		}
	}
	do_newcast( ch, argument, 0, CCT_DRUID);
}
/**************************************************************************/
void do_commune( char_data *ch, char *argument )
{
	if(!IS_NPC(ch) && (TRUE_CH(ch)->level<LEVEL_IMMORTAL) ){
		if(class_table[ch->clss].class_cast_type==CCT_NONE){
			ch->println( "What would you know about praying?" );
			return;
		}

		if(class_table[ch->clss].class_cast_type!=CCT_CLERIC){
			ch->println( "Try cast or summon." );
			return;
		}
	}

	if(!ch->deity)
	{
		ch->println( "You need to worship a diety to grant your request." );
		return;
	}
	 if(IS_WEREFORM(ch))
	{
		ch->println("This form of magic is too complex in your current condition.");
		return;

	}
	do_newcast( ch, argument, 0, CCT_CLERIC);
}
/**************************************************************************/
void do_sing( char_data *ch, char *argument )
{
	if ( class_table[ch->clss].class_cast_type != CCT_BARD )
	{	// default to the sing social
		check_social( ch, "sing", argument, false );
		return;
	}

	OBJ_DATA  *hold;

	hold = get_eq_char(ch, WEAR_HOLD);

	if (hold == NULL || hold->item_type != ITEM_INSTRUMENT)
        {
		ch->printlnf("You must be holding an instrument to accompany your singing.");
		return;
	}

	do_newcast( ch, argument, 0, CCT_BARD);
}
/**************************************************************************/
void do_cast( char_data *ch, char *argument )
{
	if(!IS_NPC(ch) && (TRUE_CH(ch)->level<LEVEL_IMMORTAL) ){		
		if(class_table[ch->clss].class_cast_type==CCT_NONE){
			if(GAMESETTING5(GAMESET5_DEDICATED_PKILL_STYLE_MUD)){
				do_newcast( ch, argument, 0, CCT_MAGE);
			}else{
				ch->println( "What would you know about magic?" );
			}
			return;
		}

		if(class_table[ch->clss].class_cast_type!=CCT_MAGE){
			ch->println( "Try commune or summon." );
			return;
		}
	}

	// mobs with the cleric bit dont cast spells, they 'pray' them
	if(IS_NPC(ch) && IS_SET(ch->act,ACT_CLERIC)){
		do_newcast( ch, argument, 0, CCT_CLERIC);
		return;
	}

	do_newcast( ch, argument, 0, CCT_MAGE);
}
/**************************************************************************/
void do_cast_redirect( char_data *ch, char *argument )
{
	if(class_table[ch->clss].class_cast_type==CCT_CLERIC){
		do_commune(ch,argument);
		return;
	}
	if(class_table[ch->clss].class_cast_type==CCT_DRUID){
		do_summon(ch,argument);
		return;
	}
	do_cast(ch,argument);
}

/**************************************************************************/
void do_castatlevel( char_data *ch, char *argument)
{
    char arg[MIL];
	int max_level;

	if (!IS_UNSWITCHED_MOB(ch))
		max_level=ch->level*3;
	else
		max_level=TRUE_CH(ch)->level;

    if (max_level >= MAX_LEVEL*3){
        max_level = MAX_LEVEL*6;
    }

	if ( IS_SET( ch->in_room->room_flags, ROOM_ANTIMAGIC )) {
		ch->println( "You cannot conjure up a spark of magic here." );
		return;
	}
	
    argument = one_argument( argument, arg );

    if ( arg[0] == '\0' || argument[0] == '\0' )
    {
        ch->println( "Castatlevel what?" );
        return;
    }

    if (is_number(arg))
    {
        int new_level = atoi(arg);
        if ((new_level<=max_level) && (new_level>0))
        {
            ch->printlnf( "ATLEVELCAST %d BEGIN.", new_level);
			do_newcast( ch, argument, new_level, CCT_MAGE );
            ch->printlnf( "ATLEVELCAST %d FINISHED.", new_level);
            return;

        }
        else // not high enough trust
        {
            ch->printlnf( "Level must be between 1 and %d.", max_level);
            return;
        }
    }

	ch->println( "Level must be a valid number." );
    return;
}

/**************************************************************************/
// Cast spells at targets using a magical object.
void obj_cast_spell( int sn, int level, char_data *ch, char_data *victim, OBJ_DATA *obj )
{
    void *vo;
    int target = TARGET_NONE;

    if ( sn <= 0 )
	return;

    if ( sn >= MAX_SKILL || skill_table[sn].spell_fun == 0 )
    {
        bugf( "Obj_cast_spell: bad sn %d.", sn );
        return;
    }

    switch ( skill_table[sn].target )
    {
    default:
	bugf( "Obj_cast_spell: bad target for sn %d.", sn );
	return;

    case TAR_IGNORE:
        vo = NULL;
        break;

    case TAR_CHAR_OFFENSIVE:
    case TAR_MOB_OFFENSIVE:
        if ( victim == NULL )
            victim = ch->fighting;
        if ( victim == NULL )
        {
            ch->println( "You can't do that." );
            return;
        }
        if (is_safe(ch,victim) && ch != victim)
        {
            ch->println( "Something isn't right..." );
            return;
        }
        vo = (void *) victim;
        target = TARGET_CHAR;
        break;

    case TAR_CHAR_DEFENSIVE:
    case TAR_CHAR_SELF:
        if ( victim == NULL ){
            victim = ch;
		}
        vo = (void *) victim;
        target = TARGET_CHAR;
        break;

    case TAR_OBJ_INV:
        if ( obj == NULL )
        {
            ch->println( "You can't do that." );
            return;
        }
        vo = (void *) obj;
        target = TARGET_OBJ;
        break;

    case TAR_OBJ_CHAR_OFF:
        if ( victim == NULL && obj == NULL)
	    if (ch->fighting != NULL)
            victim = ch->fighting;
	    else
	    {
            ch->println( "You can't do that." );
            return;
	    }

	    if (victim != NULL)
        {
            if (is_safe_spell(ch,victim,false) && ch != victim)
            {
                ch->println( "Something isn't right..." );
                return;
            }   
            vo = (void *) victim;
            target = TARGET_CHAR;
	    }
	    else
	    {
	    	vo = (void *) obj;
	    	target = TARGET_OBJ;
	    }
        break;


    case TAR_OBJ_CHAR_DEF:
        if (victim == NULL && obj == NULL)
        {
             vo = (void *) ch;
            target = TARGET_CHAR;
        }
        else if (victim != NULL)
        {
            vo = (void *) victim;
            target = TARGET_CHAR;
        }
        else
        {
            vo = (void *) obj;
            target = TARGET_OBJ;
        }    
        break;
    }

    target_name = "";
    (*skill_table[sn].spell_fun) ( sn, level, ch, vo,target);


    if ( (skill_table[sn].target == TAR_CHAR_OFFENSIVE
    ||   (skill_table[sn].target == TAR_OBJ_CHAR_OFF && target == TARGET_CHAR))
    &&   victim != ch
    &&   victim->master != ch )
    {
        char_data *vch;
        char_data *vch_next;
    
        for ( vch = ch->in_room->people; vch; vch = vch_next )
        {
            vch_next = vch->next_in_room;
            if ( victim == vch && victim->fighting == NULL )
            {
            multi_hit( victim, ch, TYPE_UNDEFINED );
            break;
            }
        }
    }

    return;
}


/**************************************************************************/
//     Spell functions.
/**************************************************************************/

/**************************************************************************/
SPRESULT spell_acid_blast( int sn, int level, char_data *ch, void *vo, int )
{
	char_data *victim = (char_data *) vo;
	int dam;

	dam = dice( level, 10 );
	if ( saves_spell( level, victim, DAMTYPE(sn)))
		dam /= 2;
	damage_spell( ch, victim, dam, sn, DAMTYPE(sn),true );
	return FULL_MANA;
}

/**************************************************************************/
SPRESULT spell_armor( int sn, int level, char_data *ch, void *vo, int )
{
	char_data *victim = (char_data *) vo;
	AFFECT_DATA af;

	if ( is_affected( victim, sn ) )
	{
		if (victim == ch)
			ch->println( "You are already armored." );
		else
			act("$N is already armored.",ch,NULL,victim,TO_CHAR);
		return HALF_MANA;
	}

	af.where	 = WHERE_AFFECTS;
	af.type      = sn;
	af.level	 = level;
	af.duration  = 24;
	af.modifier  = -20;
	af.location  = APPLY_AC;
	af.bitvector = 0;
	affect_to_char( victim, &af );
	victim->println( "You feel someone protecting you." );

	if ( ch != victim )
		act("$N is protected by your magic.",ch,NULL,victim,TO_CHAR);
    return FULL_MANA;
}


/**************************************************************************/
SPRESULT spell_bless( int sn, int level, char_data *ch, void *vo, int target)
{
	char_data *victim;
	OBJ_DATA *obj;
	AFFECT_DATA af;

	// deal with the object case first 
	if (target == TARGET_OBJ)
	{
		obj = (OBJ_DATA *) vo;
		if (IS_OBJ_STAT(obj,OBJEXTRA_BLESS))
		{
			act("$p is already blessed.",ch,obj,NULL,TO_CHAR);
			return HALF_MANA;
		}
		
		if (IS_OBJ_STAT(obj,OBJEXTRA_EVIL)
		&&	IS_GOOD(ch))
		{
			AFFECT_DATA *paf;
			
			paf = affect_find(obj->affected,gsn_curse);
			if (!saves_dispel(level,paf != NULL ? paf->level : obj->level,0))
			{
				if (paf != NULL)
					affect_remove_obj(obj,paf);
				act("$p glows a pale blue.",ch,obj,NULL,TO_ALL);
				REMOVE_BIT(obj->extra_flags,OBJEXTRA_EVIL);
				return FULL_MANA;
			}
			else
			{
				act("The evil of $p is too powerful for you to overcome.",
					ch,obj,NULL,TO_CHAR);
				return FULL_MANA;
			}
		}
		
		af.where	= WHERE_OBJEXTRA;
		af.type		= sn;
		af.level	= level;
		af.duration	= 6 + level;
		af.location	= APPLY_SAVES;
		af.modifier	= -1;
		if(!IS_EVIL(ch))
			af.bitvector= OBJEXTRA_BLESS;
		else
			af.bitvector= OBJEXTRA_EVIL;
		affect_to_obj(obj,&af);

		act("$p glows with a holy aura.",ch,obj,NULL,TO_ALL);
		return FULL_MANA;
    }

    // character target 
    victim = (char_data *) vo;

	if(is_affected( victim, gsn_curse )){
		if( check_dispel( level, victim, gsn_curse )){
			act( "Your magic unravels a spell on $N.", ch, NULL, victim, TO_CHAR );
			return FULL_MANA;
        }else{
			ch->println("You failed.");
			return FULL_MANA;
        }
	}

	if(is_affected( victim, sn )){
		if (victim == ch){
			ch->println( "You are already blessed." );
		}else{
			act("$N already has divine favor.",ch,NULL,victim,TO_CHAR);
		}
		return HALF_MANA;
	}

	af.where     = WHERE_AFFECTS;
	af.type      = sn;
	af.level	 = level;
	af.duration  = 6+level;
	af.location  = APPLY_HITROLL;
	af.modifier  = level / 8;
	af.bitvector = 0;
	affect_to_char( victim, &af );

	af.location  = APPLY_SAVES;
	af.modifier  = 0 - level / 8;
	affect_to_char( victim, &af );
	victim->println( "You feel righteous." );

	if ( ch != victim )
		act("You grant $N the favor of your god.",ch,NULL,victim,TO_CHAR);
	return FULL_MANA;
}


/**************************************************************************/
SPRESULT spell_blindness( int sn, int level, char_data *ch, void *vo, int )
{
	char_data *victim = (char_data *) vo;
	AFFECT_DATA af;

	if ( IS_AFFECTED(victim, AFF_BLIND))
	{
		ch->printlnf( "%s already appears to be blinded.", PERS(victim, ch));
		return HALF_MANA;
	}

	if (saves_spell(level,victim,DAMTYPE(sn)))
	{
		ch->printlnf( "%s seems unaffected.", PERS(victim, ch) );
		return FULL_MANA;
	}

	af.where     = WHERE_AFFECTS;
	af.type      = sn;
	af.level     = level;
	af.location  = APPLY_HITROLL;
	af.modifier  = -4;
	af.duration  = 1+level;
	af.bitvector = AFF_BLIND;
	affect_to_char( victim, &af );
	victim->println( "You are blinded!" );
	act("$n appears to be blinded.",victim,NULL,NULL,TO_ROOM);
	return FULL_MANA;
}


/**************************************************************************/
SPRESULT spell_burning_hands(int sn,int level, char_data *ch, void *vo, int )
{
	char_data *victim = (char_data *) vo;
	static const sh_int dam_each[] = 
	{
		0,
		0,  0,  0,  0,	14,	17, 20, 23, 26, 29,
		29, 29, 30, 30,	31,	31, 32, 32, 33, 33,
		34, 34, 35, 35,	36,	36, 37, 37, 38, 38,
		39, 39, 40, 40,	41,	41, 42, 42, 43, 43,
		44, 44, 45, 45,	46,	46, 47, 47, 48, 48
	};
   
	int dam;

    level	= UMIN(level, (int)sizeof(dam_each)/(int)sizeof(dam_each[0]) - 1);
    level	= UMAX(0, level);
    dam		= number_range( dam_each[level] / 2, dam_each[level] * 2 );
    if ( saves_spell( level, victim, DAMTYPE(sn)) )
		dam /= 2;
    damage_spell( ch, victim, dam, sn, DAMTYPE(sn),true);
	return FULL_MANA;
}


/**************************************************************************/
SPRESULT spell_call_lightning( int sn, int level,char_data *ch,void *,int )
{
	char_data *vch;
	char_data *vch_next;
	int dam;

	if ( !IS_OUTSIDE(ch) )
	{
		ch->println( "You must be out of doors." );
		return NO_MANA;
	}

	if ( ch->in_room->sector_type == SECT_CAVE )
	{
		ch->println( "You cannot cast this spell here." );
		return NO_MANA;
	}

	if ( weather_info[ch->in_room->sector_type].sky < SKY_RAINING )
	{
		ch->println( "You need bad weather." );
		return HALF_MANA;
	}

	dam = dice(level/2, 8);

	ch->println( "Lightning from the sky strikes your foes!" );
	act( "$n calls upon the lightning to strike $s foes!", ch, NULL, NULL, TO_ROOM );

    for ( vch = ch->in_room->people; vch; vch = vch_next )
	{
        vch_next=vch->next_in_room;
		if ( vch->in_room == NULL )
			continue;
		if ( vch->in_room == ch->in_room )
		{
			if ( vch != ch && ( IS_NPC(ch) ? !IS_NPC(vch) : IS_NPC(vch) ) )
				damage_spell( ch, vch, saves_spell( level, vch, DAMTYPE( sn )) 
					? dam / 2 : dam, sn, DAMTYPE(sn), true);
			continue;
		}

		if ( vch->in_room->area == ch->in_room->area
		&&   IS_OUTSIDE(vch)
		&&   vch->in_room->sector_type != SECT_CAVE
		&&   IS_AWAKE(vch) )
		vch->println( "Lightning flashes in the sky." );
	}

	return FULL_MANA;
}


/**************************************************************************/
// RT calm spell stops all fighting in the room

SPRESULT spell_calm( int sn, int level, char_data *ch, void *,int )
{
	char_data *vch;
	int mlevel = 0;
	int count = 0;
	int high_level = 0;    
	int chance;
	AFFECT_DATA af;

    /* get sum of all mobile levels in the room */
	for (vch = ch->in_room->people; vch != NULL; vch = vch->next_in_room)
	{
		if (vch->position == POS_FIGHTING)
		{
			count++;
			if (IS_NPC(vch))
				mlevel += vch->level;
			else
				mlevel += vch->level/2;
			high_level = UMAX(high_level,vch->level);
		}
	}

    /* compute chance of stopping combat */
	chance = 4 * level - high_level + 2 * count;

	if ( IS_IMMORTAL( ch )) /* always works */
		mlevel = 0;

	if ( number_range( 0, chance ) >= mlevel )  /* hard to stop large fights */
	{
		for ( vch = ch->in_room->people; vch != NULL; vch = vch->next_in_room )
		{
			if ( IS_NPC( vch )
			&& ( IS_SET( vch->imm_flags, IMM_MAGIC )
			||   IS_SET( vch->act, ACT_UNDEAD )))
			return FULL_MANA;

			if ( IS_AFFECTED( vch, AFF_CALM )
			||   IS_AFFECTED( vch, AFF_BERSERK )
			||   is_affected( vch, gsn_frenzy ))
			return FULL_MANA;
	    
			vch->println( "A wave of calm passes over you." );

			if (vch->fighting || vch->position == POS_FIGHTING )
				stop_fighting( vch, false );


			af.where = WHERE_AFFECTS;
			af.type = sn;
			af.level = level;
			af.duration = level/4;
			af.location = APPLY_HITROLL;

			if (!IS_NPC(vch))
				af.modifier = -5;
			else
				af.modifier = -2;

			af.bitvector = AFF_CALM;
			affect_to_char(vch,&af);
			af.location = APPLY_DAMROLL;
			affect_to_char(vch,&af);
		}
	}
	return FULL_MANA;
}

/**************************************************************************/
SPRESULT spell_cancellation( int , int level, char_data *ch, void *vo,int  )
{
	char_data *victim = (char_data *) vo;
	char_data *roomchar;
	bool found = false;

	level += 2;

	if ((!IS_NPC(ch) && IS_NPC(victim) &&
		!(IS_AFFECTED(ch, AFF_CHARM) && ch->master == victim) ) ||
		 (IS_NPC(ch) && !IS_NPC(victim)) )
	{
		ch->println( "You failed, try dispel magic." );
		return HALF_MANA;
	}

	// unlike dispel magic, the victim gets NO save 

	// begin running through the spells 

	if ( IS_SET( ch->in_room->affected_by, ROOMAFF_UTTERDARK )) {
		ch->println( "The darkness around you disappears." );
		act( "The darkness around you disappears.", ch, NULL, NULL, TO_ROOM );
		REMOVE_BIT( ch->in_room->affected_by, ROOMAFF_UTTERDARK );
		found = true;
	}

 	if (check_dispel(level,victim, gsn_regeneration ))
		found = true;
 	if (check_dispel(level,victim, gsn_hold_person ))
    	{
        	found = true;
        	act("$n is now able to move freely.",victim,NULL,NULL,TO_ROOM);
    	}
	if (check_dispel(level,victim, gsn_resist_poison ))
		found = true;
	if (check_dispel(level,victim, gsn_poison_immunity ))
		found = true;
	if (check_dispel(level,victim, gsn_prismatic_spray ))
		found = true;
	if (check_dispel(level,victim, gsn_illusions_grandeur ))
		found = true;
	if (check_dispel(level,victim, gsn_protection_fire ))
		found = true;
	if (check_dispel(level,victim, gsn_protection_cold ))
		found = true;
	if (check_dispel(level,victim, gsn_protection_lightning ))
		found = true;
	if (check_dispel(level,victim, gsn_holy_aura ))
		found = true;
	if (check_dispel(level,victim, gsn_true_sight ))
		found = true;
	if (check_dispel(level,victim, gsn_barkskin ))
		found = true;
	if (check_dispel(level,victim, gsn_magic_resistance ))
		found = true;
	if (check_dispel(level,victim, gsn_fire_shield ))
		found = true;
	if (check_dispel(level,victim, gsn_chill_shield ))
		found = true;
	if (check_dispel(level,victim, gsn_animal_essence))
		found = true;
    if (check_dispel(level,victim, gsn_armor ))
		found = true;
	if (check_dispel(level, victim, gsn_bless ))
		found = true;
    if (check_dispel(level, victim, gsn_polymorph ))
    {
        found = true;
        act("$n looks more like $mself again.",victim,NULL,NULL,TO_ROOM);
    }
	if (check_dispel(level, victim, gsn_hallucinate ))
		found = true;
	if (check_dispel(level, victim, gsn_bardic_visions ))
		found = true;
	if (check_dispel(level,victim, gsn_despair))
		found = true;
	if (check_dispel(level,victim, gsn_blindness ))
	{
		found = true;
		act("$n is no longer blinded.",victim,NULL,NULL,TO_ROOM);
    }
	if (check_dispel(level,victim, gsn_calm ))
	{
		found = true;
		act("$n no longer looks so peaceful...",victim,NULL,NULL,TO_ROOM);
	}
    if (check_dispel(level,victim, gsn_change_sex ))
    {
        found = true;
        act("$n looks more like $mself again.",victim,NULL,NULL,TO_ROOM);
    }
    if (check_dispel(level,victim, gsn_charm_person))
	{
		found = true;
		act("$n regains $s free will.",victim,NULL,NULL,TO_ROOM);
	}
	if (check_dispel(level,victim, gsn_chill_touch ))
	{
		found = true;
		act("$n looks warmer.",victim,NULL,NULL,TO_ROOM);
	}
	if (check_dispel(level,victim, gsn_curse ))
		found = true;
	if (check_dispel(level,victim, gsn_detect_evil ))
		found = true;
	if (check_dispel(level,victim, gsn_detect_good ))
		found = true;
    if (check_dispel(level,victim, gsn_detect_hidden ))
        found = true;
	if (check_dispel(level,victim, gsn_detect_invis ))
		found = true;
	if (check_dispel(level,victim, gsn_detect_magic ))
		found = true;
	if (check_dispel(level,victim, gsn_faerie_fire ))
	{
		act("$n's outline fades.",victim,NULL,NULL,TO_ROOM);
		found = true;
	}
	if (check_dispel(level,victim, gsn_fly ))
	{
		act("$n falls to the ground!",victim,NULL,NULL,TO_ROOM);
		found = true;
	}
	if (check_dispel(level,victim, gsn_frenzy ))
	{
		act("$n no longer looks so wild.",victim,NULL,NULL,TO_ROOM);;
		found = true;
	}
	if (check_dispel(level,victim, gsn_giant_strength ))
	{
		act("$n no longer looks so mighty.",victim,NULL,NULL,TO_ROOM);
		found = true;
	}
	if (check_dispel(level,victim, gsn_haste ))
	{
		act("$n is no longer moving so quickly.",victim,NULL,NULL,TO_ROOM);
		found = true;
	}
	if (check_dispel(level,victim, gsn_infravision ))
		found = true;
	if (check_dispel(level,victim, gsn_darkvision ))
		found = true;
	if (check_dispel(level,victim, gsn_invisibility ))
	{
		act("$n fades into existance.",victim,NULL,NULL,TO_ROOM);
		found = true;
	}
    if (check_dispel(level,victim, gsn_mass_invis ))
    {
		act("$n fades into existance.",victim,NULL,NULL,TO_ROOM);
		found = true;
	}
	if (check_dispel(level,victim, gsn_pass_door ))
        found = true;
	if (check_dispel(level,victim, gsn_protection_evil ))
        found = true;
	if (check_dispel(level,victim, gsn_protection_good ))
        found = true; 
	if (check_dispel(level,victim, gsn_rage ))
		found = true;
	if (check_dispel(level,victim, gsn_sanctuary ))
	{
		act("The white aura around $n's body vanishes.",victim,NULL,NULL,TO_ROOM);
		found = true;
	}
	if (check_dispel(level,victim, gsn_shield ))
	{
		act("The shield protecting $n vanishes.",victim,NULL,NULL,TO_ROOM);
		found = true;
	}
	if (check_dispel(level,victim, gsn_sleep ))
		found = true;
	if (check_dispel(level,victim, gsn_slow ))
	{
		act("$n is no longer moving so slowly.",victim,NULL,NULL,TO_ROOM);
		found = true;
	}
	if (check_dispel(level,victim, gsn_stone_skin ))
	{
		act("$n's skin regains its normal texture.",victim,NULL,NULL,TO_ROOM);
		found = true;
	}
	if (check_dispel(level,victim, gsn_weaken ))
	{
		act("$n looks stronger.",victim,NULL,NULL,TO_ROOM);
		found = true;
	}
	
	// Cancelation of the vanish skill.
	for ( roomchar = ch->in_room->people; roomchar != NULL; roomchar = roomchar->next_in_room )
	{
		if ( IS_AFFECTED2(roomchar, AFF2_VANISH))
		{
			affect_strip ( roomchar, gsn_vanish);
			REMOVE_BIT( roomchar->affected_by2, AFF2_VANISH );
			act( "A swirl of dust reveals $n.", roomchar, NULL, NULL, TO_ROOM );
			roomchar->println( "You have been revealed." );
			found = true;
		}
	}

	if (!found) {
        ch->println( "Spell failed." );
		return HALF_MANA;
	}

	ch->println( "Ok." );
	return FULL_MANA;
}

/**************************************************************************/
SPRESULT spell_cause_light( int sn, int level, char_data *ch, void *vo,int  )
{
	damage_spell( ch, (char_data *) vo, dice(1, 8) + level / 3, sn, DAMTYPE( sn ),true);
	return FULL_MANA;
}


/**************************************************************************/
SPRESULT spell_cause_critical(int sn,int level,char_data *ch,void *vo,int )
{
	damage_spell( ch, (char_data *) vo, dice(3, 8) + level - 6, sn, DAMTYPE( sn ), true);
	return FULL_MANA;
}


/**************************************************************************/
SPRESULT spell_cause_serious(int sn,int level,char_data *ch,void *vo,int )
{
	damage_spell( ch, (char_data *) vo, dice(2, 8) + level / 2, sn, DAMTYPE( sn ), true);
	return FULL_MANA;
}

/**************************************************************************/
SPRESULT spell_chain_lightning(int sn,int level,char_data *ch, void *vo,int )
{
	char_data *victim = (char_data *) vo;
	char_data *tmp_vict,*last_vict,*next_vict;
	bool found;
	int dam;

	// first strike 
	act("A lightning bolt leaps from $n's hand and arcs to $N.", ch,NULL,victim,TO_ROOM);
	act("A lightning bolt leaps from your hand and arcs to $N.", ch,NULL,victim,TO_CHAR);
	act("A lightning bolt leaps from $n's hand and hits you!",   ch,NULL,victim,TO_VICT);  

	dam = dice(level,5);
	if (saves_spell(level,victim, DAMTYPE(sn))){
		dam /= 3;
	}
	damage_spell(ch,victim,dam,sn,DAMTYPE(sn),true);
	last_vict = victim;
    level -= 4;   // decrement damage

    // new targets 
	while (level > 0)
	{
		found = false;
		for (tmp_vict = ch->in_room->people; tmp_vict != NULL; tmp_vict = next_vict) 
		{
			next_vict = tmp_vict->next_in_room;
			if (!is_safe_spell(ch,tmp_vict,true)
				&& tmp_vict != last_vict )
			{
				found = true;
				last_vict = tmp_vict;
				act("The bolt arcs to $n!",tmp_vict,NULL,NULL,TO_ROOM);
				act("The bolt hits you!",tmp_vict,NULL,NULL,TO_CHAR);
				dam = dice(level,5);
				if (saves_spell(level,tmp_vict,DAMTYPE(sn))){
					dam /= 3;
				}
				damage_spell(ch,tmp_vict,dam,sn,DAMTYPE(sn),true);
				level -= 4;  // decrement damage
			}
		}   // end target searching loop 
	
		if (!found) // no target found, hit the caster 
		{
			if (ch == NULL)
				return FULL_MANA;

			if (last_vict == ch) // no double hits 
			{
				act("The bolt seems to have fizzled out.",ch,NULL,NULL,TO_ROOM);
				act("The bolt grounds out through your body.",ch,NULL,NULL,TO_CHAR);
				return FULL_MANA;
			}

			last_vict = ch;
			act("The bolt arcs to $n...whoops!",ch,NULL,NULL,TO_ROOM);
			ch->println( "You are struck by your own lightning!" );
			dam = dice(level,6);
			if (saves_spell(level,ch,DAMTYPE(sn))){
				dam /= 3;
			}
			damage_spell(ch,ch,dam,sn,DAMTYPE(sn),true);
			level-= 4;  // decrement damage
			if (ch==NULL || ch->in_room==NULL) {
				return FULL_MANA;
			}
		}
		// now go back and find more targets 
	}
	return FULL_MANA;
}
	  
/**************************************************************************/
SPRESULT spell_change_sex( int sn, int level, char_data *ch, void *vo,int  )
{
    char_data *victim = (char_data *) vo;
    AFFECT_DATA af;

	if ( is_affected( victim, sn ))
	{
		if (victim == ch)
			ch->println( "You've already been changed." );
		else
			act("$N has already had $s(?) sex changed.",ch,NULL,victim,TO_CHAR);
		return HALF_MANA;
	}

	if (saves_spell(level , victim,DAMTYPE(sn)))
		return FULL_MANA;

	af.where     = WHERE_AFFECTS;
	af.type      = sn;
	af.level     = level;
	af.duration  = 2 * level;
	af.location  = APPLY_SEX;

	do { af.modifier  = number_range( 0, 2 ) - victim->sex; }
    while ( af.modifier == 0 );

	af.bitvector = 0;
	affect_to_char( victim, &af );
	victim->println( "You feel different." );
	act("$n doesn't look like $mself anymore...",victim,NULL,NULL,TO_ROOM);
	return FULL_MANA;
}


/**************************************************************************/
SPRESULT spell_charm_person( int sn, int level, char_data *ch, void *vo,int  )
{
	char_data *victim = (char_data *) vo;
	AFFECT_DATA af;

	if (is_safe(ch,victim)) 
	{
		ch->printlnf( "Your spell doesnt appear to have any affect on %s.", PERS(victim, ch));
		return HALF_MANA;
	}

	if ( victim == ch )
	{
		ch->println( "You like yourself even better!" );
		return HALF_MANA;
	}

	if (!IS_NPC(victim))
	{
		ch->println( "You cannot charm other players." );
		return FULL_MANA;
	}

	if ( IS_AFFECTED(victim, AFF_CHARM)
	||   IS_AFFECTED(ch, AFF_CHARM)
	||   level < victim->level
	||   IS_SET(victim->imm_flags,IMM_CHARM)
	||	 victim->modifiers[STAT_PR]>number_range(0,40)
	||   saves_spell( level, victim, DAMTYPE(sn) ) 
	||   (!IS_NPC(victim) 
			&& !GAMESETTING2(GAMESET2_NOCHARM_HAS_NOAFFECT)
			&& HAS_CONFIG(victim,CONFIG_NOCHARM) 
		 )
		 ){
		ch->println( "You failed." );
		return FULL_MANA;
	}

	if (!IS_NPC(victim) && IS_SET(victim->in_room->room_flags,ROOM_LAW))
	{
		ch->println( "The mayor does not allow charming in the city limits." );
		return HALF_MANA;
	}
  
	if ( victim->master ) {
		stop_follower( victim );
	}
    
	add_follower( victim, ch );
	victim->leader = ch;
	af.where     = WHERE_AFFECTS;
	af.type      = sn;
	af.level	 = level;
	af.duration  = number_fuzzy( level / 4 );
	af.location  = APPLY_NONE;
	af.modifier  = 0;
	af.bitvector = AFF_CHARM;
	affect_to_char( victim, &af );

	act( "Isn't $n just so nice?", ch, NULL, victim, TO_VICT );

	if ( ch != victim ) {
		act("$N looks at you with adoring eyes.",ch,NULL,victim,TO_CHAR);
	}

	if(IS_NPC(victim)) {
		REMOVE_BIT(victim->act, ACT_AGGRESSIVE);
	}
		
	// stop those who are charmed from logging out
	if (!IS_NPC(victim) && ch!=victim)
	{
		ch->pksafe=0;
		ch->pknorecall= UMAX(ch->pknorecall,2);
		ch->pknoquit  = UMAX(ch->pknorecall,7);

		if (!IS_NPC(ch))
		{
			victim->pknorecall= UMAX(victim->pknorecall,4);
			victim->pknoquit=UMAX(victim->pknoquit,10);
		}
	}
    return FULL_MANA;
}

/**************************************************************************/
SPRESULT spell_chill_touch( int sn, int level, char_data *ch, void *vo,int  )
{
	char_data *victim = (char_data *) vo;
	AFFECT_DATA af;
	int dam;

	dam		= dice(level/2, 2);
	if ( !saves_spell( level, victim,DAMTYPE(sn)))
	{
		act("$n turns blue and shivers.",victim,NULL,NULL,TO_ROOM);
		af.where     = WHERE_AFFECTS;
		af.type      = sn;
		af.level     = level;
		af.duration  = 6;
		af.location  = APPLY_ST;
		af.modifier  = -5;
		af.bitvector = 0;
		affect_join( victim, &af );
	}
	else
	{
		dam /= 2;
	}

	damage_spell( ch, victim, dam, sn, DAMTYPE(sn),true );
	return FULL_MANA;
}

/**************************************************************************/
SPRESULT spell_colour_spray( int sn, int level, char_data *ch, void *vo,int  )
{
	char_data *victim = (char_data *) vo;
	int dam			  = dice(level/3, 4)+40;

	if ( saves_spell( level, victim,DAMTYPE(sn)) )
		dam /= 2;
	else 
		spell_blindness( gsn_blindness, level/2,ch,(void *) victim,TARGET_CHAR);

	damage_spell( ch, victim, dam, sn, DAMTYPE(sn),true );
	return FULL_MANA;
}


/**************************************************************************/
SPRESULT spell_continual_light(int,int ,char_data *ch,void *,int )
{
	OBJ_DATA *light;

	if(!IS_NULLSTR(target_name))  // do a glow on some object 
	{
		light = get_obj_carry(ch,target_name);

		if (light == NULL)
		{
			ch->printlnf( "You don't see any '%s' here.", target_name );
			return NO_MANA;
		}

		if (IS_OBJ_STAT(light,OBJEXTRA_GLOW))
		{
			act("$p is already glowing.",ch,light,NULL,TO_CHAR);
			return NO_MANA;
		}

		SET_BIT(light->extra_flags,OBJEXTRA_GLOW);
		act("$p glows with a white light.",ch,light,NULL,TO_ALL);
		return FULL_MANA;
	}

	light = create_object( get_obj_index( OBJ_VNUM_LIGHT_BALL ));
	obj_to_room( light, ch->in_room );
	act( "$n twiddles $s thumbs and $p appears.",   ch, light, NULL, TO_ROOM );
	act( "You twiddle your thumbs and $p appears.", ch, light, NULL, TO_CHAR );
	return FULL_MANA;
}


/**************************************************************************/
SPRESULT spell_control_weather(int ,int level,char_data *ch,void *,int ) 
{
	if ( !str_cmp( target_name, "worse" ) )
		weather_info[ch->in_room->sector_type].change += dice( level / 3, 4 );
	else if ( !str_cmp( target_name, "better" ) )
		weather_info[ch->in_room->sector_type].change -= dice( level / 3, 4 );
	else {
		ch->println( "Do you want it to get better or worse?" );
		return NO_MANA;
	}

    ch->println( "Ok." );
	return FULL_MANA;
}

/**************************************************************************/
SPRESULT spell_create_food2( int , int level, char_data *ch, void *,int )
{
	OBJ_DATA *mushroom;

	mushroom = create_object( get_obj_index( OBJ_VNUM_MUSHROOM ));
	mushroom->value[0] = number_fuzzy(level);
	mushroom->value[1] = number_fuzzy(level)*2;
	mushroom->timer = (ch->level*2)+10;
	obj_to_room( mushroom, ch->in_room );
	if(	   ch->in_room->sector_type==SECT_AIR
		|| IS_WATER_SECTOR( ch->in_room->sector_type )){
		act( "$p suddenly appears.", ch, mushroom, NULL, TO_ROOM );
		act( "$p suddenly appears.", ch, mushroom, NULL, TO_CHAR );
	}else{
		act( "$p suddenly appears to grow from the ground.", ch, mushroom, NULL, TO_ROOM );
		act( "$p suddenly appears to grow from the ground.", ch, mushroom, NULL, TO_CHAR );
	}
	return FULL_MANA;
}

/**************************************************************************/
SPRESULT spell_create_food( int , int level, char_data *ch, void *,int )
{
	OBJ_DATA *fooditem;
	int		  foodvnum;
	char	  buf[MSL];

	foodvnum = race_table[ch->race]->food_vnum;

	if ( foodvnum == 0 )
		foodvnum = OBJ_VNUM_MUSHROOM;

	if ( get_obj_index( foodvnum ) == NULL )
	{
		bugf("Vnum %d not found for spell_create_food!", foodvnum );

		// do an autonote
		sprintf( buf, "Vnum `Y%d`x not found for race `Y%s`x.`1"
			"Please create item at next possible convenience.`1",
			foodvnum, race_table[ch->race]->name);
		autonote(NOTE_SNOTE, "spell_create_food()",	"Create food", "realm", buf, true);

		// default it to a known item so we don't go BOOM
		foodvnum = OBJ_VNUM_MUSHROOM;
	}

	fooditem = create_object( get_obj_index( foodvnum ));
	fooditem->value[0] = number_fuzzy(level);
	fooditem->value[1] = number_fuzzy(level)*2;
	fooditem->timer = (ch->level*2)+10;
	obj_to_room( fooditem, ch->in_room );

	act( "$p suddenly appears.", ch, fooditem, NULL, TO_ROOM );
	act( "$p suddenly appears.", ch, fooditem, NULL, TO_CHAR );

	return FULL_MANA;
}


/**************************************************************************/
SPRESULT spell_create_rose( int , int , char_data *ch, void *,int  )
{
	OBJ_DATA *rose;
	if (get_obj_index(OBJ_VNUM_ROSE)) {
		rose = create_object(get_obj_index(OBJ_VNUM_ROSE));
		act("$n has created a beautiful red rose.",ch,rose,NULL,TO_ROOM);
		ch->println( "You create a beautiful red rose." );
		obj_to_char(rose,ch);
	}else{
        ch->println( "BUG: No available rose object in spell_create_rose - please report!" );
		return NO_MANA;
	}

	return FULL_MANA;
}

/**************************************************************************/
SPRESULT spell_create_spring(int ,int level,char_data *ch,void *,int )
{
    OBJ_DATA *spring;

	if ( ch->in_room->sector_type == SECT_AIR )
	{
		ch->println( "You cannot create a spring in the middle of the air." );
		return HALF_MANA;
	}

	if ( IS_WATER_SECTOR( ch->in_room->sector_type ))
	{
		ch->println( "You cannot create a spring in water." );
		return HALF_MANA;
	}

	spring = create_object( get_obj_index( OBJ_VNUM_SPRING ));
	spring->timer = number_fuzzy(level);
	obj_to_room( spring, ch->in_room );
	act( "$p flows from the ground.", ch, spring, NULL, TO_ROOM );
	act( "$p flows from the ground.", ch, spring, NULL, TO_CHAR );
	return FULL_MANA;
}

/**************************************************************************/
SPRESULT spell_create_water( int , int level, char_data *ch, void *vo,int )
{
	OBJ_DATA *obj = (OBJ_DATA *) vo;
	int water;

	if ( obj->item_type != ITEM_DRINK_CON )
	{
		ch->println( "It is unable to hold water." );
		return NO_MANA;
	}

	if ( obj->value[2] != LIQ_WATER && obj->value[1] != 0 )
	{
		ch->println( "It contains some other liquid." );
		return HALF_MANA;
	}

	water = UMIN(
		level * (weather_info[ch->in_room->sector_type].sky >= SKY_RAINING ? 4 : 2),
		obj->value[0] - obj->value[1] );

	if ( water > 0 )
	{
		obj->value[2] = LIQ_WATER;
		obj->value[1] += water;
		if ( !is_name( "water", obj->name ) )
		{
			char buf[MSL];

			sprintf( buf, "%s water", obj->name );
			free_string( obj->name );
			obj->name = str_dup( buf );
		}
		act( "$p is filled.", ch, obj, NULL, TO_CHAR );
	}
	return FULL_MANA;
}


/**************************************************************************/
SPRESULT spell_cure_blindness(int ,int level,char_data *ch,void *vo,int )
{
    char_data *victim = (char_data *) vo;

	if ( !is_affected( victim, gsn_blindness ) )
	{
		if (victim == ch){
			ch->println( "You aren't blind." );
		}else{
			act("$N doesn't appear to be blinded.",ch,NULL,victim,TO_CHAR);
		}
		return HALF_MANA;
	}
 
	if (check_dispel(level,victim,gsn_blindness))
	{
		victim->println( "Your vision returns!" );
		act("$n is no longer blinded.",victim,NULL,NULL,TO_ROOM);
	}else{
		ch->println("Spell failed.");
	}

	return FULL_MANA;
}



/**************************************************************************/
SPRESULT spell_cure_critical( int , int level, char_data *ch, void *vo,int )
{
	char_data *victim = (char_data *) vo;
	int heal		  = dice(level/4+1, 2);

	victim->hit = UMIN( victim->hit + heal, victim->max_hit );
	update_pos( victim );
	victim->println( "You feel better!" );
	if ( ch != victim ){
		ch->println( "Ok." );
	}
	return FULL_MANA;
}

/**************************************************************************/
// RT added to cure plague
SPRESULT spell_cure_disease( int , int level, char_data *ch,void *vo,int )
{
	char_data *victim = (char_data *) vo;

	if ( !is_affected( victim, gsn_plague ) ){
		if (victim == ch){
			ch->println( "You aren't ill." );
		}else{
			act("$N doesn't appear to be diseased.",ch,NULL,victim,TO_CHAR);
		}
		return HALF_MANA;
	}
    
	if (check_dispel(level,victim,gsn_plague))
	{
		victim->println( "Your sores vanish." );
		act("$n looks relieved as $s sores vanish.",victim,NULL,NULL,TO_ROOM);
	}
	else
		ch->println("Spell failed.");

	return FULL_MANA;
}

/**************************************************************************/
SPRESULT spell_cure_light( int , int level, char_data *ch, void *vo,int )
{
	char_data *victim = (char_data *) vo;
	int heal		  = dice(level/12+1, 2);

	victim->hit = UMIN( victim->hit + heal, victim->max_hit );
	update_pos( victim );
	victim->println( "You feel better!" );
	if ( ch != victim ){
		ch->println( "Ok." );
	}
    return FULL_MANA;
}

/**************************************************************************/
SPRESULT spell_cure_poison( int , int level, char_data *ch, void *vo,int  )
{
	char_data *victim = (char_data *) vo;
 
	if ( !is_affected( victim, gsn_poison ) )
	{
		if (victim == ch){
			ch->println( "You aren't poisoned." );
		}else{
			act("$N doesn't appear to be poisoned.",ch,NULL,victim,TO_CHAR);
		}
		return HALF_MANA;
	}
 
	if (check_dispel(level,victim,gsn_poison))
	{
		victim->println( "A warm feeling runs through your body." );
		act("$n looks much better.",victim,NULL,NULL,TO_ROOM);
	}
	else
		ch->println("Spell failed.");
	return FULL_MANA;
}

/**************************************************************************/
SPRESULT spell_cure_serious( int , int level, char_data *ch, void *vo,int  )
{
    char_data *victim = (char_data *) vo;
    int heal		  = dice(level/8+1, 2);

	victim->hit = UMIN( victim->hit + heal, victim->max_hit );
	update_pos( victim );
	victim->println( "You feel better!" );

	if ( ch != victim ){
		ch->println( "Ok." );
	}
	return FULL_MANA;
}

/**************************************************************************/
SPRESULT spell_curse( int sn, int level, char_data *ch, void *vo,int target )
{
	char_data *victim;
	OBJ_DATA *obj;
	AFFECT_DATA af;

    // deal with the object curses first
	if (target == TARGET_OBJ)
	{
		obj = (OBJ_DATA *) vo;
		if (IS_OBJ_STAT(obj,OBJEXTRA_EVIL))
		{
			act("$p is already filled with evil.",ch,obj,NULL,TO_CHAR);
			return HALF_MANA;
		}

		if (IS_OBJ_STAT(obj,OBJEXTRA_BLESS))
		{
			AFFECT_DATA *paf;

			paf = affect_find(obj->affected, gsn_bless );
			if (!saves_dispel(level,paf != NULL ? paf->level : obj->level,0))
			{
				if (paf != NULL)
					affect_remove_obj(obj,paf);
				act("$p glows with a red aura.",ch,obj,NULL,TO_ALL);
				REMOVE_BIT(obj->extra_flags,OBJEXTRA_BLESS);
				return FULL_MANA;
			}
			else
			{
				act("The holy aura of $p is too powerful for you to overcome.",ch,obj,NULL,TO_CHAR);
				return FULL_MANA;
			}
		}

		af.where        = WHERE_OBJEXTRA;
		af.type         = sn;
		af.level        = level;
		af.duration     = 2 * level;
		af.location     = APPLY_SAVES;
		af.modifier     = +1;
		af.bitvector    = OBJEXTRA_EVIL;
		affect_to_obj(obj,&af);

		act("$p glows with a malevolent aura.",ch,obj,NULL,TO_ALL);
		return FULL_MANA;
	}

	// character curses 
	victim = (char_data *) vo;

	if( is_affected( victim, gsn_bless ))
		if( check_dispel( level, victim, gsn_bless ))
		{
			act( "Your magic unravels a spell on $N.", ch, NULL, victim, TO_CHAR );
			return FULL_MANA;
		}
		else
		{
			ch->println( "You failed." );
			return FULL_MANA;
		}

	if(IS_AFFECTED(victim,AFF_CURSE))
	{
		act("$N already looks very uncomfortable.",ch,NULL,victim,TO_CHAR);
		return HALF_MANA;
	}
		
	if(saves_spell(level,victim,DAMTYPE(sn))){
		ch->println( "Your spell doesnt appear to have much affect." );
		return FULL_MANA;
	}
			
	if(HAS_CLASSFLAG(victim, CLASSFLAG_CURSE_IMMUNITY)) // fails if paladin
	{
		ch->printlnf( "Your spell doesnt appear to have any affect on %s.", PERS(victim, ch) );
		return FULL_MANA;
	}

	af.where     = WHERE_AFFECTS;
	af.type      = sn;
	af.level     = level;
	af.duration  = level/2 + (number_fuzzy(3)*2);
	af.location  = APPLY_HITROLL;
	af.modifier  = -1 * (level / 8);
	af.bitvector = AFF_CURSE;
	affect_to_char( victim, &af );

	af.location  = APPLY_SAVES;
	af.modifier  = level / 8;
	affect_to_char( victim, &af );

	victim->println( "You feel unclean." );
	if ( ch != victim )
	{
		act("$N looks very uncomfortable.",ch,NULL,victim,TO_CHAR);
		// stop those who are slept from logging out
		if (!IS_NPC(ch))
			victim->pknoquit=UMAX(victim->pknoquit,10);
	}

	return FULL_MANA;
}

/**************************************************************************/
SPRESULT spell_detect_evil( int sn, int level, char_data *ch, void *vo,int  )
{
	char_data *victim = (char_data *) vo;
	AFFECT_DATA af;

	if ( IS_AFFECTED(victim, AFF_DETECT_EVIL) )
	{
		if (victim == ch){
			ch->println( "You can already sense evil." );
		}else{
			act("$N can already detect evil.",ch,NULL,victim,TO_CHAR);
		}
		return HALF_MANA;
	}

	af.where     = WHERE_AFFECTS;
	af.type      = sn;
	af.level	 = level;
	af.duration  = level;
	af.modifier  = 0;
	af.location  = APPLY_NONE;
	af.bitvector = AFF_DETECT_EVIL;
	affect_to_char( victim, &af );
	victim->println( "Your eyes tingle." );
	if ( ch != victim ){
		ch->println( "Ok." );
	}
	return FULL_MANA;
}

/**************************************************************************/
SPRESULT spell_detect_good( int sn, int level, char_data *ch, void *vo,int  )
{
	char_data *victim = (char_data *) vo;
	AFFECT_DATA af;
 
	if ( IS_AFFECTED(victim, AFF_DETECT_GOOD) )
	{
		if (victim == ch){
			ch->println( "You can already sense good." );
		}else{
			act("$N can already detect good.",ch,NULL,victim,TO_CHAR);
		}
		return HALF_MANA;
	}

	af.where     = WHERE_AFFECTS;
	af.type      = sn;
	af.level     = level;
	af.duration  = level;
	af.modifier  = 0;
	af.location  = APPLY_NONE;
	af.bitvector = AFF_DETECT_GOOD;
	affect_to_char( victim, &af );
	victim->println( "Your eyes tingle." );

	if ( ch != victim )
		ch->println( "Ok." );
	return FULL_MANA;
}

/**************************************************************************/
SPRESULT spell_detect_hidden(int sn,int level,char_data *ch,void *vo,int )
{
	char_data *victim = (char_data *) vo;
	AFFECT_DATA af;

	if ( IS_AFFECTED(victim, AFF_DETECT_HIDDEN) )
	{
		if (victim == ch){
			ch->println( "You are already as alert as you can be." );
		}else{
			act("$N can already sense hidden lifeforms.",ch,NULL,victim,TO_CHAR);
		}
		return HALF_MANA;
	}

	af.where     = WHERE_AFFECTS;
	af.type      = sn;
	af.level     = level;
	af.duration  = level;
	af.location  = APPLY_NONE;
	af.modifier  = 0;
	af.bitvector = AFF_DETECT_HIDDEN;
	affect_to_char( victim, &af );
	victim->println( "Your awareness improves." );
	if ( ch != victim ){
		ch->println( "Ok." );
	}
	return FULL_MANA;
}

/**************************************************************************/
SPRESULT spell_detect_invis( int sn, int level, char_data *ch, void *vo,int )
{
	char_data *victim = (char_data *) vo;
	AFFECT_DATA af;

	if ( IS_AFFECTED(victim, AFF_DETECT_INVIS) )
	{
		if (victim == ch){
			ch->println( "You can already see invisible." );
		}else{
			act("$N can already see invisible things.",ch,NULL,victim,TO_CHAR);
		}
		return HALF_MANA;
	}

	af.where     = WHERE_AFFECTS;
	af.type      = sn;
	af.level     = level;
	af.duration  = level;
	af.modifier  = 0;
	af.location  = APPLY_NONE;
	af.bitvector = AFF_DETECT_INVIS;
	affect_to_char( victim, &af );
	victim->println( "Your eyes tingle." );
	if ( ch != victim ){
		ch->println( "Ok." );
	}
	return FULL_MANA;
}

/**************************************************************************/
SPRESULT spell_detect_magic( int sn, int level, char_data *ch, void *vo,int )
{
	char_data *victim = (char_data *) vo;
	AFFECT_DATA af;

	if ( IS_AFFECTED(victim, AFF_DETECT_MAGIC) )
	{
		if (victim == ch){
			ch->println( "You can already sense magical auras." );
		}else{
			act("$N can already detect magic.",ch,NULL,victim,TO_CHAR);
		}
		return HALF_MANA;
	}

	af.where     = WHERE_AFFECTS;
	af.type      = sn;
	af.level	 = level;
	af.duration  = level;
	af.modifier  = 0;
	af.location  = APPLY_NONE;
	af.bitvector = AFF_DETECT_MAGIC;
	affect_to_char( victim, &af );
	victim->println( "Your eyes tingle." );
	if ( ch != victim ){
		ch->println( "Ok." );
	}
	return FULL_MANA;
}


/**************************************************************************/
SPRESULT spell_detect_poison( int , int , char_data *ch, void *vo,int )
{
	OBJ_DATA *obj = (OBJ_DATA *) vo;

	if ( obj->item_type == ITEM_DRINK_CON || obj->item_type == ITEM_FOOD )
	{
		if ( obj->value[3] != 0 ){
			ch->println( "You smell poisonous fumes." );
		}else{
			ch->println( "It looks delicious." );
		}
	}else{
		ch->println( "It doesn't look poisoned." );
	}

	return FULL_MANA;
}

/**************************************************************************/
SPRESULT spell_dispel_evil( int sn, int level, char_data *ch, void *vo,int )
{
	char_data *victim = (char_data *) vo;
	int dam;
  
	if ( !IS_NPC(ch) && IS_EVIL(ch) )
		victim = ch;
  
	if ( IS_GOOD(victim) )
	{
		act( "$N appears to be protected.", ch, NULL, victim, TO_ROOM );
		return FULL_MANA;
	}

	if ( IS_NEUTRAL(victim) )
	{
		act( "$N does not seem to be affected.", ch, NULL, victim, TO_CHAR );
		return FULL_MANA;
	}

	if (victim->hit > (ch->level * 4))
		dam = dice( level, 4 );
	else
		dam = UMAX(victim->hit, dice(level,4));
    
	if ( saves_spell( level, victim,DAMTYPE(sn)) )
		dam /= 2;

	damage_spell( ch, victim, dam, sn, DAMTYPE(sn),true);
	return FULL_MANA;
}

/***************************************************************************/
SPRESULT spell_dispel_good( int sn, int level, char_data *ch, void *vo,int  )
{
	char_data *victim = (char_data *) vo;
	int dam;
 
	if ( !IS_NPC(ch) && IS_GOOD(ch) )
		victim = ch;
 
	if ( IS_EVIL(victim) )
	{
		act( "$N is protected by $S evil.", ch, NULL, victim, TO_ROOM );
		return FULL_MANA;
	}
 
	if ( IS_NEUTRAL(victim) )
	{
		act( "$N does not seem to be affected.", ch, NULL, victim, TO_CHAR );
		return FULL_MANA;
	}
 
	if (victim->hit > (ch->level * 4))
		dam = dice( level, 4 );
	else
		dam = UMAX(victim->hit, dice(level,4));
	if ( saves_spell( level, victim,DAMTYPE(sn)) )
		dam /= 2;
	damage_spell( ch, victim, dam, sn, DAMTYPE(sn) ,true);
	return FULL_MANA;
}

/***************************************************************************/
// modified for enhanced use
SPRESULT spell_dispel_magic( int sn , int level, char_data *ch, void *vo,int  )
{
	char_data *victim = (char_data *) vo;
	bool found = false;

	if (saves_spell(level, victim,DAMTYPE(sn)))
	{
		victim->println( "You feel a brief tingling sensation." );
		ch->println( "You failed." );
		return FULL_MANA;
	}

	// begin running through the spells 
	found = check_dispel(level,victim,gsn_regeneration);
	found = check_dispel(level,victim,gsn_resist_poison);
	found = check_dispel(level,victim,gsn_poison_immunity);
	found = check_dispel(level,victim,gsn_prismatic_spray);
	found = check_dispel(level,victim,gsn_illusions_grandeur);
	found = check_dispel(level,victim,gsn_protection_fire);
	found = check_dispel(level,victim,gsn_protection_cold);
	found = check_dispel(level,victim,gsn_protection_acid);
	found = check_dispel(level,victim,gsn_protection_lightning);
	found = check_dispel(level,victim,gsn_holy_aura);
	found = check_dispel(level,victim,gsn_unholy_aura);
	found = check_dispel(level,victim,gsn_true_sight);
	found = check_dispel(level,victim,gsn_barkskin);
	found = check_dispel(level,victim,gsn_magic_resistance);
	found = check_dispel(level,victim,gsn_fire_shield);
	found = check_dispel(level,victim,gsn_chill_shield);
	found = check_dispel(level,victim,gsn_animal_essence);
	found = check_dispel(level,victim,gsn_armor);
	found = check_dispel(level,victim,gsn_bless);

    if (check_dispel(level, victim, gsn_polymorph ))
    {
        found = true;
        act("$n looks more like $mself again.",victim,NULL,NULL,TO_ROOM);
    }

	if (check_dispel(level,victim,gsn_blindness ))
	{
		found = true;
		act("$n is no longer blinded.",victim,NULL,NULL,TO_ROOM);
	}
	if (check_dispel(level,victim,gsn_calm))
	{
		found = true;
		act("$n no longer looks so peaceful...",victim,NULL,NULL,TO_ROOM);
	}
	if (check_dispel(level,victim, gsn_change_sex ))
	{
		found = true;
		act("$n looks more like $mself again.",victim,NULL,NULL,TO_ROOM);
	}
	if (check_dispel(level,victim,gsn_charm_person))
	{
		found = true;
		act("$n regains $s free will.",victim,NULL,NULL,TO_ROOM);
	}
	if (check_dispel(level,victim,gsn_chill_touch))
	{
		found = true;
		act("$n looks warmer.",victim,NULL,NULL,TO_ROOM);
	}
	if (check_dispel(level,victim, gsn_curse ))
		found = true;
	if (check_dispel(level,victim,gsn_detect_evil))
		found = true;
	if (check_dispel(level,victim,gsn_detect_scry ))
		found = true;
	if (check_dispel(level,victim,gsn_detect_good))
		found = true;
	if (check_dispel(level,victim,gsn_detect_hidden))
		found = true;
    if (check_dispel(level,victim,gsn_detect_invis))
        found = true;
	if (check_dispel(level,victim,gsn_detect_magic))
		found = true;
	if (check_dispel(level,victim, gsn_faerie_fire ))
	{
		act("$n's outline fades.",victim,NULL,NULL,TO_ROOM);
		found = true;
	}
	if (check_dispel(level,victim, gsn_fly ))
	{
		act("$n falls to the ground!",victim,NULL,NULL,TO_ROOM);
		found = true;
	}
	if (check_dispel(level,victim, gsn_frenzy ))
	{
		act("$n no longer looks so wild.",victim,NULL,NULL,TO_ROOM);;
		found = true;
	}
	if (check_dispel(level,victim, gsn_giant_strength ))
	{
		act("$n no longer looks so mighty.",victim,NULL,NULL,TO_ROOM);
		found = true;
	}
	if (check_dispel(level,victim, gsn_haste ))
	{
		act("$n is no longer moving so quickly.",victim,NULL,NULL,TO_ROOM);
		found = true;
	}
	if (check_dispel(level,victim,gsn_infravision))
		found = true;
	if (check_dispel(level,victim,gsn_darkvision))
		found = true;
	if (check_dispel(level,victim, gsn_invisibility ))
	{
		act("$n fades into existance.",victim,NULL,NULL,TO_ROOM);
		found = true;
	}
	if (check_dispel(level,victim,gsn_mass_invis))
	{
		act("$n fades into existance.",victim,NULL,NULL,TO_ROOM);
		found = true;
	}
	if (check_dispel(level,victim,gsn_pass_door))
		found = true;
	if (check_dispel(level,victim,gsn_protection_evil))
		found = true;
	if (check_dispel(level,victim,gsn_protection_good))
		found = true;
	if (check_dispel(level,victim,gsn_rage))
		found = true;
	if (check_dispel(level,victim, gsn_sanctuary ))
	{
		act("The white aura around $n's body vanishes.",victim,NULL,NULL,TO_ROOM);
		found = true;
	}
    if (IS_AFFECTED(victim,AFF_SANCTUARY) 
	&& !saves_dispel(level, victim->level,-1)
	&& !is_affected(victim, gsn_sanctuary ))
	{
		REMOVE_BIT(victim->affected_by,AFF_SANCTUARY);
		act("The white aura around $n's body vanishes.",victim,NULL,NULL,TO_ROOM);
		found = true;
	}
	if (check_dispel(level,victim,gsn_shield))
	{
		act("The shield protecting $n vanishes.",victim,NULL,NULL,TO_ROOM);
		found = true;
	}
	if (check_dispel(level,victim,gsn_sleep))
		found = true;
	if (check_dispel(level,victim, gsn_slow ))
	{
		act("$n is no longer moving so slowly.",victim,NULL,NULL,TO_ROOM);
		found = true;
	}
	if (check_dispel(level,victim,gsn_stone_skin))
	{
		act("$n's skin regains its normal texture.",victim,NULL,NULL,TO_ROOM);
		found = true;
	}
	if (check_dispel(level,victim, gsn_weaken ))
	{
		act("$n looks stronger.",victim,NULL,NULL,TO_ROOM);
		found = true;
	}
	if (check_dispel(level,victim,gsn_wind_shield))
	{
		act("The wind around $n's body dies down.",victim,NULL,NULL,TO_ROOM);
		found = true;
	}

    if (found)
        ch->println( "Ok." );
    else {
        ch->println("Spell failed.");
		return HALF_MANA;
	}
	return FULL_MANA;
}

/***************************************************************************/
SPRESULT spell_earthquake( int sn, int level, char_data *ch, void *,int  )
{
	char_data *vch;
	char_data *vch_next;

	ch->println( "The earth trembles beneath your feet!" );
	act( "$n makes the earth tremble and shiver.", ch, NULL, NULL, TO_ROOM );

    for ( vch = ch->in_room->people; vch; vch = vch_next )
	{
        vch_next=vch->next_in_room;
		if ( vch->in_room == NULL )
			continue;
		if ( vch->in_room == ch->in_room )
		{
			if ( vch != ch && !is_safe_spell(ch,vch,true))
			if (IS_AFFECTED(vch,AFF_FLYING))
				damage_spell(ch,vch,0,sn,DAMTYPE(sn),true);
			else
				damage_spell( ch,vch,level + dice(2, 8), sn, DAMTYPE(sn),true);
			continue;
		}

		if ( vch->in_room->area == ch->in_room->area ){
			vch->println( "The earth trembles and shivers." );
		}
	}
    return FULL_MANA;
}

/***************************************************************************/
SPRESULT spell_enchant_armor( int sn, i

Showing the first 100 KB of 205.9 KB. Download the archive for the full file.

Site Stats

Snippets: 1791
Codebases: 571