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
import EnderalLib
;=====================================================================================
; PROPERTIES
;=====================================================================================
@ -361,131 +359,126 @@ Function _SetNewStageNQ11(Int newStage)
EndIf
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
;=====================================================================================
Event OnItemAdded(Form baseItem, int count, ObjectReference itemRef, ObjectReference source)
Event OnMenuOpen(String MenuName)
Potion item = baseItem as Potion
If item
Bool bIsInCraftingMode = UI.IsMenuOpen("Crafting Menu")
If menuName == "Crafting Menu"
RemoveAllInventoryEventFilters()
GoToState("InCrafting")
return
endif
; Ignore not-custom potions (with FormID not starting with 0xFF) or already registered potions
If (Math.LogicalAnd(item.GetFormID(), 0xFF000000) == 0xFF000000) && JFormMap.hasKey(RenamedPotions, item) == False
_UpdatePotion(item, count, bIsInCraftingMode)
EndIf
EndIf
GoToState("InInventory")
EndEvent
Event OnItemRemoved(Form baseItem, int count, ObjectReference itemRef, ObjectReference dest)
; 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
Event OnMenuClose(String MenuName)
GoToState("")
Int curScriptVersion = 0
Int Property LATEST_SCRIPT_VERSION = 3 AutoReadOnly
If menuName == "Crafting Menu"
_UpdateInventoryFilters()
endif
Event OnInit()
curScriptVersion = LATEST_SCRIPT_VERSION
EndEvent
Function _UpdateToVersion3()
Potion p
Int i
Int potionArrayID = JFormMap.allKeys(RenamedPotions)
State InCrafting
Event OnItemAdded(Form baseItem, int count, ObjectReference itemRef, ObjectReference source)
JFormMap.clear(RenamedPotions)
JFormMap.clear(ModelChangedPotions)
; Update already cached potions
Int nPotions = JArray.count(potionArrayID)
i = 0
While i < nPotions
p = JArray.getForm(potionArrayID, i, None) as Potion
If p && Math.LogicalAnd(p.GetFormID(), 0xFF000000) == 0xFF000000
_UpdatePotion(p, 1, False)
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) && JFormMap.hasKey(RenamedPotions, item) == False
_UpdatePotion(item, count, true)
EndIf
EndIf
i += 1
EndWhile
; Update potions in the player's inventory
Int nItems = PlayerREF.GetNumItems()
i = 0
While i < nItems
p = PlayerREF.GetNthForm(i) as Potion
If p && Math.LogicalAnd(p.GetFormID(), 0xFF000000) == 0xFF000000 && JFormMap.hasKey(RenamedPotions, p) == False
_UpdatePotion(p, 1, False)
EndIf
i += 1
EndWhile
EndEvent
EndState
State InInventory
Event OnItemRemoved(Form baseItem, int count, ObjectReference itemRef, ObjectReference dest)
if dest != None
return
endif
; 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)
Endif
Endif
EndEvent
EndState
Debug.Trace("_00E_Theriantrophist_AlchemyControl: _UpdateToVersion3 done")
EndFunction
Int curScriptVersion = 0
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()
Bool bRestoreNamesModels = True
GoToState("")
; Version update
If curScriptVersion < LATEST_SCRIPT_VERSION
Int oldScriptVersion = curScriptVersion
curScriptVersion = LATEST_SCRIPT_VERSION
If oldScriptVersion < 3
_UpdateToVersion3()
bRestoreNamesModels = False
If oldScriptVersion < 4
UnregisterForUpdate()
RegisterForMenu("ContainerMenu")
RegisterForMenu("InventoryMenu")
RegisterForMenu("FavoritesMenu")
RegisterForMenu("Crafting Menu")
_UpdateInventoryFilters()
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
If bRestoreNamesModels
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
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)
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
EndEvent

Loading…
Cancel
Save