Refactored _00E_Theriantrophist_AlchemyControl to use vanilla arrays, removed JContainers requirement

This commit is contained in:
Eddoursul 2022-08-01 19:48:43 +02:00
parent 3923bfcfe5
commit 0c8c29a779
10 changed files with 107 additions and 110 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -1,13 +0,0 @@
Scriptname _00E_Func_CheckJContainers Hidden
Function Run() global
Int SKSEVer = SKSE.GetVersion()
if (SKSEVer == 0 || (SKSE.GetPluginVersion("JContainers64") == -1) && (SKSE.GetPluginVersion("JContainersVR") == -1))
; JContainers is only required for lycanthropy, so we just nag users without preventing playing without it
Utility.wait(2.0)
Debug.MessageBox("JContainers is not loaded! The game will not run properly. Verify integrity of your files or reinstall JContainers.")
endif
EndFunction

View File

@ -23,7 +23,6 @@ Event OnInit()
_00E_Func_CheckSKSE.Run()
_00E_Func_CheckEnderalDLL.Run()
_00E_Func_CheckJContainers.Run()
If fPatchVersion == 0.00
fPatchVersion = CURRENT_PATCH_VERSION
@ -58,7 +57,6 @@ Event OnPlayerLoadGame()
_00E_Func_CheckSKSE.Run()
_00E_Func_CheckEnderalDLL.Run()
_00E_Func_CheckJContainers.Run()
Maintenance()
If GetState() != "RealPlayer" ; Post-1.2.5.0 version update

View File

