/* NEW SPELLS */

/* Coded by Teldin of ICONOCLASM mud.
Use as you will, I don't expect,
deserve, or want your credit or thanks. :)
>>Iconoclasm.homeip.net:4200, currently beta
testing and builder port. Just thought I'd
give a few snippets to the community, since
this is where I've mostly learned how to
code it.

There are tons of how-to's on adding new
skills and spells, so I'm not going to bother
with one ;)

*/


/* Cleric (I have a new class for it) - use your mana to give mana */
void spell_channel( int sn, int level, CHAR_DATA *ch, void *vo,int target)

{

    CHAR_DATA *victim = (CHAR_DATA *) vo;

    int heal;

    heal = dice(3, 3) + (level / 3) * 2;

    if (ch == victim)

     {

      send_to_char( "You cannot channel energy into yourself.\n\r", ch );

      return;

     }

    victim->mana = UMIN( victim->mana + heal, victim->max_mana );

    update_pos( victim );

    send_to_char( "A swirling cloud of energy engulfs you!\n\r", victim );

    if ( ch != victim )

	send_to_char( "A swirling cloud of energy slips from your fingertips.\n\r", ch );

    return;

}


/* caster-only, turns all movement into mana */
void spell_investiture( int sn, int level, CHAR_DATA *ch, void *vo,int target)

{

    CHAR_DATA *victim = (CHAR_DATA *) vo;

    int heal;

    heal = ch->move;

    victim->mana = UMIN( victim->mana + heal, victim->max_mana );

    victim->move = 0;

    update_pos( victim );

    send_to_char( "{cThe forces of the earth fill you with energy!{x\n\r", victim );

    act( "$n draws magic from the very earth!", ch, NULL, NULL, TO_ROOM );

}

/* Quite strong area affect spell */
void spell_powerstorm( int sn, int level, CHAR_DATA *ch, void *vo,int target )

{
    CHAR_DATA *vch;

    CHAR_DATA *vch_next;

    act( "$n makes a firey blaze of magic engulf the room!", ch, NULL, NULL, TO_ROOM );

    for ( vch = char_list; vch != NULL; vch = vch_next )

    {

	vch_next	= vch->next;

	if ( vch->in_room == NULL )

	    continue;

	if ( vch->in_room == ch->in_room )

	{

	    if ( vch != ch && !is_safe_spell(ch,vch,TRUE))

		    damage_old( ch,vch,level / 3 * 2 + dice(20, 20), sn, DAM_FIRE,TRUE);

	    continue;

	}

	if ( vch->in_room->area == ch->in_room->area )

	    send_to_char( "A blazing storm of energy rumbles through the area.\n\r", vch );

    }

    return;

}

/* strong simple damage spell */
void spell_mana_burn( int sn, int level, CHAR_DATA *ch, void *vo, int target )

{

    CHAR_DATA *victim = (CHAR_DATA *) vo;

    int dam;

    dam = dice( level, 13 );

    if ( saves_spell( level, victim, DAM_FIRE ) )

	dam /= 2;

    fire_effect(victim,level/2,dam/10,TARGET_CHAR);

    damage_old( ch, victim, dam, sn,DAM_FIRE,TRUE);

    return;

}

/* Spellup spell a'la stone skin */
void spell_bark_skin( int sn, int level, CHAR_DATA *ch, void *vo, int target )

{

    CHAR_DATA *victim = (CHAR_DATA *) vo;

    AFFECT_DATA af;

    if ( is_affected( victim, sn ) )

    {

	if (victim == ch)

	  send_to_char("Your skin is already covered in bark.\n\r",ch);

	else

	  act("$N's skin is already bark.",ch,NULL,victim,TO_CHAR);

	return;

    }

    af.where	 = TO_AFFECTS;

    af.type      = sn;

    af.level	 = level;

    af.duration  = level/3;

    af.modifier  = -30 - level / 5;

    af.location  = APPLY_AC;

    af.bitvector = 0;

    affect_to_char( victim, &af );

    send_to_char( "Your skin becomes as tough as bark.\n\r", victim );

    if ( ch != victim )

	act("$N's skin becomes as tough as bark.",ch,NULL,victim,TO_CHAR);

    return;

}

