1
Fork 0
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

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
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)
Else
3 years ago
that.RemoveItem(item, amountThatHad)
EndIf
3 years ago
amountLeft -= amountThatHad
index = index + 1
EndWhile
3 years ago
EndFunction
3 years ago
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
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
return false
EndIf
3 years ago
Float strength = CalculateInventoryStrength()
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)
bool didAddItems = false
3 years ago
If (soulGemAmountPlayerHas >= soulGemAmount && bonemealAmountPlayerHas >= bonemealAmount && selfRef.GetNumItems() > 0)
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)
Else
3 years ago
AddItemsToPlayer()
EndIf
Else
3 years ago
cannotSpectralize.Show(bonemealAmount, bonemealAmountPlayerHas, soulGemAmount, soulGemAmountPlayerHas)
AddItemsToPlayer()
EndIf
3 years ago
Return didAddItems
EndFunction
3 years ago
Function AddItemsToPlayer()
self.getRef().removeallitems(akTransferTo = PlayerREF, abRemoveQuestItems = true)
EndFunction
3 years ago
Float Function CalculateInventoryStrength()
Return EnderalLib.calculateContentStrength(Self.GetRef())
EndFunction
Function UpdateCost()
3 years ago
float strength = CalculateInventoryStrength()
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)
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
Event OnItemRemoved(Form akBaseItem, int aiItemCount, ObjectReference akItemReference, ObjectReference akDestContainer)
3 years ago
If (self.getRef() == None) || (self.getRef().getNumItems() == 0)
return
EndIf
UpdateCost()
3 years ago
EndEvent