diff --git a/spec/System/TestItemEldritchTags_spec.lua b/spec/System/TestItemEldritchTags_spec.lua new file mode 100644 index 00000000000..b43263cb23e --- /dev/null +++ b/spec/System/TestItemEldritchTags_spec.lua @@ -0,0 +1,77 @@ +describe("TestItemEldritchTags", function() + before_each(function() + newBuild() + end) + + local function findLine(item, text) + for _, modLine in ipairs(item.implicitModLines) do + if modLine.line == text then + return modLine + end + end + end + + -- Copied from the game (Ctrl+C): implicits carry "(implicit)", not {exarch}/{eater} + local copiedGloves = [[Item Class: Gloves +Rarity: Rare +Test Grip +Sorcerer Gloves +-------- +Energy Shield: 50 +-------- +Item Level: 84 +-------- +11% increased Attack Speed (implicit) +Projectiles Pierce an additional Target (implicit) +-------- ++30 to maximum Life +-------- +Searing Exarch Item +Eater of Worlds Item]] + + it("tags eldritch implicits of a copied item (issue #4940)", function() + local item = new("Item"):Item(copiedGloves) + assert.is_true(item.cleansing) + assert.is_true(item.tangle) + local exarchLine = findLine(item, "11% increased Attack Speed") + local eaterLine = findLine(item, "Projectiles Pierce an additional Target") + assert.is_truthy(exarchLine) + assert.is_truthy(eaterLine) + assert.is_true(exarchLine.exarch) + assert.is_falsy(exarchLine.eater) + assert.is_true(eaterLine.eater) + assert.is_falsy(eaterLine.exarch) + end) + + it("keeps the tags after saving and reloading the item (issue #4940)", function() + local item = new("Item"):Item(new("Item"):Item(copiedGloves):BuildRaw()) + assert.is_true(findLine(item, "11% increased Attack Speed").exarch) + assert.is_true(findLine(item, "Projectiles Pierce an additional Target").eater) + end) + + it("does not tag implicits of an item without eldritch influence", function() + local item = new("Item"):Item((copiedGloves:gsub("\nSearing Exarch Item\nEater of Worlds Item", ""))) + assert.is_falsy(findLine(item, "11% increased Attack Speed").exarch) + assert.is_falsy(findLine(item, "Projectiles Pierce an additional Target").eater) + end) + + it("keeps existing tags", function() + local item = new("Item"):Item([[Rarity: RARE +Test Grip +Sorcerer Gloves +Searing Exarch Item +Eater of Worlds Item +Implicits: 2 +{exarch}11% increased Attack Speed +{eater}Projectiles Pierce an additional Target]]) + assert.is_true(findLine(item, "11% increased Attack Speed").exarch) + assert.is_falsy(findLine(item, "11% increased Attack Speed").eater) + assert.is_true(findLine(item, "Projectiles Pierce an additional Target").eater) + end) + + it("does not tag implicits without the matching influence", function() + local item = new("Item"):Item((copiedGloves:gsub("\nEater of Worlds Item", ""))) + assert.is_true(findLine(item, "11% increased Attack Speed").exarch) + assert.is_falsy(findLine(item, "Projectiles Pierce an additional Target").eater) + end) +end) diff --git a/src/Classes/Item.lua b/src/Classes/Item.lua index 0bbcfb13f2e..db4e5e1fe00 100644 --- a/src/Classes/Item.lua +++ b/src/Classes/Item.lua @@ -67,6 +67,9 @@ local function normaliseModLine(line) :gsub("\n", " ") end +-- Normalised eldritch implicit line -> "exarch"/"eater", built on first use +local eldritchLineTags + local uniqueModStatOrder local function sortCraftedModLines(modLines) @@ -1618,6 +1621,25 @@ function ItemClass:ParseRaw(raw, rarity, highQuality) elseif not self.foulborn and hasFoulbornPrefix then self.title = self.title:gsub("[Ff]oulborn ", "") end + -- Copied or imported items don't carry {exarch}/{eater} on their eldritch implicits, so recover them from the mod pool + if self.cleansing or self.tangle then + if not eldritchLineTags then + eldritchLineTags = { } + for _, mod in pairs(data.itemMods.Eldritch) do + for _, line in ipairs(mod) do + eldritchLineTags[normaliseModLine(line)] = mod.type == "Exarch" and "exarch" or "eater" + end + end + end + for _, modLine in ipairs(self.implicitModLines) do + if not modLine.exarch and not modLine.eater then + local tag = eldritchLineTags[normaliseModLine(modLine.line)] + if (tag == "exarch" and self.cleansing) or (tag == "eater" and self.tangle) then + modLine[tag] = true + end + end + end + end if self.baseName and self.title then self.name = self.title .. ", " .. self.baseName:gsub(" %(.+%)", "") end