diff --git a/MWSE/mods/celediel/ASinkingFeeling/common.lua b/MWSE/mods/celediel/ASinkingFeeling/common.lua index 38b6567..8df268c 100644 --- a/MWSE/mods/celediel/ASinkingFeeling/common.lua +++ b/MWSE/mods/celediel/ASinkingFeeling/common.lua @@ -29,6 +29,10 @@ this.modes = { { mode = "worstCaseScenario", description = "Calculates results from all formulas, and uses the highest value.", + }, + { + mode = "bestCaseScenario", + description = "Calculates results from all formulas, and uses the lowest value.", } } @@ -60,4 +64,17 @@ this.keyOfLargestValue = function(t) return picked end +-- picks the key of the smallest value out of a key:whatever, value:number table +this.keyOfSmallestValue = function(t) + local picked + local smallest = math.huge + for key, value in pairs(t) do + if value < smallest then + smallest = value + picked = key + end + end + return picked +end + return this diff --git a/MWSE/mods/celediel/ASinkingFeeling/config.lua b/MWSE/mods/celediel/ASinkingFeeling/config.lua index 19d64cb..0fe62da 100644 --- a/MWSE/mods/celediel/ASinkingFeeling/config.lua +++ b/MWSE/mods/celediel/ASinkingFeeling/config.lua @@ -12,7 +12,7 @@ this.defaultConfig = { encumbrancePercentage = 100 }, mode = common.modes[1].mode, - allEquipmentWorstCaseNecroMode = true + caseScenarioNecroMode = true } local currentConfig diff --git a/MWSE/mods/celediel/ASinkingFeeling/main.lua b/MWSE/mods/celediel/ASinkingFeeling/main.lua index 9cb914c..07c0bb8 100644 --- a/MWSE/mods/celediel/ASinkingFeeling/main.lua +++ b/MWSE/mods/celediel/ASinkingFeeling/main.lua @@ -35,6 +35,24 @@ end -- Formula functions local formulas = {} +-- Formula helper +local function calculateAll(actor, mobile, ref) + local results = {} + + for mode, func in pairs(formulas) do + -- don't go recursive + if not string.find(mode, "CaseScenario") then + -- sometimes I really wish lua had continue -_- + if (config.caseScenarioNecroMode and mode ~= "allEquipment") or + (not config.caseScenarioNecroMode and mode ~= "allEquipmentNecroEdit") then + results[mode] = func(actor, mobile, ref) + end + end + end + + return results +end + formulas.equippedArmour = function(actor, mobile, ref) local armourClass = getTotalArmourClass(actor) local downPull = (config.multipliers.equippedArmour / 10) * armourClass @@ -76,17 +94,7 @@ end formulas.worstCaseScenario = function(actor, mobile, ref) local downPull = 0 - local results = {} - 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 results = calculateAll(actor, mobile, ref) local largest = common.keyOfLargestValue(results) downPull = results[largest] @@ -96,6 +104,19 @@ formulas.worstCaseScenario = function(actor, mobile, ref) return downPull, debugStr end +formulas.bestCaseScenario = function(actor, mobile, ref) + local downPull = 0 + + local results = calculateAll(actor, mobile, ref) + + local smallest = common.keyOfSmallestValue(results) + downPull = results[smallest] + + local debugStr = string.format("Pulling %s down by %s using best mode:%s", ref.id, downPull, common.camelCaseToWords(smallest)) + + return downPull, debugStr +end + -- Event functions local function sinkInWater(e) -- shortcut refs diff --git a/MWSE/mods/celediel/ASinkingFeeling/mcm.lua b/MWSE/mods/celediel/ASinkingFeeling/mcm.lua index 2988ea6..8ce8654 100644 --- a/MWSE/mods/celediel/ASinkingFeeling/mcm.lua +++ b/MWSE/mods/celediel/ASinkingFeeling/mcm.lua @@ -67,13 +67,13 @@ category:createDropdown({ }) category:createDropdown({ - label = "Worst Case Scenario All Equipment variety", - description = "Chooses which variety of the All Equipment formula is used when Worst Case Scenario is selected", + label = "Worst or Best Case Scenario All Equipment variety", + description = "Chooses which variety of the All Equipment formula is used when Worst or Best Case Scenario is selected.", options = { - { label = "Original Formula", value = false }, + { label = "Original Formula)", value = false }, { label = "Necro Edit", value = true } }, - variable = createTableVar("allEquipmentWorstCaseNecroMode") + variable = createTableVar("caseScenarioNecroMode") }) for name, _ in pairs(config.defaultConfig.multipliers) do