1
Fork 0

_00E_Theriantrophist_AlchemyControl: unregister potions on game load instead of in OnItemAdded, do not unregister potions in the secure chest

development
Eddoursul 2 years ago
parent 3b5bc3fffe
commit 4737d589a2
  1. BIN
      TheriantrophistControlQuest optimization and graceful degradation.esp
  2. BIN
      scripts/_00e_theriantrophist_alchemycontrol.pex
  3. 166
      source/scripts/_00e_theriantrophist_alchemycontrol.psc

@ -66,6 +66,8 @@ MagicEffect Property AlchRestoreStamina Auto
FormList Property _00E_EmptyFormlist Auto FormList Property _00E_EmptyFormlist Auto
ObjectReference Property _00E_SecureChest_HostChestREF Auto
Int Property GreyAlchemist2PotionDurationLimitInSeconds = 180 Autoreadonly Hidden Int Property GreyAlchemist2PotionDurationLimitInSeconds = 180 Autoreadonly Hidden
{The potion duration of all werewolf potions is limited to this amount if the player has the first and second perk grey alchemist} {The potion duration of all werewolf potions is limited to this amount if the player has the first and second perk grey alchemist}
Int Property GreyAlchemist1PotionDurationLimitInSeconds = 120 Autoreadonly Hidden Int Property GreyAlchemist1PotionDurationLimitInSeconds = 120 Autoreadonly Hidden
@ -101,7 +103,7 @@ bool bDoneDarkBlood = false
bool bDoneChymikum = false bool bDoneChymikum = false
Int curScriptVersion = 0 Int curScriptVersion = 0
Int Property LATEST_SCRIPT_VERSION = 4 AutoReadOnly Int Property LATEST_SCRIPT_VERSION = 5 AutoReadOnly
bool bHasJContainers = false bool bHasJContainers = false
@ -120,8 +122,6 @@ Function _UpdatePotion(Potion item, Int count)
If bIsTheriantrophistPotion && EnderalLib.IsDLLLoaded() ; FRESHLY BREWN THERIANTROPHIST POTION If bIsTheriantrophistPotion && EnderalLib.IsDLLLoaded() ; FRESHLY BREWN THERIANTROPHIST POTION
Debug.Notification("Replacing theriantrophist potion")
PlayerREF.removeItem(item, count, abSilent = true) PlayerREF.removeItem(item, count, abSilent = true)
Bool bRemoveTheriantrophistEffects = False Bool bRemoveTheriantrophistEffects = False
@ -156,7 +156,7 @@ Function _UpdatePotion(Potion item, Int count)
EndIf EndIf
Else Else
Int maxDuration = NoAlchemistPotionDurationLimitInSeconds Int maxDuration = NoAlchemistPotionDurationLimitInSeconds
Int durationBonus = PlayerREF.GetAV("Variable02") as Int Int durationBonus = PlayerREF.GetActorValue("Variable02") as Int
If PlayerREF.hasPerk(_00E_Class_Theriantrophist_P03_GreyAlchemist_03) If PlayerREF.hasPerk(_00E_Class_Theriantrophist_P03_GreyAlchemist_03)
maxDuration = -1 ; no duration mali are required maxDuration = -1 ; no duration mali are required
@ -225,7 +225,6 @@ Function _UpdatePotion(Potion item, Int count)
EndFunction EndFunction
Function _RenamePotion(Potion p, MagicEffect[] potionEffects, Int nPotionEffects, Bool bCommonPotion) Function _RenamePotion(Potion p, MagicEffect[] potionEffects, Int nPotionEffects, Bool bCommonPotion)
Debug.Notification("Renaming potion")
String name = "" String name = ""
If bCommonPotion If bCommonPotion
@ -335,16 +334,16 @@ Function _UpdateNQ11(Potion newPotion)
Bool bUpdateNQ11 = False Bool bUpdateNQ11 = False
If newPotion.HasKeyword(_00E_Theriantrophist_ChymikumLife) && FS_NQ11.GetStage() >= 10 && !bDoneChymikum If newPotion.HasKeyword(_00E_Theriantrophist_ChymikumLife) && FS_NQ11.GetCurrentStageID() >= 10 && !bDoneChymikum
bDoneChymikum = True bDoneChymikum = True
bUpdateNQ11 = True bUpdateNQ11 = True
EndIf EndIf
If newPotion.HasKeyword(_00E_Theriantrophist_DarkBloodEffect) && FS_NQ11.GetStage() >= 10 && !bDoneDarkBlood If newPotion.HasKeyword(_00E_Theriantrophist_DarkBloodEffect) && FS_NQ11.GetCurrentStageID() >= 10 && !bDoneDarkBlood
bDoneDarkBlood = True bDoneDarkBlood = True
bUpdateNQ11 = True bUpdateNQ11 = True
EndIf EndIf
If bUpdateNQ11 && FS_NQ11.GetStage() < 17 If bUpdateNQ11 && FS_NQ11.GetCurrentStageID() < 17
FS_NQ11.ShowTutorial(2) FS_NQ11.ShowTutorial(2)
If bDoneChymikum && bDoneDarkBlood If bDoneChymikum && bDoneDarkBlood
@ -358,71 +357,29 @@ Function _UpdateNQ11(Potion newPotion)
EndFunction EndFunction
Function _SetNewStageNQ11(Int newStage) Function _SetNewStageNQ11(Int newStage)
If newStage > FS_NQ11.GetStage() If newStage > FS_NQ11.GetCurrentStageID()
FS_NQ11.SetStage(newStage) FS_NQ11.SetCurrentStageID(newStage)
EndIf EndIf
EndFunction EndFunction
Function _UpdateInventoryFilters()
RemoveAllInventoryEventFilters()
AddInventoryEventFilter(_00E_EmptyFormlist)
Int potionNames = RenamedPotions
Form k = JFormMap.nextKey(potionNames, previousKey = None, endKey = None)
while k != None
AddInventoryEventFilter(k)
k = JFormMap.nextKey(potionNames, k, endKey = None)
endwhile
EndFunction
Function _RestorePotionAttributes()
Debug.Notification("Restoring potion names")
Potion k
Int potionNames = RenamedPotions
k = JFormMap.nextKey(potionNames, previousKey = None, endKey = None) as Potion
while k != None
k.setName(JFormMap.getStr(potionNames, k))
k = JFormMap.nextKey(potionNames, k, endKey = None) as Potion
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
Function _InitAchemyControl() Function _InitAchemyControl()
;Debug.Notification("AchemyControl init")
GoToState("") GoToState("")
int iSKSEVer = SKSE.GetVersion() int iSKSEVer = SKSE.GetVersion()
if iSKSEVer < 2 if iSKSEVer < 2
RemoveAllInventoryEventFilters()
bHasJContainers = false bHasJContainers = false
;Debug.Notification("SKSE is not loaded")
Debug.Trace("SKSE is not loaded, _00E_Theriantrophist_AlchemyControl is disabled") Debug.Trace("SKSE is not loaded, _00E_Theriantrophist_AlchemyControl is disabled")
return return
endif endif
bHasJContainers = ( (SKSE.GetPluginVersion("JContainers64") != -1) || (SKSE.GetPluginVersion("JContainersVR") != -1) ) bHasJContainers = ( (SKSE.GetPluginVersion("JContainers64") != -1) || (SKSE.GetPluginVersion("JContainersVR") != -1) ) && JContainers.isInstalled()
if ! bHasJContainers && ! EnderalLib.IsDLLLoaded() if ! bHasJContainers && ! EnderalLib.IsDLLLoaded()
; Both required components are missing, do not update version and disable everything ; Both required components are missing, do not update version and disable everything
RemoveAllInventoryEventFilters()
UnregisterForAllMenus() UnregisterForAllMenus()
Debug.Trace("JContainers and fs.dll are not loaded, _00E_Theriantrophist_AlchemyControl is disabled.") Debug.Trace("JContainers and fs.dll are not loaded, _00E_Theriantrophist_AlchemyControl is disabled.")
;Debug.Notification("JContainers and fs.dll are not loaded")
return return
endif endif
@ -431,64 +388,66 @@ Function _InitAchemyControl()
Int oldScriptVersion = curScriptVersion Int oldScriptVersion = curScriptVersion
curScriptVersion = LATEST_SCRIPT_VERSION curScriptVersion = LATEST_SCRIPT_VERSION
If oldScriptVersion < 4 If oldScriptVersion < 5
;Debug.Notification("Updating AlchemyControl") RemoveAllInventoryEventFilters()
UnregisterForAllMenus()
UnregisterForUpdate() UnregisterForUpdate()
EndIf EndIf
EndIf EndIf
; Re-initialize everything to stay resilient to co-save deletion or corruption if ! bHasJContainers
if bHasJContainers
RegisterForMenu("ContainerMenu")
RegisterForMenu("InventoryMenu")
RegisterForMenu("FavoritesMenu")
;Debug.Trace("JContainers is loaded, hooking to menus")
else
RemoveAllInventoryEventFilters()
UnregisterForAllMenus()
Debug.Notification("JContainers is not loaded")
Debug.Trace("JContainers is not loaded, renaming and changing potion models is disabled") Debug.Trace("JContainers is not loaded, renaming and changing potion models is disabled")
endif endif
; Re-register menu listener to stay resilient to co-save deletion or corruption
RegisterForMenu("Crafting Menu") RegisterForMenu("Crafting Menu")
EndFunction 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 ; EVENTS
;===================================================================================== ;=====================================================================================
Event OnMenuOpen(String MenuName) Event OnMenuOpen(String MenuName)
GoToState("InCrafting")
If menuName == "Crafting Menu"
GoToState("InCrafting")
return
endif
if bHasJContainers
Debug.Notification("InInventory")
GoToState("InInventory")
endif
EndEvent EndEvent
Event OnMenuClose(String MenuName) Event OnMenuClose(String MenuName)
GoToState("") GoToState("")
EndEvent EndEvent
State InCrafting State InCrafting
Event OnBeginState()
;Debug.Notification("RemoveAllInventoryEventFilters")
RemoveAllInventoryEventFilters()
EndEvent
Event OnItemAdded(Form baseItem, int count, ObjectReference itemRef, ObjectReference source) Event OnItemAdded(Form baseItem, int count, ObjectReference itemRef, ObjectReference source)
Debug.Notification("Added " + baseItem.GetName())
Potion item = baseItem as Potion Potion item = baseItem as Potion
If item If item
; Ignore not-custom potions (with FormID not starting with 0xFF) or already registered potions ; Ignore not-custom potions (with FormID not starting with 0xFF) or already registered potions
@ -496,35 +455,6 @@ State InCrafting
_UpdatePotion(item, count) _UpdatePotion(item, count)
EndIf EndIf
EndIf EndIf
EndEvent
Event OnEndState()
if bHasJContainers && UI.IsMenuOpen("Crafting Menu") == false
Debug.Notification("_UpdateInventoryFilters")
_UpdateInventoryFilters()
endif
EndEvent
EndState
State InInventory
Event OnItemRemoved(Form baseItem, int count, ObjectReference itemRef, ObjectReference dest)
if dest != None
return
endif
Debug.Notification("Removed " + baseItem.GetName())
; Probably a potion is consumed
Potion item = baseItem as Potion
if item
; we want to prevent that all potions that have been brewed are collected in this list
; and cause performance issues. So we risk that we loose track of them by removing them
; from this list. In this case, the name will be the old vanilla skyrim one
if (PlayerREF.getItemCount(item) == 0)
JFormMap.removeKey(RenamedPotions, item)
JFormMap.removeKey(ModelChangedPotions, item)
RemoveInventoryEventFilter(baseItem)
Endif
Endif
EndEvent EndEvent
EndState EndState
@ -535,9 +465,7 @@ EndEvent
Event OnPlayerLoadGame() Event OnPlayerLoadGame()
_InitAchemyControl() _InitAchemyControl()
if bHasJContainers if bHasJContainers
_RestorePotionAttributes() _OnGameLoadJContainers()
_UpdateInventoryFilters()
endif endif
EndEvent EndEvent

Loading…
Cancel
Save