Skip to content

Commit

Permalink
Fix crash when interacting with a set crafting station
Browse files Browse the repository at this point in the history
This happened because when interacting with a set crafting station,
GetSmithingPatternInfo returns information about the set-specific
recipes (e.g. "Adept Rider's Ring") in addition to the generic ones
(e.g. "Ring"). These set-specific recipe names were unrecognised by
EqRecipe:fromName, causing an assertion failure.

Resolves #1.
  • Loading branch information
kierdavis committed Mar 14, 2021
1 parent c3e5d7c commit 2f5455f
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 22 deletions.
47 changes: 26 additions & 21 deletions Cache/CraftingStationCache.lua
Original file line number Diff line number Diff line change
Expand Up @@ -26,30 +26,35 @@ function CanICraftThis.CraftingStationCache:updateFromCurrentCraftingStation()
if not skill.equipmentInfo then return end
local recipeIndex
for recipeIndex = 1, GetNumSmithingPatterns() do
local recipeName, _, _, numMaterials = GetSmithingPatternInfo(recipeIndex)
recipeName = recipeNameExceptions[recipeName] or recipeName
local recipe = CanICraftThis.EqRecipe:fromName(recipeName)
local requiredQuantityForMainMaterial = {}
local materialIndex
for materialIndex = 1, numMaterials do
local material, _, requiredQuantity, _, _, _, _, _, _, requiredPassiveAbility = GetSmithingPatternMaterialItemInfo(recipeIndex, materialIndex)
local material = CanICraftThis.Material:sanitise(material)
if CanICraftThis.Material:isEqMain(material) then
local prevRequiredPassiveAbility = self.data.requiredPassiveAbility[material]
if prevRequiredPassiveAbility ~= nil and prevRequiredPassiveAbility ~= requiredPassiveAbility then
CanICraftThis.reportUnexpected(
"multiple values of requiredPassiveAbility for same material " .. material .. ": " ..
tostring(prevRequiredPassiveAbility) .. ", " .. tostring(requiredPassiveAbility)
)
end
self.data.requiredPassiveAbility[material] = requiredPassiveAbility
local prevRequiredQuantity = requiredQuantityForMainMaterial[material]
if prevRequiredQuantity == nil or requiredQuantity < prevRequiredQuantity then
requiredQuantityForMainMaterial[material] = requiredQuantity
local recipeName, _, _, numMaterials, numTraitsRequired = GetSmithingPatternInfo(recipeIndex)
if numTraitsRequired == 0 then
recipeName = recipeNameExceptions[recipeName] or recipeName
local recipe = CanICraftThis.EqRecipe:fromName(recipeName)
local requiredQuantityForMainMaterial = {}
local materialIndex
for materialIndex = 1, numMaterials do
local material, _, requiredQuantity, _, _, _, _, _, _, requiredPassiveAbility = GetSmithingPatternMaterialItemInfo(recipeIndex, materialIndex)
local material = CanICraftThis.Material:sanitise(material)
if CanICraftThis.Material:isEqMain(material) then
local prevRequiredPassiveAbility = self.data.requiredPassiveAbility[material]
if prevRequiredPassiveAbility ~= nil and prevRequiredPassiveAbility ~= requiredPassiveAbility then
CanICraftThis.reportUnexpected(
"multiple values of requiredPassiveAbility for same material " .. material .. ": " ..
tostring(prevRequiredPassiveAbility) .. ", " .. tostring(requiredPassiveAbility)
)
end
self.data.requiredPassiveAbility[material] = requiredPassiveAbility
local prevRequiredQuantity = requiredQuantityForMainMaterial[material]
if prevRequiredQuantity == nil or requiredQuantity < prevRequiredQuantity then
requiredQuantityForMainMaterial[material] = requiredQuantity
end
end
end
self.data.requiredQuantity[recipe.id] = requiredQuantityForMainMaterial
else
-- This is a set-specific recipe (e.g. "Adept Rider's Ring").
-- Generic recipes (e.g. "Ring") will also be listed, so we can simply skip this.
end
self.data.requiredQuantity[recipe.id] = requiredQuantityForMainMaterial
end
end

Expand Down
2 changes: 1 addition & 1 deletion CanICraftThis.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
## Description: Easily see whether you have all knowledge and materials required for a writ before opening it.
## Author: always.ada
## APIVersion: 100033 100034
## AddOnVersion: 5
## AddOnVersion: 6
## SavedVariables: CanICraftThisVars

Core.lua
Expand Down

0 comments on commit 2f5455f

Please sign in to comment.