skill.c

./mudd/src/skill.c · 34.4 KB

From the archive emlen.tar.gz

Download the archive   « Back to the archive contents

#include <sys/types.h>
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include "mud.h"

static bool used_spell[SKILL_COUNT];
static bool vert_line[100];
static int prereqs_known[3];


int 
leftover_slots (CHAR_DATA *ch, int slotnum)
{
  if (IS_MOB(ch))
    return 0;
  return total_slots (ch, slotnum) - tally_spsk (ch, slotnum);
}

int 
total_slots (CHAR_DATA *ch, int slotnum)
{
  if (IS_MOB(ch))
    return 100;
  return race_info[ch->pcdata->race].max_slots[slotnum] +
    align_info[ch->pcdata->alignment].max_slots[slotnum] +
    (slotnum == 1 ? ch->pcdata->remort_times : 
     (ch->pcdata->remort_times +1)/2);
}


void 
do_new_prereq (CHAR_DATA *ch, char *argy)
{
  SPELL_DATA *spell;
  char buff[200];
  char buf[100];
  char bf[100];
  int slots_left_now[3], diff[3];
  int i;
  DEFINE_COMMAND ("zprerequisite", do_new_prereq, POSITION_DEAD, 0, LOG_NORMAL, "Allows you to see prerequisites to the skill-big tree format.")
    
    if (IS_MOB (ch))
      return;
  for (i = 0; i < 3; i++)
    {
      prereqs_known[i] = 0;
      slots_left_now[i] = leftover_slots(ch, i);
      diff[i] = 0;
    }

  
  bf[0] = '\0';
  buf[0] = '\0';
  buff[0] = '\0';
  hugebuf_o[0] = '\0';
  for (i = 0; i < 100; i++)
    vert_line[i] = FALSE;
  for (i = 0; i < SKILL_COUNT; i++)
    used_spell[i] = FALSE;
  
  
  if (argy[0] == '\0' || (spell = skill_lookup (argy, -1)) == NULL)
    {
      send_to_char ("Syntax: Prereq <skill/spell/prof name>\n\r", ch);
      return;
    }
  if IS_SET(ch->pcdata->act2, PLR_ASCII)
  {
  sprintf (hugebuf_o, "\n\r\x1B[1;30mÄÄÄÄÄÄ\x1B[0;31mÄÄÄÄÄÄÄÄÄÄÄÄÄ\x1B[1;31mÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ\x1B[0;31mÄÄÄÄÄÄÄÄÄÄÄÄÄ\x1B[1;30mÄÄÄÄÄÄ\x1B[0;37m\n\r");
  send_to_char(buf, ch);
  }
  else
  {
  sprintf (hugebuf_o, "\n\r\x1B[1;30m------\x1B[0;31m-------------\x1B[1;31m-----------------------------------------\x1B[0;31m-------------\x1B[1;30m------\x1B[0;37m\n\r");
  send_to_char (buf, ch);
  }
  xprereq(ch, spell);
  if IS_SET(ch->pcdata->act2, PLR_ASCII)
  {
  strcat (hugebuf_o, "\x1B[1;30mÄ-Ä-Ä-Ä-Ä-Ä-Ä-Ä-Ä-Ä-Ä-Ä-Ä-Ä-Ä-Ä-Ä-Ä-Ä-Ä-Ä-Ä-Ä-Ä-Ä-Ä-Ä-Ä-Ä-Ä-Ä-Ä-Ä-Ä-Ä-Ä-Ä-Ä-Ä-Ä\x1B[0;37m\n\r");
  send_to_char(buf, ch);
  }
  else
  {
  strcat (hugebuf_o, "\x1B[1;30m- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -\x1B[0;37m\n\r");
  send_to_char (buf, ch);
  }

  for (i = 0; i < 3; i ++)
    {
      diff[i] = (slots_left_now[i]+prereqs_known[i] -spell->num_prereqs[i]);
    }

  strcat (hugebuf_o, "\x1b[1;32m[      \x1b[0;32mInfos      \x1b[1;32m][      \x1b[0;32mSkills       \x1b[1;32m][      \x1b[0;32mSpells      \x1b[1;32m][  \x1b[0;32mProficiencies  \x1b[1;32m]\x1b[0;37m\n\r");

  sprintf(buff, "Total             :        \x1b[0;32m%3d                  %3d                 %3d\x1b[0;37m\n\r"  , spell->num_prereqs[0], spell->num_prereqs[1], spell->num_prereqs[2]);
  strcat (hugebuf_o, buff);
  sprintf(buff, "Total Known       :        \x1b[0;32m%3d                  %3d                 %3d\x1b[0;37m\n\r", prereqs_known[0], prereqs_known[1], prereqs_known[2]);
  strcat (hugebuf_o, buff);
  sprintf(buff, "Total Needed      :        \x1b[0;32m%3d                  %3d                 %3d\x1b[0;37m\n\r", (spell->num_prereqs[0] -prereqs_known[0]), (spell->num_prereqs[1] - prereqs_known[1]), (spell->num_prereqs[2] - prereqs_known[2]));
  strcat (hugebuf_o, buff);
  sprintf(buff, "Slots you have    :        \x1b[0;32m%3d                  %3d                 %3d\x1b[0;37m\n\r", slots_left_now[0], slots_left_now[1], slots_left_now[2]);
  strcat (hugebuf_o, buff);
  sprintf(buff, "The difference    :        \x1b[0;32m%3d                  %3d                 %3d\x1b[0;37m\n\r" , diff[0], diff[1], diff[2]);
  strcat (hugebuf_o, buff);

  if IS_SET(ch->pcdata->act2, PLR_ASCII)
  {
  strcat (hugebuf_o, "\x1B[1;30mÄÄÄÄÄÄ\x1B[0;31mÄÄÄÄÄÄÄÄÄÄÄÄÄ\x1B[1;31mÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ\x1B[0;31mÄÄÄÄÄÄÄÄÄÄÄÄÄ\x1B[1;30mÄÄÄÄÄÄ\x1B[0;37m\n\r");
  send_to_char(buf, ch);
  }
  else
  {
  strcat (hugebuf_o, "\x1B[1;30m------\x1B[0;31m-------------\x1B[1;31m-----------------------------------------\x1B[0;31m-------------\x1B[1;30m------\x1B[0;37m\n\r");
  send_to_char (buf, ch);
  }
  page_to_char(hugebuf_o, ch);
  return;
}

