Skip to content
This repository was archived by the owner on Jul 17, 2025. It is now read-only.

Commit 85dc572

Browse files
authored
refactor: added notation and and added additional type checks
2 parents 8ecf792 + ab40960 commit 85dc572

File tree

2 files changed

+70
-50
lines changed

2 files changed

+70
-50
lines changed

scripts/contentFixer.lua

Lines changed: 45 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
tableHelper = require("tableHelper")
2+
23
require("utils")
34

5+
---@class contentFixer
46
local contentFixer = {}
57

68
local deadlyItems = { "keening", "sunder" }
@@ -14,47 +16,48 @@ fixesByCell["-2, -10"] = { disable = { 297463, 297464, 297465, 297466 }}
1416
-- Delete the census papers and unlock the doors
1517
fixesByCell["Seyda Neen, Census and Excise Office"] = { disable = { 172859 }, unlock = { 119513, 172860 }}
1618

19+
---@param pid integer Player ID
20+
---@param cellDescription string Cell Name
1721
function contentFixer.FixCell(pid, cellDescription)
22+
if fixesByCell[cellDescription] == nil then return end
1823

19-
if fixesByCell[cellDescription] ~= nil then
20-
21-
for action, refNumArray in pairs(fixesByCell[cellDescription]) do
24+
for action, refNumArray in pairs(fixesByCell[cellDescription]) do
2225

23-
dreamweave.ClearObjectList()
24-
dreamweave.SetObjectListPid(pid)
25-
dreamweave.SetObjectListCell(cellDescription)
26+
dreamweave.ClearObjectList()
27+
dreamweave.SetObjectListPid(pid)
28+
dreamweave.SetObjectListCell(cellDescription)
2629

27-
for arrayIndex, refNum in ipairs(refNumArray) do
28-
dreamweave.SetObjectRefNum(refNum)
29-
dreamweave.SetObjectMpNum(0)
30-
dreamweave.SetObjectRefId("")
31-
if action == "disable" then dreamweave.SetObjectState(false) end
32-
if action == "unlock" then dreamweave.SetObjectLockLevel(0) end
33-
dreamweave.AddObject()
34-
end
30+
for arrayIndex, refNum in ipairs(refNumArray) do
31+
dreamweave.SetObjectRefNum(refNum)
32+
dreamweave.SetObjectMpNum(0)
33+
dreamweave.SetObjectRefId("")
34+
if action == "disable" then dreamweave.SetObjectState(false) end
35+
if action == "unlock" then dreamweave.SetObjectLockLevel(0) end
36+
dreamweave.AddObject()
37+
end
3538

36-
if action == "delete" then
37-
dreamweave.SendObjectDelete()
38-
elseif action == "disable" then
39-
dreamweave.SendObjectState()
40-
elseif action == "unlock" then
41-
dreamweave.SendObjectLock()
42-
end
39+
if action == "delete" then
40+
dreamweave.SendObjectDelete()
41+
elseif action == "disable" then
42+
dreamweave.SendObjectState()
43+
elseif action == "unlock" then
44+
dreamweave.SendObjectLock()
4345
end
4446
end
4547
end
4648

4749
-- Unequip items that damage the player when worn
4850
--
4951
-- Note: Items with constant damage effects like Whitewalker and the Mantle of Woe
50-
-- are already unequipped by default in the TES3MP client, so this only needs
52+
-- are already unequipped by default in the dreamweave client, so this only needs
5153
-- to account for scripted items that are missed there
5254
--
55+
---@param pid integer Player ID
5356
function contentFixer.UnequipDeadlyItems(pid)
5457

5558
local itemsFound = 0
5659

57-
for arrayIndex, itemRefId in pairs(deadlyItems) do
60+
for _, itemRefId in pairs(deadlyItems) do
5861
if tableHelper.containsKeyValue(Players[pid].data.equipment, "refId", itemRefId, true) then
5962
local itemSlot = tableHelper.getIndexByNestedKeyValue(Players[pid].data.equipment, "refId", itemRefId, true)
6063
Players[pid].data.equipment[itemSlot] = nil
@@ -68,6 +71,7 @@ function contentFixer.UnequipDeadlyItems(pid)
6871
end
6972
end
7073

74+
---@param pid integer PlayerID
7175
function contentFixer.AdjustSharedCorprusState(pid)
7276

7377
local corprusId = "corprus"
@@ -106,44 +110,47 @@ function contentFixer.AdjustSharedCorprusState(pid)
106110
end
107111
end
108112

113+
---@param journal table
114+
---@return boolean madeAdjustment Has cell lost/gained corprus
109115
function contentFixer.AdjustWorldCorprusVariables(journal)
110-
111-
local madeAdjustment = false
112-
113116
for _, journalItem in ipairs(journal) do
114-
115117
if journalItem.quest == "a2_3_corpruscure" and journalItem.index >= 50 then
116118
WorldInstance.data.customVariables.corprusCured = true
117-
madeAdjustment = true
119+
return true
118120
elseif journalItem.quest == "a2_2_6thhouse" and journalItem.index >= 50 then
119121
WorldInstance.data.customVariables.corprusGained = true
120-
madeAdjustment = true
122+
return true
121123
end
122124
end
123125

