first commit

This commit is contained in:
Lilian Jónsdóttir 2021-08-07 22:59:41 -07:00
commit e5d333e1cf
6 changed files with 223 additions and 0 deletions

View file

@ -0,0 +1,12 @@
local this = {}
this.modName = "A Sinking Feeling"
this.author = "Celediel"
this.modInfo = "No longer can you swim in heavy plate, now your armour, equipment or carried items drag you down while swimming.\n" ..
"Options exist for formulas based on equipped armour weight class, total equipment weight or encumbrance percentage."
this.version = "1.0.0"
this.configString = string.gsub(this.modName, "%s+", "")
this.modes = {equippedArmour = 0, allEquipment = 1, encumbrancePercentage = 2}
this.log = function(...) mwse.log("[%s] %s", "Armoured Sinking", string.format(...)) end
return this

View file

@ -0,0 +1,6 @@
local common = require("celediel.ASinkingFeeling.common")
local defaultConfig = {enabled = true, debug = false, downPullMultiplier = 100, mode = common.modes.equippedArmour}
local config = mwse.loadConfig(common.configString, defaultConfig)
return config

View file

@ -0,0 +1,88 @@
local config = require("celediel.ASinkingFeeling.config")
local common = require("celediel.ASinkingFeeling.common")
-- Helper Functions
local function getTotalArmourClass(actor)
local armourClass = 0
-- get armour level for each equipped piece of armour
-- light = 0, medium = 1, heavy = 2, plus one so light armour is affected
if actor and actor.equipment then
for stack in tes3.iterate(actor.equipment) do
local item = stack.object
if item.objectType == tes3.objectType.armor then
armourClass = armourClass + item.weightClass + 1
end
end
end
return armourClass
end
local function getTotalEquipmentWeight(actor)
local weight = 0
if actor and actor.equipment then
for stack in tes3.iterate(actor.equipment) do
local item = stack.object
weight = weight + item.weight
end
end
return weight
end
-- Event functions
local function sinkInWater(e)
-- don't even calculate anything if disabled
if not config.enabled then return end
-- shortcut refs
local mobile = e.mobile
local ref = e.reference
local actor = ref.object
-- no creatures
if mobile.actorType == tes3.actorType.creature then return end
local downPull = 0
-- calculate the down-pull with the configured formula
if config.mode == common.modes.equippedArmour then
local armourClass = getTotalArmourClass(actor)
downPull = (config.downPullMultiplier / 10) * armourClass
if config.debug then
common.log("Pulling %s down by %s using equipped armour mode (%s total armour class)",
ref.id, downPull, armourClass)
end
elseif config.mode == common.modes.allEquipment then
local totalWeight = getTotalEquipmentWeight(actor)
-- doubling this keeps this formula somewhat uniform with armour class @ multiplier 100
downPull = ((config.downPullMultiplier / 100) * totalWeight) * 2
if config.debug then
common.log("Pulling %s down by %s using equipment weight mode (%s total equipment weight)",
ref.id, downPull, totalWeight)
end
elseif config.mode == common.modes.encumbrancePercentage then
local encumbrance = mobile.encumbrance
-- tripling this keeps this formula somewhat uniform with armour class @ multiplier 100
downPull = (config.downPullMultiplier * encumbrance.normalized) * 3
if config.debug then
common.log("Pulling %s down by %s using encumbrance mode (%s/%s = %s encumbrance)",
ref.id, downPull, encumbrance.current, encumbrance.base, encumbrance.normalized)
end
end
-- finally add down-pull from configured formula to tes3.mobilePlayer.velocity.z to simulate being pulled down
tes3.mobilePlayer.velocity.z = -downPull
end
local function onInitialized()
event.register("calcSwimSpeed", sinkInWater)
common.log("Successfully initialized!")
end
event.register("initialized", onInitialized)
event.register("modConfigReady", function() mwse.mcm.register(require("celediel.ASinkingFeeling.mcm")) end)

View file

@ -0,0 +1,54 @@
local common = require("celediel.ASinkingFeeling.common")
local config = require("celediel.ASinkingFeeling.config")
local function createTableVar(id) return mwse.mcm.createTableVariable {id = id, table = config} end
local template = mwse.mcm.createTemplate(common.modName)
template:saveOnClose(common.configString, config)
local page = template:createSideBarPage({
label = "Sidebar Page???",
description = string.format("%s v%s by %s\n\n%s", common.modName, common.version, common.author, common.modInfo)
})
local category = page:createCategory(common.modName)
category:createYesNoButton({
label = "Enable the mod",
description = "Does what it says!",
variable = createTableVar("enabled")
})
category:createDropdown({
label = "Down-pull formula",
description = "Formula used to calculate down-pull amount.\n\nOptions are: Equipped Armour, Equipment Weight, Encumbrance\n\n" ..
"Equipped Armour: 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.\n\n" ..
"Equipment weight: Actors are pulled down by double the weight of all equipped gear multiplied by a hundredth of the down-pull multiplier.\n\n" ..
"Encumbrance: Actors are pulled down by their encumbrance percentage multiplied by triple the down-pull multiplier.\n\n" ..
"What is dead may never die.",
options = {
{ label = "Equipped Armour", value = common.modes.equippedArmour },
{ label = "All Equipment", value = common.modes.allEquipment },
{ label = "Encumbrance", value = common.modes.encumbrancePercentage }
},
variable = createTableVar("mode")
})
category:createSlider({
label = "Down-pull multiplier",
description = "Multiplier used in the selected formula.\n\nDefault value of 100 acts similarly in all formulas.",
variable = createTableVar("downPullMultiplier"),
min = 0,
max = 300,
step = 1,
jump = 10
})
category:createYesNoButton({
label = "Debug logging",
description = "Spam mwse.log with useless nonsense.",
variable = createTableVar("debug")
})
return template