void 
xprereq (CHAR_DATA *ch, SPELL_DATA *spell)
{
  static int deppy = 0;
  int jj;
  int pad = 0;
  int len = 3*deppy+3;
  char bf[200];
  char buf[STD_LENGTH];
  char buff[200];
  char temp[20];
  if (used_spell[spell->gsn] == TRUE)
    return;
  if (ch->pcdata->learned[spell->gsn] >= pow.prereq)  
    prereqs_known[spell->slot]++;
  

  sprintf(buf, " ");
  if(deppy > 0)
    {
      for (jj = 0; jj < deppy; jj++)
        {
	  if (!vert_line[jj])
            strcat(buf, "   ");
	  else
            strcat(buf, "|  ");
	}
    }                                                     
  strcat(buf, "\\__");
  strcat(buf, "\x1b[0;32m");
  strcat(buf, spell->spell_name);
  len += strlen(spell->spell_name);
  strcat(buf, "\x1b[1;30m");
  sprintf(temp, "%d%d%d", spell->num_prereqs[0], spell->num_prereqs[1], spell->num_prereqs[2]);
  pad = 55 + (11 - strlen (how_good(ch, spell->gsn))) + (6 - strlen (temp)) - len;

  if (pad > 0)
    {
      for (jj = 0; jj < pad; jj++)
	{
	  strcat(buf, ".");
	}
    }
  else
    {
      sprintf(bf, "%d\n\r", pad);
      send_to_char(bf, ch);
    }
  sprintf(buff, " \x1b[0;37m%s \x1b[1;32m(\x1b[0;32m%d\x1b[0;37m/\x1b[0;32m%d\x1b[0;37m/\x1b[0;32m%d\x1b[1;32m)\x1b[0;37m\n\r", how_good(ch,spell->gsn), spell->num_prereqs[0], spell->num_prereqs[1], spell->num_prereqs[2]);
  strcat(buf, buff);
  strcat (hugebuf_o, buf);
  deppy++;
  used_spell[spell->gsn] = TRUE;
  vert_line[deppy] = FALSE;
  if (spell->pre1 != NULL && spell->pre2 != NULL && !used_spell[spell->pre1->gsn] && !used_spell[spell->pre2->gsn])
    {
      vert_line[deppy] = spell->go_to_second;
    }
  if (spell->pre1 != NULL )
    xprereq(ch, spell->pre1);
  vert_line[deppy] = FALSE;
  if (spell->pre2 != NULL)
    xprereq(ch, spell->pre2);
  deppy--;
  return;
}

bool
check_prereq_depth(SPELL_DATA *spell, SPELL_DATA *prereq)
{
  static int depthy = 0;
  if (depthy > 13) return TRUE;
  if (prereq == spell->pre1 || (prereq == spell->pre2 && depthy > 0))
    return FALSE;
  depthy++;
  if (spell->pre1 != NULL && !check_prereq_depth(spell->pre1, prereq))
    {
      depthy--;
      return FALSE;
    }
  if (spell->pre2 != NULL && !check_prereq_depth(spell->pre2, prereq))
    {
      depthy--;
      return FALSE;
    }
  depthy--;
  return TRUE;
}

char *
how_good (CHAR_DATA *ch, int gsn)
{
  static char bf[256];
  int i;
  int learned = 0;
  SPELL_DATA *spl;
  bf[0] = '\0';
  if (IS_MOB(ch)) 
    {
      strcpy (bf, "No Mobs Plz");
      return bf;
    }
  if ((spl = skill_lookup(NULL, gsn)) == NULL)
    {
      strcpy (bf, "No spell!");
      return (bf);
    }
  else
    {
      learned = ch->pcdata->learned[gsn];
      if (learned == 0)
        {
          strcpy(bf, "(unlearned)");
          return(bf);
        }
      for (i = 0; i < 20; i++)
	{
	  if (pow.learned[i] != NULL && learned >= pow.low_range[i] && learned <= pow.high_range[i])
	    {
	      
	      strcpy (bf, pow.learned[i]);
	      return (bf);
	    }
	}
    }
  return bf;
}