124-
return madeAdjustment
126+
return false
125127
end
126128

129+
---@param eventStatus boolean
130+
---@param pid integer Player ID
131+
---@param playerPacket table
127132
customEventHooks.registerHandler("OnPlayerJournal", function(eventStatus, pid, playerPacket)
128-
if config.shareJournal == true then
129-
local madeAdjustment = contentFixer.AdjustWorldCorprusVariables(playerPacket.journal)
133+
if config.shareJournal == false then return end
134+
local madeAdjustment = contentFixer.AdjustWorldCorprusVariables(playerPacket.journal)
130135

131-
if madeAdjustment == true then
132-
for otherPid, otherPlayer in pairs(Players) do
133-
if otherPid ~= pid then
134-
contentFixer.AdjustSharedCorprusState(otherPid)
135-
end
136-
end
136+
if madeAdjustment == false then return end
137+
for otherPid, otherPlayer in pairs(Players) do
138+
if otherPid ~= pid then
139+
contentFixer.AdjustSharedCorprusState(otherPid)
137140
end
138141
end
139142
end)
140143

144+
145+
---@param eventStatus string
146+
---@param pid integer Player ID
141147
customEventHooks.registerHandler("OnPlayerFinishLogin", function(eventStatus, pid)
142148
if config.shareJournal == true then
143149
contentFixer.AdjustSharedCorprusState(pid)
144150
end
145151
end)
146152

153+
---@param eventStatus string
147154
customEventHooks.registerHandler("OnWorldReload", function(eventStatus)
148155
if config.shareJournal == true then
149156
contentFixer.AdjustWorldCorprusVariables(WorldInstance.data.journal)

scripts/customCommandHooks.lua

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
2020
]]
2121

22-
22+
---@class customCommandHooks
2323
local customCommandHooks = {}
2424

2525
local specialCharacter = "/"
@@ -28,45 +28,58 @@ customCommandHooks.commands = {}
2828
customCommandHooks.rankRequirement = {}
2929
customCommandHooks.nameRequirement = {}
3030

31+
32+
---@param cmd string Command Syntax
33+
---@param callback string Command Response
3134
function customCommandHooks.registerCommand(cmd, callback)
35+
if type(cmd) ~= "string" then return end
3236
customCommandHooks.commands[cmd] = callback
3337
end
3438

39+
---@param cmd string Command Syntax
3540
function customCommandHooks.removeCommand(cmd)
41+
if type(cmd) ~= "string" then return end
3642
customCommandHooks.commands[cmd] = nil
3743
customCommandHooks.rankRequirement[cmd] = nil
3844
customCommandHooks.nameRequirement[cmd] = nil
3945
end
4046

47+
---@param cmd string Command Syntax
4148
function customCommandHooks.getCallback(cmd)
49+
if type(cmd) ~= "string" then return end
4250
return customCommandHooks.commands[cmd]
4351
end
4452

53+
---@param cmd string Command Syntax
54+
---@param rank string Permission Level
4555
function customCommandHooks.setRankRequirement(cmd, rank)
46-
if customCommandHooks.commands[cmd] ~= nil then
47-
customCommandHooks.rankRequirement[cmd] = rank
48-
end
56+
if customCommandHooks.commands[cmd] == nil or type(cmd) ~= "string" then return end
57+
customCommandHooks.rankRequirement[cmd] = rank
4958
end
5059

60+
---@param cmd string Command Syntax
5161
function customCommandHooks.removeRankRequirement(cmd)
5262
customCommandHooks.rankRequirement[cmd] = nil
5363
end
5464

65+
---@param cmd string Command Syntax
66+
---@param names string Name
5567
function customCommandHooks.setNameRequirement(cmd, names)
56-
if customCommandHooks.commands[cmd] ~= nil then
57-
customCommandHooks.nameRequirement[cmd] = names
58-
end
68+
if customCommandHooks.commands[cmd] ~= nil or type(cmd) ~= "string" then return end
69+
customCommandHooks.nameRequirement[cmd] = names
5970
end
6071

6172
function customCommandHooks.addNameRequirement(cmd, name)
62-
if customCommandHooks.commands[cmd] ~= nil then
63-
if customCommandHooks.nameRequirement[cmd] == nil then
64-
customCommandHooks.nameRequirement[cmd] = {}
65-
end
66-
table.insert(customCommandHooks.nameRequirement[cmd], name)
73+
if customCommandHooks.commands[cmd] == nil or type(cmd) ~= "string" then return end
74+
75+
if customCommandHooks.nameRequirement[cmd] == nil then
76+
customCommandHooks.nameRequirement[cmd] = {}
6777
end
78+
79+
table.insert(customCommandHooks.nameRequirement[cmd], name)
6880
end
6981

82+
---@param cmd string Command Syntax
7083
function customCommandHooks.removeNameRequirement(cmd)
7184
customCommandHooks.nameRequirement[cmd] = nil
7285
end

0 commit comments

Comments
 (0)