diff --git a/MWSE/mods/celediel/ASinkingFeeling/common.lua b/MWSE/mods/celediel/ASinkingFeeling/common.lua index 8e7086f..82b3f0c 100644 --- a/MWSE/mods/celediel/ASinkingFeeling/common.lua +++ b/MWSE/mods/celediel/ASinkingFeeling/common.lua @@ -8,25 +8,31 @@ this.modInfo = "No longer can you swim in heavy plate; now your armour, equipmen this.version = "1.2.1" this.configString = string.gsub(this.modName, "%s+", "") this.modes = { - equippedArmour = { + { + mode = "equippedArmour", value = 0, description = "Actors are pulled down by their combined armour class (Light = 1, Medium = 2, Heavy = 3) multiplied by a tenth of " .. "the down-pull multiplier. Default of 100 makes it impossible to surface in all heavy armour for all but the most Athletic.", }, - allEquipment = { + { + mode = "allEquipment", value = 1, description = "Actors are pulled down by double the weight of all equipped gear multiplied by a hundredth of the down-pull multiplier.", }, - encumbrancePercentage = { - value = 2, - description = "Actors are pulled down by their encumbrance percentage multiplied by triple the down-pull multiplier.", - }, - allEquipmentNecroEdit = { + -- keeping these in this order but with the values unchanged is terrible and I don't care + { + mode = "allEquipmentNecroEdit", value = 3, description = "Actors are pulled down by double the weight of all equipped gear multiplied by a hundredth of the down-pull multiplier, " .. "except any weight above 135 only counts 10%. Lessens the gap between the lightest and heaviest heavy armours.", }, - worstCaseScenario = { + { + mode = "encumbrancePercentage", + value = 2, + description = "Actors are pulled down by their encumbrance percentage multiplied by triple the down-pull multiplier.", + }, + { + mode = "worstCaseScenario", value = 4, description = "Calculates results from all formulas, and uses the highest value.", } diff --git a/MWSE/mods/celediel/ASinkingFeeling/config.lua b/MWSE/mods/celediel/ASinkingFeeling/config.lua index 4ff5654..1bcc33f 100644 --- a/MWSE/mods/celediel/ASinkingFeeling/config.lua +++ b/MWSE/mods/celediel/ASinkingFeeling/config.lua @@ -11,7 +11,7 @@ this.defaultConfig = { allEquipment = 100, encumbrancePercentage = 100 }, - mode = common.modes.equippedArmour.value, + mode = common.modes[1].value, allEquipmentWorstCaseNecroMode = true } diff --git a/MWSE/mods/celediel/ASinkingFeeling/main.lua b/MWSE/mods/celediel/ASinkingFeeling/main.lua index ca98107..d8490b4 100644 --- a/MWSE/mods/celediel/ASinkingFeeling/main.lua +++ b/MWSE/mods/celediel/ASinkingFeeling/main.lua @@ -35,7 +35,7 @@ end -- Formula functions local formulas = {} -formulas.equippedArmour = function(actor, ref) +formulas.equippedArmour = function(actor, mobile, ref) local armourClass = getTotalArmourClass(actor) local downPull = (config.multipliers.equippedArmour / 10) * armourClass local debugStr = string.format("Pulling %s down by %s using equipped armour mode (%s total armour class)", @@ -43,7 +43,7 @@ formulas.equippedArmour = function(actor, ref) return downPull, debugStr end -formulas.allEquipment = function(actor, ref) +formulas.allEquipment = function(actor, mobile, ref) local totalWeight = getTotalEquipmentWeight(actor) -- doubling this keeps this formula somewhat uniform with armour class @ multiplier 100 local downPull = ((config.multipliers.allEquipment / 100) * totalWeight) * 2 @@ -52,7 +52,7 @@ formulas.allEquipment = function(actor, ref) return downPull, debugStr end -formulas.allEquipmentNecroEdit = function(actor, ref) +formulas.allEquipmentNecroEdit = function(actor, mobile, ref) local totalWeight = getTotalEquipmentWeight(actor) -- Thanks Necrolesian for this formula -- https://forums.nexusmods.com/index.php?/topic/10349253-a-sinking-feeling/page-2#entry97870268 @@ -64,7 +64,7 @@ formulas.allEquipmentNecroEdit = function(actor, ref) return downPull, debugStr end -formulas.encumbrancePercentage = function(mobile, ref) +formulas.encumbrancePercentage = function(actor, mobile, ref) local encumbrance = mobile.encumbrance -- tripling this keeps this formula somewhat uniform with armour class @ multiplier 100 local downPull = (config.multipliers.encumbrancePercentage * encumbrance.normalized) * 3 @@ -77,14 +77,15 @@ formulas.worstCaseScenario = function(actor, mobile, ref) local downPull = 0 local results = {} - -- todo: maybe loop over formulas to calculate each instead of this - -- different formulas needing different actor/mobile might make it too unwieldy though - results.equippedArmour = formulas.equippedArmour(actor, ref) - results.encumbrancePercentage = formulas.encumbrancePercentage(mobile, ref) - if config.allEquipmentWorstCaseNecroMode then - results.allEquipmentNecroEdit = formulas.allEquipmentNecroEdit(actor, ref) - else - results.allEquipment = formulas.allEquipment(actor, ref) + for mode, func in pairs(formulas) do + -- don't go recursive + if mode ~= "worstCaseScenario" then + -- sometimes I really wish lua had continue -_- + if (config.allEquipmentWorstCaseNecroMode and mode ~= "allEquipment") or + (not config.allEquipmentWorstCaseNecroMode and mode ~= "allEquipmentNecroEdit") then + results[mode] = func(actor, mobile, ref) + end + end end local largest = common.keyOfLargestValue(results) @@ -117,6 +118,14 @@ local function sinkInWater(e) if not config.enabled then downPull = 0 -- calculate the down-pull with the configured formula + else + for _, t in ipairs(common.modes) do + if t.value == config.mode then + downPull, debugStr = formulas[t.mode](actor, mobile, ref) + break + end + end + --[[ elseif config.mode == common.modes.equippedArmour.value then downPull, debugStr = formulas.equippedArmour(actor, ref) elseif config.mode == common.modes.allEquipment.value then @@ -127,6 +136,7 @@ local function sinkInWater(e) downPull, debugStr = formulas.encumbrancePercentage(mobile, ref) elseif config.mode == common.modes.worstCaseScenario.value then downPull, debugStr = formulas.worstCaseScenario(actor, mobile, ref) + --]] end -- reset if levitating diff --git a/MWSE/mods/celediel/ASinkingFeeling/mcm.lua b/MWSE/mods/celediel/ASinkingFeeling/mcm.lua index 2fc4420..776b3a9 100644 --- a/MWSE/mods/celediel/ASinkingFeeling/mcm.lua +++ b/MWSE/mods/celediel/ASinkingFeeling/mcm.lua @@ -9,8 +9,8 @@ local function createDescriptions() local options = "" -- list all current modes - for mode, _ in pairs(common.modes) do - options = options .. common.camelCaseToWords(mode) .. ", " + for _, t in ipairs(common.modes) do + options = options .. common.camelCaseToWords(t.mode) .. ", " end -- strip off ending ", " @@ -20,8 +20,8 @@ local function createDescriptions() description = description .. options -- add descriptions to description - for mode, t in pairs(common.modes) do - description = description .. "\n\n" .. common.camelCaseToWords(mode) .. ": " .. t.description + for _, t in ipairs(common.modes) do + description = description .. "\n\n" .. common.camelCaseToWords(t.mode) .. ": " .. t.description end return description @@ -30,8 +30,8 @@ end local function createOptions() local options = {} - for mode, t in pairs(common.modes) do - options[#options+1] = {label = common.camelCaseToWords(mode), value = t.value} + for _, t in ipairs(common.modes) do + options[#options+1] = {label = common.camelCaseToWords(t.mode), value = t.value} end return options