void 
do_learn (CHAR_DATA * ch, char *argy)
{
  char buf[STD_LENGTH];
  int sn;
  int skl, spl, prf, i;
  SPELL_DATA *spell;
  int cntt = 0;
  CHAR_DATA *mob;
  DEFINE_COMMAND ("learn", do_learn, POSITION_STANDING, 0, LOG_NORMAL, "This command allows you to learn a skill or spell.  You must be at a practitioner.")

  if (IS_MOB (ch))
    return;
  
  if (!IS_AWAKE (ch))
    {
      send_to_char ("In your dreams, or what?\n\r", ch);
      return;
    }
  
  for (mob = ch->in_room->people; mob != NULL; mob = mob->next_in_room)
    {
      if (IS_MOB (mob) && IS_SET (mob->act, ACT_PRACTICE) && mob->pIndexData->opt)
	break;
    }
  
  if (mob == NULL || !IS_SET (mob->act, ACT_PRACTICE) || IS_PLAYER (mob))
    {
      send_to_char ("You can't learn anything here!\n\r", ch);
      return;
    }
  
  skl = tally_spsk (ch, 0);
  spl = tally_spsk (ch, 1);
  prf = tally_spsk (ch, 2);
  
  if (mob != NULL && (IS_MOB (mob)) && argy[0] == '\0')
    {
      int col;
      send_to_char ("\x1B[1;37m        You may learn these skills (that you do not already know):\x1B[37;0m\n\r", ch);
      send_to_char ("\x1B[1;34m---------------------------------------------------------------------------\x1B[37;0m\n\r", ch);
      col = 0;
      for (sn = 0; sn < 8; sn++)
	{
	  if (mob->pIndexData->opt->skltaught[sn] != 0 &&
	      ch->pcdata->learned[mob->pIndexData->opt->skltaught[sn]] == 0 &&
	      (spell = skill_lookup (NULL, mob->pIndexData->opt->skltaught[sn])) != NULL &&LEVEL (ch) >= spell->spell_level)
	    {
	      
              sprintf (buf, "[Level \x1B[1;37m%-2d\x1B[0;37m]\x1b[1;30m (\x1b[1;31m%2s\x1b[0;31m)\x1B[1;34m%18s\x1B[37;0m     ", spell->spell_level,(spell->slot == 0 ? "Sk" : (spell->slot == 1 ? "Sp" : "Pr")),(spell->spell_name));
	      send_to_char (buf, ch);
	      if (++col % 2 == 0)
		send_to_char ("\n\r", ch);
	    }
	}
      sprintf (buf, "\n\r\n\rYou have \x1B[1;37m%d\x1B[37;0m learning sessions left.\n\rYou may learn \x1B[1;33m%d\x1B[37;0m more skills,\x1B[1;33m%d\x1B[37;0m more proficiencies and \x1B[1;33m%d\x1B[37;0m more spells.\n\r",
	       ch->pcdata->learn, 
	       (total_slots (ch, 0) - skl),
	       (total_slots (ch, 1) - spl),
	       (total_slots (ch, 2) - prf));
	   
      send_to_char (buf, ch);
      return;
    }
  
  if (ch->pcdata->learn <= 0)
    {
      send_to_char ("You have no learning sessions left.\n\r", ch);
      return;
    }
  
  if ((spell = skill_lookup (argy, -1)) == NULL
      || IS_MOB (ch))
    {
      send_to_char ("I know nothing about that.\n\r", ch);
      return;
    }
  
  if (spell->slot == 0 && skl >= total_slots (ch, 0))
    {
      send_to_char ("You have already learned the maximum skills for your race.\n\r", ch);
      return;
    }

  if (spell->slot == 2 && prf >= total_slots (ch, 2))
    {
      send_to_char ("You have already learned the maximum proficiencies for your race.\n\r", ch);
      return;
    } 
  
  if (spell->slot == 1 && spl >= total_slots (ch, 1))
    {
      send_to_char ("You have already learned the maximum spells for your race.\n\r", ch);
      return;
    }

  if (mob == NULL || IS_PLAYER (mob))
    return;

  while (cntt <= 8)
    {
      if (spell->gsn == mob->pIndexData->opt->skltaught[cntt])
	{
	  cntt = 50;
	  break;
	}
      cntt++;
    }
  
  if (cntt != 50)
    {
      send_to_char ("I have no knowledge of that to teach you.\n\r", ch);
      return;
    }
  
  if (LEVEL (ch) < spell->spell_level)
    { 
      send_to_char ("I know nothing about that.\n\r", ch);
      return;
    }

  if (IS_PLAYER (ch))
    {
      SPELL_DATA *spl;
      if (spell->prereq_1 != NULL && (spl = skill_lookup(spell->prereq_1, -1)) != NULL && ch->pcdata->learned[spl->gsn] < pow.prereq)
	{
	  sprintf (buf, "You need to be skilled in %s first.\n\r", spl->spell_name);
	  send_to_char (buf, ch);
	  return;
	}
      if (spell->prereq_2 != NULL && (spl = skill_lookup(spell->prereq_2, -1)) != NULL && ch->pcdata->learned[spl->gsn] < pow.prereq)
	{
	  sprintf (buf, "You need to be skilled in %s first.\n\r", spl->spell_name);
	  send_to_char (buf, ch);
	  return;
	}
    }
  
  if (ch->pcdata->learned[spell->gsn] != 0)
    {
      sprintf (buf, "You already know %s.\n\r",
	       spell->spell_name);
      send_to_char (buf, ch);
      return;
    }
  for (i = 0; i < NUM_GUILDS; i++)
    {
      if (spell->guilds[i] > ch->pcdata->guilds[i])
	{
	  send_to_char("You do not have the proper guilds to learn this!\n\r", ch);
	  return;
	}
    }

  ch->pcdata->learn--;
  ch->pcdata->learned[spell->gsn] = 1;
  act ("You learn $T.", ch, NULL, spell->spell_name, TO_CHAR);
  act( "$n learns $T.", ch, NULL,spell->spell_name,TO_ROOM);
  return;
}

void 
do_skill (CHAR_DATA * ch, char *argy)
{
  char buf[STD_LENGTH];
  char hg[300];
  SPELL_DATA *spell;
  int sn;
  int col;
  DEFINE_COMMAND ("skills", do_skill, POSITION_DEAD, 0, LOG_NORMAL, "This command shows you what skills you know, if any.")

    if (IS_MOB (ch))
      return;
  hugebuf_o[0] = '\0';
  send_to_char ("\x1B[1;37mYou have knowledge in the following skills:\x1B[37;0m\n\r", ch);
  send_to_char ("\x1B[1;34m-------------------------------------------\x1B[37;0m\n\r", ch);
  col = 0;

  for (sn = 0; sn < SKILL_COUNT; sn++)
    {
      spell = skill_lookup (NULL, sn);
      if (spell == NULL)
	continue;
      if ((LEVEL (ch) < spell->spell_level)
	  || (ch->pcdata->learned[sn] == 0) || spell->slot == 1)
	continue;
      strcpy (hg, how_good (ch, sn));
      if (LEVEL (ch) >= 100)
        sprintf (buf, "%s%22s %3d%%\x1b[0;37m ",(spell->slot == 2 ? "\x1b[1;36m" : ""), spell->spell_name, ch->pcdata->learned[sn]);
      else
	sprintf (buf, "%s%22s %10s",(spell->slot == 2 ? "\x1b[1;36m" : "\x1b[0;37m"), spell->spell_name, hg);
      strcat (hugebuf_o, buf);
      if (++col % 2 == 0)
	strcat (hugebuf_o, "\n\r");
    }

  if (col % 2 != 0)
    strcat (hugebuf_o, "\n\r");
  sprintf (buf, "\n\rYou have %d practice sessions left.\n\r",
	   ch->pcdata->practice);
  strcat (hugebuf_o, buf);
  page_to_char (hugebuf_o, ch);
  return;
}


