Enderal SE https://mod.pub/enderal-se/38-enderal-se
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
110 lines
4.4 KiB
110 lines
4.4 KiB
3 years ago
|
Scriptname _00E_Phasmalist_ApparationInventory extends ReferenceAlias
|
||
|
{total strength = (speed * base damage) or (base armor rating) or 0 + enchantement strength * magicEffectStrengthWeight +
|
||
|
magicEffectStrengthWeight * spellbook spellstrength}
|
||
|
; script that manages the spectralizing process. It is attached to the alias that contains the spectralizing container.
|
||
|
; this alias is filled and the functions of this script are called mainly from _00E_Phasmalist_Workbench.
|
||
|
|
||
3 years ago
|
import EnderalLib
|
||
|
|
||
3 years ago
|
Message Property spectralizingCost auto
|
||
|
Message Property cannotSpectralize auto
|
||
|
Message Property updateCostCannotPay auto
|
||
|
Message Property updateCostCanPay auto
|
||
|
|
||
|
float Property strengthPointsPerSoulGem = 20.0 autoreadonly
|
||
|
float Property strengthPointsPerBonemealOrEctoplasma = 8.0 autoreadonly
|
||
|
|
||
|
Formlist Property soulGemTypesOrderedByStrength auto
|
||
|
Formlist Property bonemealEctoplasmaTypesOrderedByStrength auto
|
||
|
|
||
3 years ago
|
Actor Property PlayerREF Auto
|
||
|
|
||
|
Function RemoveItemsUntilLimitReached(Actor that, Formlist itemList, int amount)
|
||
|
Int index = 0
|
||
|
Int maxSize = itemList.GetSize()
|
||
|
Int amountLeft = amount
|
||
|
While index < maxSize && amountLeft > 0
|
||
|
Form item = itemList.GetAt(index)
|
||
|
Int amountThatHad = that.GetItemCount(item)
|
||
|
If amountThatHad >= amountLeft
|
||
|
that.RemoveItem(item, amountLeft)
|
||
3 years ago
|
Else
|
||
3 years ago
|
that.RemoveItem(item, amountThatHad)
|
||
3 years ago
|
EndIf
|
||
3 years ago
|
amountLeft -= amountThatHad
|
||
3 years ago
|
index = index + 1
|
||
|
EndWhile
|
||
3 years ago
|
EndFunction
|
||
3 years ago
|
|
||
3 years ago
|
Bool Function EvaluateAndClose(ObjectReference apparationContainer)
|
||
3 years ago
|
{calculates the strength of all the items in the container and asks the player wether to spectralize them or not. Appropriatly, the spectralizing cost are removed from the player and the items are
|
||
3 years ago
|
returned to him or added to the apparition. The return value is true when any item was added to the apparition}
|
||
|
;returns if an item has been added to the apparition
|
||
|
ObjectReference selfRef = self.getRef()
|
||
|
If selfRef.GetNumItems() == 0
|
||
3 years ago
|
return false
|
||
|
EndIf
|
||
3 years ago
|
Float strength = CalculateInventoryStrength()
|
||
3 years ago
|
int soulGemAmount = Math.floor(strength / strengthPointsPerSoulGem)
|
||
|
If soulGemAmount <= 0
|
||
|
soulGemAmount = 1
|
||
|
EndIf
|
||
|
int bonemealAmount = Math.ceiling(strength / strengthPointsPerBonemealOrEctoplasma)
|
||
3 years ago
|
int soulGemAmountPlayerHas = PlayerREF.GetItemCount(soulGemTypesOrderedByStrength)
|
||
|
int bonemealAmountPlayerHas = PlayerREF.GetItemCount(bonemealEctoplasmaTypesOrderedByStrength)
|
||
3 years ago
|
bool didAddItems = false
|
||
|
|
||
3 years ago
|
If (soulGemAmountPlayerHas >= soulGemAmount && bonemealAmountPlayerHas >= bonemealAmount && selfRef.GetNumItems() > 0)
|
||
3 years ago
|
int button = spectralizingCost.show(bonemealAmount, bonemealAmountPlayerHas, soulGemAmount, soulGemAmountPlayerHas)
|
||
|
If (button == 0)
|
||
|
didAddItems = true
|
||
3 years ago
|
selfRef.removeallitems(apparationContainer, false, true)
|
||
|
RemoveItemsUntilLimitReached(PlayerREF, soulGemTypesOrderedByStrength, soulGemAmount)
|
||
|
RemoveItemsUntilLimitReached(PlayerREF, bonemealEctoplasmaTypesOrderedByStrength, bonemealAmount)
|
||
3 years ago
|
Else
|
||
3 years ago
|
AddItemsToPlayer()
|
||
3 years ago
|
EndIf
|
||
|
Else
|
||
3 years ago
|
cannotSpectralize.Show(bonemealAmount, bonemealAmountPlayerHas, soulGemAmount, soulGemAmountPlayerHas)
|
||
|
AddItemsToPlayer()
|
||
3 years ago
|
EndIf
|
||
3 years ago
|
Return didAddItems
|
||
|
EndFunction
|
||
3 years ago
|
|
||
3 years ago
|
Function AddItemsToPlayer()
|
||
|
self.getRef().removeallitems(akTransferTo = PlayerREF, abRemoveQuestItems = true)
|
||
3 years ago
|
EndFunction
|
||
|
|
||
3 years ago
|
Float Function CalculateInventoryStrength()
|
||
|
Return EnderalLib.calculateContentStrength(Self.GetRef())
|
||
3 years ago
|
EndFunction
|
||
|
|
||
|
Function UpdateCost()
|
||
3 years ago
|
float strength = CalculateInventoryStrength()
|
||
3 years ago
|
int soulGemAmount = Math.floor(strength / strengthPointsPerSoulGem)
|
||
|
If soulGemAmount <= 0
|
||
|
soulGemAmount = 1
|
||
|
EndIf
|
||
|
int bonemealAmount = Math.ceiling(strength / strengthPointsPerBonemealOrEctoplasma)
|
||
3 years ago
|
int soulGemAmountPlayerHas = PlayerREF.GetItemCount(soulGemTypesOrderedByStrength)
|
||
|
int bonemealAmountPlayerHas = PlayerREF.GetItemCount(bonemealEctoplasmaTypesOrderedByStrength)
|
||
3 years ago
|
|
||
|
If (soulGemAmountPlayerHas >= soulGemAmount && bonemealAmountPlayerHas >= bonemealAmount)
|
||
|
updateCostCanPay.show(bonemealAmount, bonemealAmountPlayerHas, soulGemAmount, soulGemAmountPlayerHas)
|
||
|
Else
|
||
|
updateCostCannotPay.show(bonemealAmount, bonemealAmountPlayerHas, soulGemAmount, soulGemAmountPlayerHas)
|
||
|
EndIf
|
||
|
EndFunction
|
||
|
|
||
|
Event OnItemAdded(Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akSourceContainer)
|
||
|
UpdateCost()
|
||
3 years ago
|
EndEvent
|
||
3 years ago
|
|
||
|
Event OnItemRemoved(Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akDestContainer)
|
||
3 years ago
|
If (self.getRef() == None) || (self.getRef().getNumItems() == 0)
|
||
3 years ago
|
return
|
||
|
EndIf
|
||
|
|
||
|
UpdateCost()
|
||
3 years ago
|
EndEvent
|