/* Caster-only saves booster for magic users */
void spell_spell_mantle( int sn, int level, CHAR_DATA *ch, void *vo, int target )

{

    CHAR_DATA *victim = (CHAR_DATA *) vo;

    AFFECT_DATA af;

    if ( is_affected( victim, sn ) )

    {

	if (victim == ch)

	  send_to_char("You are already protected against magic.\n\r",ch);

	else

	  act("$N is already protected.",ch,NULL,victim,TO_CHAR);

	return;

    }

    af.where	 = TO_AFFECTS;

    af.type      = sn;

    af.level	 = level;

    af.duration  = level / 3;

    af.modifier  = 1 - level / 6;

    af.location  = APPLY_SAVES;

    af.bitvector = 0;

    affect_to_char( victim, &af );

    send_to_char( "You are surrounded by a glowing spell mantle.\n\r", victim );

    if ( ch != victim )

	act("$N is surrounded by a glowing spell mantle.",ch,NULL,victim,TO_CHAR);

    return;

}

/* Strength + damroll booster */
void spell_animal_instinct( int sn, int level, CHAR_DATA *ch, void *vo, int target )

{

    CHAR_DATA *victim = (CHAR_DATA *) vo;

    AFFECT_DATA af;

    if ( is_affected( victim, sn ) )

    {

	if (victim == ch)

	  send_to_char("You are already animalistic.\n\r",ch);

	else

	  act("$N is already animalistic.",ch,NULL,victim,TO_CHAR);

	return;

    }

    af.where	 = TO_AFFECTS;

    af.type      = sn;

    af.level	 = level;

    af.duration  = level/2;

    af.modifier  = level/25;

    af.location  = APPLY_STR;

    af.bitvector = 0;

    affect_to_char( victim, &af );

    af.where	 = TO_AFFECTS;

    af.type      = sn;

    af.level	 = level;

    af.duration  = level/2;

    af.modifier  = level/20;

    af.location  = APPLY_DAMROLL;

    af.bitvector = 0;

    affect_to_char( victim, &af );
    send_to_char( "You suddenly look like a wild beast!\n\r", victim );

    if ( ch != victim )

	act("$N suddenly grows fangs and claws!",ch,NULL,victim,TO_CHAR);

    return;


}
/* Fun spell! Does random stat changes, can easily be fixed to add maladicts/benedicts */
void spell_chaos_flare( int sn, int level, CHAR_DATA *ch, void *vo, int target )