void 
do_practice (CHAR_DATA * ch, char *argy)
{
  char buf[STD_LENGTH];
  char hg[500];
  bool found;
  int sn, i;
  int cnttt;
  SPELL_DATA *spell;
  CHAR_DATA *mob;
  int adept;
  DEFINE_COMMAND ("practice", do_practice, POSITION_STANDING, 0, LOG_NORMAL, "This command can be used to list all skills/spells you know, or, at a practitioner, can be used to practice a spell or skill.")
    hugebuf_o[0] = '\0';
  cnttt = 0;
  if (IS_MOB (ch))
    return;
  
  for (mob = ch->in_room->people; mob != NULL; mob = mob->next_in_room)
    {
      if (IS_MOB (mob) && IS_SET (mob->act, ACT_PRACTICE) && mob->pIndexData->opt)
	break;
    }
  
  if (mob != NULL && (!IS_SET (mob->act, ACT_PRACTICE) || IS_PLAYER (mob)))
    {
      if (argy[0] != '\0')
	{
	  send_to_char ("You cannot practice here!\n\r", ch);
	  return;
	}
    }
  if (mob == NULL && argy[0] == '\0')
    {
      int col;
      sprintf (hugebuf_o, "You have knowledge in the following:\n\r\n\r");
      sprintf (hugebuf_o,"\x1B[1;37mYou have knowledge in the following:\x1B[37;0m\n\r");
      sprintf (hugebuf_o+strlen(hugebuf_o),"\x1B[1;34m------------------------------------\x1B[37;0m\n\r");
      col = 0;
      
      for (sn = 0; sn < SKILL_COUNT; sn++)
	{
	  if ((spell = skill_lookup (NULL, sn)) == NULL)
	    continue;
	  if ((LEVEL (ch) < spell->spell_level)
	      || (ch->pcdata->learned[sn] < -1))
	    continue;
	  strcpy (hg, how_good (ch, sn));
	  if (LEVEL (ch) >= 100)
	    sprintf (buf, "%22s %3d%% ", spell->spell_name,
		     ch->pcdata->learned[sn]);
	  else
	    sprintf (buf, " %22s %10s", spell->spell_name, hg);
	  strcat (hugebuf_o, buf);
	  if (++col % 2 == 0)
	    strcat (hugebuf_o, "\n\r");
	}
      if (col % 2 != 0)
	strcat (hugebuf_o, "\n\r");
      sprintf (buf, "\n\rYou have %d practices and %d learns left.\x1B[0m\n\r",
	       ch->pcdata->practice, ch->pcdata->learn);
      strcat (hugebuf_o, buf);
      page_to_char (hugebuf_o, ch);
      return;
    }
  
  if (!IS_AWAKE (ch))
    {
      send_to_char ("In your dreams?  Good luck!\n\r", ch);
      return;
    }
  
  if (argy[0] == '\0')
    {
      int col;
      hugebuf_o[0] = '\0';
      send_to_char("\x1B[1;37mYou have knowledge in the following:\x1B[37;0m\n\r", ch);
      send_to_char("\x1B[1;34m------------------------------------\x1B[37;0m\n\r", ch);
      found = FALSE;
      col = 0;
      if (mob == NULL || IS_PLAYER (mob))
	return;
      
      for (sn = 0; sn <= 8; sn++)
	{
	  if (mob->pIndexData->opt->skltaught[sn] > 0 &&
	      (spell = skill_lookup (NULL, mob->pIndexData->opt->skltaught[sn])) != NULL)
	    {
	    
	      if (LEVEL (ch) >= spell->spell_level)
		{
		  char hg[300];
		  found = TRUE;
		  strcpy (hg, how_good (ch, spell->gsn));
		  sprintf (buf, " %22s %10s", spell->spell_name, hg);
		  strcat (hugebuf_o, buf);
		  if (++col % 2 == 0)
		    strcat (hugebuf_o, "\n\r");
		}
	    }
	}
      if (!found)
	strcat (hugebuf_o, "Nothing.\n\r");
      if (col % 2 != 0)
	strcat (hugebuf_o, "\n\r");
      sprintf (buf, "\n\rYou have %d practice sessions left.\n\r",
	       ch->pcdata->practice);
      strcat (hugebuf_o, buf);
      page_to_char (hugebuf_o, ch);
      return;
    }
  
  spell = skill_lookup (argy, -1);
  if (spell == NULL)
    {
      send_to_char ("What's that?\n\r", ch);
      return;
    }
  
  if (spell == NULL
      || (IS_PLAYER (ch)
	  && (LEVEL (ch) < spell->spell_level ||
	      ch->pcdata->learned[spell->gsn] == 0)))
    {
      if (spell->gsn > 0 && spell->gsn < SKILL_COUNT && ch->pcdata->learned[spell->gsn] == -100)
	{
	  do_learn (ch, argy);
	  if (ch->pcdata->learned[spell->gsn] == 0)
	    {
	      send_to_char ("For some reason or another, you could not LEARN this spell/skill.\n\r", ch);
	      send_to_char ("Perhaps you are out of learns?  Type 'learn' for more information.\n\r", ch);
	      return;
	    }
	  goto lerned_it;
	}
      
      send_to_char ("I have no knowledge in that area.\n\r", ch);
      return;
    }
lerned_it:
  if (mob == NULL)
    return;
  while (cnttt <= 10)
    {
      if (IS_MOB (mob) && mob->pIndexData->opt->skltaught[cnttt] == spell->gsn)
	{
	  cnttt = 50;
	  break;
	}
      cnttt++;
    }
  
  if (cnttt != 50)
    {
      send_to_char ("I have too little knowledge in that area to help you practice.\n\r", ch);
      return;
    }

  
  if (ch->pcdata->practice < 1)
    {
      send_to_char ("You have no practice sessions left!\n\r", ch);
      return;
    }

  if (spell->slot != 0)
    adept = pow.max_prac_spells;
  else
    adept = pow.max_prac_skills;
  {
    int jj;
    for (jj = 0; jj < NUM_STATS; jj++)
      {
	if (get_stat(ch, jj) < spell->min_stat[jj])
	  adept -= (spell->min_stat[jj] - get_stat(ch, jj))*6;
      }
  }
  
  if (IS_PLAYER (ch))
    {
      SPELL_DATA *spl;
      if (spell->prereq_1 != NULL && (spl = skill_lookup(spell->prereq_1, -1)) != NULL && ch->pcdata->learned[spl->gsn] < pow.prereq)
	{
	  sprintf (buf, "You need to be skilled in %s first.\n\r", spl->spell_name);
	  send_to_char (buf, ch);
	  return;
	}
      if (spell->prereq_2 != NULL && (spl = skill_lookup(spell->prereq_2, -1)) != NULL && ch->pcdata->learned[spl->gsn] < pow.prereq)
	{
	  sprintf (buf, "You need to be skilled in %s first.\n\r", spl->spell_name);
	  send_to_char (buf, ch);
	  return;
	}
    }
  
  if (ch->pcdata->learned[spell->gsn] >= adept)
    {
      sprintf (buf, "You are already quite good at %s.\n\r", spell->spell_name);
      send_to_char (buf, ch);
      return;
    }
  for (i = 0; i < NUM_GUILDS; i++)
    {
      if (spell->guilds[i] > ch->pcdata->guilds[i])
	{
	  send_to_char("You do not have the proper guilds to practice this!\n\r", ch);
	  return;
	}
    }
  
  ch->pcdata->practice--;
  if (spell->slot == 1)
    ch->pcdata->learned[spell->gsn] += int_app[get_curr_int (ch) - 1].learn;
  if (spell->slot != 1)
    ch->pcdata->learned[spell->gsn] += int_app[get_curr_int (ch) - 1].learn - 1;
  if (ch->pcdata->learned[spell->gsn] < adept)
    {
      act ("You practice $T.",
	   ch, NULL, spell->spell_name, TO_CHAR);
    }
  else
    {
      ch->pcdata->learned[spell->gsn] = adept;
      act ("You now have a good understanding of $T.",
	   ch, NULL, spell->spell_name, TO_CHAR);
      if (spell->gsn > 549 && IS_PLAYER(ch) && !str_cmp(race_info[ch->pcdata->race].name, "orc") && adept == pow.max_prac_skills)
	ch->pcdata->learned[spell->gsn]+= 15;
    }
  return;
}

