4
Fork 0

Optimized _00E_Theriantrophist_AlchemyControl, removed obsolete code

english-generic-dialogue
Eddoursul 2 years ago
parent b5ef32f9a3
commit 4ab9c06e57
  1. BIN
      scripts/_00e_theriantrophist_alchemycontrol.pex
  2. 191
      source/scripts/_00e_theriantrophist_alchemycontrol.psc

@ -1,7 +1,5 @@
Scriptname _00E_Theriantrophist_AlchemyControl extends ReferenceAlias Scriptname _00E_Theriantrophist_AlchemyControl extends ReferenceAlias
import EnderalLib
;===================================================================================== ;=====================================================================================
; PROPERTIES ; PROPERTIES
;===================================================================================== ;=====================================================================================
@ -361,131 +359,126 @@ Function _SetNewStageNQ11(Int newStage)
EndIf EndIf
EndFunction EndFunction
Function _UpdateInventoryFilters()
Form[] aPotions = JFormMap.allKeysPArray(RenamedPotions)
int i = aPotions.length
while i > 0
i -= 1
AddInventoryEventFilter(aPotions[i])
endwhile
aPotions = JFormMap.allKeysPArray(ModelChangedPotions)
i = aPotions.length
while i > 0
i -= 1
AddInventoryEventFilter(aPotions[i])
endwhile
EndFunction
;===================================================================================== ;=====================================================================================
; EVENTS ; EVENTS
;===================================================================================== ;=====================================================================================
Event OnItemAdded(Form baseItem, int count, ObjectReference itemRef, ObjectReference source) Event OnMenuOpen(String MenuName)
Potion item = baseItem as Potion If menuName == "Crafting Menu"
If item RemoveAllInventoryEventFilters()
Bool bIsInCraftingMode = UI.IsMenuOpen("Crafting Menu") GoToState("InCrafting")
return
endif
; Ignore not-custom potions (with FormID not starting with 0xFF) or already registered potions GoToState("InInventory")
If (Math.LogicalAnd(item.GetFormID(), 0xFF000000) == 0xFF000000) && JFormMap.hasKey(RenamedPotions, item) == False
_UpdatePotion(item, count, bIsInCraftingMode)
EndIf
EndIf
EndEvent EndEvent
Event OnItemRemoved(Form baseItem, int count, ObjectReference itemRef, ObjectReference dest) Event OnMenuClose(String MenuName)
; Probably a potion is consumed
Potion item = baseItem as Potion
if item && dest == None
; 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)
Endif
Endif
EndEvent
GoToState("")
Int curScriptVersion = 0 If menuName == "Crafting Menu"
Int Property LATEST_SCRIPT_VERSION = 3 AutoReadOnly _UpdateInventoryFilters()
endif
Event OnInit()
curScriptVersion = LATEST_SCRIPT_VERSION
EndEvent EndEvent
Function _UpdateToVersion3() State InCrafting
Potion p Event OnItemAdded(Form baseItem, int count, ObjectReference itemRef, ObjectReference source)
Int i
Int potionArrayID = JFormMap.allKeys(RenamedPotions)
JFormMap.clear(RenamedPotions) Potion item = baseItem as Potion
JFormMap.clear(ModelChangedPotions) If item
; Ignore not-custom potions (with FormID not starting with 0xFF) or already registered potions
; Update already cached potions If (Math.LogicalAnd(item.GetFormID(), 0xFF000000) == 0xFF000000) && JFormMap.hasKey(RenamedPotions, item) == False
Int nPotions = JArray.count(potionArrayID) _UpdatePotion(item, count, true)
i = 0 EndIf
While i < nPotions
p = JArray.getForm(potionArrayID, i, None) as Potion
If p && Math.LogicalAnd(p.GetFormID(), 0xFF000000) == 0xFF000000
_UpdatePotion(p, 1, False)
EndIf EndIf
i += 1
EndWhile
; Update potions in the player's inventory EndEvent
Int nItems = PlayerREF.GetNumItems() EndState
i = 0
While i < nItems State InInventory
p = PlayerREF.GetNthForm(i) as Potion Event OnItemRemoved(Form baseItem, int count, ObjectReference itemRef, ObjectReference dest)
If p && Math.LogicalAnd(p.GetFormID(), 0xFF000000) == 0xFF000000 && JFormMap.hasKey(RenamedPotions, p) == False if dest != None
_UpdatePotion(p, 1, False) return
EndIf endif
i += 1 ; Probably a potion is consumed
EndWhile 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)
Endif
Endif
EndEvent
EndState
Debug.Trace("_00E_Theriantrophist_AlchemyControl: _UpdateToVersion3 done") Int curScriptVersion = 0
EndFunction Int Property LATEST_SCRIPT_VERSION = 4 AutoReadOnly
Event OnInit()
curScriptVersion = LATEST_SCRIPT_VERSION
RegisterForMenu("ContainerMenu")
RegisterForMenu("InventoryMenu")
RegisterForMenu("FavoritesMenu")
RegisterForMenu("Crafting Menu")
EndEvent
Event OnPlayerLoadGame() Event OnPlayerLoadGame()
Bool bRestoreNamesModels = True GoToState("")
; Version update ; Version update
If curScriptVersion < LATEST_SCRIPT_VERSION If curScriptVersion < LATEST_SCRIPT_VERSION
Int oldScriptVersion = curScriptVersion Int oldScriptVersion = curScriptVersion
curScriptVersion = LATEST_SCRIPT_VERSION curScriptVersion = LATEST_SCRIPT_VERSION
If oldScriptVersion < 3 If oldScriptVersion < 4
_UpdateToVersion3() UnregisterForUpdate()
bRestoreNamesModels = False RegisterForMenu("ContainerMenu")
RegisterForMenu("InventoryMenu")
RegisterForMenu("FavoritesMenu")
RegisterForMenu("Crafting Menu")
_UpdateInventoryFilters()
EndIf EndIf
EndIf EndIf
; Fix 1.5.3.0 _IsSelfBrewnPotion stuck in permanent Wait loop.
; It may take a looong time
If criticalSectionProcesses > 0
RegisterForSingleUpdate(0.1)
EndIf
; Restore names and models ; Restore names and models
If bRestoreNamesModels Potion k
Potion k
Int potionNames = RenamedPotions
Int potionNames = RenamedPotions k = JFormMap.nextKey(potionNames, previousKey = None, endKey = None) as Potion
k = JFormMap.nextKey(potionNames, previousKey = None, endKey = None) as Potion while k != None
while k != None k.setName(JFormMap.getStr(potionNames, k))
k.setName(JFormMap.getStr(potionNames, k)) k = JFormMap.nextKey(potionNames, k, endKey = None) as Potion
k = JFormMap.nextKey(potionNames, k, endKey = None) as Potion endwhile
endwhile
Int potionModels = ModelChangedPotions
Int potionModels = ModelChangedPotions k = JFormMap.nextKey(potionModels, previousKey = None, endKey = None) as Potion
k = JFormMap.nextKey(potionModels, previousKey = None, endKey = None) as Potion while k != None
while k != None k.SetWorldModelPath(JFormMap.getStr(potionModels, k))
k.SetWorldModelPath(JFormMap.getStr(potionModels, k)) k = JFormMap.nextKey(potionModels, k, endKey = None) as Potion
k = JFormMap.nextKey(potionModels, k, endKey = None) as Potion endwhile
endwhile
EndIf
EndEvent
Event OnUpdate()
; Fix 1.5.3.0 _IsSelfBrewnPotion stuck in permanent Wait loop.
If criticalSectionProcesses <= 0
Utility.WaitMenuMode(0.1) ; Wait a bit more, just in case
If criticalSectionProcesses <= 0
;Debug.Notification("Unfucked _IsSelfBrewnPotion")
Return
EndIf
EndIf
PotionsMixedOnLastTest = Game.QueryStat("Potions Mixed") + Game.QueryStat("Poisons Mixed")
criticalSectionProcesses = 0
RegisterForSingleUpdate(0.1)
EndEvent EndEvent

Loading…
Cancel
Save