Re: [code] Do Cast Mods

From: David A. Carver (dcarver@iwaynet.net)
Date: 10/01/96


Somebody Wrote:
> > 
> > After an evening of coding fun, I've finally altered do_cast
> > into do_mpcast,  There was a number of people who said that
> > they were having problems with MobProgs and casting spells,

> 
> I then added cases to the edesc feilds in db.c.
> 
> I believe it looked something like this,
> 
> case ("Fireball"): {
>   RANGE(1, 100);
>   GET_SKILL(mob_proto, SPELL_FIREBALL) = num_arg;
>   break;
>  }
> 

Instead of modifying the mobs database format, I just came up with a 
system of calculating percentage for the skill based on the mobs 
level.  I then removed the checks to see if the Mob new the spell and 
gave the mobs all available spells.  The chance of success is based 
on their level.
> 
> The only problem is that every skill/spell you want the mob to use has to
> be added as a case here.  Did you find an easier or more efficient way?

Well this may not be the most efficient way of doing it, (in fact I 
plan to rewrite my hack) but here is my modified do_cast:

ACMD(do_cast)
{
  struct char_data *tch = NULL;
  struct obj_data *tobj = NULL;
  char *s, *t;
  int mana, spellnum, i, target = 0, mob_percent = 0, dieroll = 0;

  if (IS_NPC(ch))
   {
   /* set the percentage that a mob needs to sucessfully cast a spell
   */
    if (GET_LEVEL(ch) < 3)
        mob_percent = 10;
    if (GET_LEVEL(ch) >= 3 && GET_LEVEL(ch) < 6)
        mob_percent = 20;
    if (GET_LEVEL(ch) >= 6 && GET_LEVEL(ch) < 9)
        mob_percent = 30;
    if (GET_LEVEL(ch) >= 9 && GET_LEVEL(ch) < 12)
        mob_percent = 40;
    if (GET_LEVEL(ch) >= 12 && GET_LEVEL(ch) < 15)
        mob_percent = 50;
    if (GET_LEVEL(ch) >= 15 && GET_LEVEL(ch) < 18)
        mob_percent = 60;
    if (GET_LEVEL(ch) >= 18 && GET_LEVEL(ch) < 21)
        mob_percent = 70;
    if (GET_LEVEL(ch) >= 21 && GET_LEVEL(ch) < 24)
        mob_percent = 80;
    if (GET_LEVEL(ch) >= 24 && GET_LEVEL(ch) < 28)
        mob_percent = 90;
    if (GET_LEVEL(ch) >= 28 && GET_LEVEL(ch) < 30)
        mob_percent = 95;
    if (GET_LEVEL(ch) >= 30)
        mob_percent = 99;
    }


  /* get: blank, spell name, target name */
  s = strtok(argument, "'");

  if (s == NULL) {
    send_to_char("Cast what where?\r\n", ch);
    return;
  }
  if (!IS_NPC(ch))
  {
    if (GET_CLASS(ch) == CLASS_PALADIN)
     if (!IS_GOOD(ch))
       {
       send_to_char("The Gods have taken your powers away for not
       being of Good Alignment.\r\n",
                    ch);
       act("$n hands are slapped by the Gods.", FALSE, ch, 0, 0,
       TO_ROOM); return; }
  }

  s = strtok(NULL, "'");
  if (s == NULL) {
    send_to_char("Spell names must be enclosed in the Holy Magic
    Symbols: '\r\n", ch); return;
  }
  t = strtok(NULL, "\0");

  /* spellnum = search_block(s, spells, 0); */
  spellnum = find_skill_num(s);

  if ((spellnum < 1) || (spellnum > MAX_SPELLS)) {
    send_to_char("Cast what?!?\r\n", ch);
    return;
  }
  if (GET_LEVEL(ch) < SINFO.min_level[(int) GET_CLASS(ch)] &&
  !IS_NPC(ch)) {
    send_to_char("You do not know that spell!\r\n", ch);
    return;
  }
  if (GET_SKILL(ch, spellnum) == 0 && !IS_NPC(ch)) {
    send_to_char("You are unfamiliar with that spell.\r\n", ch);
    return;
  }
  /* Find the target */
  if (t != NULL) {
    one_argument(strcpy(arg, t), t);
    skip_spaces(&t);
  }
  if (IS_SET(SINFO.targets, TAR_IGNORE)) {
    target = TRUE;
  } else if (t != NULL && *t) {
    if (!target && (IS_SET(SINFO.targets, TAR_CHAR_ROOM))) {
      if ((tch = get_char_room_vis(ch, t)) != NULL)
    target = TRUE;
    }
    if (!target && IS_SET(SINFO.targets, TAR_CHAR_WORLD))
      if ((tch = get_char_vis(ch, t)))
    target = TRUE;

    if (!target && IS_SET(SINFO.targets, TAR_OBJ_INV))
      if ((tobj = get_obj_in_list_vis(ch, t, ch->carrying)))
    target = TRUE;

    if (!target && IS_SET(SINFO.targets, TAR_OBJ_EQUIP)) {
      for (i = 0; !target && i < NUM_WEARS; i++)
    if (GET_EQ(ch, i) && !str_cmp(t, GET_EQ(ch, i)->name)) {
      tobj = GET_EQ(ch, i);
      target = TRUE;
    }
    }
    if (!target && IS_SET(SINFO.targets, TAR_OBJ_ROOM))
      if ((tobj = get_obj_in_list_vis(ch, t,
      world[ch->in_room].contents)))
    target = TRUE;

    if (!target && IS_SET(SINFO.targets, TAR_OBJ_WORLD))
      if ((tobj = get_obj_vis(ch, t)))
    target = TRUE;

  } else {            /* if target string is empty */
    if (!target && IS_SET(SINFO.targets, TAR_FIGHT_SELF))
      if (FIGHTING(ch) != NULL) {
    tch = ch;
    target = TRUE;
      }
    if (!target && IS_SET(SINFO.targets, TAR_FIGHT_VICT))
      if (FIGHTING(ch) != NULL) {
    tch = FIGHTING(ch);
    target = TRUE;
      }
    /* if no target specified, and the spell isn't violent, default to
    self */ if (!target && IS_SET(SINFO.targets, TAR_CHAR_ROOM) &&
    !SINFO.violent) {
      tch = ch;
      target = TRUE;
    }
    if (!target) {
      sprintf(buf, "Upon %s should the spell be cast?\r\n",
     IS_SET(SINFO.targets, TAR_OBJ_ROOM | TAR_OBJ_INV | TAR_OBJ_WORLD)
     ?
          "what" : "who");
      send_to_char(buf, ch);
      return;
    }
  }

  if (target && (tch == ch) && SINFO.violent) {
    send_to_char("You shouldn't cast that on yourself -- could be bad
    for your health!\r\n", ch); return;
  }
  if (!target) {
    send_to_char("Cannot find the target of your spell!\r\n", ch);
    return;
  }
  mana = mag_manacost(ch, spellnum);
  if ((mana > 0) && (GET_MANA(ch) < mana) && (GET_LEVEL(ch) <
  LVL_IMMORT)) {
    send_to_char("You haven't the energy to cast that spell!\r\n",
    ch); return;
  }

  /* You throws the dice and you takes your chances.. 101% is total
  failure */ dieroll = number(0, 101); if (!IS_NPC(ch)) {
    if (dieroll > GET_SKILL(ch, spellnum) && !IS_NPC(ch)) {
       WAIT_STATE(ch, PULSE_VIOLENCE);
       if (!tch || !skill_message(0, ch, tch, spellnum))
         send_to_char("You lost your concentration!\r\n", ch);
       if (mana > 0)
         GET_MANA(ch) = MAX(0, MIN(GET_MAX_MANA(ch), GET_MANA(ch) -
         (mana >> 1)));
       if (SINFO.violent && tch && IS_NPC(tch))
         hit(tch, ch, TYPE_UNDEFINED);
    } else { /* cast spell returns 1 on success; subtract mana & set
    waitstate */
      if (cast_spell(ch, tch, tobj, spellnum)) {
        WAIT_STATE(ch, PULSE_VIOLENCE);
          if (mana > 0)
      GET_MANA(ch) = MAX(0, MIN(GET_MAX_MANA(ch), GET_MANA(ch) -
      mana)); }
    }
  }
  else
  {
     if (dieroll > mob_percent)
     {
        WAIT_STATE(ch, PULSE_VIOLENCE);
        if (!tch || !skill_message(0, ch, tch, spellnum))
         send_to_char("You lost your concentration!\r\n", ch);
       if (mana > 0)
         GET_MANA(ch) = MAX(0, MIN(GET_MAX_MANA(ch), GET_MANA(ch) -
         (mana >> 1)));
       if (SINFO.violent && tch)
         hit(tch, ch, TYPE_UNDEFINED);
      }
     else
     {
       if (cast_spell(ch, tch, tobj, spellnum))
       {
        WAIT_STATE(ch, PULSE_VIOLENCE);
       }
     }
   }
+-----------------------------------------------------------+
| Ensure that you have read the CircleMUD Mailing List FAQ: |
|   http://cspo.queensu.ca/~fletcher/Circle/list_faq.html   |
+-----------------------------------------------------------+



This archive was generated by hypermail 2b30 : 12/18/00 PST