void 
do_prereqs (CHAR_DATA * ch, char *argy)
{
  char buf[STD_LENGTH];
  SPELL_DATA *spell;
  DEFINE_COMMAND ("prereqs", do_prereqs, POSITION_DEAD, 0, LOG_NORMAL, "Allows you to see prerequisites to the specified skill or spell.")

    if (IS_MOB (ch))
    return;
  if (argy[0] == '\0' || (spell = skill_lookup (argy, -1)) == NULL)
    {
      send_to_char (
		     "Syntax: Prereq <skill/spell/prof name>\n\r", ch);
      return;
    }

  if (spell->prereq_1 != NULL && spell->prereq_2 != NULL)
    {
      sprintf (buf,
	       "\x1B[1m%s\x1B[0m has two prerequisites: \x1B[1;36m%s\x1B[37;0m and \x1B[1;36m%s\x1B[37;0m.\n\r",
	       spell->spell_name, spell->prereq_1, spell->prereq_2);
      send_to_char (buf, ch);
      return;
    }

  if (spell->prereq_1 != NULL)
    {
      sprintf (buf,
      "\x1B[1m%s\x1B[0m has only one prerequisite: \x1B[1;36m%s\x1B[0m.\n\r",
	       spell->spell_name, spell->prereq_1);
      send_to_char (buf, ch);
      return;
    }

  sprintf (buf,
	   "\x1B[1m%s\x1B[0m has no prerequisites whatsoever.\n\r",
	   spell->spell_name);
  send_to_char (buf, ch);
  return;
}



void 
do_spells (CHAR_DATA * ch, char *argy)
{
  char buf[STD_LENGTH];
  char bbb[50];
  char hg[300];
  SPELL_DATA *spell;
  bool fnd = FALSE;
  int sn;
  int col;
  DEFINE_COMMAND ("spells", do_spells, POSITION_DEAD, 0, LOG_NORMAL, "This command shows you all the spells you currently know.")
    hugebuf_o[0] = '\0';
  if (IS_MOB (ch))
    {
      send_to_char ("You do not know how to cast spells!\n\r", ch);
      return;
    }

  hugebuf_o[0] = '\0';
  col = 0;
  for (sn = 0; sn < SKILL_COUNT; sn++)
    {
      if ((spell = skill_lookup (NULL, sn)) == NULL)
	continue;
      if ((LEVEL (ch) < spell->spell_level)
	  || (spell->spell_level > 80))
	continue;
      if (spell->slot != 1)
	continue;
      if (ch->pcdata->learned[sn] == 0)
	continue;
      fnd = TRUE;
     
      {
	bool found = FALSE;
	int i;
	for (i = 0; str_cmp(mana_data[i].what_you_type, "end_of_list") && !found; i ++)
	  {
	    if (spell->mana_type == mana_data[i].flagname)
	      {
		char buf[50];
                sprintf (buf, "%s%s\x1b[0;37m", mana_data[i].color, mana_data[i].letter);
		strcpy(bbb, buf);
		found = TRUE;
	      }
	  }
	if (!found)
	  strcpy(bbb, " ");
      }
      
      strcpy (hg, how_good (ch, sn));
      if (LEVEL (ch) >= 100)
	sprintf (buf, "%s %3dM (%3d) %-20s ",
	    bbb, ((2 + LEVEL (ch) - spell->spell_level == 0) ? spell->mana :
		  (UMAX (spell->mana,
			 100 / (2 + LEVEL (ch) - spell->spell_level)))),
		 ch->pcdata->learned[sn], spell->spell_name);
      else
	sprintf (buf, "%s %3dM %10s %-20s ",
	    bbb, ((2 + LEVEL (ch) - spell->spell_level == 0) ? spell->mana :
	 (UMAX (spell->mana, 100 / (2 + LEVEL (ch) - spell->spell_level)))),
		 hg, spell->spell_name);
      strcat (hugebuf_o, buf);
      if (++col % 2 == 0)
	strcat (hugebuf_o, "\n\r");
    }

  if (col % 2 != 0)
    strcat (hugebuf_o, "\n\r");
  if (!fnd)
    strcpy (hugebuf_o, "You know no spells at the moment.\n\r");
  page_to_char (hugebuf_o, ch);
  return;
}