@ -77,41 +77,64 @@ Int Property NoAlchemistPotionDurationLimitInSeconds = 90 Autoreadonly Hidden
_00E_FS_NQ11_Functions Property FS_NQ11 Auto
Int Property RenamedPotions Hidden
Int Function Get()
Int result = JMap.getObj(JDB.root(), "EnderalFS.RenamedPotions")
if (result == 0)
result = JFormMap.object()
JMap.setObj(JDB.root(), "EnderalFS.RenamedPotions", result)
EndIf
return result
EndFunction
EndProperty
Int Property ModelChangedPotions Hidden
Int Function Get()
Int result = JMap.getObj(JDB.root(), "EnderalFS.ModelChangedPotions")
If (result == 0)
result = JFormMap.object()
JMap.setObj(JDB.root(), "EnderalFS.ModelChangedPotions", result)
EndIf
return result
EndFunction
EndProperty
bool bDoneDarkBlood = false
bool bDoneChymikum = false
Int curScriptVersion = 0
Int Property LATEST_SCRIPT_VERSION = 5 AutoReadOnly
bool bHasJContainers = false
Potion[] aCreatedPotions
string[] aPotionNames
string[] aPotionModels
;=====================================================================================
; FUNCTIONS
;=====================================================================================
function _addNamedPotion(Potion aPotion, string sName, string sModel)
if ! aPotion || sName == ""
return
endif
aPotion.SetName(sName)
if sModel != ""
aPotion.SetWorldModelPath(sModel)
endif
if aCreatedPotions.length == 0
aCreatedPotions = new Potion[128]
aPotionNames = new string[128]
aPotionModels = new string[128]
endif
int i = aCreatedPotions.Find(aPotion)
if i == -1
i = aCreatedPotions.Find(none)
if i > -1
aCreatedPotions[i] = aPotion
aPotionNames[i] = sName
aPotionModels[i] = sModel
endif
else
aPotionNames[i] = sName
aPotionModels[i] = sModel
endif
endfunction
function _removeNamedPotion(Potion aPotion)
if aPotion
int i = aCreatedPotions.Find(aPotion)
if i > -1
aCreatedPotions[i] = None
aPotionNames[i] = ""
aPotionModels[i] = ""
endif
endif
endfunction
Function _UpdatePotion(Potion item, Int count)
Int i
@ -196,10 +219,11 @@ Function _UpdatePotion(Potion item, Int count)
Potion newPotion = EnderalFunctions.CreatePotion(newEffects, newMagnitudes, newAreas, newDurations, nNewEffects)
If bHasJContainers && JFormMap.hasKey(RenamedPotions, newPotion) == False
_RenamePotion(newPotion, newEffects, nNewEffects, bRemoveTheriantrophistEffects)
_SetPotionModel(newPotion, firstTheriantrophistEffect, newEffects[0])
EndIf
if aCreatedPotions.Find(newPotion) == -1
string newName = _RenamePotion(newPotion, newEffects, nNewEffects, bRemoveTheriantrophistEffects)
string newModel = _SetPotionModel(newPotion, firstTheriantrophistEffect, newEffects[0])
_addNamedPotion(newPotion, newName, newModel)
endif
GoToState("") ; skip OnItemAdded
PlayerREF.addItem(newPotion, count, abSilent = true)
@ -213,10 +237,11 @@ Function _UpdatePotion(Potion item, Int count)
EndIf
if bHasJContainers && JFormMap.hasKey(RenamedPotions, item) == False ; COMMON POTION
_RenamePotion(item, potionEffects, nPotionEffects, True)
_SetPotionModel(item, None, potionEffects[0])
EndIf
if aCreatedPotions.Find(item) == -1
string newNameC = _RenamePotion(item, potionEffects, nPotionEffects, True)
string newModelC = _SetPotionModel(item, None, potionEffects[0])
_addNamedPotion(item, newNameC, newModelC)
endif
if bIsTheriantrophistPotion
_UpdateNQ11(item)
@ -224,7 +249,7 @@ Function _UpdatePotion(Potion item, Int count)
EndFunction
Function _RenamePotion(Potion p, MagicEffect[] potionEffects, Int nPotionEffects, Bool bCommonPotion)
String Function _RenamePotion(Potion p, MagicEffect[] potionEffects, Int nPotionEffects, Bool bCommonPotion)
String name = ""
If bCommonPotion
@ -245,12 +270,11 @@ Function _RenamePotion(Potion p, MagicEffect[] potionEffects, Int nPotionEffects
nEffectsAdded += 1
i += 1
EndWhile
JFormMap.setStr(RenamedPotions, p, name)
p.setName(name)
return name
EndFunction
Function _SetPotionModel(Potion p, MagicEffect firstTheriantrophistEffect, MagicEffect firstEffect)
String Function _SetPotionModel(Potion p, MagicEffect firstTheriantrophistEffect, MagicEffect firstEffect)
string modelName
string modelPath = ""
@ -321,10 +345,7 @@ Function _SetPotionModel(Potion p, MagicEffect firstTheriantrophistEffect, Magic
EndIf
If modelPath != ""
p.SetWorldModelPath(modelPath)
JFormMap.setStr(ModelChangedPotions, p, modelPath)
EndIf
return modelPath
EndFunction
Function _UpdateNQ11(Potion newPotion)
@ -366,23 +387,6 @@ Function _InitAchemyControl()
GoToState("")
int iSKSEVer = SKSE.GetVersion()
if iSKSEVer < 2
bHasJContainers = false
Debug.Trace("SKSE is not loaded, _00E_Theriantrophist_AlchemyControl is disabled")
return
endif
bHasJContainers = ( (SKSE.GetPluginVersion("JContainers64") != -1) || (SKSE.GetPluginVersion("JContainersVR") != -1) ) && JContainers.isInstalled()
if ! bHasJContainers && ! EnderalFunctions.IsDLLLoaded()
; Both required components are missing, do not update version and disable everything
UnregisterForAllMenus()
Debug.Trace("JContainers and fs.dll are not loaded, _00E_Theriantrophist_AlchemyControl is disabled.")
return
endif
; Version update
If curScriptVersion < LATEST_SCRIPT_VERSION
Int oldScriptVersion = curScriptVersion
@ -392,47 +396,15 @@ Function _InitAchemyControl()
RemoveAllInventoryEventFilters()
UnregisterForAllMenus()
UnregisterForUpdate()
_00E_Theriantrophist_Update_12.Run(self)
EndIf
EndIf
if ! bHasJContainers
Debug.Trace("JContainers is not loaded, renaming and changing potion models is disabled")
endif
; Re-register menu listener to stay resilient to co-save deletion or corruption
RegisterForMenu("Crafting Menu")
EndFunction
Function _OnGameLoadJContainers()
Potion k
Potion previousKey
Int potionNames = RenamedPotions
k = JFormMap.nextKey(potionNames, previousKey = None, endKey = None) as Potion
while k != None
; Forget items that are no longer in the inventory
if PlayerREF.GetItemCount(k) == 0 && _00E_SecureChest_HostChestREF.GetItemCount(k) == 0
JFormMap.removeKey(RenamedPotions, k)
JFormMap.removeKey(ModelChangedPotions, k)
k = JFormMap.nextKey(potionNames, previousKey, endKey = None) as Potion
else
previousKey = k
k.setName(JFormMap.getStr(potionNames, k))
k = JFormMap.nextKey(potionNames, k, endKey = None) as Potion
endif
endwhile
Int potionModels = ModelChangedPotions
k = JFormMap.nextKey(potionModels, previousKey = None, endKey = None) as Potion
while k != None
k.SetWorldModelPath(JFormMap.getStr(potionModels, k))
k = JFormMap.nextKey(potionModels, k, endKey = None) as Potion
endwhile
EndFunction
;=====================================================================================
; EVENTS
@ -448,10 +420,14 @@ EndEvent
State InCrafting
Event OnItemAdded(Form baseItem, int count, ObjectReference itemRef, ObjectReference source)
if ! UI.IsMenuOpen("Crafting Menu")
GoToState("")
return
endif
Potion item = baseItem as Potion
If item
; Ignore not-custom potions (with FormID not starting with 0xFF) or already registered potions
If (Math.LogicalAnd(item.GetFormID(), 0xFF000000) == 0xFF000000) && (!bHasJContainers || JFormMap.hasKey(RenamedPotions, item) == False)
If (Math.LogicalAnd(item.GetFormID(), 0xFF000000) == 0xFF000000) && aCreatedPotions.Find(item) == -1
_UpdatePotion(item, count)
EndIf
EndIf
@ -465,7 +441,23 @@ EndEvent
Event OnPlayerLoadGame()
_InitAchemyControl()
if bHasJContainers
_OnGameLoadJContainers()
if aCreatedPotions.length == 0
return
endif
int i = 0
while i < 128
if aCreatedPotions[i]
if PlayerREF.GetItemCount(aCreatedPotions[i]) == 0 && _00E_SecureChest_HostChestREF.GetItemCount(aCreatedPotions[i]) == 0
_removeNamedPotion(aCreatedPotions[i])
else
aCreatedPotions[i].SetName(aPotionNames[i])
if aPotionModels[i] != ""
aCreatedPotions[i].SetWorldModelPath(aPotionModels[i])
endif
endif
endif
i += 1
endwhile
EndEvent

View File

@ -0,0 +1,19 @@
scriptname _00E_Theriantrophist_Update_12 Hidden
function Run(_00E_Theriantrophist_AlchemyControl PlayerAlias) global
Potion k
int potionNames = JMap.getObj(JDB.root(), "EnderalFS.RenamedPotions")
int potionModels = JMap.getObj(JDB.root(), "EnderalFS.ModelChangedPotions")
if potionNames > 0
k = JFormMap.nextKey(potionNames, previousKey = None, endKey = None) as Potion
while k != None
PlayerAlias._addNamedPotion(k, JFormMap.getStr(potionNames, k), JFormMap.getStr(potionModels, k))
k = JFormMap.nextKey(potionNames, k, endKey = None) as Potion
endwhile
JFormMap.clear(potionNames)
JFormMap.clear(potionModels)
endif
endfunction

View File

@ -9,5 +9,6 @@ ObjectReference function GetCurrentContainer() native global
int function GetNewGameCount() native global
bool function IsDLLLoaded() global
return (SKSE.GetPluginVersion("EnderalSE") != -1)
int iVer = SKSE.GetPluginVersion("EnderalSE")
return iVer > 0
endfunction