Implementation of spellbooks. Created by: Mike Breuer Date: 2-Jul-2001 This snippet requires that the learned_spells snippet be applied to your MUD. As of this writing, the learned_spells snippet can be found at: www.circlemud.org/pub/CircleMUD/contrib/snippets/skills/learned_spells.txt This snippet, like the learned_spells snippet was written for CircleMUD30BPL18. The idea behind spellbooks is to allow players an alternative method of learning spells, although any skill can be taught using the books. On my MUD, all of the spells taught with books are "learned" spells. The following steps are used to ensure that books are ueseful and are not abused. 1. ITEM_ANTI_ flags are used to restrict the books to only those classes able to learn the spell. 2. Minimum level is tested when studying the spellbook to ensure that the spell can not be learned before the player is eligible to learn it. 3. An extra description of "book spellbook~" describes the spell in detail so that when the player types "read book" they receive a useful description of the spell. 4. Spells are learned using the "study" command. Only books that the player is holding can be studied. Once studied, the book is destroyed. 5. Spellbook object values are as follows: Value 1: % of spell learned (must be in the range of 1-100) Value 2: First spell to learn Value 3: Second spell to learn (or -1 if only one spell) Value 4: Third spell to learn (or -1 if less than 3 spells) For even more information, check out the help file entries that I've included at the bottom of this file. If you use this snippet, please drop me a note at: blitzthethief@delta-quadrant.net If you wish to credit me in your mud, you may simply give credit to "Blitz" and provide the above email address. ============================================================================= In structs.h: Look for: #define ITEM_BOAT 22 /* Item is a boat */ #define ITEM_FOUNTAIN 23 /* Item is a fountain */ Add: #define ITEM_SPELLBOOK 24 /* Item is a spellbook */ (Yours may not be 24...just add it to the end) --- In constants.c Look for: "BOAT", "FOUNTAIN", Add above the "\n": "SPELLBOOK", --- In act.wizard.c: Look for: case ITEM_SCROLL: case ITEM_POTION: sprintf(buf, "Spells: (Level %d) %s, %s, %s", GET_OBJ_VAL(j, 0), skill_name(GET_OBJ_VAL(j, 1)), skill_name(GET_OBJ_VAL(j, 2)), skill_name(GET_OBJ_VAL(j, 3))); break; Add: case ITEM_SPELLBOOK: sprintf(buf, "Spells: (Learn %d%%) %s, %s, %s", GET_OBJ_VAL(j, 0), skill_name(GET_OBJ_VAL(j, 1)), skill_name(GET_OBJ_VAL(j, 2)), skill_name(GET_OBJ_VAL(j, 3))); break; --- In interpreter.h: Look for: #define SCMD_RECITE 2 Add: #define SCMD_STUDY 3 (Make sure the number is unique) --- In interpreter.c: Look for: { "strut" , POS_STANDING, do_action , 0, 0 }, Add: { "study" , POS_RESTING , do_use , 0, SCMD_STUDY }, --- In act.other.c: Look for: ACMD(do_use) { struct obj_data *mag_item; Add: int i, spellnum; Then, look for: case SCMD_USE: sprintf(buf2, "You don't seem to be holding %s %s.\r\n", AN(arg), arg); send_to_char(buf2, ch); return; Above the case statement, add: case SCMD_STUDY: Then, look for: case SCMD_RECITE: if (GET_OBJ_TYPE(mag_item) != ITEM_SCROLL) { send_to_char("You can only recite scrolls.\r\n", ch); return; } break; Add: case SCMD_STUDY: if (GET_OBJ_TYPE(mag_item) != ITEM_SPELLBOOK) { send_to_char("You can only study spell books.\r\n", ch); return; } for (i = 1; i <= 3; i++) { spellnum = GET_OBJ_VAL(mag_item, i); if (spellnum < 0 || spellnum > TOP_SPELL_DEFINE) continue; if (spell_info[spellnum].min_level[(int)GET_CLASS(ch)] > GET_LEVEL(ch)) { send_to_char("You are not experienced enough.\r\n", ch); return; } } break; --- In spell_parser.c: Look for: * potion - [0] level [1] spell num [2] spell num [3] spell num Add: * spellbook[0] % learn [1] spell num [2] spell num [3] spell num Then, look for: case ITEM_POTION: tch = ch; act("You quaff $p.", FALSE, ch, obj, NULL, TO_CHAR); if (obj->action_description) act(obj->action_description, FALSE, ch, obj, NULL, TO_ROOM); else act("$n quaffs $p.", TRUE, ch, obj, NULL, TO_ROOM); WAIT_STATE(ch, PULSE_VIOLENCE); for (i = 1; i <= 3; i++) if (call_magic(ch, ch, NULL, GET_OBJ_VAL(obj, i), GET_OBJ_VAL(obj, 0), CAST_POTION) <= 0) break; if (obj != NULL) extract_obj(obj); break; Add: case ITEM_SPELLBOOK: tch = ch; act("You study $p.", FALSE, ch, obj, NULL, TO_CHAR); if (obj->action_description) act(obj->action_description, FALSE, ch, obj, NULL, TO_ROOM); else act("$n studies $p.", TRUE, ch, obj, NULL, TO_ROOM); WAIT_STATE(ch, PULSE_VIOLENCE); for (i = 1; i <= 3; i++) { if (GET_OBJ_VAL(obj, i) < 0) break; if (GET_SKILL(ch, GET_OBJ_VAL(obj, i)) < 1) SET_SKILL(ch, GET_OBJ_VAL(obj, i), GET_OBJ_VAL(obj, 0)); } if (obj != NULL) extract_obj(obj); break; I use the following help file entries. Your entries may differ depending on how you use the books, so these are only recommendations: --- info.hlp: LIBRARY LIBRARIES A library is really just a shop that sells spellbooks. Think of the money you pay for a spellbook as a deposit. Most libraries will buy back your unused spellbooks at cost, minus a small percentage. You are free to read a spellbook to find out more about the spell(s) it contains. If you actually study the spellbook, you will learn the spell it contains and the book will be destroyed (ending your chances of selling it back). Only characters capable of learning the spell will be able to study the book. Rent on a spellbook is typically the same as its cost, so it is advisable to immediately return (sell) books that you do not intend to study. See also: STUDY, SPELLBOOKS, SHOPS # --- info.hlp: SPELLBOOK SPELLBOOKS Spellbooks are a way of learning spells that might not otherwise be available to you. Some spellbooks can be found in the Library in , while others may be scattered throughout the game. There are typically two things you can do with a spellbook: read it, or study it. Reading a spellbook gives you a simple description of the spell (or spells) it contains. Any character can read a spellbook. Studying a spellbook causes your character to learn the spell (or spells) it contains. Only characters of the proper class and level will be able to study a spellbook. Once you have learned a spell, you are can improve your proficiency at it by practicing in your guild. Studying a spellbook will destroy the book. See also: STUDY, LIBRARY # --- commands.hlp: STUDY Usage: study Used to learn new spells from a spellbook. Once it has been studied, the spellbook disintegrates. You must be holding the book to study it. See also: SPELLBOOKS #