void 
do_info_sp_sk (CHAR_DATA * ch, SPELL_DATA * spell)
{
char buffy[500];
char hg[300];
bool prereq = FALSE;
bool found_mana = FALSE;
bool stat_needed = FALSE;
bool guild_needed = FALSE;
bool prev = FALSE;
int i;
if (IS_MOB (ch))
  {
    send_to_char ("NPC's cannot do this!\n\r", ch);
    return;
  }

if (spell == NULL)
  {
    send_to_char ("Does not exist.\n\r", ch);
    return;
  }
sprintf(buffy,"\x1b[0;35m-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-\x1b[0;37m\n\r");
send_to_char(buffy, ch);
sprintf(buffy, "\x1b[1;30mLevel \x1b[1;34m%2d\x1b[0;37m:\n\r",spell->spell_level);
send_to_char(buffy, ch);
sprintf(buffy, "\x1b[1;36m%s   ", capitalize(spell->spell_name));
send_to_char(buffy, ch);
if (spell->slot == 0)
  {
    sprintf(buffy, "    \x1b[1;30m(\x1b[1;36mSkill\x1b[1;30m)\n\r");
    send_to_char(buffy, ch);
  }
else if (spell->slot == 2)
  {
    sprintf(buffy, "    \x1b[1;30m(\x1b[1;36mProficiency\x1b[1;30m)\n\r");
    send_to_char(buffy, ch);
  }
else
  { 
    sprintf(buffy, "\x1b[1;30m(");
    send_to_char(buffy, ch);
    if (spell->spell_type == TAR_CHAR_OFFENSIVE)
      send_to_char("\x1b[1;36mOffensive ", ch);
    else if (spell->spell_type == TAR_CHAR_DEFENSIVE)
      send_to_char("\x1b[1;36mDefensive ", ch);
    else if (spell->spell_type == TAR_CHAR_SELF)
      send_to_char("\x1b[1;36mSelf Only ", ch);
    else
      send_to_char("\x1b[1;36mSpecial ", ch);
    send_to_char("Spell\x1b[1;30m)\n\r", ch);
    sprintf(buffy, "\x1b[0;32m{\x1b[1;37m%d\x1b[0;32m} ",spell->mana);
    send_to_char(buffy, ch);
    {
      int i;
      for (i = 0; str_cmp(mana_data[i].what_you_type, "end_of_list") && !found_mana; i ++)
	{
	  if (spell->mana_type == mana_data[i].flagname)
	    {
	      sprintf(buffy, "%s%s\x1b[0;37m", mana_data[i].color, mana_data[i].what_you_type);
	      found_mana = TRUE;
	      
	    }
	}
    }
    if (!found_mana)
      sprintf(buffy, "Unknown");
    send_to_char (buffy, ch);
    send_to_char("\x1b[0;32m mana is required to cast this spell.\x1b[0;37m\n\r", ch);
  }  
send_to_char("\x1b[1;30mPrerequisites\x1b[0;37m:  ", ch);
if (spell->prereq_1 && str_cmp(spell->prereq_1, "none") &&str_cmp(spell->prereq_1, "None"))
  {
    sprintf (buffy, "\x1b[0;36m%s", spell->prereq_1);
    send_to_char(buffy, ch); 
    prereq = TRUE;
  }
if (spell->prereq_2 && str_cmp(spell->prereq_2, "none") &&str_cmp(spell->prereq_2,"None"))
  {
    if (prereq)
      send_to_char(", ", ch);
    sprintf (buffy, "\x1b[0;36m%s", spell->prereq_2);
    send_to_char(buffy, ch);
    prereq = TRUE;
  }
if (!prereq)
  send_to_char("\x1b[0;36mNone", ch);
send_to_char(".\n\r",ch);  



if (spell->slot == 0)
  {
    strcpy (hg, how_good (ch, spell->gsn));
    sprintf (buffy, "Your proficiency in this skill is \x1B[1;37m%s\x1B[0m.\n\r", hg);
  }
else if (spell->slot == 2)
    {
    strcpy (hg, how_good (ch, spell->gsn));
    sprintf (buffy, "Your ability in this proficiency is \x1B[1;37m%s\x1B[0m.\n\r", hg);
  }
else if (spell->slot == 1)
  {
    strcpy (hg, how_good (ch, spell->gsn));
    sprintf (buffy, "Your proficiency in this spell is \x1B[1;37m%s\x1B[0;37m.\n\n\r", hg);
  }
send_to_char(buffy, ch);


for (i = 0; i < NUM_STATS; i++)
  {
    if (spell->min_stat[i] > 0)
      {
	stat_needed = TRUE;
	break;
      }
  }
if (stat_needed)
  {
    prev = FALSE;
    sprintf(buffy, "Minimum stats needed to practice fully:");
    for (i = 0; i < NUM_STATS; i++)
      {
	if (spell->min_stat[i] > 0)
	  {
	    if (prev)
	      strcat(buffy, ",");
	    else
	      prev = TRUE;
	    sprintf (buffy + strlen(buffy), " M%s: %d", stat_short_name[i], spell->min_stat[i]);
	  }
      }
    strcat(buffy, ".\n\r");
    send_to_char(buffy, ch);
  }

if (spell->slot == 1)
  {
    if (spell->spell_type == TAR_CHAR_OFFENSIVE)
      {
	sprintf(buffy, "This spell requires a minimum of \x1b[1;34m%d\x1b[0;37m intelligence to cast effectively.\n\r", (17 + (spell->spell_level)/6));
	send_to_char(buffy, ch);
      }
    else 
      if (IS_SET(spell->spell_bits, SPELL_HEALS_DAM) || IS_SET(spell->spell_bits, SPELL_ADD_MOVE))
	{
	  sprintf(buffy, "This spell requires a minimum of \x1b[1;34m%d\x1b[0;37m wisdom to cast effectively.\n\r", (10+(spell->spell_level)*2/7));
	  send_to_char(buffy, ch);  
	}
  }
for (i = 0; i < NUM_GUILDS; i++)
  {
    if (spell->guilds[i] > 0)
      {
	guild_needed = TRUE;
	break;
      }
  }
if (guild_needed)
  {
    prev = FALSE;
    sprintf(buffy, "Guild(s) required to practice this:");
    for (i = 0; i < NUM_GUILDS; i++)
      {
	if (spell->guilds[i] > 0)
	  {
	    if (prev)
	      strcat(buffy, ",");
	    else
	      prev = TRUE;
	    sprintf (buffy + strlen(buffy), " Tier %d %s", spell->guilds[i], guild_data[i].what_you_see);
	  }
      }
    strcat(buffy, ".\n\r");
    send_to_char(buffy, ch);
  }

send_to_char ("\n\rExtra Enhancements:\n\n\r", ch);

if (spell->slot == 1 && spell->spell_level >= 20 && (spell->spell_type == TAR_CHAR_OFFENSIVE || spell->spell_type == TAR_CHAR_DEFENSIVE))
  {
    send_to_char ("\x1b[1;31mA spell must be level 20 or greater to be area or range cast.\x1b[0;37m\n\r", ch);
    sprintf (buffy, "Area        Level \x1b[1;35m%3d\x1b[0;37m, \x1b[1;33m%3d\x1b[0;37m mana, 2x time, 2/3 damage.\n\r", (spell->spell_level * 5/4), (spell->mana * 8/5));
    send_to_char (buffy, ch);
    sprintf (buffy, "Ranged      Level \x1b[1;35m%3d\x1b[0;37m, \x1b[1;33m%3d\x1b[0;37m mana, 3x time, 1/2 damage.\n\r", (spell->spell_level * 5/4), (spell->mana * 8/5));
    send_to_char (buffy, ch);
    sprintf (buffy, "Ranged&Area Level \x1b[1;35m%3d\x1b[0;37m, \x1b[1;33m%3d\x1b[0;37m mana, 4x time, 1/3 damage.\n\r",
	     (spell->spell_level * 3/2), (spell->mana * 11/5));
    send_to_char (buffy, ch);
  }
if (spell->slot == 1 && spell->spell_type == TAR_CHAR_SELF)
  {
    sprintf (buffy,  "Other Person  Level \x1b[1;35m%3d\x1b[0;37m, \x1b[1;33m%3d\x1b[0;37m mana, 2x casting time, 1/2 effect.\n\r", spell->spell_level, (spell->mana * 2));
    send_to_char (buffy, ch);
    send_to_char ("Self-Only spells can never be ranged or area cast.\n\r", ch);
  }
  sprintf (buffy, "HIDDEN %s", spell->spell_name);
  show_help_text (ch, buffy);

sprintf(buffy,"\x1b[0;35m-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-\x1b[0;37m\n\r");
send_to_char(buffy, ch);
return;
}



