Skip to content

Enchanting items may sometimes identify them #787

@brturn

Description

@brturn

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():

boolean readScroll(item *theItem) {

First, the itemTable for the appropriate scrollKind is copied to a local variable:

itemTable scrollKind = tableForItemCategory(theItem->category)[theItem->kind];

Then, the appropriate case in the switch statement is executed, for SCROLL_ENCHANTING:

BrogueCE/src/brogue/Items.c

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.

BrogueCE/src/brogue/Items.c

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:

BrogueCE/src/brogue/Items.c

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:

  • theItem points to the item which has just been enchanted, NOT the scroll which was just read.
  • scrollKind is a copy of the itemTable for the SCROLL_ENCHANTMENT kind.
  • 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions