Skip to content

Commit

Permalink
change catalyst scalar into generic range scalar function
Browse files Browse the repository at this point in the history
  • Loading branch information
Regisle committed Aug 14, 2024
1 parent 6d4680c commit 8c474ba
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 104 deletions.
39 changes: 26 additions & 13 deletions src/Classes/Item.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,29 @@ local catalystTags = {
{ "critical" },
}

local function getCatalystScalar(catalystId, tags, quality)
if not catalystId or type(catalystId) ~= "number" or not catalystTags[catalystId] or not tags or type(tags) ~= "table" or #tags == 0 then
-- Helper Function used by tinctures and catalysts
-- (can be used in future for heist enchants/jewellery)
---@param typeID type of mod, either tincture or catalystID
---@param tags list of tags on the mod
---@param quality number of quality, either item base, or catalyst
---@param extraMult any extra multipliers (eg increased effect for tinctures)
---@return multiplier value for the mod based on the tags
local function getRangeScalarFromTag(typeID, tags, quality, extraMult)
if not typeID or (typeID ~= "tincture" and (type(typeID) ~= "number" or not catalystTags[typeID])) or not tags or type(tags) ~= "table" or #tags == 0 then
return 1
end
if not quality then
quality = 20
end

if typeID == "tincture" then
for _, curTag in ipairs(tags) do
if curTag == "tincture" then
return (100 + (extraMult or 0)) / 100 * (100 + quality) / 100
end
end
return 1
end

-- Create a fast lookup table for all provided tags
local tagLookup = {}
Expand All @@ -40,7 +56,7 @@ local function getCatalystScalar(catalystId, tags, quality)
end