void 
do_slist (CHAR_DATA * ch, char *argy)
{
  SPELL_DATA *spellstuff[500];
  char buf[STD_LENGTH];
  char arg1[SML_LENGTH];
  SPELL_DATA *spell;
  int sn;
  int mnum = 0;
  int level;
  int i;
  char bbb[40];
  short slot = -1;
  short guild = -1;
  short mana_type = 0;
  bool found = FALSE;
  bool offensive = FALSE;
  bool defensive = FALSE;
  bool healing = FALSE;
  DEFINE_COMMAND ("slist", do_slist, POSITION_DEAD, 1, LOG_NORMAL, "This command lists spells/skills.")

    if (argy[0] == '\0' || argy == "")
      {
	send_to_char ("'slist spells': list all spells in the game.\n\r", ch);
	send_to_char("'slist skills': list all skills in the game.\n\r", ch);
	send_to_char("'slist prof' lists all of the proficiencies in the game.\n\r", ch);
	return;
      }

  /* Sorting by guilds allows all spells/skills/profs to be listed at
     once under one heading. */


  while (argy[0] != '\0' && argy != "")
    {
      argy = one_argy(argy, arg1);
      found = FALSE;
      if (guild == -1)
	{
	  for (i = 0; i < NUM_GUILDS; i++)
	    {
	      if (!str_cmp(guild_data[i].what_you_type, arg1))
		{
		  guild = i;
		  found = TRUE;
		  break;
		}
	    }
	}
      if (!found)
	{
	  for (i  = 0; mana_data[i].flagname != 0; i++)
	    {
	      if (!str_cmp(arg1, mana_data[i].what_you_type))
		{
		  if (mana_type != 0)
		    {
		      send_to_char("Bah, you can't try this for two mana types at once.\n\r", ch);
		      return;
		    }
		  mana_type = mana_data[i].flagname;
		  slot = 1;
		  found = TRUE;
		  break;
		}
	    }
	}
      if (!found)
	{
	  if (!str_cmp(arg1, "offensive"))
	    {
	      if (healing || defensive)
		{
		  send_to_char("Bah, pick one of healing, defensive, offensive.\n\r", ch);
		  return;
		}
	      offensive = TRUE;
	      slot = 1;
	      found = TRUE;
	    }
	  else if (!str_cmp(arg1, "defensive"))
	    {
	      if (healing || offensive)
		{
		  send_to_char("Bah, pick one of healing, defensive, offensive.\n\r", ch);
		  return;
		}
	      defensive = TRUE;
	      slot = 1;
	    }
	  else if (!str_cmp(arg1, "healing"))
	    {
	      if (offensive || defensive)
		{
		  send_to_char("Bah, pick one of healing, defensive, offensive.\n\r", ch);
		  return;
		}
	      healing = TRUE;
	      slot = 1;
	    }
	  else if (!str_cmp (arg1, "spells"))
	    slot = 1;
	  else if (!str_cmp (arg1, "skills"))
	    slot = 0;
	  else if (!str_cmp (arg1, "prof") || !str_cmp(arg1, "proficiencies"))
	    slot = 2;
	  else
	    {
	      if ((spell = skill_lookup (arg1, -1)) == NULL)
		{
		  send_to_char ("Valid argys are 'spells' or 'skills' or 'prof' ...or slist <specific spell/skill>.\n\r", ch);
		  return;
		}
	      do_info_sp_sk (ch, spell);
	      return;
	    }
	}
    }
  hugebuf_o[0] = '\0';
  switch(slot)
    {
    case 0:
      strcat(hugebuf_o, "Skills available:\n\rLv Skills\n\r----------\n\r");
      break;
    case 1:
      strcat(hugebuf_o, "Spells available:\n\rLv Spells\n\r----------\n\r");
      break;
    case 2:
      strcat(hugebuf_o, "Proficiencies available:\n\rLv Proficiencies\n\r----------\n\r");
      break;
    default:
      strcat(hugebuf_o, "Available abilities:\n\rLv Name\n\r-----------\n\r");
      break;
    }
  
  for (sn = 0; sn < SKILL_COUNT; sn++)
    {
      if ((spell = skill_lookup (NULL, sn)) == NULL)
	continue;

      /* If slot is -1 we accept ANYTHING in slist. */
      
      if (slot >= 0 && spell->slot != slot)
	continue;
      
      
      /* Sort by guild...all guild spells go into one slot area */

      if (guild != -1 && !spell->guilds[guild])
	continue;

      if (slot == 1)
	{
	  /* If we sort by mana type, we only pick those that have that
	     mana type. */
	  
	  if (mana_type > 0 && !IS_SET(spell->mana_type, mana_type))
	    continue;
	  
	  /* We only want offensive spells. */
	  
	  if (offensive && spell->spell_type != TAR_CHAR_OFFENSIVE)
	    continue;

	  /* Defensive and healing spells are self or defensive only. */

	  if ((defensive || healing)  && 
	      spell->spell_type != TAR_CHAR_DEFENSIVE && 
	      spell->spell_type != TAR_CHAR_SELF)
	    continue;
	  
	  
	  /* Defensive spells do not add hps or moves, nor do they
	     remove bits. */
	  
	  if (defensive && IS_SET(spell->spell_bits, SPELL_HEALS_DAM + SPELL_REMOVES_BIT + SPELL_ADD_MOVE))
	    continue;
	  
	  /* Healing spells heal hps, moves or remove bits. */
	  
	  if (healing && !IS_SET(spell->spell_bits, SPELL_HEALS_DAM + SPELL_REMOVES_BIT + SPELL_ADD_MOVE))
	    continue;
	}

      spellstuff[mnum] = spell;
      mnum++;
    }
  for (level = 0; level <= 90; level++)
    {
      for (sn = 0; sn < mnum; sn++)
	{
	  spell = spellstuff[sn];
	  if (spell->spell_level != level)
	    continue;
	  sprintf (buf, "\x1b[0;35m(\x1b[0;32m%2d\x1b[0;35m)",level);
	  strcat (hugebuf_o, buf);
	  if (guild != -1)
	    {
	      sprintf(buf, "\x1b[1;30m[\x1b[0;31mTier %d\x1b[1;30m] ", spell->guilds[guild]);
	      strcat(hugebuf_o, buf);
	    }
	  {
	    bool found = FALSE;
	    int i;
	    for (i = 0; str_cmp(mana_data[i].what_you_type, "end_of_list") && !found; i ++)
	      {
		if (spell->mana_type == mana_data[i].flagname)
		  {
		    char bufff[50];
		    sprintf (bufff, "%s%s\x1b[0;37m", mana_data[i].color, mana_data[i].letter);
		    strcpy(bbb, bufff);
		    found = TRUE;
		  }
	      }
	    if (!found)
	      strcpy(bbb, " ");
	  }
	  if (slot == 1)
	    sprintf (buf, "\x1b[1;36m%-21s %s \x1b[1;30m(\x1b[1;37m%2d\x1b[1;30m)\x1b[0;37m ",    spell->spell_name, bbb, spell->mana);
	  else
	    sprintf (buf, "\x1b[1;36m%-20s  ", spell->spell_name);
	  strcat (hugebuf_o, buf);
	  if (spell->prereq_1 && str_cmp(spell->prereq_1, "none") &&
str_cmp(spell->prereq_1, "None"))
           {
             sprintf (buf, "\x1b[0;36m%-18s", spell->prereq_1);
             strcat (hugebuf_o, buf);
           }
	  if (spell->prereq_2 && str_cmp(spell->prereq_2, "none") &&
str_cmp(spell->prereq_2,"None"))
           {
             sprintf (buf, "\x1b[0;36m%-18s", spell->prereq_2);
             strcat (hugebuf_o, buf);
           }
        strcat (hugebuf_o, "\n\r");
       }
    }
  strcat (hugebuf_o, "\x1b[0;37m");
  page_to_char (hugebuf_o, ch);
  return;
}

Site Stats

Snippets: 1791
Codebases: 571