{

    CHAR_DATA *victim = (CHAR_DATA *) vo;

    AFFECT_DATA af;

    int rnum;
    if ( is_affected( victim, sn ) )

    {

	if (victim == ch)

	  send_to_char("You are already touched by chaos.\n\r",ch);

	else

	  act("$N's skin is already touched by chaos.",ch,NULL,victim,TO_CHAR);

	return;

    }

    af.where	 = TO_AFFECTS;

    af.type      = sn;

    af.level	 = level;

    af.duration  = level/3;

    rnum = number_percent();
    if (rnum <= 5)
	{	
	    af.modifier  = -30 - level / 5;
	    af.location  = APPLY_AC;	
	    af.bitvector = 0;

	    affect_to_char( victim, &af );

	    send_to_char( "Glinting scales form over your skin!\n\r", victim );

	    if ( ch != victim )

		act("$N's skin is suddenly covered with metallic scales.",ch,NULL,victim,TO_CHAR);

	    return;
	}
    if (rnum <= 15)
	{	
	    af.modifier  = level / 20;
	    af.location  = APPLY_DAMROLL;	
	    af.bitvector = 0;

	    affect_to_char( victim, &af );

	    send_to_char( "Sharp spikes jut out of your skin!\n\r", victim );

	    if ( ch != victim )

		act("$N's skin is suddenly covered with jagged spikes.",ch,NULL,victim,TO_CHAR);

	    return;
	}
    if (rnum <= 25)
	{	
	    af.modifier  = level / 20;
	    af.location  = APPLY_HITROLL;	
	    af.bitvector = 0;

	    affect_to_char( victim, &af );

	    send_to_char( "Your eyes gleam.\n\r", victim );

	    if ( ch != victim )

		act("$N's eyes gleam.",ch,NULL,victim,TO_CHAR);

	    return;
	}
    if (rnum <= 35)
	{	
	    af.modifier  = level*2;
	    af.location  = APPLY_MOVE;	
	    af.bitvector = 0;

	    affect_to_char( victim, &af );

	    send_to_char( "You suddenly grow an extra set of legs!\n\r", victim );

	    if ( ch != victim )

		act("$N suddenly grows an extra set of legs! Yipes!",ch,NULL,victim,TO_CHAR);

	    return;
	}
    if (rnum <= 45)
	{	
	    af.modifier  = level / 20;
	    af.location  = APPLY_CON;	
	    af.bitvector = 0;

	    affect_to_char( victim, &af );

	    send_to_char( "You grow much tougher!\n\r", victim );

	    if ( ch != victim )

		act("$N seems much tougher all of a sudden.",ch,NULL,victim,TO_CHAR);

	    return;
	}
    if (rnum <= 50)
	{	
	    af.modifier  = level / 4;
	    af.location  = APPLY_DAMROLL;	
	    af.bitvector = 0;

	    affect_to_char( victim, &af );

	    send_to_char( "{YA blaze of light surrounds you!{x\n\r", victim );

	    if ( ch != victim )

		act("{YA blazing halo surrounds $N!{x",ch,NULL,victim,TO_CHAR);

	    return;
	}
    if (rnum <= 65)
	{	
	    af.modifier  = 1 - level / 20;
	    af.location  = APPLY_DEX;	
	    af.bitvector = 0;

	    affect_to_char( victim, &af );

	    send_to_char( "One of your arms suddenly turns into a flipper.\n\r", victim );

	    if ( ch != victim )

		act("One of $N's arms turns into a.. dolphin flipper.",ch,NULL,victim,TO_CHAR);

	    return;
	}
    if (rnum <= 75)
	{	
	    af.modifier  = 1 - level / 20;
	    af.location  = APPLY_INT;	
	    af.bitvector = 0;

	    affect_to_char( victim, &af );

	    send_to_char( "Me say wah? You suddenly feel very stoopid.\n\r", victim );

	    if ( ch != victim )

		act("$N is suddenly looking very stupid.",ch,NULL,victim,TO_CHAR);

	    return;
	}
    if (rnum <= 85)
	{	
	    af.modifier  = level * 3;
	    af.location  = APPLY_HIT;	
	    af.bitvector = 0;

	    affect_to_char( victim, &af );

	    send_to_char( "You grow two sizes bigger!\n\r", victim );

	    if ( ch != victim )

		act("$N suddenly gets bigger.. and bigger.. and bigger.",ch,NULL,victim,TO_CHAR);

	    return;
	}
    if (rnum <= 95)
	{	
	    af.modifier  = 1 + level * 2;
	    af.location  = APPLY_AC;	
	    af.bitvector = 0;

	    affect_to_char( victim, &af );

	    send_to_char( "You suddenly feel quite vulnerable. They're all out to get you!\n\r", victim );

	    if ( ch != victim )

		act("$N looks might paranoid all of a sudden.",ch,NULL,victim,TO_CHAR);

	    return;
	}
    if (rnum <= 100)
	{	
	    af.modifier  = 1 - level;
	    af.location  = APPLY_DAMROLL;	
	    af.bitvector = 0;

	    affect_to_char( victim, &af );

	    send_to_char( "{cAck! You turn into an oozing gelatinous blob!\n\r", victim );

	    if ( ch != victim )

		act("{c$N's been turned into a green oozing blob!{c",ch,NULL,victim,TO_ROOM);

	    return;
	}


    return;

}