-- Find if any of the catalyst's tags match the provided tags
for _, catalystTag in ipairs(catalystTags[catalystId]) do
for _, catalystTag in ipairs(catalystTags[typeID]) do
if tagLookup[catalystTag] then
return (100 + quality) / 100
end
Expand Down Expand Up @@ -721,14 +737,14 @@ function ItemClass:ParseRaw(raw, rarity, highQuality)
foundImplicit = true
gameModeStage = "IMPLICIT"
end
local catalystScalar = getCatalystScalar(self.catalyst, modLine.modTags, self.catalystQuality)
local rangedLine = itemLib.applyRange(line, 1, catalystScalar)
local rangeScalar = getRangeScalarFromTag(self.base.tincture and "tincture" or self.catalyst, modLine.modTags, self.quality or self.catalystQuality, self.base.tincture and 0 or 0)
local rangedLine = itemLib.applyRange(line, 1, rangeScalar)
local modList, extra = modLib.parseMod(rangedLine)
if (not modList or extra) and self.rawLines[l+1] then
-- Try to combine it with the next line
local nextLine = self.rawLines[l+1]:gsub("%b{}", ""):gsub(" ?%(%l+%)","")
local combLine = line.." "..nextLine
rangedLine = itemLib.applyRange(combLine, 1, catalystScalar)
rangedLine = itemLib.applyRange(combLine, 1, rangeScalar)
modList, extra = modLib.parseMod(rangedLine, true)
if modList and not extra then
line = line.."\n"..nextLine
Expand Down Expand Up @@ -778,7 +794,7 @@ function ItemClass:ParseRaw(raw, rarity, highQuality)
if modList then
modLine.modList = modList
modLine.extra = extra
modLine.valueScalar = catalystScalar
modLine.valueScalar = rangeScalar
modLine.range = modLine.range or main.defaultItemAffixQuality
t_insert(modLines, modLine)
if mode == "GAME" then
Expand Down Expand Up @@ -1177,10 +1193,7 @@ function ItemClass:Craft()
self.nameSuffix = " " .. mod.affix
end
self.requirements.level = m_max(self.requirements.level or 0, m_floor(mod.level * 0.8))
local rangeScalar = getCatalystScalar(self.catalyst, mod.modTags, self.catalystQuality)
if self.base.tincture and mod.type ~= "Prefix" then
rangeScalar = rangeScalar * (1 + (self.tinctureData.effectInc or 0) / 100) * (1 + (self.quality or 0) / 100)
end
local rangeScalar = getRangeScalarFromTag(self.base.tincture and "tincture" or self.catalyst, mod.modTags, self.quality or self.catalystQuality, self.base.tincture and self.tinctureData.effectInc)
for i, line in ipairs(mod) do
line = itemLib.applyRange(line, affix.range or 0.5, rangeScalar)
local order = mod.statOrder[i]
Expand Down Expand Up @@ -1584,9 +1597,9 @@ function ItemClass:BuildModList()
-- Check if line actually has a range
if modLine.line:find("%((%-?%d+%.?%d*)%-(%-?%d+%.?%d*)%)") then
local strippedModeLine = modLine.line:gsub("\n"," ")
local catalystScalar = getCatalystScalar(self.catalyst, modLine.modTags, self.catalystQuality)
local rangeScalar = getRangeScalarFromTag(self.base.tincture and "tincture" or self.catalyst, modLine.modTags, self.quality or self.catalystQuality, self.base.tincture and self.tinctureData.effectInc)
-- Put the modified value into the string
local line = itemLib.applyRange(strippedModeLine, modLine.range, catalystScalar)
local line = itemLib.applyRange(strippedModeLine, modLine.range, rangeScalar)
-- Check if we can parse it before adding the mods
local list, extra = modLib.parseMod(line)
if list and not extra then
Expand Down
18 changes: 9 additions & 9 deletions src/Data/Bases/tincture.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ itemBases["Prismatic Tincture"] = {
type = "Tincture",
tags = { tincture = true, default = true, },
implicit = "(70-100)% increased Elemental Damage with Melee Weapons",
implicitModTypes = { { "elemental_damage", "damage", "elemental", "attack" }, },
implicitModTypes = { { "elemental_damage", "damage", "elemental", "attack", "tincture" }, },
tincture = { manaBurn = 0.7, cooldown = 8 },
req = { },
}
Expand All @@ -22,63 +22,63 @@ itemBases["Ironwood Tincture"] = {
type = "Tincture",
tags = { tincture = true, default = true, },
implicit = "40% reduced Enemy Stun Threshold with Melee Weapons\n(15-25)% increased Stun Duration with Melee Weapons",
implicitModTypes = { { "attack" }, { "attack" }, },
implicitModTypes = { { "attack", "tincture" }, { "attack", "tincture" }, },
tincture = { manaBurn = 0.9, cooldown = 10 },
req = { },
}
itemBases["Ashbark Tincture"] = {
type = "Tincture",
tags = { tincture = true, default = true, },
implicit = "25% chance to Ignite with Melee Weapons\n(60-90)% increased Damage with Ignite from Melee Weapons",
implicitModTypes = { { "elemental_damage", "damage", "elemental", "fire", "attack", "ailment" }, { "elemental_damage", "damage", "elemental", "fire", "attack", "ailment" }, },
implicitModTypes = { { "elemental_damage", "damage", "elemental", "fire", "attack", "ailment", "tincture" }, { "elemental_damage", "damage", "elemental", "fire", "attack", "ailment", "tincture" }, },
tincture = { manaBurn = 0.6, cooldown = 7 },
req = { },
}
itemBases["Borealwood Tincture"] = {
type = "Tincture",
tags = { tincture = true, default = true, },
implicit = "25% chance to Freeze with Melee Weapons\n(25-35)% increased Effect of Chill from Melee Weapons",
implicitModTypes = { { "elemental_damage", "damage", "elemental", "cold", "attack", "ailment" }, { "elemental_damage", "damage", "elemental", "cold", "attack", "ailment" }, },
implicitModTypes = { { "elemental_damage", "damage", "elemental", "cold", "attack", "ailment", "tincture" }, { "elemental_damage", "damage", "elemental", "cold", "attack", "ailment", "tincture" }, },
tincture = { manaBurn = 0.6, cooldown = 7 },
req = { },
}
itemBases["Fulgurite Tincture"] = {
type = "Tincture",
tags = { tincture = true, default = true, },
implicit = "25% chance to Shock with Melee Weapons\n(25-35)% increased Effect of Shock from Melee Weapons",
implicitModTypes = { { "elemental_damage", "damage", "elemental", "lightning", "attack", "ailment" }, { "elemental_damage", "damage", "elemental", "lightning", "attack", "ailment" }, },
implicitModTypes = { { "elemental_damage", "damage", "elemental", "lightning", "attack", "ailment", "tincture" }, { "elemental_damage", "damage", "elemental", "lightning", "attack", "ailment", "tincture" }, },
tincture = { manaBurn = 0.6, cooldown = 7 },
req = { },
}
itemBases["Poisonberry Tincture"] = {
type = "Tincture",
tags = { tincture = true, default = true, },
implicit = "20% chance to Poison with Melee Weapons\n(60-90)% increased Damage with Poison from Melee Weapons",
implicitModTypes = { { "chaos_damage", "poison", "damage", "chaos", "attack", "ailment" }, { "chaos_damage", "poison", "damage", "chaos", "attack", "ailment" }, },
implicitModTypes = { { "chaos_damage", "poison", "damage", "chaos", "attack", "ailment", "tincture" }, { "chaos_damage", "poison", "damage", "chaos", "attack", "ailment", "tincture" }, },
tincture = { manaBurn = 0.7, cooldown = 6 },
req = { },
}
itemBases["Blood Sap Tincture"] = {
type = "Tincture",
tags = { tincture = true, default = true, },
implicit = "20% chance to cause Bleeding with Melee Weapons\n(60-90)% increased Damage with Bleeding from Melee Weapons",
implicitModTypes = { { "physical_damage", "bleed", "damage", "physical", "attack", "ailment" }, { "physical_damage", "bleed", "damage", "physical", "attack", "ailment" }, },
implicitModTypes = { { "physical_damage", "bleed", "damage", "physical", "attack", "ailment", "tincture" }, { "physical_damage", "bleed", "damage", "physical", "attack", "ailment", "tincture" }, },
tincture = { manaBurn = 0.7, cooldown = 6 },
req = { },
}
itemBases["Oakbranch Tincture"] = {
type = "Tincture",
tags = { tincture = true, default = true, },
implicit = "Gain 3 Rage on Melee Weapon Hit",
implicitModTypes = { { "attack" }, },
implicitModTypes = { { "attack", "tincture" }, },
tincture = { manaBurn = 0.5, cooldown = 8 },
req = { },
}
itemBases["Sporebloom Tincture"] = {
type = "Tincture",
tags = { tincture = true, default = true, },
implicit = "25% chance to Blind Enemies on Hit with Melee Weapons\n(25-35)% increased Effect of Blind from Melee Weapons",
implicitModTypes = { { "attack" }, { "attack" }, },
implicitModTypes = { { "attack", "tincture" }, { "attack", "tincture" }, },
tincture = { manaBurn = 0.9, cooldown = 8 },
req = { },
}
Loading

0 comments on commit 8c474ba

Please sign in to comment.