enderalse/source/scripts/_00e_phasmalist_apparationinventory.psc

108 lines
4.4 KiB
Plaintext
Raw Normal View History

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.
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
2021-10-05 22:59:59 +00:00
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)
Else
2021-10-05 22:59:59 +00:00
that.RemoveItem(item, amountThatHad)
EndIf
2021-10-05 22:59:59 +00:00
amountLeft -= amountThatHad
index = index + 1
EndWhile
2021-10-05 22:59:59 +00:00
EndFunction
2021-10-05 22:59:59 +00:00
Bool Function EvaluateAndClose(ObjectReference apparationContainer)
{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
2021-10-05 22:59:59 +00:00
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
return false
EndIf
2021-10-05 22:59:59 +00:00
Float strength = CalculateInventoryStrength()
int soulGemAmount = Math.floor(strength / strengthPointsPerSoulGem)
If soulGemAmount <= 0
soulGemAmount = 1
EndIf
int bonemealAmount = Math.ceiling(strength / strengthPointsPerBonemealOrEctoplasma)
2021-10-05 22:59:59 +00:00
int soulGemAmountPlayerHas = PlayerREF.GetItemCount(soulGemTypesOrderedByStrength)
int bonemealAmountPlayerHas = PlayerREF.GetItemCount(bonemealEctoplasmaTypesOrderedByStrength)
bool didAddItems = false
2021-10-05 22:59:59 +00:00
If (soulGemAmountPlayerHas >= soulGemAmount && bonemealAmountPlayerHas >= bonemealAmount && selfRef.GetNumItems() > 0)
int button = spectralizingCost.show(bonemealAmount, bonemealAmountPlayerHas, soulGemAmount, soulGemAmountPlayerHas)
If (button == 0)
didAddItems = true
2021-10-05 22:59:59 +00:00
selfRef.removeallitems(apparationContainer, false, true)
RemoveItemsUntilLimitReached(PlayerREF, soulGemTypesOrderedByStrength, soulGemAmount)
RemoveItemsUntilLimitReached(PlayerREF, bonemealEctoplasmaTypesOrderedByStrength, bonemealAmount)
Else
2021-10-05 22:59:59 +00:00
AddItemsToPlayer()
EndIf
Else
2021-10-05 22:59:59 +00:00
cannotSpectralize.Show(bonemealAmount, bonemealAmountPlayerHas, soulGemAmount, soulGemAmountPlayerHas)
AddItemsToPlayer()
EndIf
2021-10-05 22:59:59 +00:00
Return didAddItems
EndFunction
2021-10-05 22:59:59 +00:00
Function AddItemsToPlayer()
self.getRef().removeallitems(akTransferTo = PlayerREF, abRemoveQuestItems = true)
EndFunction
2021-10-05 22:59:59 +00:00
Float Function CalculateInventoryStrength()
Return EnderalFunctions.CalculateContentStrength(Self.GetRef())
EndFunction
Function UpdateCost()
2021-10-05 22:59:59 +00:00
float strength = CalculateInventoryStrength()
int soulGemAmount = Math.floor(strength / strengthPointsPerSoulGem)
If soulGemAmount <= 0
soulGemAmount = 1
EndIf
int bonemealAmount = Math.ceiling(strength / strengthPointsPerBonemealOrEctoplasma)
2021-10-05 22:59:59 +00:00
int soulGemAmountPlayerHas = PlayerREF.GetItemCount(soulGemTypesOrderedByStrength)
int bonemealAmountPlayerHas = PlayerREF.GetItemCount(bonemealEctoplasmaTypesOrderedByStrength)
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()
2021-10-05 22:59:59 +00:00
EndEvent
Event OnItemRemoved(Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akDestContainer)
2021-10-05 22:59:59 +00:00
If (self.getRef() == None) || (self.getRef().getNumItems() == 0)
return
EndIf
UpdateCost()
2021-10-05 22:59:59 +00:00
EndEvent