writing an unknown spellbook when the spell is known

Allow hero to write an unknown spellbook if the spell is freshly known
(from divine knowledge).  If the spell is going stale, the chance of
successfully writing the spellbook depends on Luck, but only rnl(5)
(like a Wizard) instead of rnl(15).  Forgotten spells do not help when
writing unknown spellbooks.
This commit is contained in:
vultur-cadens
2023-07-01 12:59:33 -07:00
committed by PatR
parent 78a2260830
commit 72213bf48f

View File

@@ -111,6 +111,7 @@ dowrite(struct obj *pen)
int first, last, i, deferred, deferralchance, real;
boolean by_descr = FALSE;
const char *typeword;
int spell_knowledge;
if (nohands(gy.youmonst.data)) {
You("need hands to be able to write!");
@@ -314,6 +315,10 @@ dowrite(struct obj *pen)
* book type. One has previously been read (and its effect
* was evident) or been ID'd via scroll/spell/throne and it
* will be on the discoveries list.
* Unknown spellbooks can also be written by name if the hero
* has fresh knowledge of the spell, or if the spell is almost
* forgotten and the hero is Lucky (with a greater chance than
* if the spell is unknown or forgotten).
* (Previous versions allowed scrolls and books to be written
* by type name if they were on the discoveries list via being
* given a user-assigned name, even though doing the latter
@@ -332,12 +337,20 @@ dowrite(struct obj *pen)
* Normal requirements can be overridden if hero is Lucky.
*/
if (paper->oclass == SPBOOK_CLASS) {
spell_knowledge = known_spell(new_obj->otyp);
} else {
spell_knowledge = spe_Unknown;
}
/* if known, then either by-name or by-descr works */
if (!objects[new_obj->otyp].oc_name_known
/* else if named, then only by-descr works */
&& !(by_descr && label_known(new_obj->otyp, gi.invent))
/* and Luck might override after both checks have failed */
&& rnl(Role_if(PM_WIZARD) ? 5 : 15)) {
/* else fresh knowledge of the spell works */
&& spell_knowledge != spe_Fresh
/* and Luck might override after previous checks have failed */
&& rnl((Role_if(PM_WIZARD) || spell_knowledge == spe_GoingStale)
? 5 : 15)) {
You("%s to write that.", by_descr ? "fail" : "don't know how");
/* scrolls disappear, spellbooks don't */
if (paper->oclass == SPBOOK_CLASS) {