magic.c

toc/code/magic.c · 237.0 KB

From the archive fear2.1.3.tar.gz

Download the archive   « Back to the archive contents

/****************************************************************************
 * [S]imulated [M]edieval [A]dventure multi[U]ser [G]ame      |   \\._.//   *
 * -----------------------------------------------------------|   (0...0)   *
 * SMAUG 1.4 (C) 1994, 1995, 1996, 1998  by Derek Snider      |    ).:.(    *
 * -----------------------------------------------------------|    {o o}    *
 * SMAUG code team: Thoric, Altrag, Blodkai, Narn, Haus,      |   / ' ' \   *
 * Scryn, Rennard, Swordbearer, Gorog, Grishnakh, Nivek,      |~'~.VxvxV.~'~*
 * Tricops and Fireblade                                      |             *
 * ------------------------------------------------------------------------ *
 * Merc 2.1 Diku Mud improvments copyright (C) 1992, 1993 by Michael        *
 * Chastain, Michael Quan, and Mitchell Tse.                                *
 * Original Diku Mud copyright (C) 1990, 1991 by Sebastian Hammer,          *
 * Michael Seifert, Hans Henrik St{rfeldt, Tom Madsen, and Katja Nyboe.     *
 * ------------------------------------------------------------------------ *
 *			     Spell handling module			    *
 ****************************************************************************/

#include <sys/types.h>
#include <ctype.h>
#include <stdio.h>
#include <string.h>
#ifdef sun
#include <strings.h>
#endif
#include <time.h>
#include "mud.h"


/*
 * Local functions.
 */
void say_spell args((CHAR_DATA * ch, int sn));

/*
CHAR_DATA *make_poly_mob args( (CHAR_DATA *ch, int vnum) );
*/
ch_ret spell_affect args((int sn, int level, CHAR_DATA * ch, void *vo));
ch_ret spell_affectchar args((int sn, int level, CHAR_DATA * ch, void *vo));
int dispel_casting(AFFECT_DATA * paf, CHAR_DATA * ch, CHAR_DATA * victim, int affect, bool dispel);


//Othertypes is used for acutal resist flag checks.  Set to -1 to disable
/*
 * Is immune to a damage type
 */
bool is_immune(CHAR_DATA * ch, sh_int damtype, int othertypes)
{
   if (othertypes >= 0)
   {
      if (IS_SET(ch->immune, othertypes))
         return TRUE;
      if (othertypes == RIS_MAGIC)
         if (ch->apply_res_magic[0] == -1)
            return TRUE;
      if (othertypes == RIS_NONMAGIC)
         if (ch->apply_res_nonmagic[0] == -1)
            return TRUE;
      if (othertypes == RIS_SLEEP)
         if (ch->apply_res_nonmagic[0] == -1)
            return TRUE;
      return FALSE;
   }
   switch (damtype)
   {
      case SD_FIRE:
         if (IS_SET(ch->immune, RIS_FIRE) || ch->apply_res_fire[0] == -500)
            return TRUE;
         break;
      case SD_WATER:
         if (IS_SET(ch->immune, RIS_WATER) || ch->apply_res_water[0] == -500)
            return TRUE;
         break;
      case SD_EARTH:
         if (IS_SET(ch->immune, RIS_EARTH) || ch->apply_res_earth[0] == -500)
            return TRUE;
         break;
      case SD_ENERGY:
         if (IS_SET(ch->immune, RIS_ENERGY) || ch->apply_res_energy[0] == -500)
            return TRUE;
         break;
      case SD_AIR:
         if (IS_SET(ch->immune, RIS_AIR) || ch->apply_res_air[0] == -500)
            return TRUE;
         break;
      case SD_HOLY:
         if (IS_SET(ch->immune, RIS_HOLY) || ch->apply_res_holy[0] == -500)
            return TRUE;
         break;
      case SD_UNHOLY:
         if (IS_SET(ch->immune, RIS_UNHOLY) || ch->apply_res_unholy[0] == -500)
            return TRUE;
         break;
      case SD_UNDEAD:
         if (IS_SET(ch->immune, RIS_UNDEAD) || ch->apply_res_undead[0] == -500)
            return TRUE;
         break;
   }
   return FALSE;
}

/*
 * Lookup a skill by name, only stopping at skills the player has.
 */
int ch_slookup(CHAR_DATA * ch, const char *name)
{
   int sn;

   if (IS_NPC(ch))
      return skill_lookup(name);
   for (sn = 0; sn < top_sn; sn++)
   {
      if (!skill_table[sn]->name)
         break;
      if (ch->pcdata->learned[sn] > 0
         && ch->pcdata->ranking[sn] > 0 && LOWER(name[0]) == LOWER(skill_table[sn]->name[0]) && !str_prefix(name, skill_table[sn]->name))
         return sn;
   }

   return -1;
}

/*
 * Lookup an herb by name.
 */
int herb_lookup(const char *name)
{
   int sn;

   for (sn = 0; sn < top_herb; sn++)
   {
      if (!herb_table[sn] || !herb_table[sn]->name)
         return -1;
      if (LOWER(name[0]) == LOWER(herb_table[sn]->name[0]) && !str_prefix(name, herb_table[sn]->name))
         return sn;
   }
   return -1;
}

/*
 * Lookup a personal skill
 * Unused for now.  In place to allow a player to have a custom spell/skill.
 * When this is put in make sure you put in cleanup code if you do any
 * sort of allocating memory in free_char --Shaddai
 */
int personal_lookup(CHAR_DATA * ch, const char *name)
{
   int sn;

   if (!ch->pcdata)
      return -1;
   for (sn = 0; sn < MAX_PERSONAL; sn++)
   {
      if (!ch->pcdata->special_skills[sn] || !ch->pcdata->special_skills[sn]->name)
         return -1;
      if (LOWER(name[0]) == LOWER(ch->pcdata->special_skills[sn]->name[0]) && !str_prefix(name, ch->pcdata->special_skills[sn]->name))
         return sn;
   }
   return -1;
}

/*
 * Lookup a skill by name.
 */
int skill_lookup(const char *name)
{
   int sn;

   if ((sn = bsearch_skill_exact(name, gsn_first_spell, gsn_first_skill - 1)) == -1)
      if ((sn = bsearch_skill_exact(name, gsn_first_skill, gsn_first_weapon - 1)) == -1)
         if ((sn = bsearch_skill_exact(name, gsn_first_weapon, gsn_first_tongue - 1)) == -1)
            if ((sn = bsearch_skill_exact(name, gsn_first_tongue, gsn_top_sn - 1)) == -1)
               if ((sn = bsearch_skill_prefix(name, gsn_first_spell, gsn_first_skill - 1)) == -1)
                  if ((sn = bsearch_skill_prefix(name, gsn_first_skill, gsn_first_weapon - 1)) == -1)
                     if ((sn = bsearch_skill_prefix(name, gsn_first_weapon, gsn_first_tongue - 1)) == -1)
                        if ((sn = bsearch_skill_prefix(name, gsn_first_tongue, gsn_top_sn - 1)) == -1 && gsn_top_sn < top_sn)
                        {
                           for (sn = gsn_top_sn; sn < top_sn; sn++)
                           {
                              if (!skill_table[sn] || !skill_table[sn]->name)
                                 return -1;
                              if (LOWER(name[0]) == LOWER(skill_table[sn]->name[0]) && !str_prefix(name, skill_table[sn]->name))
                                 return sn;
                           }
                           return -1;
                        }
   return sn;
}

/*
 * Return a skilltype pointer based on sn			-Thoric
 * Returns NULL if bad, unused or personal sn.
 */
SKILLTYPE *get_skilltype(int sn)
{
   if (sn >= TYPE_PERSONAL)
      return NULL;
   if (sn >= TYPE_HERB)
      return IS_VALID_HERB(sn - TYPE_HERB) ? herb_table[sn - TYPE_HERB] : NULL;
   if (sn >= TYPE_HIT)
      return NULL;
   return IS_VALID_SN(sn) ? skill_table[sn] : NULL;
}

/*
 * Perform a binary search on a section of the skill table	-Thoric
 * Each different section of the skill table is sorted alphabetically
 *
 * Check for prefix matches
 */
int bsearch_skill_prefix(const char *name, int first, int top)
{
   int sn;

   for (;;)
   {
      sn = (first + top) >> 1;

      if (LOWER(name[0]) == LOWER(skill_table[sn]->name[0]) && !str_prefix(name, skill_table[sn]->name))
         return sn;
      if (first >= top)
         return -1;
      if (strcmp(name, skill_table[sn]->name) < 1)
         top = sn - 1;
      else
         first = sn + 1;
   }
   return -1;
}

/*
 * Perform a binary search on a section of the skill table	-Thoric
 * Each different section of the skill table is sorted alphabetically
 *
 * Check for exact matches only
 */
int bsearch_skill_exact(const char *name, int first, int top)
{
   int sn;

   for (;;)
   {
      sn = (first + top) >> 1;
      if (!str_cmp(name, skill_table[sn]->name))
         return sn;
      if (first >= top)
         return -1;
      if (strcmp(name, skill_table[sn]->name) < 1)
         top = sn - 1;
      else
         first = sn + 1;
   }
   return -1;
}

/*
 * Perform a binary search on a section of the skill table	-Thoric
 * Each different section of the skill table is sorted alphabetically
 *
 * Check exact match first, then a prefix match
 */
int bsearch_skill(const char *name, int first, int top)
{
   int sn = bsearch_skill_exact(name, first, top);

   return (sn == -1) ? bsearch_skill_prefix(name, first, top) : sn;
}

/*
 * Perform a binary search on a section of the skill table
 * Each different section of the skill table is sorted alphabetically
 * Only match skills player knows				-Thoric
 */
int ch_bsearch_skill_prefix(CHAR_DATA * ch, const char *name, int first, int top)
{
   int sn;

   for (;;)
   {
      sn = (first + top) >> 1;

      if (LOWER(name[0]) == LOWER(skill_table[sn]->name[0])
         && !str_prefix(name, skill_table[sn]->name) && ch->pcdata->learned[sn] > 0 && ch->pcdata->ranking[sn] > 0)
         return sn;
      if (first >= top)
         return -1;
      if (strcmp(name, skill_table[sn]->name) < 1)
         top = sn - 1;
      else
         first = sn + 1;
   }
   return -1;
}

int ch_bsearch_skill_exact(CHAR_DATA * ch, const char *name, int first, int top)
{
   int sn;

   for (;;)
   {
      sn = (first + top) >> 1;

      if (!str_cmp(name, skill_table[sn]->name) && ch->pcdata->learned[sn] > 0 && ch->pcdata->ranking[sn] > 0)
         return sn;
      if (first >= top)
         return -1;
      if (strcmp(name, skill_table[sn]->name) < 1)
         top = sn - 1;
      else
         first = sn + 1;
   }
   return -1;
}

int ch_bsearch_skill(CHAR_DATA * ch, const char *name, int first, int top)
{
   int sn = ch_bsearch_skill_exact(ch, name, first, top);

   return (sn == -1) ? ch_bsearch_skill_prefix(ch, name, first, top) : sn;
}

int find_spell(CHAR_DATA * ch, const char *name, bool know)
{
   if (IS_NPC(ch) || !know)
      return bsearch_skill(name, gsn_first_spell, gsn_first_skill - 1);
   else
      return ch_bsearch_skill(ch, name, gsn_first_spell, gsn_first_skill - 1);
}

int find_skill(CHAR_DATA * ch, const char *name, bool know)
{
   if (IS_NPC(ch) || !know)
      return bsearch_skill(name, gsn_first_skill, gsn_first_weapon - 1);
   else
      return ch_bsearch_skill(ch, name, gsn_first_skill, gsn_first_weapon - 1);
}

int find_weapon(CHAR_DATA * ch, const char *name, bool know)
{
   if (IS_NPC(ch) || !know)
      return bsearch_skill(name, gsn_first_weapon, gsn_first_tongue - 1);
   else
      return ch_bsearch_skill(ch, name, gsn_first_weapon, gsn_first_tongue - 1);
}

int find_tongue(CHAR_DATA * ch, const char *name, bool know)
{
   if (IS_NPC(ch) || !know)
      return bsearch_skill(name, gsn_first_tongue, gsn_top_sn - 1);
   else
      return ch_bsearch_skill(ch, name, gsn_first_tongue, gsn_top_sn - 1);
}


/*
 * Lookup a skill by slot number.
 * Used for object loading.
 */
int slot_lookup(int slot)
{
   extern bool fBootDb;
   int sn;

   if (slot <= 0)
      return -1;

   for (sn = 0; sn < top_sn; sn++)
      if (slot == skill_table[sn]->slot)
         return sn;

   if (fBootDb)
   {
      bug("Slot_lookup: bad slot %d.", slot);
      return -1;
   }

   return -1;
}

/*
 * Handler to tell the victim which spell is being affected.
 * Shaddai
 */
int dispel_casting(AFFECT_DATA * paf, CHAR_DATA * ch, CHAR_DATA * victim, int affect, bool dispel)
{
   char buf[MSL];
   char *spell;
   SKILLTYPE *sktmp;
   int has_detect = FALSE;
   EXT_BV ext_bv = meb(affect);

   if (IS_AFFECTED(ch, AFF_DETECT_MAGIC))
      has_detect = TRUE;

   if (paf)
   {
      if ((sktmp = get_skilltype(paf->type)) == NULL)
         return 0;
      spell = sktmp->name;
   }
   else
      spell = affect_bit_name(&ext_bv);

   set_char_color(AT_MAGIC, ch);
   set_char_color(AT_HITME, victim);

   if (!can_see(ch, victim))
      strcpy(buf, "Someone");
   else
   {
      strcpy(buf, (IS_NPC(victim) ? victim->short_descr : PERS_MAP(victim, ch)));
      buf[0] = toupper(buf[0]);
   }

   if (dispel)
   {
         return 0; /* So we give the default Ok. Message */
   }
   else
   {
         return 0; /* The wonderful Failed. Message */
   }
   return 1;
}

/*
 * Fancy message handling for a successful casting		-Thoric
 */
