Optimized _00E_Theriantrophist_AlchemyControl, removed obsolete code
This commit is contained in:
parent
b5ef32f9a3
commit
4ab9c06e57
Binary file not shown.
@ -1,7 +1,5 @@
|
||||
Scriptname _00E_Theriantrophist_AlchemyControl extends ReferenceAlias
|
||||
|
||||
import EnderalLib
|
||||
|
||||
;=====================================================================================
|
||||
; PROPERTIES
|
||||
;=====================================================================================
|
||||
@ -361,28 +359,72 @@ 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)
|
||||
Event OnMenuClose(String MenuName)
|
||||
|
||||
GoToState("")
|
||||
|
||||
If menuName == "Crafting Menu"
|
||||
_UpdateInventoryFilters()
|
||||
endif
|
||||
|
||||
EndEvent
|
||||
|
||||
State InCrafting
|
||||
Event OnItemAdded(Form baseItem, int count, ObjectReference itemRef, ObjectReference source)
|
||||
|
||||
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
|
||||
|
||||
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 && dest == None
|
||||
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
|
||||
@ -391,72 +433,39 @@ Event OnItemRemoved(Form baseItem, int count, ObjectReference itemRef, ObjectRef
|
||||
JFormMap.removeKey(ModelChangedPotions, item)
|
||||
Endif
|
||||
Endif
|
||||
EndEvent
|
||||
|
||||
EndEvent
|
||||
EndState
|
||||
|
||||
Int curScriptVersion = 0
|
||||
Int Property LATEST_SCRIPT_VERSION = 3 AutoReadOnly
|
||||
Int Property LATEST_SCRIPT_VERSION = 4 AutoReadOnly
|
||||
|
||||
Event OnInit()
|
||||
curScriptVersion = LATEST_SCRIPT_VERSION
|
||||
RegisterForMenu("ContainerMenu")
|
||||
RegisterForMenu("InventoryMenu")
|
||||
RegisterForMenu("FavoritesMenu")
|
||||
RegisterForMenu("Crafting Menu")
|
||||
EndEvent
|
||||
|
||||
Function _UpdateToVersion3()
|
||||
Potion p
|
||||
Int i
|
||||
|
||||
Int potionArrayID = JFormMap.allKeys(RenamedPotions)
|
||||
|
||||
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)
|
||||
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
|
||||
|
||||
Debug.Trace("_00E_Theriantrophist_AlchemyControl: _UpdateToVersion3 done")
|
||||
EndFunction
|
||||
|
||||
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
|
||||
@ -472,20 +481,4 @@ Event OnPlayerLoadGame()
|
||||
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)
|
||||
EndEvent
|
||||
|
Loading…
Reference in New Issue
Block a user