new mode: best case scenario
This commit is contained in:
parent
39898fed1a
commit
b3b54fbe0c
4 changed files with 54 additions and 16 deletions
|
@ -29,6 +29,10 @@ this.modes = {
|
||||||
{
|
{
|
||||||
mode = "worstCaseScenario",
|
mode = "worstCaseScenario",
|
||||||
description = "Calculates results from all formulas, and uses the highest value.",
|
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
|
return picked
|
||||||
end
|
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
|
return this
|
||||||
|
|
|
@ -12,7 +12,7 @@ this.defaultConfig = {
|
||||||
encumbrancePercentage = 100
|
encumbrancePercentage = 100
|
||||||
},
|
},
|
||||||
mode = common.modes[1].mode,
|
mode = common.modes[1].mode,
|
||||||
allEquipmentWorstCaseNecroMode = true
|
caseScenarioNecroMode = true
|
||||||
}
|
}
|
||||||
|
|
||||||
local currentConfig
|
local currentConfig
|
||||||
|
|
|
@ -35,6 +35,24 @@ end
|
||||||
-- Formula functions
|
-- Formula functions
|
||||||
local formulas = {}
|
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)
|
formulas.equippedArmour = function(actor, mobile, ref)
|
||||||
local armourClass = getTotalArmourClass(actor)
|
local armourClass = getTotalArmourClass(actor)
|
||||||
local downPull = (config.multipliers.equippedArmour / 10) * armourClass
|
local downPull = (config.multipliers.equippedArmour / 10) * armourClass
|
||||||
|
@ -76,17 +94,7 @@ end
|
||||||
formulas.worstCaseScenario = function(actor, mobile, ref)
|
formulas.worstCaseScenario = function(actor, mobile, ref)
|
||||||
local downPull = 0
|
local downPull = 0
|
||||||
|
|
||||||
local results = {}
|
local results = calculateAll(actor, mobile, 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)
|
local largest = common.keyOfLargestValue(results)
|
||||||
downPull = results[largest]
|
downPull = results[largest]
|
||||||
|
@ -96,6 +104,19 @@ formulas.worstCaseScenario = function(actor, mobile, ref)
|
||||||
return downPull, debugStr
|
return downPull, debugStr
|
||||||
end
|
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
|
-- Event functions
|
||||||
local function sinkInWater(e)
|
local function sinkInWater(e)
|
||||||
-- shortcut refs
|
-- shortcut refs
|
||||||
|
|
|
@ -67,13 +67,13 @@ category:createDropdown({
|
||||||
})
|
})
|
||||||
|
|
||||||
category:createDropdown({
|
category:createDropdown({
|
||||||
label = "Worst Case Scenario All Equipment variety",
|
label = "Worst or Best Case Scenario All Equipment variety",
|
||||||
description = "Chooses which variety of the All Equipment formula is used when Worst Case Scenario is selected",
|
description = "Chooses which variety of the All Equipment formula is used when Worst or Best Case Scenario is selected.",
|
||||||
options = {
|
options = {
|
||||||
{ label = "Original Formula", value = false },
|
{ label = "Original Formula)", value = false },
|
||||||
{ label = "Necro Edit", value = true }
|
{ label = "Necro Edit", value = true }
|
||||||
},
|
},
|
||||||
variable = createTableVar("allEquipmentWorstCaseNecroMode")
|
variable = createTableVar("caseScenarioNecroMode")
|
||||||
})
|
})
|
||||||
|
|
||||||
for name, _ in pairs(config.defaultConfig.multipliers) do
|
for name, _ in pairs(config.defaultConfig.multipliers) do
|
||||||
|
|
Loading…
Add table
Reference in a new issue