11tableHelper = require (" tableHelper" )
2+
23require (" utils" )
34
5+ --- @class contentFixer
46local contentFixer = {}
57
68local deadlyItems = { " keening" , " sunder" }
@@ -14,47 +16,48 @@ fixesByCell["-2, -10"] = { disable = { 297463, 297464, 297465, 297466 }}
1416-- Delete the census papers and unlock the doors
1517fixesByCell [" Seyda Neen, Census and Excise Office" ] = { disable = { 172859 }, unlock = { 119513 , 172860 }}
1618
19+ --- @param pid integer Player ID
20+ --- @param cellDescription string Cell Name
1721function 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
4547end
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
5356function 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
6972end
7073
74+ --- @param pid integer PlayerID
7175function contentFixer .AdjustSharedCorprusState (pid )
7276
7377 local corprusId = " corprus"
@@ -106,44 +110,47 @@ function contentFixer.AdjustSharedCorprusState(pid)
106110 end
107111end
108112
113+ --- @param journal table
114+ --- @return boolean madeAdjustment Has cell lost /gained corprus
109115function 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
125127end
126128
129+ --- @param eventStatus boolean
130+ --- @param pid integer Player ID
131+ --- @param playerPacket table
127132customEventHooks .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
139142end )
140143
144+
145+ --- @param eventStatus string
146+ --- @param pid integer Player ID
141147customEventHooks .registerHandler (" OnPlayerFinishLogin" , function (eventStatus , pid )
142148 if config .shareJournal == true then
143149 contentFixer .AdjustSharedCorprusState (pid )
144150 end
145151end )
146152
153+ --- @param eventStatus string
147154customEventHooks .registerHandler (" OnWorldReload" , function (eventStatus )
148155 if config .shareJournal == true then
149156 contentFixer .AdjustWorldCorprusVariables (WorldInstance .data .journal )
0 commit comments