Skip to content

Commit 161d3c4

Browse files
author
LocalIdentity
committed
Revert "Use offset mods for Cryogenesis redirect, label source"
This reverts commit baee98d.
1 parent baee98d commit 161d3c4

4 files changed

Lines changed: 76 additions & 8 deletions

File tree

src/Classes/ModDB.lua

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,44 @@ function ModDBClass:ReplaceModInternal(mod)
6666
return false
6767
end
6868

69+
---ConvertModInternal
70+
--- Converts an existing mod with oldName to a new mod with a different name.
71+
--- Moves the mod from the old name's bucket to the new name's bucket.
72+
--- If no matching mod exists, then the function returns false
73+
---@param oldName string @The name of the existing mod to find
74+
---@param mod table @The new mod to replace it with
75+
---@return boolean @Whether any mod was converted
76+
function ModDBClass:ConvertModInternal(oldName, mod)
77+
if not self.mods[oldName] then
78+
if self.parent then
79+
return self.parent:ConvertModInternal(oldName, mod)
80+
end
81+
return false
82+
end
83+
84+
local oldList = self.mods[oldName]
85+
for i = 1, #oldList do
86+
local curMod = oldList[i]
87+
if oldName == curMod.name and mod.type == curMod.type and mod.flags == curMod.flags and mod.keywordFlags == curMod.keywordFlags and mod.source == curMod.source and not curMod.converted then
88+
-- Remove from old name's bucket
89+
t_remove(oldList, i)
90+
-- Add to new name's bucket
91+
local newName = mod.name
92+
if not self.mods[newName] then
93+
self.mods[newName] = { }
94+
end
95+
mod.converted = true
96+
t_insert(self.mods[newName], mod)
97+
return true
98+
end
99+
end
100+
101+
if self.parent then
102+
return self.parent:ConvertModInternal(oldName, mod)
103+
end
104+
105+
return false
106+
end
69107

70108
function ModDBClass:AddList(modList)
71109
local mods = self.mods

src/Classes/ModList.lua

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,26 @@ function ModListClass:ReplaceModInternal(mod)
4545
return false
4646
end
4747

48+
---ConvertModInternal
49+
--- Converts an existing mod with oldName to a new mod with a different name.
50+
--- If no matching mod exists, then the function returns false
51+
---@param oldName string @The name of the existing mod to find
52+
---@param mod table @The new mod to replace it with
53+
---@return boolean @Whether any mod was converted
54+
function ModListClass:ConvertModInternal(oldName, mod)
55+
for i, curMod in ipairs(self) do
56+
if oldName == curMod.name and mod.type == curMod.type and mod.flags == curMod.flags and mod.keywordFlags == curMod.keywordFlags and mod.source == curMod.source then
57+
self[i] = mod
58+
return true
59+
end
60+
end
61+
62+
if self.parent then
63+
return self.parent:ConvertModInternal(oldName, mod)
64+
end
65+
66+
return false
67+
end
4868

4969
function ModListClass:MergeMod(mod, skipNonAdditive)
5070
if mod.type == "BASE" or mod.type == "INC" or mod.type == "MORE" then

src/Classes/ModStore.lua

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,18 @@ function ModStoreClass:ReplaceMod(...)
110110
end
111111
end
112112

113+
---ConvertMod
114+
--- Converts an existing mod to a new name, replacing it in the store.
115+
--- Finds a mod matching oldName with the same type, flags, keywordFlags, and source as the new mod.
116+
--- If no matching mod exists, the new mod is added instead.
117+
---@param oldName string @The name of the existing mod to convert
118+
---@param ... any @Parameters to be passed along to the modLib.createMod function (new name, type, value, source, ...)
119+
function ModStoreClass:ConvertMod(oldName, ...)
120+
local mod = mod_createMod(...)
121+
if not self:ConvertModInternal(oldName, mod) then
122+
self:AddMod(mod)
123+
end
124+
end
113125

114126
function ModStoreClass:Combine(modType, cfg, ...)
115127
if modType == "MORE" then

src/Modules/CalcOffence.lua

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3063,15 +3063,13 @@ function calcs.offence(env, actor, activeSkill)
30633063
if not skipRedirect then
30643064
for _, damageType in ipairs(dmgTypeList) do
30653065
if damageType ~= addedDamageRedirectType then
3066-
local addedMin = skillModList:Sum("BASE", cfg, damageType.."Min")
3067-
local addedMax = skillModList:Sum("BASE", cfg, damageType.."Max")
3068-
if addedMin ~= 0 then
3069-
skillModList:NewMod(damageType.."Min", "BASE", -addedMin, "Cryogenesis Conversion")
3070-
skillModList:NewMod(addedDamageRedirectType.."Min", "BASE", addedMin, "Cryogenesis Conversion")
3066+
for _, value in ipairs(skillModList:Tabulate("BASE", cfg, damageType.."Min")) do
3067+
local mod = value.mod
3068+
skillModList:ConvertMod(damageType.."Min", addedDamageRedirectType.."Min", "BASE", mod.value, mod.source, mod.flags, mod.keywordFlags, unpack(mod))
30713069
end
3072-
if addedMax ~= 0 then
3073-
skillModList:NewMod(damageType.."Max", "BASE", -addedMax, "Cryogenesis Conversion")
3074-
skillModList:NewMod(addedDamageRedirectType.."Max", "BASE", addedMax, "Cryogenesis Conversion")
3070+
for _, value in ipairs(skillModList:Tabulate("BASE", cfg, damageType.."Max")) do
3071+
local mod = value.mod
3072+
skillModList:ConvertMod(damageType.."Max", addedDamageRedirectType.."Max", "BASE", mod.value, mod.source, mod.flags, mod.keywordFlags, unpack(mod))
30753073
end
30763074
end
30773075
end

0 commit comments

Comments
 (0)