-
Notifications
You must be signed in to change notification settings - Fork 139
Description
Reported by BaroqueBickle on Discord (and earlier by Deleted User on Discord).
Occasionally, when enchanting an item (including runics), it will auto-identify.
ANALYSIS:
Enchanting an item occurs in readScroll():
Line 6957 in 2e0ea9a
| boolean readScroll(item *theItem) { |
First, the itemTable for the appropriate scrollKind is copied to a local variable:
Line 6964 in 2e0ea9a
| itemTable scrollKind = tableForItemCategory(theItem->category)[theItem->kind]; |
Then, the appropriate case in the switch statement is executed, for SCROLL_ENCHANTING:
Lines 7025 to 7027 in 2e0ea9a
| case SCROLL_ENCHANTING: | |
| identify(theItem); | |
| messageWithColor("this is a scroll of enchanting.", &itemMessageColor, REQUIRE_ACKNOWLEDGMENT); |
Note that the variable theItem is currently assigned to the scroll which is being read.
Next, the player chooses an item to enchant. The chosen item is assigned to the existing theItem variable, overwriting the pointer to the scroll.
Lines 7034 to 7036 in 2e0ea9a
| theItem = promptForItemOfType((WEAPON | ARMOR | RING | STAFF | WAND | CHARM), 0, 0, | |
| KEYBOARD_LABELS ? "Enchant what? (a-z; shift for more info)" : "Enchant what?", | |
| false); |
After the selection theItem is upgraded appropriately for the kind of item.
On completion of the enchantment's case statement, execution jumps to the bottom of the function and the following code executes:
Lines 7214 to 7220 in 2e0ea9a
| // all scrolls auto-identify on use | |
| if (!scrollKind.identified | |
| && (theItem->kind != SCROLL_ENCHANTING) | |
| && (theItem->kind != SCROLL_IDENTIFY)) { | |
| autoIdentify(theItem); | |
| } |
At this point:
theItempoints to the item which has just been enchanted, NOT the scroll which was just read.scrollKindis a copy of theitemTablefor theSCROLL_ENCHANTMENTkind.- Even though enchanting scrolls have been identified by this point, the copy of the itemTable was made before the scroll was identified and still has them marked as unidentified.
THE BUG:
IF enchanting scrolls have not been identified yet,
AND an unidentified item is enchanted,
AND it does not have kind == 0 or kind == 1,
THEN the item will be auto-identified.
This bug will identify any ring, staff, wand, weapon, or armor except the first two items in kind-order. So for weapons, it will not identify a dagger (kind == 0) or sword (kind == 1).
RECOMMENDED FIX:
Keep a copy of the pointer to the scroll and use that in the later checks.