void successful_casting(SKILLTYPE * skill, CHAR_DATA * ch, CHAR_DATA * victim, OBJ_DATA * obj)
{
   sh_int chitroom = (skill->type == SKILL_SPELL ? AT_MAGIC : AT_ACTION);
   sh_int chit = (skill->type == SKILL_SPELL ? AT_MAGIC : AT_HIT);
   sh_int chitme = (skill->type == SKILL_SPELL ? AT_MAGIC : AT_HITME);

   if (skill->target != TAR_CHAR_OFFENSIVE)
   {
      chit = chitroom;
      chitme = chitroom;
   }

   if (ch && ch != victim)
   {
      if (skill->hit_char && skill->hit_char[0] != '\0')
         act(chit, skill->hit_char, ch, obj, victim, TO_CHAR);
      else if (skill->type == SKILL_SPELL)
         act(chit, "Ok.", ch, NULL, NULL, TO_CHAR);
   }
   if (ch && skill->hit_room && skill->hit_room[0] != '\0')
      act(chitroom, skill->hit_room, ch, obj, victim, TO_NOTVICT);
   if (ch && victim && skill->hit_vict && skill->hit_vict[0] != '\0')
   {
      if (ch != victim)
         act(chitme, skill->hit_vict, ch, obj, victim, TO_VICT);
      else
         act(chitme, skill->hit_vict, ch, obj, victim, TO_CHAR);
   }
   else if (ch && ch == victim && skill->type == SKILL_SPELL)
      act(chitme, "Ok.", ch, NULL, NULL, TO_CHAR);
}

/*
 * Fancy message handling for a failed casting			-Thoric
 */
void failed_casting(SKILLTYPE * skill, CHAR_DATA * ch, CHAR_DATA * victim, OBJ_DATA * obj)
{
   sh_int chitroom = (skill->type == SKILL_SPELL ? AT_MAGIC : AT_ACTION);
   sh_int chit = (skill->type == SKILL_SPELL ? AT_MAGIC : AT_HIT);
   sh_int chitme = (skill->type == SKILL_SPELL ? AT_MAGIC : AT_HITME);

   if (skill->target != TAR_CHAR_OFFENSIVE)
   {
      chit = chitroom;
      chitme = chitroom;
   }

   if (ch && ch != victim)
   {
      if (skill->miss_char && skill->miss_char[0] != '\0')
         act(chit, skill->miss_char, ch, obj, victim, TO_CHAR);
      else if (skill->type == SKILL_SPELL)
         act(chit, "You failed.", ch, NULL, NULL, TO_CHAR);
   }
   if (ch && skill->miss_room && skill->miss_room[0] != '\0' && str_cmp(skill->miss_room, "supress"))
      act(chitroom, skill->miss_room, ch, obj, victim, TO_NOTVICT);
   if (ch && victim && skill->miss_vict && skill->miss_vict[0] != '\0')
   {
      if (ch != victim)
         act(chitme, skill->miss_vict, ch, obj, victim, TO_VICT);
      else
         act(chitme, skill->miss_vict, ch, obj, victim, TO_CHAR);
   }
   else if (ch && ch == victim)
   {
      if (skill->miss_char && skill->miss_char[0] != '\0')
         act(chitme, skill->miss_char, ch, obj, victim, TO_CHAR);
      else if (skill->type == SKILL_SPELL)
         act(chitme, "You failed.", ch, NULL, NULL, TO_CHAR);
   }
}

/*
 * Fancy message handling for being immune to something		-Thoric
 */
void immune_casting(SKILLTYPE * skill, CHAR_DATA * ch, CHAR_DATA * victim, OBJ_DATA * obj)
{
   sh_int chitroom = (skill->type == SKILL_SPELL ? AT_MAGIC : AT_ACTION);
   sh_int chit = (skill->type == SKILL_SPELL ? AT_MAGIC : AT_HIT);
   sh_int chitme = (skill->type == SKILL_SPELL ? AT_MAGIC : AT_HITME);

   if (skill->target != TAR_CHAR_OFFENSIVE)
   {
      chit = chitroom;
      chitme = chitroom;
   }

   if (ch && ch != victim)
   {
      if (skill->imm_char && skill->imm_char[0] != '\0')
         act(chit, skill->imm_char, ch, obj, victim, TO_CHAR);
      else if (skill->miss_char && skill->miss_char[0] != '\0')
         act(chit, skill->hit_char, ch, obj, victim, TO_CHAR);
      else if (skill->type == SKILL_SPELL || skill->type == SKILL_SKILL)
         act(chit, "That appears to have no effect.", ch, NULL, NULL, TO_CHAR);
   }
   if (ch && skill->imm_room && skill->imm_room[0] != '\0')
      act(chitroom, skill->imm_room, ch, obj, victim, TO_NOTVICT);
   else if (ch && skill->miss_room && skill->miss_room[0] != '\0')
      act(chitroom, skill->miss_room, ch, obj, victim, TO_NOTVICT);
   if (ch && victim && skill->imm_vict && skill->imm_vict[0] != '\0')
   {
      if (ch != victim)
         act(chitme, skill->imm_vict, ch, obj, victim, TO_VICT);
      else
         act(chitme, skill->imm_vict, ch, obj, victim, TO_CHAR);
   }
   else if (ch && victim && skill->miss_vict && skill->miss_vict[0] != '\0')
   {
      if (ch != victim)
         act(chitme, skill->miss_vict, ch, obj, victim, TO_VICT);
      else
         act(chitme, skill->miss_vict, ch, obj, victim, TO_CHAR);
   }
   else if (ch && ch == victim)
   {
      if (skill->imm_char && skill->imm_char[0] != '\0')
         act(chit, skill->imm_char, ch, obj, victim, TO_CHAR);
      else if (skill->miss_char && skill->miss_char[0] != '\0')
         act(chit, skill->hit_char, ch, obj, victim, TO_CHAR);
      else if (skill->type == SKILL_SPELL || skill->type == SKILL_SKILL)
         act(chit, "That appears to have no affect.", ch, NULL, NULL, TO_CHAR);
   }
}


/*
 * Utter mystical words for an sn.
 */