/* Damage spell, hits random vulns + weapon effects */
void spell_wild_magic( int sn, int level, CHAR_DATA *ch, void *vo, int target )

{
	
    CHAR_DATA *victim = (CHAR_DATA *) vo;
	
    int dam;
	
    int numba;    
    dam = dice( level * 3 / 2, 14 );
	
    numba = number_percent();
    if (numba <= 10)
	{
		if ( saves_spell( level, victim, DAM_ACID ) )
			
			dam /= 2;
		
		damage_old( ch, victim, dam, sn,DAM_ACID,TRUE);
		acid_effect(victim,level,dam,TARGET_CHAR);
		return;
	}
    if (numba <= 20)
	{
		if ( saves_spell( level, victim, DAM_FIRE ) )
			
			dam /= 2;
		
		damage_old( ch, victim, dam, sn,DAM_FIRE,TRUE);
		fire_effect(victim,level,dam,TARGET_CHAR);
		return;
	}
    if (numba <= 30)
	{
		if ( saves_spell( level, victim, DAM_LIGHTNING ) )
			
			dam /= 2;
		
		damage_old( ch, victim, dam, sn,DAM_LIGHTNING,TRUE);
		shock_effect(victim,level,dam,TARGET_CHAR);
		return;
	}
    if (numba <= 40)
	{
		if ( saves_spell( level, victim, DAM_COLD ) )
			
			dam /= 2;
		
		damage_old( ch, victim, dam, sn,DAM_COLD,TRUE);
		cold_effect(victim,level,dam,TARGET_CHAR);
		return;
	}
    if (numba <= 50)
	{
		if ( saves_spell( level, victim, DAM_HOLY ) )
			
			dam /= 2;
		
		damage_old( ch, victim, dam, sn,DAM_HOLY,TRUE);
		return;
	}
    if (numba <= 60)
	{
		if ( saves_spell( level, victim, DAM_LIGHT ) )
			
			dam /= 2;
		
		damage_old( ch, victim, dam, sn,DAM_LIGHT,TRUE);
	/*	brilliant_effect(victim,level,dam,TARGET_CHAR); */ /* Iconoclasm effect */ 
		return;
	}
    if (numba <= 70)
	{
		if ( saves_spell( level, victim, DAM_DROWNING ) )
			
			dam /= 2;
		
		damage_old( ch, victim, dam, sn,DAM_DROWNING,TRUE);
	/*	flood_effect(victim,level,dam,TARGET_CHAR); */
		return;
	}
    if (numba <= 80)
	{
		if ( saves_spell( level, victim, DAM_DISEASE ) )
			
			dam /= 2;
		
		damage_old( ch, victim, dam, sn,DAM_DISEASE,TRUE);
		return;
	}
    if (numba <= 90)
	{
		if ( saves_spell( level, victim, DAM_SLASH ) )
			
			dam /= 2;
		
		damage_old( ch, victim, dam, sn,DAM_SLASH,TRUE);
		return;
	}
    if (numba <= 100)
	{
		if ( saves_spell( level, victim, DAM_NEGATIVE ) )
			
			dam /= 2;
		dam /=5;
		
		damage_old( ch, victim, dam, sn,DAM_NEGATIVE,TRUE);
	/*	flood_effect(victim,level,dam,TARGET_CHAR); iconoclasm effect */
		acid_effect(victim,level,dam,TARGET_CHAR);
		fire_effect(victim,level,dam,TARGET_CHAR);
		cold_effect(victim,level,dam,TARGET_CHAR);
		shock_effect(victim,level,dam,TARGET_CHAR);
		return;
	}
    return;
	
}