void say_spell(CHAR_DATA * ch, int sn)
{
   char buf[MSL];
   char buf2[MSL];
   CHAR_DATA *rch;
   char *pName;
   int iSyl;
   int length;
   SKILLTYPE *skill = get_skilltype(sn);

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

   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"},
      {"polymorph", "iaddahs"},
      {"ra", "gru"},
      {"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->name; *pName != '\0'; pName += length)
   {
      for (iSyl = 0; (length = strlen(syl_table[iSyl].old)) != 0; iSyl++)
      {
         if (!str_prefix(syl_table[iSyl].old, pName))
         {
            strcat(buf, syl_table[iSyl].new);
            break;
         }
      }

      if (length == 0)
         length = 1;
   }

   sprintf(buf2, "$n utters the words, '%s'.", buf);
   sprintf(buf, "$n utters the words, '%s'.", skill->name);

   for (rch = ch->in_room->first_person; rch; rch = rch->next_in_room)
   {
      if (rch != ch && rch->coord->x == ch->coord->x && rch->coord->y == ch->coord->y
         && ch->map == rch->map)
      {
         act(AT_MAGIC, buf2, ch, NULL, rch, TO_VICT);
      }
   }

   return;
}


/*
 * Make adjustments to saving throw based in RIS		-Thoric
 */
int ris_save(CHAR_DATA * ch, int chance, int ris)
{   
   sh_int modifier = 0;
   
   if (ris == RIS_FIRE)
      modifier = ch->apply_res_fire[0];
   if (ris == RIS_WATER)
      modifier = ch->apply_res_water[0];
   if (ris == RIS_EARTH)
      modifier = ch->apply_res_earth[0];
   if (ris == RIS_ENERGY)
      modifier = ch->apply_res_energy[0];
   if (ris == RIS_AIR)
      modifier = ch->apply_res_air[0];
   if (ris == RIS_NONMAGIC)
      modifier = ch->apply_res_nonmagic[0];
   if (ris == RIS_MAGIC)
      modifier = ch->apply_res_magic[0];
   if (ris == RIS_BLUNT)
      modifier = ch->apply_res_blunt[0];
   if (ris == RIS_PIERCE)
      modifier = ch->apply_res_pierce[0];
   if (ris == RIS_SLASH)
      modifier = ch->apply_res_slash[0];
   if (ris == RIS_PARALYSIS)
      modifier = ch->apply_res_paralysis[0];
   if (ris == RIS_POISON)
      modifier = ch->apply_res_poison[0];
   if (ris == RIS_UNHOLY)
      modifier = ch->apply_res_unholy[0];
   if (ris == RIS_HOLY)
      modifier = ch->apply_res_holy[0];

   if (modifier >= -499 && modifier <= 0)
      modifier = 1;
   if (modifier == -500)
      return 1000;

   if (IS_SET(ch->immune, ris) && !IS_SET(ch->no_immune, ris))
      return 1000;
   if (IS_SET(ch->resistant, ris) && !IS_SET(ch->no_resistant, ris))
      modifier -= 30;
   if (IS_SET(ch->susceptible, ris) && !IS_SET(ch->no_susceptible, ris))
      modifier += 50;
   return (chance * modifier) / 100;
}


/*								    -Thoric
 * Fancy dice expression parsing complete with order of operations,
 * simple exponent support, dice support as well as a few extra
 * variables: L = level, H = hp, M = mana, V = move, S = str, X = dex
 *            I = int, W = wis, C = con, A = cha, U = luck, A = age
 *            R = Ranking/Mastery (New) P = Skill Points (New)
              B - Point based Level (New)
 * Used for spell dice parsing, ie: 3d8+L-6
 *
 */
 
/* Usage Notes because I spent too much time fucking with this thing
 * Parses in correct order, will do * before +, etc
 * If you plan on using { or } make sure to put the comparing arguments
 * in ( ), ex: (2d3+b*2)}15 
 * Do not use spaces
 */
int rd_parse(CHAR_DATA * ch, int level, char *exp, int sn)
{
   int x, lop = 0, gop = 0, eop = 0;
   char operation;
   char *sexp[2];
   int total = 0, len = 0;
   int isobj = 0;
   int tlevel;

   if (level >= SPOWER_MIN)
   {
      isobj = 1; //mob or obj now, no difference
      tlevel = level;
   }
   else
      tlevel = level;

    /* take care of nulls coming in */
    if (!exp || !strlen(exp))
	return 0;

    /* get rid of brackets if they surround the entire expresion */
    if ( (*exp == '(') && !index(exp+1,'(') && exp[strlen(exp)-1] == ')' )
    {
	exp[strlen(exp)-1] = '\0';
	exp++;
    }

    /* check if the expresion is just a number */
    len = strlen(exp);
    if ( len == 1 && isalpha(exp[0]) )
    {
	switch(exp[0])
	{
	    case 'L': case 'l':	return level;
	    case 'H': case 'h':	return ch->hit;
	    case 'M': case 'm':	return ch->mana;
	    case 'V': case 'v':	return ch->move;
	    case 'S': case 's':	return get_curr_str(ch);
	    case 'I': case 'i':	return get_curr_int(ch);
	    case 'W': case 'w':	return get_curr_wis(ch);
	    case 'X': case 'x':	return get_curr_dex(ch);
	    case 'C': case 'c':	return get_curr_con(ch);
	    case 'A': case 'a':	return get_curr_cha(ch);
	    case 'U': case 'u':	return get_curr_lck(ch);
	    case 'Y': case 'y':	return get_age(ch);
	    case 'R': case 'r': 
	       if (isobj)
	          return GET_MASTERY(ch, sn, isobj, tlevel);
	       else 
	          return MASTERED(ch, sn);
        case 'P': case 'p': 
           if (isobj)
              return GET_POINTS(ch, sn, isobj, tlevel);
           else
              return LEARNED(ch, sn);        
 
        case 'B': case 'b': 
           if (isobj)
              return POINT_LEVEL(GET_POINTS(ch, sn, isobj, tlevel), GET_MASTERY(ch, sn, isobj, tlevel));
           else
              return POINT_LEVEL(LEARNED(ch, sn), MASTERED(ch, sn));
	}
    }

    for (x = 0; x < len; ++x)
	if (!isdigit(exp[x]) && !isspace(exp[x]))
	    break;
    if (x == len)
	return atoi(exp);
  
    /* break it into 2 parts */
    for (x = 0; x < strlen(exp); ++x)
	switch(exp[x])
	{
	    case '^':
	      if (!total)
		eop = x;
	      break;
	    case '-': case '+':
	      if (!total) 
		lop = x;
	      break;
	    case '*': case '/': case '%': case 'd': case 'D':
	    case '<': case '>': case '{': case '}': case '=':
	      if (!total) 
		gop =  x;
	      break;
	    case '(':
	      ++total;
	      break;
	    case ')':
	      --total;
	      break;
	}
    if (lop)
	x = lop;
    else
    if (gop)
	x = gop;
    else
	x = eop;
    operation = exp[x];
    exp[x] = '\0';
    sexp[0] = exp;
    sexp[1] = (char *)(exp+x+1);

    /* work it out */
    total = rd_parse(ch, level, sexp[0], sn);
    switch(operation)
    {
	case '-':		total -= rd_parse(ch, level, sexp[1], sn);	break;
	case '+':		total += rd_parse(ch, level, sexp[1], sn);	break;
	case '*':		total *= rd_parse(ch, level, sexp[1], sn);	break;
	case '/':		total /= rd_parse(ch, level, sexp[1], sn);	break;
	case '%':		total %= rd_parse(ch, level, sexp[1], sn);	break;
	case 'd': case 'D':	total = dice( total, rd_parse(ch, level, sexp[1], sn) );	break;
	case '<':		total = (total < rd_parse(ch, level, sexp[1], sn));		break;
	case '>':		total = (total > rd_parse(ch, level, sexp[1], sn));		break;
	case '=':		total = (total == rd_parse(ch, level, sexp[1], sn));	break;
	case '{':	        total = UMIN( total, rd_parse(ch, level, sexp[1], sn) );   break;
	case '}':		total = UMAX( total, rd_parse(ch, level, sexp[1], sn) );   break;

	case '^':
	{
	    int y = rd_parse(ch, level, sexp[1], sn), z = total;

	    for (x = 1; x < y; ++x, z *= total);
	    total = z;
	    break;
	}
    }
    return total;
} 

/* wrapper function so as not to destroy exp */
/* sn added for dice checks on mastery rankings -- Xerves 1/00 */
int dice_parse(CHAR_DATA * ch, int level, char *exp, int sn)
{
   char buf[MIL];

   strcpy(buf, exp);
   return rd_parse(ch, level, buf, sn);
}

bool save_chance(CHAR_DATA *ch, int save)
{
   int ms;
   
   ms = 10 - abs(ch->mental_state);
   
   if (ms <= -90)
      ms = -25;
   else if (ms <= -70)
      ms = -15;
   else if (ms <= -50)
      ms = -10;
   else if (ms <= -30)
      ms = -7;
   else if (ms <= -10)
      ms = -5;
   else if (ms <= 0)
      ms = -3;
   else
      ms = 0;
   save = URANGE(5, 50+(save*3/4), 100);
   if ((number_percent() + UMIN(5, (get_curr_lck(ch)-14)/2) + ms) >= save)
      return TRUE;
   else
      return FALSE;
}
/*
 * Compute a saving throw.
 * Negative apply's make saving throw better.
 */
bool saves_poison_death(int level, CHAR_DATA * victim)
{
   int save;
   
   if (is_immune(victim, -1, RIS_MAGIC))
      return TRUE;

   save = level + (victim->saving_poison_death * 5); //negative still better
   return save_chance(victim, save);
}

bool saves_wands(int level, CHAR_DATA * victim)
{
   int save;
   
   if (is_immune(victim, -1, RIS_MAGIC))
      return TRUE;
   
   save = level + (victim->saving_wand * 5);
   return save_chance(victim, save);
}

bool saves_para_petri(int level, CHAR_DATA * victim)
{
   int save;
   
   if (is_immune(victim, -1, RIS_MAGIC))
      return TRUE;

   save = level + (victim->saving_para_petri * 5);
   return save_chance(victim, save);
}

bool saves_breath(int level, CHAR_DATA * victim)
{
   int save;
   
   if (is_immune(victim, -1, RIS_MAGIC))
      return TRUE;

   save = level + (victim->saving_breath * 5);
   return save_chance(victim, save);
}

bool saves_spell_staff(int level, CHAR_DATA * victim)
{
   int save;
   bool saved;

   if (is_immune(victim, -1, RIS_MAGIC))
      return TRUE;

   save = level + (victim->saving_spell_staff * 5);
   saved = save_chance(victim, save);
   return saved;
}


/*
 * Process the spell's required components, if any		-Thoric
 * -----------------------------------------------
 * T###		check for item of type ###
 * V#####	check for item of vnum #####
 * Kword	check for item with keyword 'word'
 * G#####	check if player has ##### amount of gold
 * H####	check if player has #### amount of hitpoints
 *
 * Special operators:
 * ! spell fails if player has this
 * + don't consume this component
 * @ decrease component's value[0], and extract if it reaches 0
 * # decrease component's value[1], and extract if it reaches 0
 * $ decrease component's value[2], and extract if it reaches 0
 * % decrease component's value[3], and extract if it reaches 0
 * ^ decrease component's value[4], and extract if it reaches 0
 * & decrease component's value[5], and extract if it reaches 0
 */
bool process_spell_components(CHAR_DATA * ch, int sn)
{
   SKILLTYPE *skill = get_skilltype(sn);
   char *comp = skill->components;
   char *check;
   char arg[MIL];
   bool consume, fail, found;
   int val, value;
   OBJ_DATA *obj;

   /* if no components necessary, then everything is cool */
   if (!comp || comp[0] == '\0')
      return TRUE;

   while (comp[0] != '\0')
   {
      comp = one_argument(comp, arg);
      consume = TRUE;
      fail = found = FALSE;
      val = -1;
      switch (arg[1])
      {
         default:
            check = arg + 1;
            break;
         case '!':
            check = arg + 2;
            fail = TRUE;
            break;
         case '+':
            check = arg + 2;
            consume = FALSE;
            break;
         case '@':
            check = arg + 2;
            val = 0;
            break;
         case '#':
            check = arg + 2;
            val = 1;
            break;
         case '$':
            check = arg + 2;
            val = 2;
            break;
         case '%':
            check = arg + 2;
            val = 3;
            break;
         case '^':
            check = arg + 2;
            val = 4;
            break;
         case '&':
            check = arg + 2;
            val = 5;
            break;
            /*   reserve '*', '(' and ')' for v6, v7 and v8   */
      }
      value = atoi(check);
      obj = NULL;
      switch (UPPER(arg[0]))
      {
         case 'T':
            for (obj = ch->first_carrying; obj; obj = obj->next_content)
               if (obj->item_type == value)
               {
                  if (fail)
                  {
                     send_to_char("Something disrupts the casting of this spell...\n\r", ch);
                     return FALSE;
                  }
                  found = TRUE;
                  break;
               }
            break;
         case 'V':
            for (obj = ch->first_carrying; obj; obj = obj->next_content)
               if (obj->pIndexData->vnum == value)
               {
                  if (fail)
                  {
                     send_to_char("Something disrupts the casting of this spell...\n\r", ch);
                     return FALSE;
                  }
                  found = TRUE;
                  break;
               }
            break;
         case 'K':
            for (obj = ch->first_carrying; obj; obj = obj->next_content)
               if (nifty_is_name(check, obj->name))
               {
                  if (fail)
                  {
                     send_to_char("Something disrupts the casting of this spell...\n\r", ch);
                     return FALSE;
                  }
                  found = TRUE;
                  break;
               }
            break;
         case 'G':
            if (ch->gold >= value)
            {
               if (fail)
               {
                  send_to_char("Something disrupts the casting of this spell...\n\r", ch);
                  return FALSE;
               }
               else
               {
                  if (consume)
                  {
                     set_char_color(AT_GOLD, ch);
                     send_to_char("You feel a little lighter...\n\r", ch);
                     ch->gold -= value;
                  }
                  continue;
               }
            }
            break;
         case 'H':
            if (ch->hit >= value)
            {
               if (fail)
               {
                  send_to_char("Something disrupts the casting of this spell...\n\r", ch);
                  return FALSE;
               }
               else
               {
                  if (consume)
                  {
                     set_char_color(AT_BLOOD, ch);
                     send_to_char("You feel a little weaker...\n\r", ch);
                     ch->hit -= value;
                     update_pos(ch);
                  }
                  continue;
               }
            }
            break;
      }
      /* having this component would make the spell fail... if we get
         here, then the caster didn't have that component */
      if (fail)
         continue;
      if (!found)
      {
         send_to_char("Something is missing...\n\r", ch);
         return FALSE;
      }
      if (obj)
      {
         if (val >= 0 && val < 6)
         {
            separate_obj(obj);
            if (obj->value[val] <= 0)
            {
               act(AT_MAGIC, "$p disappears in a puff of smoke!", ch, obj, NULL, TO_CHAR);
               act(AT_MAGIC, "$p disappears in a puff of smoke!", ch, obj, NULL, TO_ROOM);
               extract_obj(obj);
               return FALSE;
            }
            else if (--obj->value[val] == 0)
            {
               act(AT_MAGIC, "$p glows briefly, then disappears in a puff of smoke!", ch, obj, NULL, TO_CHAR);
               act(AT_MAGIC, "$p glows briefly, then disappears in a puff of smoke!", ch, obj, NULL, TO_ROOM);
               extract_obj(obj);
            }
            else
               act(AT_MAGIC, "$p glows briefly and a whisp of smoke rises from it.", ch, obj, NULL, TO_CHAR);
         }
         else if (consume)
         {
            separate_obj(obj);
            act(AT_MAGIC, "$p glows brightly, then disappears in a puff of smoke!", ch, obj, NULL, TO_CHAR);
            act(AT_MAGIC, "$p glows brightly, then disappears in a puff of smoke!", ch, obj, NULL, TO_ROOM);
            extract_obj(obj);
         }
         else
         {
            int count = obj->count;

            obj->count = 1;
            act(AT_MAGIC, "$p glows briefly.", ch, obj, NULL, TO_CHAR);
            obj->count = count;
         }
      }
   }
   return TRUE;
}

int pAbort;

/*
 * Locate targets.
 */
void *locate_targets(CHAR_DATA * ch, char *arg, int sn, CHAR_DATA ** victim, OBJ_DATA ** obj)
{
   SKILLTYPE *skill = get_skilltype(sn);
   void *vo = NULL;

   *victim = NULL;
   *obj = NULL;

   switch (skill->target)
   {
      default:
         bug("Do_cast: bad target for sn %d.", sn);
         return &pAbort;

      case TAR_IGNORE:
         break;

      case TAR_CHAR_OFFENSIVE:
         if (arg[0] == '\0')
         {
            if ((*victim = who_fighting(ch)) == NULL)
            {
               send_to_char("Cast the spell on whom?\n\r", ch);
               return &pAbort;
            }
            //There should be some kind of stop here if you aren't in the room ya
            if (*victim)
            {
               if (!IN_SAME_ROOM(ch, *victim))
               {
                  send_to_char("Your target is not in the same room as you!\n\r", ch);
                  return &pAbort;
               }
            }
         }
         else
         {
            if ((*victim = get_char_room_new(ch, arg, 1)) == NULL)
            {
               send_to_char("They aren't here.\n\r", ch);
               return &pAbort;
            }
         }

         /* Offensive spells will choose the ch up to 92% of the time
          * if the nuisance flag is set -- Shaddai 
          */
         if (!IS_NPC(ch) && ch->pcdata->nuisance &&
            ch->pcdata->nuisance->flags > 5 && number_percent() < (((ch->pcdata->nuisance->flags - 5) * 8) + ch->pcdata->nuisance->power * 6))
            *victim = ch;

         if (is_safe(ch, *victim))
            return &pAbort;

         if (ch == *victim)
         {
            if (SPELL_FLAG(get_skilltype(sn), SF_NOSELF))
            {
               send_to_char("You can't cast this on yourself!\n\r", ch);
               return &pAbort;
            }
            send_to_char("Cast this on yourself?  Okay...\n\r", ch);
            /*
               send_to_char( "You can't do that to yourself.\n\r", ch );
               return &pAbort;
             */
         }

         if (!IS_NPC(ch))
         {
            if (!IS_NPC(*victim))
            {
               if (xIS_SET(ch->act, PLR_NICE) && ch != *victim)
               {
                  send_to_char("You are too nice to attack another player.\n\r", ch);
                  return &pAbort;
               }
            }

            if (IS_AFFECTED(ch, AFF_CHARM) && ch->master == *victim)
            {
               send_to_char("You can't do that on your own follower.\n\r", ch);
               return &pAbort;
            }
         }

         check_illegal_pk(ch, *victim);
         vo = (void *) *victim;
         break;

      case TAR_CHAR_DEFENSIVE:
         if (arg[0] == '\0')
            *victim = ch;
         else
         {
            if ((*victim = get_char_room_new(ch, arg, 1)) == NULL)
            {
               send_to_char("They aren't here.\n\r", ch);
               return &pAbort;
            }
         }

         /* Nuisance flag will pick who you are fighting for defensive
          * spells up to 36% of the time -- Shaddai
          */

         if (!IS_NPC(ch) && ch->fighting && ch->pcdata->nuisance &&
            ch->pcdata->nuisance->flags > 5 && number_percent() < (((ch->pcdata->nuisance->flags - 5) * 8) + 6 * ch->pcdata->nuisance->power))
            *victim = who_fighting(ch);

         if (ch == *victim && SPELL_FLAG(get_skilltype(sn), SF_NOSELF))
         {
            send_to_char("You can't cast this on yourself!\n\r", ch);
            return &pAbort;
         }

         vo = (void *) *victim;
         break;

      case TAR_CHAR_SELF:
         if (arg[0] != '\0' && !nifty_is_name(arg, ch->name))
         {
            send_to_char("You cannot cast this spell on another.\n\r", ch);
            return &pAbort;
         }

         vo = (void *) ch;
         break;

      case TAR_OBJ_INV:
         if (arg[0] == '\0')
         {
            send_to_char("What should the spell be cast upon?\n\r", ch);
            return &pAbort;
         }

         if ((*obj = get_obj_carry(ch, arg)) == NULL)
         {
            send_to_char("You are not carrying that.\n\r", ch);
            return &pAbort;
         }

         vo = (void *) *obj;
         break;
         
      case TAR_OBJ_ROOM:
         if (arg[0] == '\0')
         {
            send_to_char("What should the spell be cast upon?\n\r", ch);
            return &pAbort;
         }

         if ((*obj = get_obj_here(ch, arg)) == NULL)
         {
            send_to_char("You are not in the room with that.\n\r", ch);
            return &pAbort;
         }

         vo = (void *) *obj;
         break;
   }

   return vo;
}

void gain_mana_per(CHAR_DATA *ch, CHAR_DATA *victim, int mana)
{
   if (!IS_NPC(ch))
   {
      int mmana;
      int manai = 1;
      
      ch->pcdata->mana_cnt++;
      
      mmana = mana;     
         
      if (ch->perm_int < 11)
         mmana *= .6;
      if (ch->perm_int >= 11 && ch->perm_int <= 13)
         mmana *= .85;
      if (ch->perm_int >= 14 && ch->perm_int <= 16)
         mmana *= 1.05;
      if (ch->perm_int >= 17 && ch->perm_int <= 19)
         mmana *= 1.15;
      if (ch->perm_int >= 20 && ch->perm_int <= 22)
         mmana *= 1.25;
      if (ch->perm_int >= 23 && ch->perm_int < 25)
         mmana *= 1.4;
      if (ch->perm_int == 25)
         mmana *= 1.6;  
    
      if (ch->max_mana < 50)
         mmana *= 1.7;
      else if (ch->max_mana < 100)
         mmana *= 1.3;
      else if (ch->max_mana < 150)
         mmana *= 1;
      else if (ch->max_mana < 200)
         mmana *= .8;
      else if (ch->max_mana < 250)
         mmana *= .6;
      else if (ch->max_mana < 300)
         mmana *= .5;
      else if (ch->max_mana < 350)
         mmana *= .4;
      else if (ch->max_mana < 400)
         mmana *= .3;
      else if (ch->max_mana < 450)
         mmana *= .25;
      else if (ch->max_mana < 500)
         mmana *= .2;
      else if (ch->max_mana < 550)
         mmana *= .1;
      else if (ch->max_mana < 600)
         mmana *= .095;
      else if (ch->max_mana < 650)
         mmana *= .09;
      else if (ch->max_mana < 700)
         mmana *= .08;
      else if (ch->max_mana < 800)
         mmana *= .07;   
      else if (ch->max_mana < 1000)
         mmana *= .06;   
      else if (ch->max_mana < 1500)
         mmana *= .05;   
      else
         mmana *= .04;
        
      if (sysdata.stat_gain <= 1)
         mmana = number_range(mmana*.35, mmana*.45);
      else if (sysdata.stat_gain <= 3)
         mmana = number_range(mmana*.5, mmana*.65);
      else if (sysdata.stat_gain >= 5)
         mmana = number_range(mmana*.75, mmana);
         
      if (ch->pcdata->mana_cnt >= 60)
      {
         send_to_char("&rYour body is starting to weaken from so much casting, might want to stop for awhile.\n\r", ch);
         ch->mana -= UMAX(2, ch->max_mana/30);
         if (ch->mana < 0)
            ch->mana = 0;
         mmana = number_range(-20, -30);
      }
         
      if (mmana == 0)
         mmana = 1;   
      
      if (mmana > 0 && ch->max_mana >= (800+get_talent_increase(ch, 10)) && ch->pcdata->per_mana >= 300)
         mmana = 0;
         
      if (mmana < 0 && ch->max_mana <= 20)
         mmana = 0;
            
      if (victim && IS_NPC(victim) && xIS_SET(victim->act, ACT_MOUNTSAVE))
      {
         if (mmana > 0)
            mmana = 0;
      } 
            
      ch->pcdata->per_mana += mmana;
        
      if (ch->pcdata->per_mana > 1000)
      {
         if (sysdata.stat_gain <= 1)
         {
            if (ch->max_mana < 70)
               manai = number_range(5, 7);
            else if (ch->max_mana < 100)
               manai = number_range(4, 6);
            else if (ch->max_mana < 150)
               manai = number_range(2, 4);
            else if (ch->max_mana < 200)
               manai = number_range(1, 3);
            else
               manai = 1;
         }
         else if (sysdata.stat_gain <= 2)
         {
            if (ch->max_mana < 70)
               manai = number_range(5, 7);
            else if (ch->max_mana < 100)
               manai = number_range(4, 6);
            else if (ch->max_mana < 200)
               manai = number_range(3, 5);
            else if (ch->max_mana < 300)
               manai = number_range(2, 4);
            else
               manai = number_range(1, 2);
         }
         else if (sysdata.stat_gain >= 4)
         {
            if (ch->max_mana < 150)
               manai = number_range(5, 7);
            else if (ch->max_mana < 300)
               manai = number_range(4, 6);
            else if (ch->max_mana < 600)
               manai = number_range(3, 5);
            else if (ch->max_mana < 900)
               manai = number_range(2, 4);
            else
               manai = number_range(1, 2);
         }
         ch->max_mana += manai;
         send_to_char("&B************************************\n\r", ch);
         ch_printf(ch, "&B******You Gain %d Point of Mana******\n\r", manai);
         send_to_char("&B************************************\n\r", ch);
         ch->pcdata->per_mana = 0;
      }  
      if (ch->pcdata->per_mana < 0)
      {
         if (ch->max_mana < 70)
            manai = number_range(5, 7);
         else if (ch->max_mana < 100)
            manai = number_range(4, 6);
         else if (ch->max_mana < 150)
            manai = number_range(2, 4);
         else if (ch->max_mana < 200)
            manai = number_range(1, 3);
         else
            manai = 1;
         ch->max_mana -= manai;
         send_to_char("&b************************************\n\r", ch);
         ch_printf(ch, "&b******You Lose %d Point of Mana******\n\r", manai);
         send_to_char("&b************************************\n\r", ch);
         ch->pcdata->per_mana = 999;
      }     
   }
}


/*
 * The kludgy global is for spells who want more stuff from command line.
 */
char *target_name;
char *ranged_target_name = NULL;


/*
 * Cast a spell.  Multi-caster and component support by Thoric
 */
void do_cast(CHAR_DATA * ch, char *argument)
{
   char arg1[MIL];
   char arg2[MIL];
   static char staticbuf[MIL];
   CHAR_DATA *victim;
   OBJ_DATA *obj;
   void *vo = NULL;
   int mana;
   int blood;
   int sn;
   int suc;
   ch_ret retcode;
   bool dont_wait = FALSE;
   OBJ_DATA *tmpobj;
   SKILLTYPE *skill = NULL;
   struct timeval time_used;

   retcode = rNONE;

   switch (ch->substate)
   {
      default:
         /* no ordering charmed mobs to cast spells */

         if (IS_NPC(ch) && (IS_AFFECTED(ch, AFF_CHARM) || IS_AFFECTED(ch, AFF_POSSESS)))
         {
            send_to_char("You can't seem to do that right now...\n\r", ch);
            return;
         }

         if (xIS_SET(ch->in_room->room_flags, ROOM_NO_MAGIC) || wIS_SET(ch, ROOM_NO_MAGIC))
         {
            set_char_color(AT_MAGIC, ch);
            send_to_char("You failed.\n\r", ch);
            return;
         }
         if (ch->fighting && (tmpobj = get_eq_char(ch, WEAR_SHIELD)) != NULL && IS_OBJ_STAT(tmpobj, ITEM_TWOHANDED))
         {
            send_to_char("You cannot cast spells in battle if you have a two-handed shield.\n\r", ch);
            return;
         }
         
         if (IS_AFFECTED(ch, AFF_GAGGED))
         {
            send_to_char("Hard to say the words to a spell when you are GAGGED!\n\r", ch);
            return;
         }

         target_name = one_argument(argument, arg1);
         one_argument(target_name, arg2);
         if (ranged_target_name)
            DISPOSE(ranged_target_name);
         ranged_target_name = str_dup(target_name);

         if (arg1[0] == '\0')
         {
            send_to_char("Cast which what where?\n\r", ch);
            return;
         }
         /* Regular mortal spell casting */
         if (get_trust(ch) < LEVEL_IMM) /* Tracker1 */
         {
            if ((sn = find_spell(ch, arg1, TRUE)) < 0 || (!IS_NPC(ch) && (ch->pcdata->ranking[sn] < 1 || ch->pcdata->ranking[sn] > MAX_RANKING)))
            {
               send_to_char("You can't do that.\n\r", ch);
               return;
            }
            if ((skill = get_skilltype(sn)) == NULL)
            {
               send_to_char("You can't do that right now...\n\r", ch);
               return;
            }
         }
         else
            /*
             * Godly "spell builder" spell casting with debugging messages
             */
         {
            if ((sn = skill_lookup(arg1)) < 0)
            {
               send_to_char("We didn't create that yet...\n\r", ch);
               return;
            }
            if (!IS_NPC(ch) && (ch->pcdata->ranking[sn] < 1 || ch->pcdata->ranking[sn] > MAX_RANKING))
            {
               send_to_char("You can't do that.\n\r", ch);
               return;
            }
            if (sn >= MAX_SKILL)
            {
               send_to_char("Hmm... that might hurt.\n\r", ch);
               return;
            }
            if ((skill = get_skilltype(sn)) == NULL)
            {
               send_to_char("Something is severely wrong with that one...\n\r", ch);
               return;
            }
            if (skill->type != SKILL_SPELL)
            {
               send_to_char("That isn't a spell.\n\r", ch);
               return;
            }
            if (!skill->spell_fun)
            {
               send_to_char("We didn't finish that one yet...\n\r", ch);
               return;
            }
         }

         /*
          * Something else removed by Merc   -Thoric
          */
         /* Band-aid alert!  !IS_NPC check -- Blod */
         if (ch->position < skill->minimum_position && !IS_NPC(ch))
         {
            switch (ch->position)
            {
               default:
                  send_to_char("You can't concentrate enough.\n\r", ch);
                  break;
               case POS_SITTING:
                  send_to_char("You can't summon enough energy sitting down.\n\r", ch);
                  break;
               case POS_RESTING:
                  send_to_char("You're too relaxed to cast that spell.\n\r", ch);
                  break;
               case POS_FIGHTING:
                  if (skill->minimum_position <= POS_EVASIVE)
                  {
                     send_to_char("This fighting style is too demanding for that!\n\r", ch);
                  }
                  else
                  {
                     send_to_char("No way!  You are still fighting!\n\r", ch);
                  }
                  break;
               case POS_DEFENSIVE:
                  if (skill->minimum_position <= POS_EVASIVE)
                  {
                     send_to_char("This fighting style is too demanding for that!\n\r", ch);
                  }
                  else
                  {
                     send_to_char("No way!  You are still fighting!\n\r", ch);
                  }
                  break;
               case POS_AGGRESSIVE:
                  if (skill->minimum_position <= POS_EVASIVE)
                  {
                     send_to_char("This fighting style is too demanding for that!\n\r", ch);
                  }
                  else
                  {
                     send_to_char("No way!  You are still fighting!\n\r", ch);
                  }
                  break;
               case POS_BERSERK:
                  if (skill->minimum_position <= POS_EVASIVE)
                  {
                     send_to_char("This fighting style is too demanding for that!\n\r", ch);
                  }
                  else
                  {
                     send_to_char("No way!  You are still fighting!\n\r", ch);
                  }
                  break;
               case POS_EVASIVE:
                  send_to_char("No way!  You are still fighting!\n\r", ch);
                  break;
               case POS_SLEEPING:
                  send_to_char("You dream about great feats of magic.\n\r", ch);
                  break;
            }
            return;
         }

         if (skill->spell_fun == spell_null)
         {
            send_to_char("That's not a spell!\n\r", ch);
            return;
         }

         if (!skill->spell_fun)
         {
            send_to_char("You cannot cast that... yet.\n\r", ch);
            return;
         }

         mana = IS_NPC(ch) ? 0 : skill->min_mana;
         if (ch->race == RACE_FAIRY)
         {
            mana = mana * 66 / 100;
         }
         if (ch->race == RACE_ELF)
         {
            mana = mana * 85 / 100;
         }
         
         if (!IS_NPC(ch) && ch->pcdata->ranking[sn] >= 3)
         {
            if (ch->pcdata->ranking[sn] == 3)
               mana = mana * 80 / 100;
            if (ch->pcdata->ranking[sn] == 4)
               mana = mana * 66 / 100;
            if (ch->pcdata->ranking[sn] == 5)
               mana = mana * 50 / 100;
            if (ch->pcdata->ranking[sn] == 6)
               mana = mana * 33 / 100;
         }
         mana = UMAX(1, mana);

         if (HAS_WAIT(ch))
         {
            send_to_char("You are too busy in battle to do that.\n\r", ch);
            return;
         }

         /*
          * Locate targets.
          */
         vo = locate_targets(ch, arg2, sn, &victim, &obj);
         if (vo == &pAbort)
            return;

         if (skill->target == TAR_CHAR_OFFENSIVE)
            if (!IS_NPC(ch) && !IS_NPC(victim))
               if ((IS_IMMORTAL(ch) && !IS_IMMORTAL(victim)) || (!IS_IMMORTAL(ch) && IS_IMMORTAL(victim)))
               {
                  sprintf(log_buf, "%s or %s is casting a spell on the other.", ch->name, victim->name);
                  log_string_plus(log_buf, LOG_NORMAL, LEVEL_ADMIN);
                  send_to_char("Sorry, offensive spells cannot be casted by or towards an immortal.\n\r", ch);
                  return;
               }
         /*
          * Vampire spell casting    -Thoric
          */
         blood = UMAX(1, (mana + 4) / 8); /* NPCs don't have PCDatas. -- Altrag */
         if (IS_VAMPIRE(ch))
         {
            if (ch->pcdata->condition[COND_BLOODTHIRST] < blood)
            {
               send_to_char("You don't have enough blood power.\n\r", ch);
               return;
            }
         }
         else if (!IS_NPC(ch) && ch->mana < mana)
         {
            send_to_char("You don't have enough mana.\n\r", ch);
            return;
         }

         if (skill->participants <= 1)
            break;

         /* multi-participant spells   -Thoric */
         add_timer(ch, TIMER_DO_FUN, UMIN(skill->beats, 3), do_cast, 1);
         act(AT_MAGIC, "You begin to chant...", ch, NULL, NULL, TO_CHAR);
         act(AT_MAGIC, "$n begins to chant...", ch, NULL, NULL, TO_ROOM);
         sprintf(staticbuf, "%s %s", arg2, target_name);
         ch->alloc_ptr = str_dup(staticbuf);
         ch->tempnum = sn;
         return;
      case SUB_TIMER_DO_ABORT:
         DISPOSE(ch->alloc_ptr);
         if (IS_VALID_SN((sn = ch->tempnum)))
         {
            if ((skill = get_skilltype(sn)) == NULL)
            {
               send_to_char("Something went wrong...\n\r", ch);
               bug("do_cast: SUB_TIMER_DO_ABORT: bad sn %d", sn);
               return;
            }
            mana = IS_NPC(ch) ? 0 : skill->min_mana;
            blood = UMAX(1, (mana + 4) / 8);
            if (IS_VAMPIRE(ch))
               gain_condition(ch, COND_BLOODTHIRST, -UMAX(1, blood / 3));
            else if (ch->level < LEVEL_IMMORTAL) /* so imms dont lose mana */
               ch->mana -= mana / 3;
         }
         set_char_color(AT_MAGIC, ch);
         send_to_char("You stop chanting...\n\r", ch);
         /* should add chance of backfire here */
         return;
      case 1:
         sn = ch->tempnum;
         if ((skill = get_skilltype(sn)) == NULL)
         {
            send_to_char("Something went wrong...\n\r", ch);
            bug("do_cast: substate 1: bad sn %d", sn);
            return;
         }
         if (!ch->alloc_ptr || !IS_VALID_SN(sn) || skill->type != SKILL_SPELL)
         {
            send_to_char("Something cancels out the spell!\n\r", ch);
            bug("do_cast: ch->alloc_ptr NULL or bad sn (%d)", sn);
            return;
         }
         mana = IS_NPC(ch) ? 0 : skill->min_mana;
         blood = UMAX(1, (mana + 4) / 8);
         strcpy(staticbuf, ch->alloc_ptr);
         target_name = one_argument(staticbuf, arg2);
         DISPOSE(ch->alloc_ptr);
         ch->substate = SUB_NONE;
         if (skill->participants > 1)
         {
            int cnt = 1;
            CHAR_DATA *tmp;
            TIMER *t;

            for (tmp = ch->in_room->first_person; tmp; tmp = tmp->next_in_room)
               if (tmp != ch
                  && (t = get_timerptr(tmp, TIMER_DO_FUN)) != NULL
                  && t->count >= 1 && t->do_fun == do_cast && tmp->tempnum == sn && tmp->alloc_ptr && !str_cmp(tmp->alloc_ptr, staticbuf))
                  ++cnt;
            if (cnt >= skill->participants)
            {
               for (tmp = ch->in_room->first_person; tmp; tmp = tmp->next_in_room)
                  if (tmp != ch
                     && (t = get_timerptr(tmp, TIMER_DO_FUN)) != NULL
                     && t->count >= 1 && t->do_fun == do_cast && tmp->tempnum == sn && tmp->alloc_ptr && !str_cmp(tmp->alloc_ptr, staticbuf))
                  {
                     extract_timer(tmp, t);
                     act(AT_MAGIC, "Channeling your energy into $n, you help cast the spell!", ch, NULL, tmp, TO_VICT);
                     act(AT_MAGIC, "$N channels $S energy into you!", ch, NULL, tmp, TO_CHAR);
                     act(AT_MAGIC, "$N channels $S energy into $n!", ch, NULL, tmp, TO_NOTVICT);
                     if (victim)
                        learn_from_success(tmp, sn, victim);
                     else
                        learn_from_success(tmp, sn, NULL);
                     if (IS_VAMPIRE(ch))
                        gain_condition(tmp, COND_BLOODTHIRST, -blood);
                     else
                        tmp->mana -= mana;
                     tmp->substate = SUB_NONE;
                     tmp->tempnum = -1;
                     DISPOSE(tmp->alloc_ptr);
                  }
               dont_wait = TRUE;
               send_to_char("You concentrate all the energy into a burst of mystical words!\n\r", ch);
               vo = locate_targets(ch, arg2, sn, &victim, &obj);
               if (vo == &pAbort)
                  return;
            }
            else
            {
               set_char_color(AT_MAGIC, ch);
               send_to_char("There was not enough power for the spell to succeed...\n\r", ch);
               if (IS_VAMPIRE(ch))
                  gain_condition(ch, COND_BLOODTHIRST, -UMAX(1, blood / 2));
               else if (ch->level < LEVEL_IMMORTAL) /* so imms dont lose mana */
                  ch->mana -= mana / 2;
               if (victim)
                  learn_from_failure(ch, sn, victim);
               else
                  learn_from_success(ch, sn, NULL);
               return;
            }
         }
   }

   /* uttering those magic words unless casting "ventriloquate" */
   if (str_cmp(skill->name, "ventriloquate"))
      say_spell(ch, sn);

   /*
    * Getting ready to cast... check for spell components -Thoric
    */
   if (!process_spell_components(ch, sn))
   {
      if (IS_VAMPIRE(ch))
         gain_condition(ch, COND_BLOODTHIRST, -UMAX(1, blood / 2));
      else if (ch->level < LEVEL_IMMORTAL) /* so imms dont lose mana */
         ch->mana -= mana / 2;
      if (victim)
         learn_from_failure(ch, sn, victim);
      else
         learn_from_failure(ch, sn, NULL);
      
      if (!dont_wait)
      {
         if (!ch->fighting)
            WAIT_STATE(ch, skill->beats*2);
         else
            ch->fight_timer = get_btimer(ch, sn, NULL);
      }
      return;
   }

   suc = 1;
   if (!IS_NPC(ch))
   {
      if ((number_percent() + skill->difficulty * 5) > (90 + (ch->pcdata->learned[sn]*10)))
         suc = 0;
   }


   if (suc == 0)
   {
      /* Some more interesting loss of concentration messages  -Thoric */
      switch (number_bits(2))
      {
         case 0: /* too busy */
            if (ch->fighting)
               send_to_char("This round of battle is too hectic to concentrate properly.\n\r", ch);
            else
               send_to_char("You lost your concentration.\n\r", ch);
            break;
         case 1: /* irritation */
            if (number_bits(2) == 0)
            {
               switch (number_bits(2))
               {
                  case 0:
                     send_to_char("A tickle in your nose prevents you from keeping your concentration.\n\r", ch);
                     break;
                  case 1:
                     send_to_char("An itch on your leg keeps you from properly casting your spell.\n\r", ch);
                     break;
                  case 2:
                     send_to_char("Something in your throat prevents you from uttering the proper phrase.\n\r", ch);
                     break;
                  case 3:
                     send_to_char("A twitch in your eye disrupts your concentration for a moment.\n\r", ch);
                     break;
               }
            }
            else
               send_to_char("Something distracts you, and you lose your concentration.\n\r", ch);
            break;
         case 2: /* not enough time */
            if (ch->fighting)
               send_to_char("There wasn't enough time this round to complete the casting.\n\r", ch);
            else
               send_to_char("You lost your concentration.\n\r", ch);
            break;
         case 3:
            send_to_char("You get a mental block mid-way through the casting.\n\r", ch);
            break;
      }
      if (IS_VAMPIRE(ch))
         gain_condition(ch, COND_BLOODTHIRST, -UMAX(1, blood / 2));
      else if (ch->level < LEVEL_IMMORTAL) /* so imms dont lose mana */
         ch->mana -= mana / 2;
      if (victim)
         learn_from_failure(ch, sn, victim);
      else
         learn_from_failure(ch, sn, NULL);
      return;
   }
   else
   {
      int mint = 0, bint;
      
      //There should be some kind of stop here if you aren't in the room ya
      if (skill->target == TAR_CHAR_OFFENSIVE && victim)
      {
         if (!IN_SAME_ROOM(ch, victim))
         {
            send_to_char("Your target is not in the same room as you!\n\r", ch);
            return;
         }
      }
      
      if (IS_VAMPIRE(ch))
         gain_condition(ch, COND_BLOODTHIRST, -blood);
      else
         ch->mana -= mana;
      
      if (!IS_NPC(ch))
      {           
         if (sysdata.stat_gain <= 1)
            mint = number_range(4+(mana/24), 7+(mana/16));
         else if (sysdata.stat_gain <= 3)
            mint = number_range(7+(mana/16), 10+(mana/12));
         else if (sysdata.stat_gain >= 5)
            mint = number_range(10+(mana/10), 10+(mana/7));
         
         bint = 14 + race_table[ch->race]->int_plus;
         if (mint == bint - 4)
            bint *= 2;
         if (mint == bint - 3)
            bint *= 1.7;
         if (mint == bint - 2)
            bint *= 1.5;
         if (mint == bint - 1)
            bint *= 1.2;
         if (mint == bint)
            bint *= 1;
         if (mint == bint + 1)
            bint *= .85;
         if (mint == bint + 2)
            bint *= .7;
         if (mint == bint + 3)
            bint *= .6;
         if (mint == bint + 4)
            bint *= .4;
         if (mint == bint + 5)
            bint *= .3;
         if (mint == bint + 6)
            bint *= .275;
         if (mint == bint + 7)
            bint *= .25;
         if (mint == bint + 8)
            bint *= .225;
         if (mint > bint + 8) //Base + 8 should be the max unless you screwed it up
            bint = 0;
         else
         {
            if (mint == 0)
               mint = 1;
         }
      
         if (ch->perm_int >= (14 + race_table[ch->race]->int_plus + race_table[ch->race]->int_range + get_talent_increase(ch, 3)) && ch->pcdata->per_int >= 3000)
            mint = 0;
            
         if (victim && IS_NPC(victim) && xIS_SET(victim->act, ACT_MOUNTSAVE))
         {
            if (mint > 0)
               mint = 0;
         } 
         
         ch->pcdata->per_int += mint;
         if (ch->pcdata->per_int > 10000)
         {
            ch->perm_int++;
            send_to_char("&R******************************************\n\r", ch);
            send_to_char("&R*****You Gain 1 Point of Intelligence*****\n\r", ch);
            send_to_char("&R******************************************\n\r", ch);
            ch->pcdata->per_int = 0;
         }
         if (ch->pcdata->per_lck < 0)
         {
            ch->perm_int--;
            send_to_char("&r******************************************\n\r", ch);
            send_to_char("&r*****You Lose 1 Point of Intelligence*****\n\r", ch);
            send_to_char("&r******************************************\n\r", ch);
            ch->pcdata->per_int = 9999;
         }
      } 
      gain_mana_per(ch, victim, mana);
      /*
       * If it is offensive or ignore it won't work
       * 
       * otherwise spells will have to check themselves
       */
      if (((skill->target == TAR_CHAR_OFFENSIVE || skill->target == TAR_IGNORE) && victim && is_immune(victim, -1, RIS_MAGIC)))
      {
         immune_casting(skill, ch, victim, NULL);
         retcode = rSPELL_FAILED;
      }
      else
      {
         int level;
         
         start_timer(&time_used);
         level = POINT_LEVEL(LEARNED(ch, sn), MASTERED(ch, sn));
         retcode = (*skill->spell_fun) (sn, level, ch, vo);
         end_timer(&time_used);
         update_userec(&time_used, &skill->userec);
      }
   }

   if (retcode == rCHAR_DIED || retcode == rERROR || char_died(ch))
      return;

   /* learning */
   if (retcode != rSPELL_FAILED)
      learn_from_success(ch, sn, victim);
   else
      learn_from_failure(ch, sn, victim);

   /* favor adjustments */
   if (victim && victim != ch && !IS_NPC(victim) && skill->target == TAR_CHAR_DEFENSIVE)
      adjust_favor(ch, 7, 1);

   if (victim && victim != ch && !IS_NPC(ch) && skill->target == TAR_CHAR_DEFENSIVE)
      adjust_favor(victim, 13, 1);

   if (victim && victim != ch && !IS_NPC(ch) && skill->target == TAR_CHAR_OFFENSIVE)
      adjust_favor(ch, 4, 1);

   /*
    * Fixed up a weird mess here, and added double safeguards -Thoric
    */
   if (skill->target == TAR_CHAR_OFFENSIVE && victim && !char_died(victim) && victim != ch)
   {
      CHAR_DATA *vch, *vch_next;

      for (vch = ch->in_room->first_person; vch; vch = vch_next)
      {
         vch_next = vch->next_in_room;

         if (vch == victim)
         {
            if (victim->master != ch && !victim->fighting)
               retcode = one_hit(victim, ch, TYPE_UNDEFINED, LM_BODY);
            break;
         }
      }
   }
   if (!dont_wait)
   {
      int beats = 0;
      if (MASTERED(ch, sn) == 4)
         beats++;
      if (MASTERED(ch, sn) == 6)
         beats++;
      if (!ch->fighting)
      {
         
         WAIT_STATE(ch, UMAX(1, skill_table[sn]->beats-beats)*2);
      }
      else
      {
         ch->fight_timer = get_btimer(ch, sn, NULL);
         ch->fight_timer = UMAX(1, ch->fight_timer -= beats);
      }
         
   }

   return;
}

/*
 * Will find if they can use the "portal" system.
 */
bool can_use_portal(CHAR_DATA * ch, int type)
{
   int p;
   int count = 0;
   int standing = 0;

   if (in_hellmaze(ch)
      || (!IS_NPC(ch) && ch->pcdata->caste < 2) || (!IS_NPC(ch) && xIS_SET(ch->act, PLR_GAMBLER)))
   {
      if (type == 3)
         send_to_char("Sorry, you cannot use your rune right now.\n\r", ch);
      else
         send_to_char("Sorry, you cannot cast that spell right now.\n\r", ch);
      return FALSE;
   }
   if (type != 2)
   {
      if (xIS_SET(ch->act, PLR_PORTALHUNT))
      {
         send_to_char("Sorry, you cannot use this spell while portal hunting.\n\r", ch);
         return FALSE;
      }
   }
   for (p = 0; p < sysdata.last_portal; p++)
   {
      if (xIS_SET(ch->pcdata->portalfnd, p))
      {
         count++;
         if (portal_show[p]->x == ch->coord->x && portal_show[p]->y == ch->coord->y && portal_show[p]->map == ch->map)
         {
            standing++;
         }
      }
   }
   if (count == 0)
   {
      send_to_char("You have not found any portals, you need to hunt some down.\n\r", ch);
      return FALSE;
   }
   if (ch->in_room->vnum == ROOM_VNUM_PORTAL)
      standing++;

   if (standing == 0 && (type == 0 || type == 3))
   {
      if (type == 3)
         send_to_char("You can only use this rune at a portal or poral room.\n\r", ch);
      else
         send_to_char("You can only cast this spell at a portal or portal room.\n\r", ch);
      return FALSE;
   }
   return TRUE;
}

/*
 * Cast spells at targets using a magical object.
 */
ch_ret obj_cast_spell(int sn, int level, CHAR_DATA * ch, CHAR_DATA * victim, OBJ_DATA * obj)
{
   void *vo;
   ch_ret retcode = rNONE;
   SKILLTYPE *skill = get_skilltype(sn);
   struct timeval time_used;
   int passarg = 0;

   if (sn >= 9999)
   {
      sn -= 10000;
      skill = get_skilltype(sn);
      passarg = 1;
   }
   if (sn == -1)
      return retcode;
   if (!skill || !skill->spell_fun)
   {
      bug("Obj_cast_spell: bad sn %d.", sn);
      return rERROR;
   }

   if (xIS_SET(ch->in_room->room_flags, ROOM_NO_MAGIC) || wIS_SET(ch, ROOM_NO_MAGIC))
   {
      set_char_color(AT_MAGIC, ch);
      send_to_char("Nothing seems to happen...\n\r", ch);
      return rNONE;
   }

   if (ch && victim && !IS_NPC(ch) && !IS_NPC(victim))
   {
      if ((check_room_pk(ch) == 1) && skill->target == TAR_CHAR_OFFENSIVE)
      {
         set_char_color(AT_MAGIC, ch);
         send_to_char("Nothing seems to happen...\n\r", ch);
         return rNONE;
      }
   }
   else
   {
      if (is_room_safe(ch) && skill->target == TAR_CHAR_OFFENSIVE)
      {
         set_char_color(AT_MAGIC, ch);
         send_to_char("Nothing seems to happen...\n\r", ch);
         return rNONE;
      }
   }
   
   
   if (!passarg)
      target_name = "";
   switch (skill->target)
   {
      default:
         bug("Obj_cast_spell: bad target for sn %d.", sn);
         return rERROR;

      case TAR_IGNORE:
         vo = NULL;
         if (victim)
            target_name = victim->name;
         else if (obj)
            target_name = obj->name;
         break;

      case TAR_CHAR_OFFENSIVE:
         if (victim != ch)
         {
            if (!victim)
               victim = who_fighting(ch);
            if (!victim || (!IS_NPC(victim) && !in_arena(victim)))
            {
               send_to_char("You can't do that.\n\r", ch);
               return rNONE;
            }
         }
         if (ch != victim && is_safe(ch, victim))
            return rNONE;
         vo = (void *) victim;
         break;

      case TAR_CHAR_DEFENSIVE:
         if (victim == NULL)
            victim = ch;
         vo = (void *) victim;
         break;

      case TAR_CHAR_SELF:
         vo = (void *) ch;
         break;

      case TAR_OBJ_INV: case TAR_OBJ_ROOM:
         if (obj == NULL)
         {
            send_to_char("You can't do that.\n\r", ch);
            return rNONE;
         }
         vo = (void *) obj;
         break;
   }
   
   if (victim && !IS_NPC(ch) && IS_NPC(victim))
   {
      if (xIS_SET(victim->act, ACT_MOUNTSAVE))
         return rNONE;
      if (victim->master == ch)
         return rNONE;
   }
       
   start_timer(&time_used);
   retcode = (*skill->spell_fun) (sn, level, ch, vo);
   end_timer(&time_used);
   update_userec(&time_used, &skill->userec);

   if (retcode == rSPELL_FAILED)
      retcode = rNONE;

   if (retcode == rCHAR_DIED || retcode == rERROR)
      return retcode;

   if (char_died(ch))
      return rCHAR_DIED;
      
   if (victim && victim != ch && skill->target == TAR_CHAR_OFFENSIVE)
      retcode = one_hit(victim, ch, TYPE_UNDEFINED, LM_BODY);
   /*if (SPELL_FLAG(skill, SF_AREA))
   {     
      for (vch = ch->in_room->first_person; vch; vch = vch_next)
      {
         vch_next = vch->next_in_room;
         if (ch->coord->x != vch->coord->x || ch->coord->y != vch->coord->y || ch->map != vch->map)
            continue;
         if (!IS_NPC(ch) && IS_NPC(vch))
         {
            if (!IS_NPC(ch) && xIS_SET(vch->act, ACT_MOUNTSAVE))
               continue;
            if (IS_NPC(vch) && IS_AFFECTED(vch, AFF_CHARM) && vch->master == ch)
               continue;         
            if (IS_NPC(vch) && xIS_SET(ch->act, ACT_MOUNTABLE))
               continue;
            if (vch->master == ch)
               continue;
         }
         if (vch == ch)
            continue;
         obj_cast_spell(sn, level, ch, vch, obj);
      }   
   }*/
   return retcode;
}

ch_ret spell_web(int sn, int level, CHAR_DATA *ch, void *vo)
{
   sh_int points;
   int chance;
   sh_int isobj = 0;
   AFFECT_DATA af;
   CHAR_DATA *victim = (CHAR_DATA *) vo;
   int str;
   
   if (level >= 999)
   {
      isobj = 1;
   }
   points = POINT_LEVEL(GET_POINTS(ch, sn, isobj, level), GET_MASTERY(ch, sn, isobj, level));
   
   str = get_curr_str(victim);
   chance = 20+(UMIN(25, level/3))-((str-16)*3);
   chance = ris_save(victim, chance, RIS_PARALYSIS);
   if (chance < 1000)
      chance = URANGE(5, chance, 55);
   
   if (number_range(1, 100) <= chance && chance != 1000)
   {
      af.type = sn;
      af.duration = 40+UMIN(15, level/5);
      af.location = APPLY_NONE;
      af.modifier = 0;
      af.bitvector = meb(AFF_WEB);
      affect_join(victim, &af);
      act(AT_MAGIC, "[WEB] $N tries to move but $S feet are cought in some nasty webs.", ch, NULL, victim, TO_CHAR);
      act(AT_MAGIC, "[WEB] $N tries to move but $S feet are cought in some nasty webs.", ch, NULL, victim, TO_NOTVICT);
      act(AT_MAGIC, "[WEB] You try to move but your feet are cought in some nasty webs.", ch, NULL, victim, TO_VICT);
      adjust_aggression_list(victim, ch, 20, 4, 0);
      return rNONE;
   }
   else
   {
      act(AT_MAGIC, "[web] You try to surround $N's feet in webs but fails.", ch, NULL, victim, TO_CHAR);
      act(AT_MAGIC, "[web] $n tries to surround $N's feet in webs but fails.", ch, NULL, victim, TO_NOTVICT);
      act(AT_MAGIC, "[web] $n tries to surround your feet in webs but fails.", ch, NULL, victim, TO_VICT);  
      adjust_aggression_list(victim, ch, 5, 4, 0);
      return rSPELL_FAILED;
   } 
   return rNONE;
}

ch_ret spell_snare(int sn, int level, CHAR_DATA *ch, void *vo)
{
   sh_int points;
   int chance;
   sh_int isobj = 0;
   AFFECT_DATA af;
   CHAR_DATA *victim = (CHAR_DATA *) vo;
   int str;
   
   if (level >= 999)
   {
      isobj = 1;
   }
   points = POINT_LEVEL(GET_POINTS(ch, sn, isobj, level), GET_MASTERY(ch, sn, isobj, level));
   
   str = get_curr_str(victim);
   chance = 40+(UMIN(25, level/3))-((str-16)*3);
   chance = ris_save(victim, chance, RIS_PARALYSIS);
   if (chance < 1000)
      chance = URANGE(5, chance, 75);
   
   if (number_range(1, 100) <= chance && chance != 1000)
   {
      af.type = sn;
      af.duration = 70+UMIN(20, level/4);
      af.location = APPLY_NONE;
      af.modifier = 0;
      af.bitvector = meb(AFF_WEB);
      af.bitvector = meb(AFF_SNARE); //For damage break checks mainly, harder to break a snare
      affect_join(victim, &af);
      act(AT_MAGIC, "[SNARE] $N tries to move but $S feet are cought in a nasty magical snare.", ch, NULL, victim, TO_CHAR);
      act(AT_MAGIC, "[SNARE] $N tries to move but $S feet are cought in a nasty magical snare.", ch, NULL, victim, TO_NOTVICT);
      act(AT_MAGIC, "[SNARE] You try to move but your feet are cought in a nasty magical snare.", ch, NULL, victim, TO_VICT);
      adjust_aggression_list(victim, ch, 20, 4, 0);
      return rNONE;
   }
   else
   {
      act(AT_MAGIC, "[snare] You try to surround $N's feet in a magical snare but fails.", ch, NULL, victim, TO_CHAR);
      act(AT_MAGIC, "[snare] $n tries to surround $N's feet in a magical snare but fails.", ch, NULL, victim, TO_NOTVICT);
      act(AT_MAGIC, "[snare] $n tries to surround your feet in a magical snare but fails.", ch, NULL, victim, TO_VICT);  
      adjust_aggression_list(victim, ch, 5, 4, 0);
      return rSPELL_FAILED;
   } 
   return rNONE;
}
      
ch_ret spell_greater_resurrection(int sn, int level, CHAR_DATA *ch, void *vo)
{
   OBJ_DATA *corpse = (OBJ_DATA *) vo;
   sh_int points;
   sh_int mastery; 
   sh_int isobj = 0;
   char *pd;
   DESCRIPTOR_DATA *d;
   char name[MSL];
   int rezpercent;

   if (level >= 999)
   {
      isobj = 1;
   }
   points = GET_POINTS(ch, sn, isobj, level);
   mastery = GET_MASTERY(ch, sn, isobj, level);
   points = POINT_LEVEL(points, mastery);   
   
   if (!corpse)
   {
      send_to_char("That corpse is not here!\n\r", ch);
      return rSPELL_FAILED;
   }
   if (corpse->item_type != ITEM_CORPSE_PC)
   {
      send_to_char("That is not a corpse!\n\r", ch);
      return rSPELL_FAILED;
   }
   pd = corpse->short_descr;
   pd = one_argument(pd, name);
   pd = one_argument(pd, name);
   pd = one_argument(pd, name);
   pd = one_argument(pd, name);
   
   for (d = first_descriptor; d; d = d->next)
   {
      if (d->connected == CON_PLAYING && d->character->in_room && d->newstate != 2 && d->character && d->character->pcdata)
      {
         if (!str_cmp(name, d->character->name))
            break;
      }
   }
   if (!d)
   {
      send_to_char("Your target is not online or present atm.\n\r", ch);
      return rSPELL_FAILED;
   }
   if (d->character->pcdata->lostcon >= 0)
   {
      send_to_char("Your target has already been revived, you cannot do it again.\n\r", ch);
      return rSPELL_FAILED;
   }
   if (IN_WILDERNESS(ch))
   {
      if (room_is_private_wilderness(ch, ch->in_room, ch->coord->x, ch->coord->y, ch->map))
      {
         send_to_char("This room is private.\n\r", ch);
         return rSPELL_FAILED;
      }
   }
   else
   {
      if (room_is_private(ch->in_room))
      {
         send_to_char("This room is private.\n\r", ch);
         return rSPELL_FAILED;
      }
   }
   if (IS_OBJ_STAT(corpse, ITEM_CORPSEREVIVE))
   {
      send_to_char("This corpse has already been granted a revival, no use doing it twice.\n\r", ch);
      return rSPELL_FAILED;
   }
   rezpercent = (60+UMIN(40, (points * 57 / 100)));
   if (rezpercent <= d->character->pcdata->rezpercent)
   {
      send_to_char("Your target already has a better resurrection offered.\n\r", ch);
      return rSPELL_FAILED;
   }
   d->character->pcdata->rezpercent = rezpercent;
   d->character->pcdata->rezcorpse = corpse;
   d->character->pcdata->rezroom = ch->in_room;
   d->character->pcdata->rezx = ch->coord->x;
   d->character->pcdata->rezy = ch->coord->y;
   d->character->pcdata->rezmap = ch->map;
   ch_printf(d->character, "You are being offered a %d%% Resurrection by %s.\n\r", d->character->pcdata->rezpercent, PERS_MAP(ch, d->character));
   ch_printf(ch, "You offered your target a %d%% Resurrection.\n\r", d->character->pcdata->rezpercent);
   return rNONE;
}

ch_ret spell_summon_corpse(int sn, int level, CHAR_DATA *ch, void *vo)
{
   OBJ_DATA *obj;
   OBJ_DATA *idol;
   OBJ_INDEX_DATA *iobj;
   CHAR_DATA *victim;
   sh_int points;
   sh_int mastery;
   sh_int isobj = 0;
   char *pd;
   char name[MSL];
   int fnd = 0;
   int quest = 0;

   if (level >= 999)
   {
      isobj = 1;
   }
   points = GET_POINTS(ch, sn, isobj, level);
   mastery = GET_MASTERY(ch, sn, isobj, level);
   points = POINT_LEVEL(points, mastery);  
   
   if ((victim = get_char_world(ch, target_name)) == NULL)
   {
      send_to_char("Failed to locate your target.\n\r", ch);
      return rSPELL_FAILED;
   }
   
   if (IS_NPC(victim))
   {
      send_to_char("Not on npcs.\n\r", ch);
      return rSPELL_FAILED;
   }
   
   if ((iobj = get_obj_index(OBJ_VNUM_IDOL)) == NULL)
   {
      send_to_char("Idol does not exist in the game, notify an immortal.\n\r", ch);
      bug("Idol needed for summon corpse does not exist!!!");
      return rSPELL_FAILED;
   }
   
   idol = get_obj_carry(ch, iobj->name);
   if (!idol || idol->pIndexData->vnum != iobj->vnum)
   {
      send_to_char("You need a Divine Idol to cast this spell.\n\r", ch);
      return rSPELL_FAILED;
   }
   
   for (obj = first_object; obj; obj = obj->next)
   {
      if (obj->item_type != ITEM_CORPSE_PC)
         continue;
      if (!obj->in_room)
         continue;
      if (obj->in_room->area != ch->in_room->area)
         continue;
      pd = obj->short_descr;
      pd = one_argument(pd, name);
      pd = one_argument(pd, name);
      pd = one_argument(pd, name);
      pd = one_argument(pd, name); 
      if (!str_cmp(name, victim->name))
      {
         obj_from_room(obj);
         obj_to_room(obj, ch->in_room, ch);
         fnd++;
      }
   } 
   if (fnd > 0)
   {
      act(AT_BLUE, "You summon the corpse(s) of $N", ch, NULL, victim, TO_CHAR);
      act(AT_BLUE, "$n summons the corpse(s) of $N", ch, NULL, victim, TO_ROOM);
      if (ch->in_room->area->low_r_vnum >= START_QUEST_VNUM && ch->in_room->area->low_r_vnum <= END_QUEST_VNUM)
         quest = 1;
      if (number_range(1, 100) > UMAX(20, level/4) && !quest)
      {
         act(AT_RED, "The idol shimmers and is gone.", ch, NULL, victim, TO_ROOM);
         act(AT_RED, "The idol shimmers and is gone.", ch, NULL, victim, TO_CHAR);
         separate_obj(idol);
         obj_from_char(idol);
         extract_obj(idol);
      }
      learn_from_success(ch, gsn_summon_corpse, NULL);
      return rNONE;
   }
   else
   {
      send_to_char("No corpses could be found in this area.\n\r", ch);
      return rSPELL_FAILED;
   }
}

ch_ret spell_lesser_resurrection(int sn, int level, CHAR_DATA *ch, void *vo)
{
   OBJ_DATA *corpse = (OBJ_DATA *) vo;
   sh_int points;
   sh_int mastery;
   sh_int isobj = 0;
   char *pd;
   DESCRIPTOR_DATA *d;
   char name[MSL];
   int rezpercent;

   if (level >= 999)
   {
      isobj = 1;
   }
   points = GET_POINTS(ch, sn, isobj, level);
   mastery = GET_MASTERY(ch, sn, isobj, level);
   points = POINT_LEVEL(points, mastery);   

   
   if (!corpse)
   {
      send_to_char("That corpse is not here!\n\r", ch);
      return rSPELL_FAILED;
   }
   if (corpse->item_type != ITEM_CORPSE_PC)
   {
      send_to_char("That is not a corpse!\n\r", ch);
      return rSPELL_FAILED;
   }
   pd = corpse->short_descr;
   pd = one_argument(pd, name);
   pd = one_argument(pd, name);
   pd = one_argument(pd, name);
   pd = one_argument(pd, name);
   
   for (d = first_descriptor; d; d = d->next)
   {
      if (d->connected == CON_PLAYING && d->character->in_room && d->newstate != 2 && d->character && d->character->pcdata)
      {
         if (!str_cmp(name, d->character->name))
            break;
      }
   }
   if (corpse->timer < 2880 - 60 - (level*3))
   {
      send_to_char("Your target has been dead for too long to use this spell.\n\r", ch);
      return rSPELL_FAILED;
   }
   if (!d)
   {
      send_to_char("Your target is not online or present atm.\n\r", ch);
      return rSPELL_FAILED;
   }
   if (d->character->pcdata->lostcon >= 0)
   {
      send_to_char("Your target has already been revived, you cannot do it again.\n\r", ch);
      return rSPELL_FAILED;
   }
   if (IN_WILDERNESS(ch))
   {
      if (room_is_private_wilderness(ch, ch->in_room, ch->coord->x, ch->coord->y, ch->map))
      {
         send_to_char("This room is private.\n\r", ch);
         return rSPELL_FAILED;
      }
   }
   else
   {
      if (room_is_private(ch->in_room))
      {
         send_to_char("This room is private.\n\r", ch);
         return rSPELL_FAILED;
      }
   }
      
   if (IS_OBJ_STAT(corpse, ITEM_CORPSEREVIVE))
   {
      send_to_char("This corpse has already been granted a revival, no use doing it twice.\n\r", ch);
      return rSPELL_FAILED;
   }
   rezpercent = UMAX(20, points/4);
   if (rezpercent <= d->character->pcdata->rezpercent)
   {
      send_to_char("Your target already has a better resurrection offered.\n\r", ch);
      return rSPELL_FAILED;
   }
   d->character->pcdata->rezpercent = rezpercent;
   d->character->pcdata->rezcorpse = corpse;
   d->character->pcdata->rezroom = ch->in_room;
   d->character->pcdata->rezx = ch->coord->x;
   d->character->pcdata->rezy = ch->coord->y;
   d->character->pcdata->rezmap = ch->map;
   ch_printf(d->character, "You are being offered a %d%% Resurrection by %s.\n\r", d->character->pcdata->rezpercent, PERS_MAP(ch, d->character));
   ch_printf(ch, "You offered your target a %d%% Resurrection.\n\r", d->character->pcdata->rezpercent);
   return rNONE;
}

ch_ret spell_resurrection(int sn, int level, CHAR_DATA *ch, void *vo)
{
   OBJ_DATA *corpse = (OBJ_DATA *) vo;
   sh_int points;
   sh_int mastery;
   sh_int isobj = 0;
   char *pd;
   DESCRIPTOR_DATA *d;
   char name[MSL];
   int rezpercent;

   if (level >= 999)
   {
      isobj = 1;
   }
   points = GET_POINTS(ch, sn, isobj, level);
   mastery = GET_MASTERY(ch, sn, isobj, level);
   points = POINT_LEVEL(points, mastery);   

   
   if (!corpse)
   {
      send_to_char("That corpse is not here!\n\r", ch);
      return rSPELL_FAILED;
   }
   if (corpse->item_type != ITEM_CORPSE_PC)
   {
      send_to_char("That is not a corpse!\n\r", ch);
      return rSPELL_FAILED;
   }
   pd = corpse->short_descr;
   pd = one_argument(pd, name);
   pd = one_argument(pd, name);
   pd = one_argument(pd, name);
   pd = one_argument(pd, name);
   
   for (d = first_descriptor; d; d = d->next)
   {
      if (d->connected == CON_PLAYING && d->character->in_room && d->newstate != 2 && d->character && d->character->pcdata)
      {
         if (!str_cmp(name, d->character->name))
            break;
      }
   }
   if (corpse->timer < 2880 - 60 - (level*3))
   {
      send_to_char("Your target has been dead for too long to use this spell.\n\r", ch);
      return rSPELL_FAILED;
   }
   if (!d)
   {
      send_to_char("Your target is not online or present atm.\n\r", ch);
      return rSPELL_FAILED;
   }
   if (d->character->pcdata->lostcon >= 0)
   {
      send_to_char("Your target has already been revived, you cannot do it again.\n\r", ch);
      return rSPELL_FAILED;
   }
   if (IN_WILDERNESS(ch))
   {
      if (room_is_private_wilderness(ch, ch->in_room, ch->coord->x, ch->coord->y, ch->map))
      {
         send_to_char("This room is private.\n\r", ch);
         return rSPELL_FAILED;
      }
   }
   else
   {
      if (room_is_private(ch->in_room))
      {
         send_to_char("This room is private.\n\r", ch);
         return rSPELL_FAILED;
      }
   }
      
   if (IS_OBJ_STAT(corpse, ITEM_CORPSEREVIVE))
   {
      send_to_char("This corpse has already been granted a revival, no use doing it twice.\n\r", ch);
      return rSPELL_FAILED;
   }
   rezpercent = (20+UMIN(40, (points * 57 / 100)));
   if (rezpercent <= d->character->pcdata->rezpercent)
   {
      send_to_char("Your target already has a better resurrection offered.\n\r", ch);
      return rSPELL_FAILED;
   }
   d->character->pcdata->rezpercent = rezpercent;
   d->character->pcdata->rezcorpse = corpse;
   d->character->pcdata->rezroom = ch->in_room;
   d->character->pcdata->rezx = ch->coord->x;
   d->character->pcdata->rezy = ch->coord->y;
   d->character->pcdata->rezmap = ch->map;
   ch_printf(d->character, "You are being offered a %d%% Resurrection by %s.\n\r", d->character->pcdata->rezpercent, PERS_MAP(ch, d->character));
   ch_printf(ch, "You offered your target a %d%% Resurrection.\n\r", d->character->pcdata->rezpercent);
   return rNONE;
}
void write_corpses args((CHAR_DATA * ch, char *name, OBJ_DATA * objrem));

//Used with the resurrection spells to accept a rez
void do_resurrection(CHAR_DATA *ch, char *argument)
{
   AFFECT_DATA af;
   AFFECT_DATA af2;
   AFFECT_DATA af3;
   AFFECT_DATA af4;
   
   if (check_npc(ch))
      return;
   if (argument[0] == '\0')
   {
      if (ch->pcdata->rezpercent == 0)
      {
         send_to_char("No one has attempted to resurrect you yet.\n\r", ch);
      }
      else
      {
         ch_printf(ch, "You have been offered a %d%% resurrection.\n\r", ch->pcdata->rezpercent);
      }
      send_to_char("Syntax:  resurrection yes\n\r", ch);
      send_to_char("Syntax:  resurrection cost\n\r", ch);
      return;
   }
   if (ch->position < POS_STANDING)
   {
      send_to_char("You can only do this standing or mounted.\n\r", ch);
      return;
   }
   if (!ch->pcdata->rezcorpse || !ch->pcdata->rezroom)
   {
      send_to_char("There is a problem with the resurrection spell, tell an immortal.\n\r", ch);
      return;
   }
   if (!str_cmp(argument, "cost"))
   {
      int hpcost = 0;
      if (ch->max_hit > 100)
      {
         hpcost = ch->max_hit * 10/100;
         hpcost -= hpcost * ch->pcdata->rezpercent / 100;
         ch->max_hit -= hpcost;
      }   
      ch_printf(ch, "Your cost to your total HP would be %d", hpcost);
      return;
   }
   if (!str_cmp(argument, "yes"))
   {
      int hpcost = 0;
      act(AT_MAGIC, "$n disappears as an angel of light sweeps $m away.", ch, NULL, NULL, TO_CANSEE);
      char_from_room(ch);
      char_to_room(ch, ch->pcdata->rezroom);
      ch->coord->x = ch->pcdata->rezx;
      ch->coord->y = ch->pcdata->rezx;
      ch->map = ch->pcdata->rezmap;
      ch->hit = ch->max_hit * ch->pcdata->rezpercent / 100;
      ch->mana = ch->max_mana * ch->pcdata->rezpercent / 100;
      ch->move = ch->max_move * ch->pcdata->rezpercent / 100;
      ch->con_rarm = 1000 * ch->pcdata->rezpercent / 100;
      ch->con_larm = 1000 * ch->pcdata->rezpercent / 100;
      ch->con_rleg = 1000 * ch->pcdata->rezpercent / 100;
      ch->con_lleg = 1000 * ch->pcdata->rezpercent / 100;
      ch->pcdata->lostcon = 0;
      if (ch->max_hit > 100)
      {
         hpcost = ch->max_hit * 10/100;
         hpcost -= hpcost * ch->pcdata->rezpercent / 100;
         ch->max_hit -= hpcost;
      }
      ch_printf(ch, "The cost of your actions is %d HP\n\r", hpcost);
      if (IN_WILDERNESS(ch))
         SET_ONMAP_FLAG(ch);
      else
         REMOVE_ONMAP_FLAG(ch); 
      xSET_BIT(ch->pcdata->rezcorpse->extra_flags, ITEM_CORPSEREVIVE);
      if (ch->pcdata->mount)
      {
         char_from_room(ch->pcdata->mount);
         char_to_room(ch->pcdata->mount, ch->pcdata->rezroom);
         ch->pcdata->mount->coord->x = ch->pcdata->rezx;
         ch->pcdata->mount->coord->y = ch->pcdata->rezx;
         ch->pcdata->mount->map = ch->pcdata->rezx;
         if (IN_WILDERNESS(ch))
            SET_ONMAP_FLAG(ch->pcdata->mount);
         else
            REMOVE_ONMAP_FLAG(ch->pcdata->mount); 
      }
      update_objects(ch, ch->map, ch->coord->x, ch->coord->y);
      write_corpses(NULL, ch->pcdata->rezcorpse->short_descr + 14, NULL);
      ch->pcdata->rezx = ch->pcdata->rezy = ch->pcdata->rezmap = ch->pcdata->rezpercent = 0;
      ch->pcdata->rezroom = NULL;
      ch->pcdata->rezcorpse = NULL;
      act(AT_MAGIC, "You disappear as an angel of light sweeps you away and drops you off at your corpse.", ch, NULL, NULL, TO_CHAR);
      act(AT_MAGIC, "$n appears as an angel of light drops $m in this room with you.", ch, NULL, NULL, TO_CANSEE);
      af.type = gsn_resurrection;
      af.location = APPLY_ARMOR;
      af.modifier = -2;
      af.duration = 60;
      af.bitvector = meb(AFF_REZ);
      affect_to_char(ch, &af);
      
      af2.type = gsn_resurrection;
      af2.location = APPLY_TOHIT;
      af2.modifier = -2;
      af2.duration = 60;
      af2.bitvector = meb(AFF_REZ);
      affect_to_char(ch, &af2);
      
      af3.type = gsn_resurrection;
      af3.location = APPLY_MANATICK;
      af3.modifier = 40;
      af3.duration = 60;
      af3.bitvector = meb(AFF_REZ);
      affect_to_char(ch, &af3);
      
      af4.type = gsn_resurrection;
      af4.location = APPLY_HPTICK;
      af4.modifier = 40;
      af4.duration = 60;
      af4.bitvector = meb(AFF_REZ);
      affect_to_char(ch, &af4);
         
      do_look(ch, "auto");
      save_char_obj(ch);
      return;
   }
   do_resurrection(ch, "");
}
   
   

/*
 * Spell functions.
 */
ch_ret spell_blindness(int sn, int level, CHAR_DATA * ch, void *vo)
{
   CHAR_DATA *victim = (CHAR_DATA *) vo;
   AFFECT_DATA af;
   int tmp;
   sh_int tl;
   SKILLTYPE *skill = get_skilltype(sn);
   sh_int points;
   sh_int mastery;
   sh_int isobj = 0;

   if (level >= 999)
   {
      isobj = 1;
   }
   points = GET_POINTS(ch, sn, isobj, level);
   mastery = GET_MASTERY(ch, sn, isobj, level);
   
   

   tmp = POINT_LEVEL(points, mastery);
   tl = tmp;

   if (SPELL_FLAG(skill, SF_PKSENSITIVE) && !IS_NPC(ch) && !IS_NPC(victim))
   {
      tmp = tmp / 2;
      tl = tl / 2;
   }

   if (is_immune(victim, -1, RIS_MAGIC))
   {
      immune_casting(skill, ch, victim, NULL);
      return rSPELL_FAILED;
   }
   if (IS_AFFECTED(victim, AFF_BLIND) || saves_spell_staff(tl*.4, victim))
   {
      failed_casting(skill, ch, victim, NULL);
      return rSPELL_FAILED;
   }

   af.type = sn;
   af.duration = (4+tmp/5);
   af.bitvector = meb(AFF_BLIND);
   af.location = APPLY_NONE;
   af.modifier = 0;
   affect_to_char(victim, &af);
   set_char_color(AT_MAGIC, victim);
   send_to_char("You are blinded!\n\r", victim);
   if (ch != victim)
   {
      act(AT_MAGIC, "You weave a spell of blindness around $N.", ch, NULL, victim, TO_CHAR);
      act(AT_MAGIC, "$n weaves a spell of blindness about $N.", ch, NULL, victim, TO_NOTVICT);
   }
   return rNONE;
}

ch_ret spell_revitalize_spirit(int sn, int level, CHAR_DATA *ch, void *vo)
{
   sh_int points;
   sh_int mastery;
   sh_int isobj = 0;
   CHAR_DATA *victim = (CHAR_DATA *) vo;

   if (level >= 999)
   {
      isobj = 1;
   }
   points = GET_POINTS(ch, sn, isobj, level);
   mastery = GET_MASTERY(ch, sn, isobj, level);
   level = POINT_LEVEL(points, mastery);

   if (!victim)
   {
      send_to_char("That target is not here!\n\r", ch);
      return rSPELL_FAILED;
   }
   if (victim->mental_state > 0)
   {
      victim->mental_state -= UMAX(1, level/3);
      if (victim->mental_state < 0)
         victim->mental_state = 0;
      act(AT_WHITE, "$n is filled with a revitalizing aura that lifts $s spirit.", victim, NULL, NULL, TO_NOTVICT);
      act(AT_WHITE, "You are filled with a a revitalizing aura that lifts your spirit.", victim, NULL, NULL, TO_CHAR);
      return rNONE;
   }
   else
   {
      victim->mental_state += UMAX(1, level/8);
      if (victim->mental_state > 0)
         victim->mental_state = 0;
      act(AT_WHITE, "$n is filled with a revitalizing aura that lifts $s spirit.", victim, NULL, NULL, TO_NOTVICT);
      act(AT_WHITE, "You are filled with a a revitalizing aura that lifts your spirit.", victim, NULL, NULL, TO_CHAR);
      return rNONE;
   }
   return rSPELL_FAILED;
}
      
   
ch_ret spell_restore_limb(int sn, int level, CHAR_DATA * ch, void *vo)
{
   sh_int points;
   sh_int mastery;
   sh_int isobj = 0;
   CHAR_DATA *victim = (CHAR_DATA *) vo;

   if (level >= 999)
   {
      isobj = 1;
   }
   points = GET_POINTS(ch, sn, isobj, level);
   mastery = GET_MASTERY(ch, sn, isobj, level);

   if (!victim)
   {
      send_to_char("That target is not here!\n\r", ch);
      return rSPELL_FAILED;
   }
   
   if (victim->con_rarm < 0)
   {
      victim->con_rarm = 1+ ((mastery-1) * 50) + ((points-1) * 3);
      if (ch == victim)
         act(AT_WHITE, "$n holds $s hands in front of $S broken right arm and heals it.", ch, NULL, victim, TO_CANSEE);
      else
         act(AT_WHITE, "$n holds $s hands in front of $N's broken right arm and heals it.", ch, NULL, victim, TO_CANSEE); 
      act(AT_WHITE, "$n holds $s hands in front of your broken right arm and heals it.", ch, NULL, victim, TO_VICT);
      if (ch == victim)
         act(AT_WHITE, "You hold you hands in front of your broken right arm and heal it.", ch, NULL, victim, TO_CHAR);
      else  
         act(AT_WHITE, "You hold you hands in front of $N's broken right arm and heal it.", ch, NULL, victim, TO_CHAR);
      return rNONE;
   }
   if (victim->con_larm < 0)
   {
      victim->con_larm = 1+ ((mastery-1) * 50) + ((points-1) * 3);
      if (ch == victim)
         act(AT_WHITE, "$n holds $s hands in front of $S broken left arm and heals it.", ch, NULL, victim, TO_CANSEE);
      else
         act(AT_WHITE, "$n holds $s hands in front of $N's broken left arm and heals it.", ch, NULL, victim, TO_CANSEE); 
      act(AT_WHITE, "$n holds $s hands in front of your broken left arm and heals it.", ch, NULL, victim, TO_VICT);
      if (ch == victim)
         act(AT_WHITE, "You hold you hands in front of your broken left arm and heal it.", ch, NULL, victim, TO_CHAR);
      else  
         act(AT_WHITE, "You hold you hands in front of $N's broken left arm and heal it.", ch, NULL, victim, TO_CHAR);
      return rNONE;
   }
   if (victim->con_rleg < 0)
   {
      victim->con_rleg = 1+ ((mastery-1) * 50) + ((points-1) * 3);
      if (ch == victim)
         act(AT_WHITE, "$n holds $s hands in front of $S broken right leg and heals it.", ch, NULL, victim, TO_CANSEE);
      else
         act(AT_WHITE, "$n holds $s hands in front of $N's broken right leg and heals it.", ch, NULL, victim, TO_CANSEE); 
      act(AT_WHITE, "$n holds $s hands in front of your broken right leg and heals it.", ch, NULL, victim, TO_VICT);
      if (ch == victim)
         act(AT_WHITE, "You hold you hands in front of your broken right leg and heal it.", ch, NULL, victim, TO_CHAR);
      else  
         act(AT_WHITE, "You hold you hands in front of $N's broken right leg and heal it.", ch, NULL, victim, TO_CHAR);
      return rNONE;
   }
   if (victim->con_lleg < 0)
   {
      victim->con_lleg = 1+ ((mastery-1) * 50) + ((points-1) * 3);
      if (ch == victim)
         act(AT_WHITE, "$n holds $s hands in front of $S broken left leg and heals it.", ch, NULL, victim, TO_CANSEE);
      else
         act(AT_WHITE, "$n holds $s hands in front of $N's broken left leg and heals it.", ch, NULL, victim, TO_CANSEE); 
      act(AT_WHITE, "$n holds $s hands in front of your broken left leg and heals it.", ch, NULL, victim, TO_VICT);
      if (ch == victim)
         act(AT_WHITE, "You hold you hands in front of your broken left leg and heal it.", ch, NULL, victim, TO_CHAR);
      else  
         act(AT_WHITE, "You hold you hands in front of $N's broken left leg and heal it.", ch, NULL, victim, TO_CHAR);
      return rNONE;
   }
   send_to_char("There are no limbs to restore on your target.\n\r", ch);
   return rSPELL_FAILED;
}

ch_ret spell_revitalize_limb(int sn, int level, CHAR_DATA * ch, void *vo)
{
   sh_int points;
   sh_int mastery;
   sh_int isobj = 0;
   CHAR_DATA *victim = (CHAR_DATA *) vo;

   if (level >= 999)
   {
      isobj = 1;
   }
   points = GET_POINTS(ch, sn, isobj, level);
   mastery = GET_MASTERY(ch, sn, isobj, level);

   if (!victim)
   {
      send_to_char("That target is not here!\n\r", ch);
      return rSPELL_FAILED;
   }
   
   if (victim->con_rarm > -1 && victim->con_rarm < 1000)
   {
      victim->con_rarm = UMIN(1000, victim->con_rarm + 50+ ((mastery-1) * 80) + ((points-1) * 10));
      if (ch == victim)
         act(AT_WHITE, "$n holds $s hands in front of $S injured right arm and heals it.", ch, NULL, victim, TO_CANSEE);
      else
         act(AT_WHITE, "$n holds $s hands in front of $N's injured right arm and heals it.", ch, NULL, victim, TO_CANSEE); 
      act(AT_WHITE, "$n holds $s hands in front of your injured right arm and heals it.", ch, NULL, victim, TO_VICT);
      if (ch == victim)
         act(AT_WHITE, "You hold you hands in front of your injured right arm and heal it.", ch, NULL, victim, TO_CHAR);
      else  
         act(AT_WHITE, "You hold you hands in front of $N's injured right arm and heal it.", ch, NULL, victim, TO_CHAR);
      return rNONE;
   }
   if (victim->con_larm > -1 && victim->con_larm < 1000)
   {
      victim->con_larm = UMIN(1000, victim->con_larm + 50+ ((mastery-1) * 80) + ((points-1) * 10));
      if (ch == victim)
         act(AT_WHITE, "$n holds $s hands in front of $S injured left arm and heals it.", ch, NULL, victim, TO_CANSEE);
      else
         act(AT_WHITE, "$n holds $s hands in front of $N's injured left arm and heals it.", ch, NULL, victim, TO_CANSEE); 
      act(AT_WHITE, "$n holds $s hands in front of your injured left arm and heals it.", ch, NULL, victim, TO_VICT);
      if (ch == victim)
         act(AT_WHITE, "You hold you hands in front of your injured left arm and heal it.", ch, NULL, victim, TO_CHAR);
      else  
         act(AT_WHITE, "You hold you hands in front of $N's injured left arm and heal it.", ch, NULL, victim, TO_CHAR);
      return rNONE;
   }
   if (victim->con_rleg > -1 && victim->con_rleg < 1000)
   {
      victim->con_rleg = UMIN(1000, victim->con_rleg + 50+ ((mastery-1) * 80) + ((points-1) * 10));
      if (ch == victim)
         act(AT_WHITE, "$n holds $s hands in front of $S injured right leg and heals it.", ch, NULL, victim, TO_CANSEE);
      else
         act(AT_WHITE, "$n holds $s hands in front of $N's injured right leg and heals it.", ch, NULL, victim, TO_CANSEE); 
      act(AT_WHITE, "$n holds $s hands in front of your injured right leg and heals it.", ch, NULL, victim, TO_VICT);
      if (ch == victim)
         act(AT_WHITE, "You hold you hands in front of your injured right leg and heal it.", ch, NULL, victim, TO_CHAR);
      else  
         act(AT_WHITE, "You hold you hands in front of $N's injured right leg and heal it.", ch, NULL, victim, TO_CHAR);
      return rNONE;
   }
   if (victim->con_lleg > -1 && victim->con_lleg < 1000)
   {
      victim->con_lleg = UMIN(1000, victim->con_lleg + 50+ ((mastery-1) * 80) + ((points-1) * 10));
      if (ch == victim)
         act(AT_WHITE, "$n holds $s hands in front of $S injured left leg and heals it.", ch, NULL, victim, TO_CANSEE);
      else
         act(AT_WHITE, "$n holds $s hands in front of $N's injured left leg and heals it.", ch, NULL, victim, TO_CANSEE); 
      act(AT_WHITE, "$n holds $s hands in front of your injured left leg and heals it.", ch, NULL, victim, TO_VICT);
      if (ch == victim)
         act(AT_WHITE, "You hold you hands in front of your injured left leg and heal it.", ch, NULL, victim, TO_CHAR);
      else  
         act(AT_WHITE, "You hold you hands in front of $N's injured left leg and heal it.", ch, NULL, victim, TO_CHAR);
      return rNONE;
   }
   send_to_char("There are no limbs to revitalize on your target.\n\r", ch);
   return rSPELL_FAILED;
}

ch_ret spell_cause_light(int sn, int level, CHAR_DATA * ch, void *vo)
{
   sh_int points;
   sh_int mastery;
   sh_int isobj = 0;

   if (level >= 999)
   {
      isobj = 1;
   }
   points = GET_POINTS(ch, sn, isobj, level);
   mastery = GET_MASTERY(ch, sn, isobj, level);
   return damage(ch, (CHAR_DATA *) vo, UMAX(1, points-1), sn, 0, -1);
}



ch_ret spell_cause_critical(int sn, int level, CHAR_DATA * ch, void *vo)
{
   sh_int points;
   sh_int mastery;
   sh_int isobj = 0;

   if (level >= 999)
   {
      isobj = 1;
   }
   points = GET_POINTS(ch, sn, isobj, level);
   mastery = GET_MASTERY(ch, sn, isobj, level);
   return damage(ch, (CHAR_DATA *) vo, UMAX(5, POINT_LEVEL(points, mastery)/2+2), sn, 0, -1);
}



ch_ret spell_cause_serious(int sn, int level, CHAR_DATA * ch, void *vo)
{
   sh_int points;
   sh_int mastery;
   sh_int isobj = 0;

   if (level >= 999)
   {
      isobj = 1;
   }
   points = GET_POINTS(ch, sn, isobj, level);
   mastery = GET_MASTERY(ch, sn, isobj, level);
   return damage(ch, (CHAR_DATA *) vo, UMAX(2, POINT_LEVEL(points, mastery)/2-5), sn, 0, -1);
}

ch_ret spell_charm_person(int sn, int level, CHAR_DATA * ch, void *vo)
{
   CHAR_DATA *victim = (CHAR_DATA *) vo;
   AFFECT_DATA af;
   int chance;
   char buf[MSL];
   SKILLTYPE *skill = get_skilltype(sn);
   sh_int points;
   sh_int mastery;
   sh_int isobj = 0;

   if (level >= 999)
   {
      isobj = 1;
   }
   points = GET_POINTS(ch, sn, isobj, level);
   mastery = GET_MASTERY(ch, sn, isobj, level);

   level = POINT_LEVEL(points, mastery)/2;

   if (victim == ch)
   {
      send_to_char("You like yourself even better!\n\r", ch);
      return rSPELL_FAILED;
   }

   if (is_immune(victim, -1, RIS_MAGIC) || is_immune(victim, -1, RIS_CHARM))
   {
      immune_casting(skill, ch, victim, NULL);
      return rSPELL_FAILED;
   }

   if (!IS_NPC(victim) && !IS_NPC(ch))
   {
      send_to_char("I don't think so...\n\r", ch);
      send_to_char("You feel charmed...\n\r", victim);
      return rSPELL_FAILED;
   }
   chance = ris_save(victim, level, RIS_CHARM);
   level = level-45;

   if (IS_AFFECTED(victim, AFF_CHARM)
      || chance == 1000 || IS_AFFECTED(ch, AFF_CHARM) || circle_follow(victim, ch) || saves_spell_staff(chance, victim))
   {
      failed_casting(skill, ch, victim, NULL);
      return rSPELL_FAILED;
   }
   if (victim->max_hit > ch->max_hit*2)
   {
      failed_casting(skill, ch, victim, NULL);
 

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

Site Stats

Snippets: 1791
Codebases: 571